pthreads, part 3

Alex Waugh alex at alexwaugh.com
Thu Dec 26 10:28:17 PST 2002


Some miscellaneous pthreads changes:

Changed errno back to a global variable, as some programs had problems
with the macro
Fix problem with programs like links that have their own sched.h
Add support for restoring the CPSR on a 32bit OS
Various APCS32 fixes


Index: unixlib/source/errno.c
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/errno.c,v
retrieving revision 1.3
diff -u -r1.3 errno.c
--- unixlib/source/errno.c	15 Dec 2002 13:16:55 -0000	1.3
+++ unixlib/source/errno.c	26 Dec 2002 17:40:35 -0000
@@ -14,7 +14,5 @@
 
 #include <errno.h>
 
-#if !__FEATURE_PTHREADS
 int errno = 0;
-#endif
 
Index: unixlib/source/clib/errno.h
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/clib/errno.h,v
retrieving revision 1.6
diff -u -r1.6 errno.h
--- unixlib/source/clib/errno.h	15 Dec 2002 13:16:55 -0000	1.6
+++ unixlib/source/clib/errno.h	26 Dec 2002 17:40:39 -0000
@@ -21,16 +21,7 @@
 
 #ifndef errno
 
-#if __FEATURE_PTHREADS
-
-#define __need_pthread_t
-#include <pthread.h>
-
-#define errno (__pthread_running_thread->thread_errno)
-
-#else
 extern int errno;
-#endif /* __FEATURE_PTHREADS */
 
 #define __errno errno
 
@@ -144,11 +135,7 @@
    threads ever appear.  We also give a return value so we can use
    return __set_errno () which can allow function tail calling.  */
 #ifndef __set_errno
-#if __FEATURE_PTHREADS
-#define __set_errno(val) (__pthread_running_thread->thread_errno = (val), -1)
-#else
 #define __set_errno(val) (errno = (val), -1)
-#endif
 #endif
 #endif
 
Index: unixlib/source/clib/pthread.h
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/clib/pthread.h,v
retrieving revision 1.3
diff -u -r1.3 pthread.h
--- unixlib/source/clib/pthread.h	15 Dec 2002 13:16:55 -0000	1.3
+++ unixlib/source/clib/pthread.h	26 Dec 2002 17:40:40 -0000
@@ -22,7 +22,8 @@
 #define __need_clock_t
 #include <time.h>
 
-#include <sched.h> /* for struct sched_param */
+#include "sched.h" /* for struct sched_param */
+/* uses "" rather than <> to prevent problems with programs that have their own sched.h */
 
 #if !defined __pthread_t_defined && (defined __PTHREAD_H || defined __need_pthread_t)
 #define __pthread_t_defined
@@ -453,6 +454,7 @@
 struct __pthread_saved_context
 {
   int r[16]; /* User mode integer registers */
+  int spsr;
   char fpregs[12*8]; /* Floating point registers */
   int fpstatus; /* Floatingpoint status register */
 };
Index: unixlib/source/pthread/_context.s
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/pthread/_context.s,v
retrieving revision 1.1
diff -u -r1.1 _context.s
--- unixlib/source/pthread/_context.s	15 Dec 2002 13:16:55 -0000	1.1
+++ unixlib/source/pthread/_context.s	26 Dec 2002 17:41:17 -0000
@@ -145,9 +145,8 @@
 	TEQP	pc, #USR_Mode	; Switch to user mode, IRQs on
 	|
 	MRS	a1, CPSR
-	BIC	a1, a1, #&9F
-	ORR	a1, a1, #&10 ;USR Mode
-	MSR	CPSR, a1
+	BIC	a1, a1, #&8F	; Switch to user mode, IRQs on
+	MSR	CPSR_c, a1
 	]
 	MOV	a1, a1
 
@@ -162,6 +161,13 @@
 	STMIA	a1!, {a3, a4, v1, v2, v3, v4, v5, v6}
 	LDMIA	a2!, {a3, a4, v1, v2, v3, v4, v5, v6}
 	STMIA	a1!, {a3, a4, v1, v2, v3, v4, v5, v6}
