Error handler patch

James Bursa bursa at users.sourceforge.net
Fri Apr 16 13:36:15 PDT 2004


Hi,

This patch makes some improvements to the handler for RISC OS errors.

1. Print the error message for non-serious errors, as long as there is no 
signal handler for SIGOSERROR (currently the only output is "Termination 
signal received: RISC OS error").
2. Print the pc that RISC OS stored with the error.
3. Dump floating point registers for FP errors.

However, I'm not sure that this is correct for pthreads, because I notice that 
the error buffer is copied for some reason in __h_error_entry.

James



Index: _signal.s
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/signal/_signal.s,v
retrieving revision 1.17
diff -d -u -3 -r1.17 _signal.s
--- _signal.s	24 Mar 2004 22:30:35 -0000	1.17
+++ _signal.s	16 Apr 2004 20:23:12 -0000
@@ -388,10 +388,10 @@
 	; Bit 31-was set, therefore it was a hardware error.
 
 	; Print the error
-        STMFD   sp!, {a1-a4}
-        ADD     a1, a2, #4
-        BL      __write_unrecoverable
-        LDMFD   sp!, {a1-a4}
+        ;STMFD   sp!, {a1-a4}
+        ;ADD     a1, a2, #4
+        ;BL      __write_unrecoverable
+        ;LDMFD   sp!, {a1-a4}
 
 	; Test the type of hardware error.  We currently aren't doing
 	; much other than saying it was a Floating Point Exception
@@ -402,8 +402,25 @@
 	MOV	a3, a3, LSR #8
 	AND	a3, a3, #&FF
 	CMP	a3, #&02
-	MOVEQ	a2, #SIGFPE	;  A floating point exception
 	MOVNE	a2, #SIGEMT	;  A RISC OS exception.
+	BNE	|non_fp_exception|
+
+	; Store FP registers.
+	LDR	a1, =|__ul_fp_registers|
+	STFD	f0, [a1], #8
+	STFD	f1, [a1], #8
+	STFD	f2, [a1], #8
+	STFD	f3, [a1], #8
+	STFD	f4, [a1], #8
+	STFD	f5, [a1], #8
+	STFD	f6, [a1], #8
+	STFD	f7, [a1], #8
+	RFS	a2		; Read FP status register
+	STR	a2, [a1]
+
+	MOV	a2, #SIGFPE	;  A floating point exception
+
+non_fp_exception
 	MOV	a1, #0
 
 ;	LDR	a3, =|__ul_errbuf|
@@ -883,4 +900,8 @@
 	%	252	; Error string, zero terminated
 |__ul_errbuf__size|	EQU	{PC} - |__ul_errbuf_errblock|
 
+	EXPORT |__ul_fp_registers|
+|__ul_fp_registers|
+	%	8 * 8 + 4	; 8 double-precision registers and FPSR
+
 	END
Index: post.c
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/signal/post.c,v
retrieving revision 1.10
diff -d -u -3 -r1.10 post.c
--- post.c	23 Feb 2004 16:07:29 -0000	1.10
+++ post.c	16 Apr 2004 20:23:12 -0000
@@ -31,6 +31,9 @@
 
 /* #define DEBUG 1 */
 
+extern struct { int pc; int errnum; char errmess[252]; } __ul_errbuf;
+extern struct { double f[8]; int fpsr; } __ul_fp_registers;
+
 /* This function chooses a suitable execution environment
    for the signal handler and calls the appropriate function
    to perform the job.
@@ -411,6 +414,23 @@
 #ifdef DEBUG
 	__os_print ("post_signal: term/core\r\n");
 #endif
+
+	if (signo == SIGOSERROR || signo == SIGFPE || signo == SIGEMT)
+	  {
+	    fprintf(stderr, "\nError 0x%x: %s\n pc: %8x\n", __ul_errbuf.errnum,
+			    __ul_errbuf.errmess, __ul_errbuf.pc);
+	  }
+	if (signo == SIGFPE)
+	  {
+	    fprintf(stderr, " f0: %f  f1: %f  f2: %f  f3: %f\n"
+			    " f4: %f  f5: %f  f6: %f  f7: %f  fpsr: %x\n",
+			    __ul_fp_registers.f[0], __ul_fp_registers.f[1],
+			    __ul_fp_registers.f[2], __ul_fp_registers.f[3],
+			    __ul_fp_registers.f[4], __ul_fp_registers.f[5],
+			    __ul_fp_registers.f[5], __ul_fp_registers.f[7],
+			    __ul_fp_registers.fpsr);
+	  }
+
 	if (act == term)
 	  {
 	    write_termination (signo);




More information about the gcc mailing list