Browse Source

Fix Cortex m0 Raw32 scheduler.
Ensure 8 byte alignment of the stack for all ARM specific scheduler code.

inmarket 3 years ago
parent
commit
6a30927a91

+ 19 - 10
src/gos/gos_x_threads_cortexm01.h

@@ -27,8 +27,10 @@
27 27
 							"mov     r6, r10                                \n\t"
28 28
 							"mov     r7, r11                                \n\t"
29 29
 							"push    {r4, r5, r6, r7}						\n\t"
30
-							"str	sp, %[oldtcxt]							\n\t"
31
-							"ldr	sp, %[newtcxt]							\n\t"
30
+							"mov     r4, sp                                 \n\t"
31
+							"str     r4, %[oldtcxt]							\n\t"
32
+							"ldr     r4, %[newtcxt]							\n\t"
33
+							"mov     sp, r4                                 \n\t"
32 34
 							"pop     {r4, r5, r6, r7}                   	\n\t"
33 35
 							"mov     r8, r4                                 \n\t"
34 36
 							"mov     r9, r5                                 \n\t"
@@ -41,15 +43,17 @@
41 43
 	}
42 44
 
43 45
 	static __attribute__((pcs("aapcs"),naked)) void _gfxStartThread(thread *oldt, thread *newt) {
44
-		newt->cxt = (char *)newt + newt->size;
46
+		newt->cxt = (void *)(((unsigned)newt + newt->size) & ~7);
45 47
 		__asm__ volatile (	"push    {r4, r5, r6, r7, lr}                   \n\t"
46 48
 							"mov     r4, r8                                 \n\t"
47 49
 							"mov     r5, r9                                 \n\t"
48 50
 							"mov     r6, r10                                \n\t"
49 51
 							"mov     r7, r11                                \n\t"
50 52
 							"push    {r4, r5, r6, r7}						\n\t"
51
-							"str	sp, %[oldtcxt]							\n\t"
52
-							"ldr	sp, %[newtcxt]							\n\t"
53
+							"mov     r4, sp                                 \n\t"
54
+							"str     r4, %[oldtcxt]							\n\t"
55
+							"ldr     r4, %[newtcxt]							\n\t"
56
+							"mov     sp, r4                                 \n\t"
53 57
 							: [newtcxt] "=m" (newt->cxt)
54 58
 							: [oldtcxt] "m" (oldt->cxt)
55 59
 							: "memory");
@@ -72,10 +76,12 @@
72 76
 		mov     r6, r10
73 77
 		mov     r7, r11
74 78
 		push    {r4, r5, r6, r7}
75
-		str	sp, [r0,#__cpp(offsetof(thread,cxt))]		// oldt->cxt
79
+		mov		r4, sp
80
+		str		r4, [r0,#__cpp(offsetof(thread,cxt))]		// oldt->cxt
76 81
 		
77 82
 		// Load the new context
78
-		ldr	sp, [r1,#__cpp(offsetof(thread,cxt))]		// newt->cxt
83
+		ldr		r4, [r1,#__cpp(offsetof(thread,cxt))]		// newt->cxt
84
+		mov		sp, r4
79 85
 		pop     {r4, r5, r6, r7}
80 86
 		mov     r8, r4
81 87
 		mov     r9, r5
@@ -88,9 +94,10 @@
88 94
 		PRESERVE8
89 95
 
90 96
 		// Calculate where to generate the new context
91
-		//		newt->cxt = (char *)newt + newt->size;
97
+		//		newt->cxt = (void *)(((unsigned)newt + newt->size) & ~7);
92 98
 		ldr      r2,[r1,#__cpp(offsetof(thread,size))]
93 99
 		add      r2,r2,r1
100
+		and      r2, r2, #0xFFFFFFF8
94 101
 		str      r2,[r1,#__cpp(offsetof(thread,cxt))]
95 102
 		
96 103
 		// Save the old context
@@ -100,10 +107,12 @@
100 107
 		mov     r6, r10
101 108
 		mov     r7, r11
102 109
 		push    {r4, r5, r6, r7}
103
-		str		sp, [r0,#__cpp(offsetof(thread,cxt))]	// oldt->cxt
110
+		mov		r4, sp
111
+		str		r4, [r0,#__cpp(offsetof(thread,cxt))]	// oldt->cxt
104 112
 		
105 113
 		// Load the new (imcomplete) context
106
-		ldr		sp, [r1,#__cpp(offsetof(thread,cxt))]	// newt->cxt
114
+		ldr		r4, [r1,#__cpp(offsetof(thread,cxt))]	// newt->cxt
115
+		mov		sp, r4
107 116
 		
108 117
 		// Run the users function - we save some code because gfxThreadExit() never returns
109 118
 		//		gfxThreadExit(_gfxCurrentThread->fn(_gfxCurrentThread->param));

+ 3 - 2
src/gos/gos_x_threads_cortexm347.h

@@ -32,7 +32,7 @@
32 32
 	}
33 33
 
34 34
 	static __attribute__((pcs("aapcs"),naked)) void _gfxStartThread(thread *oldt, thread *newt) {
35
-		newt->cxt = (char *)newt + newt->size;
35
+		newt->cxt = (void *)(((unsigned)newt + newt->size) & ~7);
36 36
 		__asm__ volatile (	"push	{r4, r5, r6, r7, r8, r9, r10, r11, lr}	\n\t"
37 37
 							"str	sp, %[oldtcxt]							\n\t"
38 38
 							"ldr	sp, %[newtcxt]							\n\t"
@@ -64,9 +64,10 @@
64 64
 		PRESERVE8
65 65
 
66 66
 		// Calculate where to generate the new context
67
-		//		newt->cxt = (char *)newt + newt->size;
67
+		//		newt->cxt = (void *)(((unsigned)newt + newt->size) & ~7);
68 68
 		ldr      r2,[r1,#__cpp(offsetof(thread,size))]
69 69
 		add      r2,r2,r1
70
+		and      r2, r2, #0xFFFFFFF8
70 71
 		str      r2,[r1,#__cpp(offsetof(thread,cxt))]
71 72
 		
72 73
 		// Save the old context

+ 3 - 6
src/gos/gos_x_threads_cortexm47fp.h

@@ -12,10 +12,6 @@
12 12
  * The context is saved at the current stack location and a pointer is maintained in the thread structure.
13 13
  */
14 14
 
15
-#if !CORTEX_USE_FPU
16
-	#warning "GOS Threads: You have specified GFX_CPU=GFX_CPU_CORTX_M?_FP with hardware floating point support but CORTEX_USE_FPU is FALSE. Try using GFX_CPU_GFX_CPU_CORTEX_M? instead"
17
-#endif
18
-
19 15
 #if GFX_COMPILER == GFX_COMPILER_GCC || GFX_COMPILER == GFX_COMPILER_CYGWIN || GFX_COMPILER == GFX_COMPILER_MINGW32 || GFX_COMPILER == GFX_COMPILER_MINGW64
20 16
 	#define GFX_THREADS_DONE
21 17
 	#define _gfxThreadsInit()
@@ -33,7 +29,7 @@
33 29
 	}
34 30
 
35 31
 	static __attribute__((pcs("aapcs-vfp"),naked)) void _gfxStartThread(thread *oldt, thread *newt) {
36
-		newt->cxt = (char *)newt + newt->size;
32
+		newt->cxt = (void *)(((unsigned)newt + newt->size) & ~7);
37 33
 		__asm__ volatile (	"push	{r4, r5, r6, r7, r8, r9, r10, r11, lr}	\n\t"
38 34
 							"vpush	{s16-s31}								\n\t"
39 35
 							"str	sp, %[oldtcxt]							\n\t"
@@ -68,9 +64,10 @@
68 64
 		PRESERVE8
69 65
 
70 66
 		// Calculate where to generate the new context
71
-		//		newt->cxt = (char *)newt + newt->size;
67
+		//		newt->cxt = (void *)(((unsigned)newt + newt->size) & ~7);
72 68
 		ldr      r2,[r1,#__cpp(offsetof(thread,size))]
73 69
 		add      r2,r2,r1
70
+		and      r2, r2, #0xFFFFFFF8
74 71
 		str      r2,[r1,#__cpp(offsetof(thread,cxt))]
75 72
 		
76 73
 		// Save the old context