[libc] Rewrite setjmp() and longjmp()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -1,40 +1,50 @@
|
||||
#ifndef ETHERBOOT_SETJMP_H
|
||||
#define ETHERBOOT_SETJMP_H
|
||||
#ifndef _SETJMP_H
|
||||
#define _SETJMP_H
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER );
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <stdint.h>
|
||||
#include <realmode.h>
|
||||
|
||||
/** A jump buffer */
|
||||
typedef struct {
|
||||
/** Saved return address */
|
||||
uint32_t retaddr;
|
||||
/** Saved stack pointer */
|
||||
uint32_t stack;
|
||||
/** Saved %ebx */
|
||||
uint32_t ebx;
|
||||
uint32_t esp;
|
||||
uint32_t ebp;
|
||||
/** Saved %esi */
|
||||
uint32_t esi;
|
||||
/** Saved %edi */
|
||||
uint32_t edi;
|
||||
/** Saved %ebp */
|
||||
uint32_t ebp;
|
||||
} jmp_buf[1];
|
||||
|
||||
/** A real-mode-extended jump buffer */
|
||||
typedef struct {
|
||||
/** Jump buffer */
|
||||
jmp_buf env;
|
||||
uint16_t rm_ss;
|
||||
uint16_t rm_sp;
|
||||
/** Real-mode stack pointer */
|
||||
segoff_t rm_stack;
|
||||
} rmjmp_buf[1];
|
||||
|
||||
extern int __asmcall setjmp ( jmp_buf env );
|
||||
extern void __asmcall longjmp ( jmp_buf env, int val );
|
||||
extern int __asmcall __attribute__ (( returns_twice ))
|
||||
setjmp ( jmp_buf env );
|
||||
|
||||
#define rmsetjmp( _env ) ( { \
|
||||
(_env)->rm_ss = rm_ss; \
|
||||
(_env)->rm_sp = rm_sp; \
|
||||
setjmp ( (_env)->env ); } ) \
|
||||
extern void __asmcall __attribute__ (( noreturn ))
|
||||
longjmp ( jmp_buf env, int val );
|
||||
|
||||
#define rmlongjmp( _env, _val ) do { \
|
||||
rm_ss = (_env)->rm_ss; \
|
||||
rm_sp = (_env)->rm_sp; \
|
||||
longjmp ( (_env)->env, (_val) ); \
|
||||
#define rmsetjmp( _env ) ( { \
|
||||
(_env)->rm_stack.segment = rm_ss; \
|
||||
(_env)->rm_stack.offset = rm_sp; \
|
||||
setjmp ( (_env)->env ); } ) \
|
||||
|
||||
#define rmlongjmp( _env, _val ) do { \
|
||||
rm_ss = (_env)->rm_stack.segment; \
|
||||
rm_sp = (_env)->rm_stack.offset; \
|
||||
longjmp ( (_env)->env, (_val) ); \
|
||||
} while ( 0 )
|
||||
|
||||
#endif /* ETHERBOOT_SETJMP_H */
|
||||
#endif /* _SETJMP_H */
|
||||
|
||||
Reference in New Issue
Block a user