diff options
author | inmarket <inmarket@ugfx.org> | 2016-12-06 12:16:19 +1000 |
---|---|---|
committer | inmarket <inmarket@ugfx.org> | 2016-12-06 12:16:19 +1000 |
commit | c1e2863078baaa0afbfbd31af5cc9f9978778dda (patch) | |
tree | eadfbdbdf9717a1119db89148afad21ff2a014e5 /src/gos/gos_x_threads_cortexm347.h | |
parent | 4b61ae71fed651b9f1f925d0056825359f289c29 (diff) | |
download | uGFX-c1e2863078baaa0afbfbd31af5cc9f9978778dda.tar.gz uGFX-c1e2863078baaa0afbfbd31af5cc9f9978778dda.tar.bz2 uGFX-c1e2863078baaa0afbfbd31af5cc9f9978778dda.zip |
Fix a bug in the Cortex M0 task switcher
Start of Keil compiler CPU specific switching
Diffstat (limited to 'src/gos/gos_x_threads_cortexm347.h')
-rw-r--r-- | src/gos/gos_x_threads_cortexm347.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/gos/gos_x_threads_cortexm347.h b/src/gos/gos_x_threads_cortexm347.h new file mode 100644 index 00000000..0392e674 --- /dev/null +++ b/src/gos/gos_x_threads_cortexm347.h @@ -0,0 +1,74 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * Thread Switching Functions for the Cortex M3, M4 & M7 without hardware floating point + * + * Use the EABI calling standard (ARM's AAPCS) - Save r4 - r11 + * 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? with no hardware floating point support but CORTEX_USE_FPU is TRUE. Try using GFX_CPU_GFX_CPU_CORTEX_M?_FP instead" +#endif + +#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 _gfxThreadsInit() + + static __attribute__((pcs("aapcs"),naked)) void _gfxTaskSwitch(thread *oldt, thread *newt) { + __asm__ volatile ( "push {r4, r5, r6, r7, r8, r9, r10, r11, lr} \n\t" + "str sp, %[oldtcxt] \n\t" + "ldr sp, %[newtcxt] \n\t" + "pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} \n\t" + : [newtcxt] "=m" (newt->cxt) + : [oldtcxt] "m" (oldt->cxt) + : "memory"); + } + + static __attribute__((pcs("aapcs"),naked)) void _gfxStartThread(thread *oldt, thread *newt) { + newt->cxt = (char *)newt + newt->size; + __asm__ volatile ( "push {r4, r5, r6, r7, r8, r9, r10, r11, lr} \n\t" + "str sp, %[oldtcxt] \n\t" + "ldr sp, %[newtcxt] \n\t" + : [newtcxt] "=m" (newt->cxt) + : [oldtcxt] "m" (oldt->cxt) + : "memory"); + + // Run the users function + gfxThreadExit(current->fn(current->param)); + } + +#elif GFX_COMPILER == GFX_COMPILER_KEIL || GFX_COMPILER == GFX_COMPILER_ARMCC + + static /*__arm*/ void _gfxTaskSwitch(thread *oldt, thread *newt) { +/* push {r4, r5, r6, r7, r8, r9, r10, r11, lr} + str sp, %[oldtcxt] + ldr sp, %[newtcxt] + pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} + : [newtcxt] "=m" (newt->cxt) + : [oldtcxt] "m" (oldt->cxt) + : "memory"); +*/ } + + static /* __arm */ void _gfxStartThread(thread *oldt, thread *newt) { + newt->cxt = (char *)newt + newt->size; +/* push {r4, r5, r6, r7, r8, r9, r10, r11, lr} + str sp, %[oldtcxt] + ldr sp, %[newtcxt] + : [newtcxt] "=m" (newt->cxt) + : [oldtcxt] "m" (oldt->cxt) + : "memory"); +*/ + // Run the users function + gfxThreadExit(current->fn(current->param)); + } + +#else + #warning "GOS: Threads: You have specified a specific CPU but your compiler is not supported. Defaulting to CLIB switching" +#endif |