summaryrefslogtreecommitdiff
path: root/lib/mlibc/options/internal/x86_64/setjmp.S
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mlibc/options/internal/x86_64/setjmp.S')
-rw-r--r--lib/mlibc/options/internal/x86_64/setjmp.S54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/mlibc/options/internal/x86_64/setjmp.S b/lib/mlibc/options/internal/x86_64/setjmp.S
new file mode 100644
index 0000000..aa8a134
--- /dev/null
+++ b/lib/mlibc/options/internal/x86_64/setjmp.S
@@ -0,0 +1,54 @@
+
+.type __setjmp, "function"
+__setjmp:
+ mov %rbx, 0x00(%rdi)
+ mov %rbp, 0x08(%rdi)
+ mov %r12, 0x10(%rdi)
+ mov %r13, 0x18(%rdi)
+ mov %r14, 0x20(%rdi)
+ mov %r15, 0x28(%rdi)
+
+ lea 8(%rsp), %rax # rsp before return rip is pushed
+ mov %rax, 0x30(%rdi)
+ mov (%rsp), %rax # return rip
+ mov %rax, 0x38(%rdi)
+
+ test %rdx, %rdx
+ jnz 1f
+ xor %rax, %rax
+ ret
+
+1:
+ jmp __sigsetjmp
+
+.global setjmp
+.type setjmp, "function"
+setjmp:
+ xor %rdx, %rdx
+ jmp __setjmp
+
+.global sigsetjmp
+.type sigsetjmp, "function"
+sigsetjmp:
+ mov $1, %rdx
+ jmp __setjmp
+
+.global longjmp
+.type longjmp, "function"
+longjmp:
+ mov 0x00(%rdi), %rbx
+ mov 0x08(%rdi), %rbp
+ mov 0x10(%rdi), %r12
+ mov 0x18(%rdi), %r13
+ mov 0x20(%rdi), %r14
+ mov 0x28(%rdi), %r15
+
+ mov %rsi, %rax
+ test %rax, %rax
+ jnz 1f
+ inc %rax
+1:
+ mov 0x30(%rdi), %rsp
+ jmp *0x38(%rdi)
+.section .note.GNU-stack,"",%progbits
+