Created
July 17, 2012 12:47
-
-
Save buserror/3129219 to your computer and use it in GitHub Desktop.
cortex-m4/stm32f4 longjmp/setjmp implementation with FPU store/restore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* tested with gcc on an stm32f4 | |
* Michel Pollet <[email protected]> | |
*/ | |
#if defined(__VFP_FP__) | |
typedef long __jmp_buf[10 + 8 + 1]; // d8-d15 fpu + fpscr | |
#else | |
typedef long __jmp_buf[10]; | |
#endif | |
static int __setjmp(__jmp_buf buf) __attribute__ ((noinline)); | |
static int __setjmp(__jmp_buf buf) | |
{ | |
register void * r0 __asm__("r0") = buf; | |
__asm__( | |
"mov %%ip, %%sp\n" | |
"stmia %[store]!, {%%r4-%%r9, %%sl, %%fp, %%ip, %%lr}\n" | |
#if defined(__VFP_FP__) | |
"vstmia %[store]!, {%%d8-%%d15}\n" | |
"vmrs %%r1, fpscr\n" | |
"str %%r1, [%[store]], #4\n" | |
#endif | |
"mov.w %r0, #0\n" | |
: : [store] "r" (r0) :); | |
} | |
static void __longjmp(__jmp_buf buf, long value) __attribute__((noreturn)); | |
static void __longjmp(__jmp_buf buf, long value) | |
{ | |
__asm__( | |
"ldmia %[load]!, {%%r4-%%r9, %%sl, %%fp, %%ip, %%lr}\n" | |
#if defined(__VFP_FP__) | |
"vldmia %[load]!, {%%d8-%%d15}\n" | |
"ldr %%r0, [%[load]], #4\n" | |
"vmsr fpscr, %%r0\n" | |
#endif | |
"mov %%sp, %%ip\n" | |
"movs %%r0, %%r1\n" | |
"it eq\n" | |
"moveq %%r0, #1\n" | |
"bx lr\n" | |
: : [load] "r" (buf), [value] "r" (value):); | |
__builtin_unreachable(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment