diff --git a/include/setjmp.h b/include/setjmp.h index 3202eb4..73fe01c 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -3,27 +3,18 @@ #include #include - -/* Get '__jmp_buf' */ #include -/* User jmp_buf alias */ +/* Make jmp_buf an array type. (7.13§2) */ typedef struct __jmp_buf jmp_buf[1]; - -/* -** Store the calling environment in ENV, also saving the signal mask. -** Return 0. -*/ -extern int setjmp(jmp_buf env); +/* Save the calling environment in __env (not the signal mask), return 0. */ +extern int setjmp(jmp_buf __env); /* Standard requires setjmp to be a macro (7.13§1) */ #define setjmp setjmp -/* -** Store the calling environment in ENV, not saving the signal mask. -** Return 0. -*/ -extern void longjmp(jmp_buf env, int val); +/* Restore the calling environment from __env, return __val to setjmp. */ +extern void longjmp(jmp_buf __env, int __val); #endif /*__SETJMP_H__*/ diff --git a/include/target/sh-generic/bits/setjmp.h b/include/target/sh-generic/bits/setjmp.h new file mode 100644 index 0000000..18dc999 --- /dev/null +++ b/include/target/sh-generic/bits/setjmp.h @@ -0,0 +1,23 @@ +#ifndef __BITS_SETJMP_H__ +# define __BITS_SETJMP_H__ + +#include +#include + +/* +** Custom(?) jmp_buf struct +** The SR register is saved first because the long jump can be involved with +** different register bank. So to avoid this, it's simpler to restore the saved +** SR first (see ) +*/ +struct __jmp_buf +{ + uint32_t sr; + uint32_t reg[8]; + uint32_t gbr; + uint32_t macl; + uint32_t mach; + uint32_t pr; +}; + +#endif /*__BITS_SETJMP_H__*/ diff --git a/include/target/vhex-generic/bits/setjmp.h b/include/target/vhex-generic/bits/setjmp.h deleted file mode 100644 index 08fbfa1..0000000 --- a/include/target/vhex-generic/bits/setjmp.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef __BITS_SETJMP_H__ -# define __BITS_SETJMP_H__ - -#include -#include - -/* -** Custom(?) jmp_buf struct -** @note: save only r8 ~ r15 and SR / PC registers -** The SR register is saved first because the longjump can be involved with -** different register bank. So to avoid this, it's more simple to restore the -** saved SR first then restore all register (see ) -** -** TODO: save process signal mask ? -*/ -struct __jmp_buf -{ - uint32_t sr; - uint32_t reg[8]; - uint32_t gbr; - uint32_t macl; - uint32_t mach; - uint32_t pr; -}; - -#endif /*__BITS_SETJMP_H__*/ diff --git a/src/libc/setjmp/target/sh-generic/longjmp.S b/src/libc/setjmp/target/sh-generic/longjmp.S index d4b2d82..6da0532 100644 --- a/src/libc/setjmp/target/sh-generic/longjmp.S +++ b/src/libc/setjmp/target/sh-generic/longjmp.S @@ -28,7 +28,7 @@ int_block: ldc r1, sr context_switch: - ! load the old SR regsiter first to force register bank switch + ! load the old SR register first to force register bank switch ! (if needed) then move the context and the returned value into ! non-saved (by the setjmp context) registers. ldc.l @r8+, sr diff --git a/src/libc/setjmp/target/sh-generic/setjmp.S b/src/libc/setjmp/target/sh-generic/setjmp.S index 53492c1..596231c 100644 --- a/src/libc/setjmp/target/sh-generic/setjmp.S +++ b/src/libc/setjmp/target/sh-generic/setjmp.S @@ -7,8 +7,6 @@ ** int setjmp(jmp_buf env) ** Store the calling environment in ENV, also saving the signal mask. ** Return 0. -** -** TODO: hande signal mask */ _setjmp: ! block interrupt @@ -43,4 +41,3 @@ _setjmp: ! return rts mov #0, r0 -.end