diff options
| author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-11-18 21:38:57 +0100 |
|---|---|---|
| committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-11-19 13:34:29 +0000 |
| commit | 4d048194cd0323e1deffce96e88e8a672a08732d (patch) | |
| tree | c2817ff2ad5fec76c2e36de4aeedb38a8e57d339 /src/runtime/sys_windows_arm.s | |
| parent | 5ba1c3f290ef8f3c373c560d3608325b07f44f7a (diff) | |
| download | go-4d048194cd0323e1deffce96e88e8a672a08732d.tar.xz | |
runtime: support new callbackasm1 calling convention on windows/arm
This updates the callbacks implementation on windows/arm for the
changes made in CL 258938. At the time, that was left as a TODO.
At the same time, it also extends the previous support for only 4
arguments to also support additional arguments on the stack. This is
required for functions like SetWinEventHook, which take 7 arguments. It
does this by pushing r0-r3 onto the stack before the normal prologue,
and then pointing the args struct to that location.
This is derived from CL 270077 and CL 270078.
Updates #40724.
Fixes #42591.
Change-Id: Icc199e7f2c24205e41be4e00015283c7e2a9b797
Reviewed-on: https://go-review.googlesource.com/c/go/+/271178
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/sys_windows_arm.s')
| -rw-r--r-- | src/runtime/sys_windows_arm.s | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/src/runtime/sys_windows_arm.s b/src/runtime/sys_windows_arm.s index 3fc6d27cb0..fe267080cc 100644 --- a/src/runtime/sys_windows_arm.s +++ b/src/runtime/sys_windows_arm.s @@ -314,48 +314,42 @@ TEXT runtime·externalthreadhandler(SB),NOSPLIT|NOFRAME,$0 GLOBL runtime·cbctxts(SB), NOPTR, $4 TEXT runtime·callbackasm1(SB),NOSPLIT|NOFRAME,$0 - // TODO(austin): This needs to be converted to match changes - // in cgocallback, but I have no way to test. See CL 258938, - // and callbackasm1 on amd64 and 386. - MOVM.DB.W [R4-R11, R14], (R13) // push {r4-r11, lr} - SUB $36, R13 // space for locals + // On entry, the trampoline in zcallback_windows_arm.s left + // the callback index in R12 (which is volatile in the C ABI). - // save callback arguments to stack. We currently support up to 4 arguments - ADD $16, R13, R4 - MOVM.IA [R0-R3], (R4) + // Push callback register arguments r0-r3. We do this first so + // they're contiguous with stack arguments. + MOVM.DB.W [R0-R3], (R13) + // Push C callee-save registers r4-r11 and lr. + MOVM.DB.W [R4-R11, R14], (R13) + SUB $(16 + callbackArgs__size), R13 // space for locals - // load cbctxts[i]. The trampoline in zcallback_windows.s puts the callback - // index in R12 - MOVW runtime·cbctxts(SB), R4 - MOVW R12<<2(R4), R4 // R4 holds pointer to wincallbackcontext structure - - // extract callback context - MOVW wincallbackcontext_argsize(R4), R5 - MOVW wincallbackcontext_gobody(R4), R4 - - // we currently support up to 4 arguments - CMP $(4 * 4), R5 - BL.GT runtime·abort(SB) - - // extend argsize by size of return value - ADD $4, R5 - - // Build 'type args struct' - MOVW R4, 4(R13) // fn - ADD $16, R13, R0 // arg (points to r0-r3, ret on stack) - MOVW R0, 8(R13) - MOVW R5, 12(R13) // argsize + // Create a struct callbackArgs on our stack. + MOVW R12, (16+callbackArgs_index)(R13) // callback index + MOVW $(16+callbackArgs__size+4*9)(R13), R0 + MOVW R0, (16+callbackArgs_args)(R13) // address of args vector + MOVW $0, R0 + MOVW R0, (16+callbackArgs_result)(R13) // result + // Prepare for entry to Go. BL runtime·load_g(SB) - BL runtime·cgocallback_gofunc(SB) - ADD $16, R13, R0 // load arg - MOVW 12(R13), R1 // load argsize - SUB $4, R1 // offset to return value - MOVW R1<<0(R0), R0 // load return value + // Call cgocallback, which will call callbackWrap(frame). + MOVW $0, R0 + MOVW R0, 12(R13) // context + MOVW $16(R13), R1 // R1 = &callbackArgs{...} + MOVW R1, 8(R13) // frame (address of callbackArgs) + MOVW $·callbackWrap(SB), R1 + MOVW R1, 4(R13) // PC of function to call + BL runtime·cgocallback(SB) + + // Get callback result. + MOVW (16+callbackArgs_result)(R13), R0 - ADD $36, R13 // free locals - MOVM.IA.W (R13), [R4-R11, R15] // pop {r4-r11, pc} + ADD $(16 + callbackArgs__size), R13 // free locals + MOVM.IA.W (R13), [R4-R11, R12] // pop {r4-r11, lr=>r12} + ADD $(4*4), R13 // skip r0-r3 + B (R12) // return // uint32 tstart_stdcall(M *newm); TEXT runtime·tstart_stdcall(SB),NOSPLIT|NOFRAME,$0 |
