|
4 | 4 | .file "nlr.s" |
5 | 5 | .text |
6 | 6 |
|
| 7 | +#if !defined(__CYGWIN__) |
| 8 | + |
7 | 9 | /* uint nlr_push(rdi=nlr_buf_t *nlr) */ |
8 | 10 | #if !(defined(__APPLE__) && defined(__MACH__)) |
9 | 11 | .globl nlr_push |
@@ -82,4 +84,63 @@ nlr_jump: |
82 | 84 | .local nlr_top |
83 | 85 | #endif |
84 | 86 | .comm nlr_top,8,8 |
85 | | -#endif |
| 87 | + |
| 88 | +#else // !defined(__CYGWIN__) |
| 89 | + |
| 90 | +/* uint nlr_push(rcx=nlr_buf_t *nlr) */ |
| 91 | + .globl nlr_push |
| 92 | +nlr_push: |
| 93 | + movq (%rsp), %rax # load return %rip |
| 94 | + movq %rax, 16(%rcx) # store %rip into nlr_buf |
| 95 | + movq %rbp, 24(%rcx) # store %rbp into nlr_buf |
| 96 | + movq %rsp, 32(%rcx) # store %rsp into nlr_buf |
| 97 | + movq %rbx, 40(%rcx) # store %rbx into nlr_buf |
| 98 | + movq %r12, 48(%rcx) # store %r12 into nlr_buf |
| 99 | + movq %r13, 56(%rcx) # store %r13 into nlr_buf |
| 100 | + movq %r14, 64(%rcx) # store %r14 into nlr_buf |
| 101 | + movq %r15, 72(%rcx) # store %r15 into |
| 102 | + movq %rdi, 80(%rcx) # store %rdr into |
| 103 | + movq %rsi, 88(%rcx) # store %rsi into |
| 104 | + movq nlr_top(%rip), %rax # get last nlr_buf |
| 105 | + movq %rax, (%rcx) # store it |
| 106 | + movq %rcx, nlr_top(%rip) # stor new nlr_buf (to make linked list) |
| 107 | + xorq %rax, %rax # return 0, normal return |
| 108 | + ret # return |
| 109 | + |
| 110 | +/* void nlr_jump(rcx=uint val) */ |
| 111 | + |
| 112 | + .globl nlr_jump |
| 113 | +nlr_jump: |
| 114 | + movq %rcx, %rax # put return value in %rax |
| 115 | + movq nlr_top(%rip), %rcx # get nlr_top into %rsi |
| 116 | + movq %rax, 8(%rcx) # store return value |
| 117 | + movq (%rcx), %rax # load prev nlr_buf |
| 118 | + movq %rax, nlr_top(%rip) # store prev nlr_buf (to unlink list) |
| 119 | + movq 72(%rcx), %r15 # load saved %r15 |
| 120 | + movq 64(%rcx), %r14 # load saved %r14 |
| 121 | + movq 56(%rcx), %r13 # load saved %r13 |
| 122 | + movq 48(%rcx), %r12 # load saved %r12 |
| 123 | + movq 40(%rcx), %rbx # load saved %rbx |
| 124 | + movq 32(%rcx), %rsp # load saved %rsp |
| 125 | + movq 24(%rcx), %rbp # load saved %rbp |
| 126 | + movq 16(%rcx), %rax # load saved %rip |
| 127 | + movq 80(%rcx), %rdi # store %rdr into |
| 128 | + movq 88(%rcx), %rsi # store %rsi into |
| 129 | + movq %rax, (%rsp) # store saved %rip to stack |
| 130 | + xorq %rax, %rax # clear return register |
| 131 | + inc %al # increase to make 1, non-local return |
| 132 | + ret # return |
| 133 | + |
| 134 | + .comm nlr_top,8,8 |
| 135 | + |
| 136 | + /* void nlr_pop() */ |
| 137 | + .globl nlr_pop |
| 138 | +nlr_pop: |
| 139 | + movq nlr_top(%rip), %rax # get nlr_top into %rax |
| 140 | + movq (%rax), %rax # load prev nlr_buf |
| 141 | + movq %rax, nlr_top(%rip) # store prev nlr_buf (to unlink list) |
| 142 | + ret # return |
| 143 | + |
| 144 | +#endif // !defined(__CYGWIN__) |
| 145 | + |
| 146 | +#endif // __x86_64__ |
0 commit comments