use R10 instead of R12 (#61)
on x86-64 R12 is callee-saved which means if we use it in callbackasm1 we MUST preserve its value. We were not doing that so it caused the SIGSEGV to happen in Oto. I replaced R12 with R10 because R10 is caller-saved so we don't need to worry about throwing away the value inside of it. Closes #60
- commit
- 382f4c69b85482e885511dd001710fd145469a76
- author
- TotallyGamerJet · · 2022-11-07 04:01 UTC
- committer
- GitHub · · 2022-11-07 04:01 UTC
- parent
- 13a6f78
- signature
- GPG Unverified
4AEE18F83AFDEB23The key is unknown
1 file · +4 -4
M sys_darwin_amd64.s +4 -4
| @@ -84,7 +84,7 @@ TEXT callbackasm1(SB), NOSPLIT, $0 | |||
| 84 | 84 | MOVQ 0(SP), AX | |
| 85 | 85 | ADDQ $8, SP | |
| 86 | 86 | ||
| 87 | - | MOVQ 0(SP), R12 // get the return SP so that we can align register args with stack args | |
| 87 | + | MOVQ 0(SP), R10 // get the return SP so that we can align register args with stack args | |
| 88 | 88 | ||
| 89 | 89 | // make space for first six arguments below the frame | |
| 90 | 90 | ADJSP $6*8, SP | |
| @@ -96,7 +96,7 @@ TEXT callbackasm1(SB), NOSPLIT, $0 | |||
| 96 | 96 | MOVQ R9, 48(SP) | |
| 97 | 97 | LEAQ 8(SP), R8 // R8 = address of args vector | |
| 98 | 98 | ||
| 99 | - | MOVQ R12, 0(SP) // push the stack pointer below registers | |
| 99 | + | MOVQ R10, 0(SP) // push the stack pointer below registers | |
| 100 | 100 | ||
| 101 | 101 | // determine index into runtime·cbs table | |
| 102 | 102 | MOVQ $callbackasm(SB), DX | |
| @@ -131,10 +131,10 @@ TEXT callbackasm1(SB), NOSPLIT, $0 | |||
| 131 | 131 | ||
| 132 | 132 | POP_REGS_HOST_TO_ABI0() | |
| 133 | 133 | ||
| 134 | - | MOVQ 0(SP), R12 // get the SP back | |
| 134 | + | MOVQ 0(SP), R10 // get the SP back | |
| 135 | 135 | ||
| 136 | 136 | ADJSP $-6*8, SP // remove arguments | |
| 137 | 137 | ||
| 138 | - | MOVQ R12, 0(SP) | |
| 138 | + | MOVQ R10, 0(SP) | |
| 139 | 139 | ||
| 140 | 140 | RET | |
| @@ -84,7 +84,7 @@ TEXT callbackasm1(SB), NOSPLIT, $0 | |||||
| 84 | MOVQ 0(SP), AX | 84 | MOVQ 0(SP), AX | ||
| 85 | ADDQ $8, SP | 85 | ADDQ $8, SP | ||
| 86 | 86 | ||||
| 87 | - | MOVQ 0(SP), R12 // get the return SP so that we can align register args with stack args | 87 | + | MOVQ 0(SP), R10 // get the return SP so that we can align register args with stack args |
| 88 | 88 | ||||
| 89 | // make space for first six arguments below the frame | 89 | // make space for first six arguments below the frame | ||
| 90 | ADJSP $6*8, SP | 90 | ADJSP $6*8, SP | ||
| @@ -96,7 +96,7 @@ TEXT callbackasm1(SB), NOSPLIT, $0 | |||||
| 96 | MOVQ R9, 48(SP) | 96 | MOVQ R9, 48(SP) | ||
| 97 | LEAQ 8(SP), R8 // R8 = address of args vector | 97 | LEAQ 8(SP), R8 // R8 = address of args vector | ||
| 98 | 98 | ||||
| 99 | - | MOVQ R12, 0(SP) // push the stack pointer below registers | 99 | + | MOVQ R10, 0(SP) // push the stack pointer below registers |
| 100 | 100 | ||||
| 101 | // determine index into runtime·cbs table | 101 | // determine index into runtime·cbs table | ||
| 102 | MOVQ $callbackasm(SB), DX | 102 | MOVQ $callbackasm(SB), DX | ||
| @@ -131,10 +131,10 @@ TEXT callbackasm1(SB), NOSPLIT, $0 | |||||
| 131 | 131 | ||||
| 132 | POP_REGS_HOST_TO_ABI0() | 132 | POP_REGS_HOST_TO_ABI0() | ||
| 133 | 133 | ||||
| 134 | - | MOVQ 0(SP), R12 // get the SP back | 134 | + | MOVQ 0(SP), R10 // get the SP back |
| 135 | 135 | ||||
| 136 | ADJSP $-6*8, SP // remove arguments | 136 | ADJSP $-6*8, SP // remove arguments | ||
| 137 | 137 | ||||
| 138 | - | MOVQ R12, 0(SP) | 138 | + | MOVQ R10, 0(SP) |
| 139 | 139 | ||||
| 140 | RET | 140 | RET | ||