Port musl to x86-64. One giant commit!
[musl] / src / setjmp / x86_64 / longjmp.s
1 /* Copyright 2011 Nicholas J. Kain, licensed GNU LGPL 2.1 or later */
2 .global _longjmp
3 .global longjmp
4 .type _longjmp,%function
5 .type longjmp,%function
6 _longjmp:
7 longjmp:
8         mov %rsi,%rax           /* val will be longjmp return */
9         test %rax,%rax
10         jnz .L0
11         inc %rax                /* if val==0, val=1 per longjmp semantics */
12 .L0:
13         movq (%rdi),%rbx        /* rdi is the jmp_buf, restore regs from it */
14         movq 8(%rdi),%rbp
15         movq 16(%rdi),%r12
16         movq 24(%rdi),%r13
17         movq 32(%rdi),%r14
18         movq 40(%rdi),%r15
19         movq 48(%rdi),%rdx      /* this ends up being the stack pointer */
20         mov %rdx,%rsp
21         movq 56(%rdi),%rdx      /* this is the instruction pointer */
22         jmp *%rdx               /* goto saved address without altering rsp */
23 .size _longjmp,.-_longjmp
24 .size longjmp,.-longjmp