nlrx64.S 2.92 KB
Newer Older
1
2
#ifdef __x86_64__
/* x64 callee save: bx, bp, sp, r12, r14, r14, r15 */
3
4
5
6

    .file   "nlr.s"
    .text

7
/* uint nlr_push(rdi=nlr_buf_t *nlr) */
8
#ifndef __apple_build_version__
9
10
11
    .globl  nlr_push
    .type   nlr_push, @function
nlr_push:
12
13
14
15
#else
    .globl  _nlr_push
_nlr_push:
#endif
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    movq    (%rsp), %rax            # load return %rip
    movq    %rax, 16(%rdi)          # store %rip into nlr_buf
    movq    %rbp, 24(%rdi)          # store %rbp into nlr_buf
    movq    %rsp, 32(%rdi)          # store %rsp into nlr_buf
    movq    %rbx, 40(%rdi)          # store %rbx into nlr_buf
    movq    %r12, 48(%rdi)          # store %r12 into nlr_buf
    movq    %r13, 56(%rdi)          # store %r13 into nlr_buf
    movq    %r14, 64(%rdi)          # store %r14 into nlr_buf
    movq    %r15, 72(%rdi)          # store %r15 into nlr_buf
    movq    nlr_top(%rip), %rax     # get last nlr_buf
    movq    %rax, (%rdi)            # store it
    movq    %rdi, nlr_top(%rip)     # stor new nlr_buf (to make linked list)
    xorq    %rax, %rax              # return 0, normal return
    ret                             # return
30
#ifndef __apple_build_version__
31
32
    .size   nlr_push, .-nlr_push
#endif
33

34
/* void nlr_pop() */
35
#ifndef __apple_build_version__
36
37
38
    .globl  nlr_pop
    .type   nlr_pop, @function
nlr_pop:
39
40
41
42
#else
    .globl  _nlr_pop
_nlr_pop:
#endif
43
44
45
46
    movq    nlr_top(%rip), %rax     # get nlr_top into %rax
    movq    (%rax), %rax            # load prev nlr_buf
    movq    %rax, nlr_top(%rip)     # store prev nlr_buf (to unlink list)
    ret                             # return
47
#ifndef __apple_build_version__
48
49
    .size   nlr_pop, .-nlr_pop
#endif
50

51
/* void nlr_jump(rdi=uint val) */
52
#ifndef __apple_build_version__
53
54
55
    .globl  nlr_jump
    .type   nlr_jump, @function
nlr_jump:
56
57
58
59
#else
    .globl  _nlr_jump
    _nlr_jump:
#endif
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    movq    %rdi, %rax              # put return value in %rax
    movq    nlr_top(%rip), %rdi     # get nlr_top into %rdi
    movq    %rax, 8(%rdi)           # store return value
    movq    (%rdi), %rax            # load prev nlr_buf
    movq    %rax, nlr_top(%rip)     # store prev nlr_buf (to unlink list)
    movq    72(%rdi), %r15          # load saved %r15
    movq    64(%rdi), %r14          # load saved %r14
    movq    56(%rdi), %r13          # load saved %r13
    movq    48(%rdi), %r12          # load saved %r12
    movq    40(%rdi), %rbx          # load saved %rbx
    movq    32(%rdi), %rsp          # load saved %rsp
    movq    24(%rdi), %rbp          # load saved %rbp
    movq    16(%rdi), %rax          # load saved %rip
    movq    %rax, (%rsp)            # store saved %rip to stack
    xorq    %rax, %rax              # clear return register
    inc     %al                     # increase to make 1, non-local return
    ret                             # return
77
#ifndef __apple_build_version__
78
    .size   nlr_jump, .-nlr_jump
79
#endif
80

81
#ifndef __apple_build_version__
82
    .local  nlr_top
83
#endif
84
    .comm   nlr_top,8,8
85
#endif