mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:47:45 +00:00
LibC: Implement setjmp() and longjmp().
I think this is correct. The following registers are saved and restored: EBX, ESI, EDI, EBP, ESP and EIP.
This commit is contained in:
parent
f34c0e414b
commit
57fb027216
1 changed files with 28 additions and 9 deletions
|
@ -2,13 +2,32 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <Kernel/Syscall.h>
|
#include <Kernel/Syscall.h>
|
||||||
|
|
||||||
int setjmp(jmp_buf)
|
asm(
|
||||||
{
|
"setjmp:\n\
|
||||||
//assert(false);
|
movl %ebx, 0(%eax)\n\
|
||||||
return 0;
|
movl %esi, 4(%eax)\n\
|
||||||
}
|
movl %edi, 8(%eax)\n\
|
||||||
|
movl %ebp, 12(%eax)\n\
|
||||||
|
movl %esp, 16(%eax)\n\
|
||||||
|
movl (%esp), %ecx\n\
|
||||||
|
movl %ecx, 20(%eax)\n\
|
||||||
|
xorl %eax, %eax\n\
|
||||||
|
ret\n\
|
||||||
|
");
|
||||||
|
|
||||||
void longjmp(jmp_buf, int)
|
asm(
|
||||||
{
|
"longjmp:\n\
|
||||||
assert(false);
|
xchgl %edx, %eax\n\
|
||||||
}
|
test %eax, %eax\n\
|
||||||
|
jnz 1f\n\
|
||||||
|
incl %eax\n\
|
||||||
|
1:\n\
|
||||||
|
mov 0(%edx), %ebx\n\
|
||||||
|
mov 4(%edx), %esi\n\
|
||||||
|
mov 8(%edx), %edi\n\
|
||||||
|
mov 12(%edx), %ebp\n\
|
||||||
|
mov 16(%edx), %ecx\n\
|
||||||
|
mov %ecx, %esp\n\
|
||||||
|
mov 20(%edx), %ecx\n\
|
||||||
|
jmp *%ecx\n\
|
||||||
|
");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue