Fix Cortex m0 Raw32 scheduler.

Ensure 8 byte alignment of the stack for all ARM specific scheduler code.
release/v2.9
inmarket 2016-12-30 18:57:09 +10:00
parent 06de6f1931
commit 6a30927a91
3 changed files with 25 additions and 18 deletions

View File

@ -27,8 +27,10 @@
"mov r6, r10 \n\t" "mov r6, r10 \n\t"
"mov r7, r11 \n\t" "mov r7, r11 \n\t"
"push {r4, r5, r6, r7} \n\t" "push {r4, r5, r6, r7} \n\t"
"str sp, %[oldtcxt] \n\t" "mov r4, sp \n\t"
"ldr sp, %[newtcxt] \n\t" "str r4, %[oldtcxt] \n\t"
"ldr r4, %[newtcxt] \n\t"
"mov sp, r4 \n\t"
"pop {r4, r5, r6, r7} \n\t" "pop {r4, r5, r6, r7} \n\t"
"mov r8, r4 \n\t" "mov r8, r4 \n\t"
"mov r9, r5 \n\t" "mov r9, r5 \n\t"
@ -41,15 +43,17 @@
} }
static __attribute__((pcs("aapcs"),naked)) void _gfxStartThread(thread *oldt, thread *newt) { static __attribute__((pcs("aapcs"),naked)) void _gfxStartThread(thread *oldt, thread *newt) {
newt->cxt = (char *)newt + newt->size; newt->cxt = (void *)(((unsigned)newt + newt->size) & ~7);
__asm__ volatile ( "push {r4, r5, r6, r7, lr} \n\t" __asm__ volatile ( "push {r4, r5, r6, r7, lr} \n\t"
"mov r4, r8 \n\t" "mov r4, r8 \n\t"
"mov r5, r9 \n\t" "mov r5, r9 \n\t"
"mov r6, r10 \n\t" "mov r6, r10 \n\t"
"mov r7, r11 \n\t" "mov r7, r11 \n\t"
"push {r4, r5, r6, r7} \n\t" "push {r4, r5, r6, r7} \n\t"
"str sp, %[oldtcxt] \n\t" "mov r4, sp \n\t"
"ldr sp, %[newtcxt] \n\t" "str r4, %[oldtcxt] \n\t"
"ldr r4, %[newtcxt] \n\t"
"mov sp, r4 \n\t"
: [newtcxt] "=m" (newt->cxt) : [newtcxt] "=m" (newt->cxt)
: [oldtcxt] "m" (oldt->cxt) : [oldtcxt] "m" (oldt->cxt)
: "memory"); : "memory");
@ -72,10 +76,12 @@
mov r6, r10 mov r6, r10
mov r7, r11 mov r7, r11
push {r4, r5, r6, r7} push {r4, r5, r6, r7}
str sp, [r0,#__cpp(offsetof(thread,cxt))] // oldt->cxt mov r4, sp
str r4, [r0,#__cpp(offsetof(thread,cxt))] // oldt->cxt
// Load the new context // Load the new context
ldr sp, [r1,#__cpp(offsetof(thread,cxt))] // newt->cxt ldr r4, [r1,#__cpp(offsetof(thread,cxt))] // newt->cxt
mov sp, r4
pop {r4, r5, r6, r7} pop {r4, r5, r6, r7}
mov r8, r4 mov r8, r4
mov r9, r5 mov r9, r5
@ -88,9 +94,10 @@
PRESERVE8 PRESERVE8
// Calculate where to generate the new context // Calculate where to generate the new context
// newt->cxt = (char *)newt + newt->size; // newt->cxt = (void *)(((unsigned)newt + newt->size) & ~7);
ldr r2,[r1,#__cpp(offsetof(thread,size))] ldr r2,[r1,#__cpp(offsetof(thread,size))]
add r2,r2,r1 add r2,r2,r1
and r2, r2, #0xFFFFFFF8
str r2,[r1,#__cpp(offsetof(thread,cxt))] str r2,[r1,#__cpp(offsetof(thread,cxt))]
// Save the old context // Save the old context
@ -100,10 +107,12 @@
mov r6, r10 mov r6, r10
mov r7, r11 mov r7, r11
push {r4, r5, r6, r7} push {r4, r5, r6, r7}
str sp, [r0,#__cpp(offsetof(thread,cxt))] // oldt->cxt mov r4, sp
str r4, [r0,#__cpp(offsetof(thread,cxt))] // oldt->cxt
// Load the new (imcomplete) context // Load the new (imcomplete) context
ldr sp, [r1,#__cpp(offsetof(thread,cxt))] // newt->cxt ldr r4, [r1,#__cpp(offsetof(thread,cxt))] // newt->cxt
mov sp, r4
// Run the users function - we save some code because gfxThreadExit() never returns // Run the users function - we save some code because gfxThreadExit() never returns
// gfxThreadExit(_gfxCurrentThread->fn(_gfxCurrentThread->param)); // gfxThreadExit(_gfxCurrentThread->fn(_gfxCurrentThread->param));

View File

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

View File

@ -12,10 +12,6 @@
* The context is saved at the current stack location and a pointer is maintained in the thread structure. * The context is saved at the current stack location and a pointer is maintained in the thread structure.
*/ */
#if !CORTEX_USE_FPU
#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"
#endif
#if GFX_COMPILER == GFX_COMPILER_GCC || GFX_COMPILER == GFX_COMPILER_CYGWIN || GFX_COMPILER == GFX_COMPILER_MINGW32 || GFX_COMPILER == GFX_COMPILER_MINGW64 #if GFX_COMPILER == GFX_COMPILER_GCC || GFX_COMPILER == GFX_COMPILER_CYGWIN || GFX_COMPILER == GFX_COMPILER_MINGW32 || GFX_COMPILER == GFX_COMPILER_MINGW64
#define GFX_THREADS_DONE #define GFX_THREADS_DONE
#define _gfxThreadsInit() #define _gfxThreadsInit()
@ -33,7 +29,7 @@
} }
static __attribute__((pcs("aapcs-vfp"),naked)) void _gfxStartThread(thread *oldt, thread *newt) { static __attribute__((pcs("aapcs-vfp"),naked)) void _gfxStartThread(thread *oldt, thread *newt) {
newt->cxt = (char *)newt + newt->size; newt->cxt = (void *)(((unsigned)newt + newt->size) & ~7);
__asm__ volatile ( "push {r4, r5, r6, r7, r8, r9, r10, r11, lr} \n\t" __asm__ volatile ( "push {r4, r5, r6, r7, r8, r9, r10, r11, lr} \n\t"
"vpush {s16-s31} \n\t" "vpush {s16-s31} \n\t"
"str sp, %[oldtcxt] \n\t" "str sp, %[oldtcxt] \n\t"
@ -68,9 +64,10 @@
PRESERVE8 PRESERVE8
// Calculate where to generate the new context // Calculate where to generate the new context
// newt->cxt = (char *)newt + newt->size; // newt->cxt = (void *)(((unsigned)newt + newt->size) & ~7);
ldr r2,[r1,#__cpp(offsetof(thread,size))] ldr r2,[r1,#__cpp(offsetof(thread,size))]
add r2,r2,r1 add r2,r2,r1
and r2, r2, #0xFFFFFFF8
str r2,[r1,#__cpp(offsetof(thread,cxt))] str r2,[r1,#__cpp(offsetof(thread,cxt))]
// Save the old context // Save the old context