forked from Lephenixnoir/gint
52 lines
1.6 KiB
C
52 lines
1.6 KiB
C
#ifndef GINT_STD_SETJMP
|
|
# define GINT_STD_SETJMP
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
/* Custom(?) jmp_buf struct
|
|
|
|
@note:
|
|
We save only r8 ~ r15 and SR / PC registers. The SR register is saved first
|
|
because the longjump() can be involved with a different register bank.
|
|
So, to avoid this, it's simpler to restore the saved SR first then restore
|
|
all registers (see <src/setjmp/longjmp.S>). */
|
|
struct __jmp_buf
|
|
{
|
|
uint32_t sr;
|
|
uint32_t reg[8];
|
|
uint32_t gbr;
|
|
uint32_t macl;
|
|
uint32_t mach;
|
|
uint32_t pr;
|
|
};
|
|
|
|
/* User jmp_buf alias */
|
|
typedef struct __jmp_buf jmp_buf[1];
|
|
|
|
|
|
|
|
/* setjmp(): store the calling environment in ENV
|
|
|
|
This function saves various information about the calling environment
|
|
(typically, the stack pointer, the instruction pointer, the values of some
|
|
registers and the signal mask) in the buffer ENV for later use by longjmp().
|
|
In this case, setjmp() returns 0 */
|
|
extern int setjmp(jmp_buf env);
|
|
|
|
/* longjmp(): effectuate non-local goto using the saved ENV
|
|
|
|
This function uses the information saved in env to transfer control back to
|
|
the point where setjmp() was called and to restore ("rewind") the stack to its
|
|
state at the time of the setjmp() call.
|
|
|
|
Following a successful longjmp(), execution continues as if setjmp() had
|
|
returned for a second time. This "fake" return can be distinguished from a
|
|
true setjmp() call because the "fake return" returns the value provided in
|
|
val. If the programmer mistakenly passes the value 0 in val, the "fake" return
|
|
will instead return 1. */
|
|
extern void longjmp(jmp_buf env, int val);
|
|
|
|
|
|
#endif /* GINT_STD_SETJMP */
|