From 59000174aa50ed6b2d24a71576d15e6a53c5be0c Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sat, 16 Jul 2016 01:28:04 +0200 Subject: Add stubs for many libc functions, and a few implemenations too --- src/lib/libc/setjmp.s | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/lib/libc/setjmp.s (limited to 'src/lib/libc/setjmp.s') diff --git a/src/lib/libc/setjmp.s b/src/lib/libc/setjmp.s new file mode 100644 index 0000000..164cc5b --- /dev/null +++ b/src/lib/libc/setjmp.s @@ -0,0 +1,53 @@ +[GLOBAL setjmp] +setjmp: + ; Store general purpose registers + ; (in new stack frame) + mov [esp+4], eax + mov [esp+8], ebx + mov [esp+12], ecx + mov [esp+16], edx + mov [esp+20], edi + mov [esp+24], esi + mov [esp+28], ebp + mov [esp+32], esp + + ; Store flags + pushf + pop eax + mov [esp+36], eax + + ; Store return address + mov eax, [esp] + mov [esp+40], eax + + ; return 0 + xor eax, eax + ret + + +[GLOBAL longjmp] +longjmp: + ; on previous stack, resume return address + mov eax, [esp+32] + mov ebx, [esp+40] + mov [eax], ebx + + ; resume flags + mov eax, [esp+36] + push eax + popf + + ; load return value in eax + mov eax, [esp+44] + ; resume geneal purpose registers, except eax/esp + mov ebx, [esp+8] + mov ecx, [esp+12] + mov edx, [esp+16] + mov edi, [esp+20] + mov esi, [esp+24] + mov ebp, [esp+28] + + ; resume previous esp + mov esp, [esp+32] + ; return as if we were the setjmp call + ret -- cgit v1.2.3