+	[ {CONFIG} = 32
+	; Copy SPSR
+	LDR	a3, [a2]
+	STR	a3, [a1], #4
+	|
+	ADD	a1, a1, #4
+	]
 
 ; Save floating point regs
 	LDR	a4, =|__fpflag|
@@ -178,7 +184,8 @@
 	STFE	f6, [a1], #12
 	STFE	f7, [a1], #12
 	|
-	SFM	f0, 8, [a1], #96
+	SFM	f0, 4, [a1], #48
+	SFM	f4, 4, [a1], #48
 	]
 	RFS	a2	; Read floating status
 	STR	a2, [a1], #12
@@ -202,7 +209,7 @@
 	LDR	a4, [a4]
 	CMP	a4, #0
 	BEQ	no_fp2
-	ADD	a2, a2, #16*4
+	ADD	a2, a2, #17*4
 	[ {CONFIG} = 26
 	LDFE	f0, [a2], #12
 	LDFE	f1, [a2], #12
@@ -213,7 +220,8 @@
 	LDFE	f6, [a2], #12
 	LDFE	f7, [a2], #12
 	|
-	LFM	f0, 8, [a2], #96
+	LFM	f0, 4, [a2], #48
+	LFM	f4, 4, [a2], #48
 	]
 	LDR	a1, [a2], #12
 	WFS	a1	; Write floating status
@@ -235,9 +243,9 @@
 	TEQP	pc, #IFlag+SVC_Mode	; Force SVC mode, IRQs off
 	|
 	MRS	a2, CPSR
-	BIC	a2, a2, #&9F
-	ORR	a2, a2, #&93 ;SVC Mode
-	MSR	CPSR, a2
+	BIC	a2, a2, #&0F
+	ORR	a2, a2, #&83 ;SVC Mode, IRQs off
+	MSR	CPSR_c, a2
 	]
 	MOV	a1, a1
 
@@ -246,11 +254,15 @@
 	STR	a3, [a2]
 
 	MOV	r14, a1
-	LDMIA	r14, {r0-r14}^	; Load USR mode regs
+	[ {CONFIG} = 32
+	LDR	a1, [r14, #16*4]	; Get user PSR
+	MSR	SPSR_cxsf, a1		; Put it into SPSR_SVC/IRQ (NOP on ARM2/3, shouldn't have any effect in 26bit mode)
+	]
+	LDMIA	r14, {r0-r14}^		; Load USR mode regs
 	MOV	a1, a1
 
 	LDR	r14, [r14, #15*4]	; Load the old PC value
-	MOVS	pc, lr			; Return
+	MOVS	pc, lr			; Return (Valid for 26 and 32bit modes)
 
 |skip_contextswitch|
 	LDR	a3, =|__pthread_callback_missed|	; Indicate that this context switch did not occur
@@ -267,7 +279,7 @@
 	LDR	a4, [a4]
 	CMP	a4, #0
 	return	EQ, pc, lr
-	ADD	a2, a1, #16*4
+	ADD	a2, a1, #17*4
 	[ {CONFIG} = 26
 	STFE	f0, [a2], #12
 	STFE	f1, [a2], #12
@@ -278,7 +290,8 @@
 	STFE	f6, [a2], #12
 	STFE	f7, [a2], #12
 	|
-	SFM	f0, 8, [a2], #96
+	SFM	f0, 4, [a2], #48
+	SFM	f4, 4, [a2], #48
 	]
 	RFS	a1	; Read floating status
 	STR	a1, [a2], #12
Index: unixlib/source/pthread/context.c
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/pthread/context.c,v
retrieving revision 1.1
diff -u -r1.1 context.c
--- unixlib/source/pthread/context.c	15 Dec 2002 13:16:55 -0000	1.1
+++ unixlib/source/pthread/context.c	26 Dec 2002 17:41:17 -0000
@@ -82,6 +82,7 @@
   __os_print ("\r\n");
 #endif
 
+  __pthread_running_thread->thread_errno = errno;
   next = __pthread_running_thread->next;
 
   /* Loop around the list looking for a thread that is running */
@@ -132,6 +133,8 @@
 
     }
   while (__pthread_running_thread->state < STATE_RUNNING);
+
+  errno = __pthread_running_thread->thread_errno;
 
   if (__pthread_running_thread->cancelpending && __pthread_running_thread->cancelstate == PTHREAD_CANCEL_ENABLE && __pthread_running_thread->canceltype == PTHREAD_CANCEL_ASYNCHRONOUS)
     {
Index: unixlib/source/sys/_alloca.s
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/sys/_alloca.s,v
retrieving revision 1.6
diff -u -r1.6 _alloca.s
--- unixlib/source/sys/_alloca.s	15 Dec 2002 13:16:55 -0000	1.6
+++ unixlib/source/sys/_alloca.s	26 Dec 2002 17:41:40 -0000
@@ -67,7 +67,7 @@
 	BIC	a3, a3, #&fc000003
 	ORR	a2, a2, a3
 	|
-	ADR	a3, |__alloca_free|
+	ADR	a2, |__alloca_free|
 	]
 	STR	a2, [fp, #-4]
 	ADD	a1, a1, #8
Index: unixlib/source/sys/_syslib.s
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/sys/_syslib.s,v
retrieving revision 1.8
diff -u -r1.8 _syslib.s
--- unixlib/source/sys/_syslib.s	15 Dec 2002 13:16:55 -0000	1.8
+++ unixlib/source/sys/_syslib.s	26 Dec 2002 17:41:44 -0000
@@ -671,7 +671,7 @@
 	[ {CONFIG} = 26
 	AND	a2, a2, #&fc000003
 	BIC	a3, a3, #&fc000003
-	ORR	a2, a2, a3
+	ORR	a3, a2, a3
 	]
 	STR	a3, [fp, #-4]	; Replace it with our chunk free procedure
 
@@ -740,7 +740,11 @@
 	CMP	a1, #0
 	BLNE	|__pthread_enable_ints|
 	]
+	[ {CONFIG} = 26
 	LDMEA	fp, {a1, a2, a3, a4, v1, v2, fp, sp, pc}^
+	|
+	LDMEA	fp, {a1, a2, a3, a4, v1, v2, fp, sp, pc}
+	]
 __check_stack_l4
 	BL	__check_chunk
 	LDR	a1, [a1, #CHUNK_PREV]
@@ -781,14 +785,18 @@
 	BCS	stack_corrupt
 
 	LDR	v1, [a1, #CHUNK_DEALLOC]
-	BIC	v1, v1, #&fc000003
+	TEQ	a1, a1
+	TEQ	pc, pc	; EQ if in a 32-bit mode, NE if 26-bit
+	BICNE	v1, v1, #&fc000003
 	CMP	v1, a4
 	BCC	stack_corrupt
 	CMP	v1, a3
 	BCS	stack_corrupt
 
 	LDR	v1, [a1, #CHUNK_RETURN]
-	BIC	v1, v1, #&fc000003
+	TEQ	a1, a1
+	TEQ	pc, pc	; EQ if in a 32-bit mode, NE if 26-bit
+	BICNE	v1, v1, #&fc000003
 	CMP	v1, a4
 	BCC	stack_corrupt
 	CMP	v1, a3
Index: unixlib/source/sys/errlist.c
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/sys/errlist.c,v
retrieving revision 1.5
diff -u -r1.5 errlist.c
--- unixlib/source/sys/errlist.c	15 Dec 2002 13:16:55 -0000	1.5
+++ unixlib/source/sys/errlist.c	26 Dec 2002 17:41:47 -0000
@@ -14,6 +14,7 @@
 
 #include <string.h>
 #include <errno.h>
+#include <pthread.h>
 
 int sys_nerr = __SYS_NERR + 1;
 

-- 
Alex Waugh                                           alex at alexwaugh.com

PHP, Roots, Subversion, WebJames and more from http://www.alexwaugh.com/



More information about the gcc mailing list