Implementing setjmp.h
Implementing setjmp.h
Has anyone implemented setjmp() and longjmp() in their kernel? I thought these might've been builtin functions in C (like sizeof() and offsetof()) but it doesn't seem to be that simple. How would I go about implementing setjmp?
Valix is an experiment in an interpreted userspace with object-oriented and functional design patterns. Developers needed! Join #valix on irc.freenode.net
- Owen
- Member
- Posts: 1700
- Joined: Fri Jun 13, 2008 3:21 pm
- Location: Cambridge, United Kingdom
- Contact:
Re: Implementing setjmp.h
GCC provides __builtin_setjmp and __builtin_longjmp. The alternative is to implement it using (inline) assembly.
Ignoring SSE and the FPU, one i386 option would be
However, the builtin option will probably perform better. If my memory serves me right, the builtins use a jmp_buf type of "typedef void* env[4];"
Above assembly code untested. MASM dialect
Ignoring SSE and the FPU, one i386 option would be
Code: Select all
setjmp: mov ecx, 4[esp]
mov 0[ecx], ebp
mov 4[ecx], esi
mov 8[ecx], edi
mov 12[ecx], ebx
mov eax, 0[esp]
mov 16[ecx], eax
xor eax, eax
ret
longjmp: mov ecx, 4[esp]
mov ebp, 0[ecx]
mov esi, 4[ecx]
mov edi, 8[ecx]
mov ebx, 12[ecx]
mov 8[esp], eax
jmp 16[ecx]16
Above assembly code untested. MASM dialect