diff --git a/src/runtime/asm_arm64.s b/src/runtime/asm_arm64.s index 62deb070aa..9ef7346e00 100644 --- a/src/runtime/asm_arm64.s +++ b/src/runtime/asm_arm64.s @@ -311,74 +311,42 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0 // spillArgs stores return values from registers to a *internal/abi.RegArgs in R20. TEXT ·spillArgs(SB),NOSPLIT,$0-0 - MOVD R0, (0*8)(R20) - MOVD R1, (1*8)(R20) - MOVD R2, (2*8)(R20) - MOVD R3, (3*8)(R20) - MOVD R4, (4*8)(R20) - MOVD R5, (5*8)(R20) - MOVD R6, (6*8)(R20) - MOVD R7, (7*8)(R20) - MOVD R8, (8*8)(R20) - MOVD R9, (9*8)(R20) - MOVD R10, (10*8)(R20) - MOVD R11, (11*8)(R20) - MOVD R12, (12*8)(R20) - MOVD R13, (13*8)(R20) - MOVD R14, (14*8)(R20) - MOVD R15, (15*8)(R20) - FMOVD F0, (16*8)(R20) - FMOVD F1, (17*8)(R20) - FMOVD F2, (18*8)(R20) - FMOVD F3, (19*8)(R20) - FMOVD F4, (20*8)(R20) - FMOVD F5, (21*8)(R20) - FMOVD F6, (22*8)(R20) - FMOVD F7, (23*8)(R20) - FMOVD F8, (24*8)(R20) - FMOVD F9, (25*8)(R20) - FMOVD F10, (26*8)(R20) - FMOVD F11, (27*8)(R20) - FMOVD F12, (28*8)(R20) - FMOVD F13, (29*8)(R20) - FMOVD F14, (30*8)(R20) - FMOVD F15, (31*8)(R20) + STP (R0, R1), (0*8)(R20) + STP (R2, R3), (2*8)(R20) + STP (R4, R5), (4*8)(R20) + STP (R6, R7), (6*8)(R20) + STP (R8, R9), (8*8)(R20) + STP (R10, R11), (10*8)(R20) + STP (R12, R13), (12*8)(R20) + STP (R14, R15), (14*8)(R20) + FSTPD (F0, F1), (16*8)(R20) + FSTPD (F2, F3), (18*8)(R20) + FSTPD (F4, F5), (20*8)(R20) + FSTPD (F6, F7), (22*8)(R20) + FSTPD (F8, F9), (24*8)(R20) + FSTPD (F10, F11), (26*8)(R20) + FSTPD (F12, F13), (28*8)(R20) + FSTPD (F14, F15), (30*8)(R20) RET // unspillArgs loads args into registers from a *internal/abi.RegArgs in R20. TEXT ·unspillArgs(SB),NOSPLIT,$0-0 - MOVD (0*8)(R20), R0 - MOVD (1*8)(R20), R1 - MOVD (2*8)(R20), R2 - MOVD (3*8)(R20), R3 - MOVD (4*8)(R20), R4 - MOVD (5*8)(R20), R5 - MOVD (6*8)(R20), R6 - MOVD (7*8)(R20), R7 - MOVD (8*8)(R20), R8 - MOVD (9*8)(R20), R9 - MOVD (10*8)(R20), R10 - MOVD (11*8)(R20), R11 - MOVD (12*8)(R20), R12 - MOVD (13*8)(R20), R13 - MOVD (14*8)(R20), R14 - MOVD (15*8)(R20), R15 - FMOVD (16*8)(R20), F0 - FMOVD (17*8)(R20), F1 - FMOVD (18*8)(R20), F2 - FMOVD (19*8)(R20), F3 - FMOVD (20*8)(R20), F4 - FMOVD (21*8)(R20), F5 - FMOVD (22*8)(R20), F6 - FMOVD (23*8)(R20), F7 - FMOVD (24*8)(R20), F8 - FMOVD (25*8)(R20), F9 - FMOVD (26*8)(R20), F10 - FMOVD (27*8)(R20), F11 - FMOVD (28*8)(R20), F12 - FMOVD (29*8)(R20), F13 - FMOVD (30*8)(R20), F14 - FMOVD (31*8)(R20), F15 + LDP (0*8)(R20), (R0, R1) + LDP (2*8)(R20), (R2, R3) + LDP (4*8)(R20), (R4, R5) + LDP (6*8)(R20), (R6, R7) + LDP (8*8)(R20), (R8, R9) + LDP (10*8)(R20), (R10, R11) + LDP (12*8)(R20), (R12, R13) + LDP (14*8)(R20), (R14, R15) + FLDPD (16*8)(R20), (F0, F1) + FLDPD (18*8)(R20), (F2, F3) + FLDPD (20*8)(R20), (F4, F5) + FLDPD (22*8)(R20), (F6, F7) + FLDPD (24*8)(R20), (F8, F9) + FLDPD (26*8)(R20), (F10, F11) + FLDPD (28*8)(R20), (F12, F13) + FLDPD (30*8)(R20), (F14, F15) RET // reflectcall: call a function with the given argument list @@ -480,10 +448,8 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-48; \ // arguments in registers. TEXT callRet<>(SB), NOSPLIT, $48-0 NO_LOCAL_POINTERS - MOVD R7, 8(RSP) - MOVD R3, 16(RSP) - MOVD R5, 24(RSP) - MOVD R4, 32(RSP) + STP (R7, R3), 8(RSP) + STP (R5, R4), 24(RSP) MOVD R20, 40(RSP) BL runtime·reflectcallmove(SB) RET @@ -1215,8 +1181,7 @@ TEXT ·checkASM(SB),NOSPLIT,$0-1 // calls to it directly and it does not use the stack-based Go ABI. TEXT runtime·gcWriteBarrier(SB),NOSPLIT,$200 // Save the registers clobbered by the fast path. - MOVD R0, 184(RSP) - MOVD R1, 192(RSP) + STP (R0, R1), 184(RSP) MOVD g_m(g), R0 MOVD m_p(R0), R0 MOVD (p_wbBuf+wbBuf_next)(R0), R1 @@ -1232,8 +1197,7 @@ TEXT runtime·gcWriteBarrier(SB),NOSPLIT,$200 // Is the buffer full? (flags set in CMP above) BEQ flush ret: - MOVD 184(RSP), R0 - MOVD 192(RSP), R1 + LDP 184(RSP), (R0, R1) // Do the write. MOVD R3, (R2) RET @@ -1241,32 +1205,20 @@ ret: flush: // Save all general purpose registers since these could be // clobbered by wbBufFlush and were not saved by the caller. - MOVD R2, 8(RSP) // Also first argument to wbBufFlush - MOVD R3, 16(RSP) // Also second argument to wbBufFlush - // R0 already saved - // R1 already saved - MOVD R4, 24(RSP) - MOVD R5, 32(RSP) - MOVD R6, 40(RSP) - MOVD R7, 48(RSP) - MOVD R8, 56(RSP) - MOVD R9, 64(RSP) - MOVD R10, 72(RSP) - MOVD R11, 80(RSP) - MOVD R12, 88(RSP) - MOVD R13, 96(RSP) - MOVD R14, 104(RSP) - MOVD R15, 112(RSP) + // R0 and R1 already saved + STP (R2, R3), 1*8(RSP) // Also first and second arguments to wbBufFlush + STP (R4, R5), 3*8(RSP) + STP (R6, R7), 5*8(RSP) + STP (R8, R9), 7*8(RSP) + STP (R10, R11), 9*8(RSP) + STP (R12, R13), 11*8(RSP) + STP (R14, R15), 13*8(RSP) // R16, R17 may be clobbered by linker trampoline // R18 is unused. - MOVD R19, 120(RSP) - MOVD R20, 128(RSP) - MOVD R21, 136(RSP) - MOVD R22, 144(RSP) - MOVD R23, 152(RSP) - MOVD R24, 160(RSP) - MOVD R25, 168(RSP) - MOVD R26, 176(RSP) + STP (R19, R20), 15*8(RSP) + STP (R21, R22), 17*8(RSP) + STP (R23, R24), 19*8(RSP) + STP (R25, R26), 21*8(RSP) // R27 is temp register. // R28 is g. // R29 is frame pointer (unused). @@ -1275,29 +1227,17 @@ flush: // This takes arguments R2 and R3. CALL runtime·wbBufFlush(SB) - - MOVD 8(RSP), R2 - MOVD 16(RSP), R3 - MOVD 24(RSP), R4 - MOVD 32(RSP), R5 - MOVD 40(RSP), R6 - MOVD 48(RSP), R7 - MOVD 56(RSP), R8 - MOVD 64(RSP), R9 - MOVD 72(RSP), R10 - MOVD 80(RSP), R11 - MOVD 88(RSP), R12 - MOVD 96(RSP), R13 - MOVD 104(RSP), R14 - MOVD 112(RSP), R15 - MOVD 120(RSP), R19 - MOVD 128(RSP), R20 - MOVD 136(RSP), R21 - MOVD 144(RSP), R22 - MOVD 152(RSP), R23 - MOVD 160(RSP), R24 - MOVD 168(RSP), R25 - MOVD 176(RSP), R26 + LDP 1*8(RSP), (R2, R3) + LDP 3*8(RSP), (R4, R5) + LDP 5*8(RSP), (R6, R7) + LDP 7*8(RSP), (R8, R9) + LDP 9*8(RSP), (R10, R11) + LDP 11*8(RSP), (R12, R13) + LDP 13*8(RSP), (R14, R15) + LDP 15*8(RSP), (R19, R20) + LDP 17*8(RSP), (R21, R22) + LDP 19*8(RSP), (R23, R24) + LDP 21*8(RSP), (R25, R26) JMP ret // Note: these functions use a special calling convention to save generated code space. diff --git a/src/runtime/cgo/abi_arm64.h b/src/runtime/cgo/abi_arm64.h new file mode 100644 index 0000000000..e2b5e6d0be --- /dev/null +++ b/src/runtime/cgo/abi_arm64.h @@ -0,0 +1,43 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Macros for transitioning from the host ABI to Go ABI0. +// +// These macros save and restore the callee-saved registers +// from the stack, but they don't adjust stack pointer, so +// the user should prepare stack space in advance. +// SAVE_R19_TO_R28(offset) saves R19 ~ R28 to the stack space +// of ((offset)+0*8)(RSP) ~ ((offset)+9*8)(RSP). +// +// SAVE_F8_TO_F15(offset) saves F8 ~ F15 to the stack space +// of ((offset)+0*8)(RSP) ~ ((offset)+7*8)(RSP). +// +// R29 is not saved because Go will save and restore it. + +#define SAVE_R19_TO_R28(offset) \ + STP (R19, R20), ((offset)+0*8)(RSP) \ + STP (R21, R22), ((offset)+2*8)(RSP) \ + STP (R23, R24), ((offset)+4*8)(RSP) \ + STP (R25, R26), ((offset)+6*8)(RSP) \ + STP (R27, g), ((offset)+8*8)(RSP) + +#define RESTORE_R19_TO_R28(offset) \ + LDP ((offset)+0*8)(RSP), (R19, R20) \ + LDP ((offset)+2*8)(RSP), (R21, R22) \ + LDP ((offset)+4*8)(RSP), (R23, R24) \ + LDP ((offset)+6*8)(RSP), (R25, R26) \ + LDP ((offset)+8*8)(RSP), (R27, g) /* R28 */ + +#define SAVE_F8_TO_F15(offset) \ + FSTPD (F8, F9), ((offset)+0*8)(RSP) \ + FSTPD (F10, F11), ((offset)+2*8)(RSP) \ + FSTPD (F12, F13), ((offset)+4*8)(RSP) \ + FSTPD (F14, F15), ((offset)+6*8)(RSP) + +#define RESTORE_F8_TO_F15(offset) \ + FLDPD ((offset)+0*8)(RSP), (F8, F9) \ + FLDPD ((offset)+2*8)(RSP), (F10, F11) \ + FLDPD ((offset)+4*8)(RSP), (F12, F13) \ + FLDPD ((offset)+6*8)(RSP), (F14, F15) + diff --git a/src/runtime/cgo/asm_arm64.s b/src/runtime/cgo/asm_arm64.s index 1cb25cf89e..e808dedcfc 100644 --- a/src/runtime/cgo/asm_arm64.s +++ b/src/runtime/cgo/asm_arm64.s @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. #include "textflag.h" +#include "abi_arm64.h" // Called by C code generated by cmd/cgo. // func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr) @@ -14,57 +15,23 @@ TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0 * push 3 args for fn (R0, R1, R3), skipping R2. * Also note that at procedure entry in gc world, 8(RSP) will be the * first arg. - * TODO(minux): use LDP/STP here if it matters. */ SUB $(8*24), RSP - MOVD R0, (8*1)(RSP) - MOVD R1, (8*2)(RSP) + STP (R0, R1), (8*1)(RSP) MOVD R3, (8*3)(RSP) - MOVD R19, (8*4)(RSP) - MOVD R20, (8*5)(RSP) - MOVD R21, (8*6)(RSP) - MOVD R22, (8*7)(RSP) - MOVD R23, (8*8)(RSP) - MOVD R24, (8*9)(RSP) - MOVD R25, (8*10)(RSP) - MOVD R26, (8*11)(RSP) - MOVD R27, (8*12)(RSP) - MOVD g, (8*13)(RSP) - MOVD R29, (8*14)(RSP) - MOVD R30, (8*15)(RSP) - FMOVD F8, (8*16)(RSP) - FMOVD F9, (8*17)(RSP) - FMOVD F10, (8*18)(RSP) - FMOVD F11, (8*19)(RSP) - FMOVD F12, (8*20)(RSP) - FMOVD F13, (8*21)(RSP) - FMOVD F14, (8*22)(RSP) - FMOVD F15, (8*23)(RSP) + + SAVE_R19_TO_R28(8*4) + SAVE_F8_TO_F15(8*14) + STP (R29, R30), (8*22)(RSP) + // Initialize Go ABI environment BL runtime·load_g(SB) - BL runtime·cgocallback(SB) - MOVD (8*4)(RSP), R19 - MOVD (8*5)(RSP), R20 - MOVD (8*6)(RSP), R21 - MOVD (8*7)(RSP), R22 - MOVD (8*8)(RSP), R23 - MOVD (8*9)(RSP), R24 - MOVD (8*10)(RSP), R25 - MOVD (8*11)(RSP), R26 - MOVD (8*12)(RSP), R27 - MOVD (8*13)(RSP), g - MOVD (8*14)(RSP), R29 - MOVD (8*15)(RSP), R30 - FMOVD (8*16)(RSP), F8 - FMOVD (8*17)(RSP), F9 - FMOVD (8*18)(RSP), F10 - FMOVD (8*19)(RSP), F11 - FMOVD (8*20)(RSP), F12 - FMOVD (8*21)(RSP), F13 - FMOVD (8*22)(RSP), F14 - FMOVD (8*23)(RSP), F15 + RESTORE_R19_TO_R28(8*4) + RESTORE_F8_TO_F15(8*14) + LDP (8*22)(RSP), (R29, R30) + ADD $(8*24), RSP RET diff --git a/src/runtime/race_arm64.s b/src/runtime/race_arm64.s index 8c0dd25f0b..edbb3b12c7 100644 --- a/src/runtime/race_arm64.s +++ b/src/runtime/race_arm64.s @@ -8,6 +8,7 @@ #include "funcdata.h" #include "textflag.h" #include "tls_arm64.h" +#include "cgo/abi_arm64.h" // The following thunks allow calling the gcc-compiled race runtime directly // from Go code without going all the way through cgo. @@ -450,13 +451,12 @@ TEXT runtime·racecallbackthunk(SB), NOSPLIT|NOFRAME, $0 rest: // Save callee-saved registers (Go code won't respect that). // 8(RSP) and 16(RSP) are for args passed through racecallback - SUB $112, RSP + SUB $176, RSP MOVD LR, 0(RSP) - STP (R19, R20), 24(RSP) - STP (R21, R22), 40(RSP) - STP (R23, R24), 56(RSP) - STP (R25, R26), 72(RSP) - STP (R27, g), 88(RSP) + + SAVE_R19_TO_R28(8*3) + SAVE_F8_TO_F15(8*13) + MOVD R29, (8*21)(RSP) // Set g = g0. // load_g will clobber R0, Save R0 MOVD R0, R13 @@ -479,12 +479,10 @@ rest: ret: // Restore callee-saved registers. MOVD 0(RSP), LR - LDP 24(RSP), (R19, R20) - LDP 40(RSP), (R21, R22) - LDP 56(RSP), (R23, R24) - LDP 72(RSP), (R25, R26) - LDP 88(RSP), (R27, g) - ADD $112, RSP + MOVD (8*21)(RSP), R29 + RESTORE_F8_TO_F15(8*13) + RESTORE_R19_TO_R28(8*3) + ADD $176, RSP JMP (LR) noswitch: diff --git a/src/runtime/rt0_darwin_arm64.s b/src/runtime/rt0_darwin_arm64.s index 0040361215..697104ac64 100644 --- a/src/runtime/rt0_darwin_arm64.s +++ b/src/runtime/rt0_darwin_arm64.s @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. #include "textflag.h" +#include "cgo/abi_arm64.h" TEXT _rt0_arm64_darwin(SB),NOSPLIT|NOFRAME,$0 MOVD $runtime·rt0_go(SB), R2 @@ -18,26 +19,10 @@ exit: // // Note that all currently shipping darwin/arm64 platforms require // cgo and do not support c-shared. -TEXT _rt0_arm64_darwin_lib(SB),NOSPLIT,$168 +TEXT _rt0_arm64_darwin_lib(SB),NOSPLIT,$152 // Preserve callee-save registers. - MOVD R19, 24(RSP) - MOVD R20, 32(RSP) - MOVD R21, 40(RSP) - MOVD R22, 48(RSP) - MOVD R23, 56(RSP) - MOVD R24, 64(RSP) - MOVD R25, 72(RSP) - MOVD R26, 80(RSP) - MOVD R27, 88(RSP) - MOVD g, 96(RSP) - FMOVD F8, 104(RSP) - FMOVD F9, 112(RSP) - FMOVD F10, 120(RSP) - FMOVD F11, 128(RSP) - FMOVD F12, 136(RSP) - FMOVD F13, 144(RSP) - FMOVD F14, 152(RSP) - FMOVD F15, 160(RSP) + SAVE_R19_TO_R28(8) + SAVE_F8_TO_F15(88) MOVD R0, _rt0_arm64_darwin_lib_argc<>(SB) MOVD R1, _rt0_arm64_darwin_lib_argv<>(SB) @@ -57,24 +42,8 @@ TEXT _rt0_arm64_darwin_lib(SB),NOSPLIT,$168 ADD $16, RSP // Restore callee-save registers. - MOVD 24(RSP), R19 - MOVD 32(RSP), R20 - MOVD 40(RSP), R21 - MOVD 48(RSP), R22 - MOVD 56(RSP), R23 - MOVD 64(RSP), R24 - MOVD 72(RSP), R25 - MOVD 80(RSP), R26 - MOVD 88(RSP), R27 - MOVD 96(RSP), g - FMOVD 104(RSP), F8 - FMOVD 112(RSP), F9 - FMOVD 120(RSP), F10 - FMOVD 128(RSP), F11 - FMOVD 136(RSP), F12 - FMOVD 144(RSP), F13 - FMOVD 152(RSP), F14 - FMOVD 160(RSP), F15 + RESTORE_R19_TO_R28(8) + RESTORE_F8_TO_F15(88) RET diff --git a/src/runtime/rt0_freebsd_arm64.s b/src/runtime/rt0_freebsd_arm64.s index a938d98262..e517ae059d 100644 --- a/src/runtime/rt0_freebsd_arm64.s +++ b/src/runtime/rt0_freebsd_arm64.s @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. #include "textflag.h" +#include "cgo/abi_arm64.h" // On FreeBSD argc/argv are passed in R0, not RSP TEXT _rt0_arm64_freebsd(SB),NOSPLIT|NOFRAME,$0 @@ -14,24 +15,8 @@ TEXT _rt0_arm64_freebsd(SB),NOSPLIT|NOFRAME,$0 // library is loaded. TEXT _rt0_arm64_freebsd_lib(SB),NOSPLIT,$184 // Preserve callee-save registers. - MOVD R19, 24(RSP) - MOVD R20, 32(RSP) - MOVD R21, 40(RSP) - MOVD R22, 48(RSP) - MOVD R23, 56(RSP) - MOVD R24, 64(RSP) - MOVD R25, 72(RSP) - MOVD R26, 80(RSP) - MOVD R27, 88(RSP) - FMOVD F8, 96(RSP) - FMOVD F9, 104(RSP) - FMOVD F10, 112(RSP) - FMOVD F11, 120(RSP) - FMOVD F12, 128(RSP) - FMOVD F13, 136(RSP) - FMOVD F14, 144(RSP) - FMOVD F15, 152(RSP) - MOVD g, 160(RSP) + SAVE_R19_TO_R28(24) + SAVE_F8_TO_F15(104) // Initialize g as null in case of using g later e.g. sigaction in cgo_sigaction.go MOVD ZR, g @@ -63,24 +48,8 @@ nocgo: restore: // Restore callee-save registers. - MOVD 24(RSP), R19 - MOVD 32(RSP), R20 - MOVD 40(RSP), R21 - MOVD 48(RSP), R22 - MOVD 56(RSP), R23 - MOVD 64(RSP), R24 - MOVD 72(RSP), R25 - MOVD 80(RSP), R26 - MOVD 88(RSP), R27 - FMOVD 96(RSP), F8 - FMOVD 104(RSP), F9 - FMOVD 112(RSP), F10 - FMOVD 120(RSP), F11 - FMOVD 128(RSP), F12 - FMOVD 136(RSP), F13 - FMOVD 144(RSP), F14 - FMOVD 152(RSP), F15 - MOVD 160(RSP), g + RESTORE_R19_TO_R28(24) + RESTORE_F8_TO_F15(104) RET TEXT _rt0_arm64_freebsd_lib_go(SB),NOSPLIT,$0 diff --git a/src/runtime/rt0_linux_arm64.s b/src/runtime/rt0_linux_arm64.s index f48a8d6190..0eb8fc2f48 100644 --- a/src/runtime/rt0_linux_arm64.s +++ b/src/runtime/rt0_linux_arm64.s @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. #include "textflag.h" +#include "cgo/abi_arm64.h" TEXT _rt0_arm64_linux(SB),NOSPLIT|NOFRAME,$0 MOVD 0(RSP), R0 // argc @@ -13,24 +14,8 @@ TEXT _rt0_arm64_linux(SB),NOSPLIT|NOFRAME,$0 // library is loaded. TEXT _rt0_arm64_linux_lib(SB),NOSPLIT,$184 // Preserve callee-save registers. - MOVD R19, 24(RSP) - MOVD R20, 32(RSP) - MOVD R21, 40(RSP) - MOVD R22, 48(RSP) - MOVD R23, 56(RSP) - MOVD R24, 64(RSP) - MOVD R25, 72(RSP) - MOVD R26, 80(RSP) - MOVD R27, 88(RSP) - FMOVD F8, 96(RSP) - FMOVD F9, 104(RSP) - FMOVD F10, 112(RSP) - FMOVD F11, 120(RSP) - FMOVD F12, 128(RSP) - FMOVD F13, 136(RSP) - FMOVD F14, 144(RSP) - FMOVD F15, 152(RSP) - MOVD g, 160(RSP) + SAVE_R19_TO_R28(24) + SAVE_F8_TO_F15(104) // Initialize g as null in case of using g later e.g. sigaction in cgo_sigaction.go MOVD ZR, g @@ -62,24 +47,8 @@ nocgo: restore: // Restore callee-save registers. - MOVD 24(RSP), R19 - MOVD 32(RSP), R20 - MOVD 40(RSP), R21 - MOVD 48(RSP), R22 - MOVD 56(RSP), R23 - MOVD 64(RSP), R24 - MOVD 72(RSP), R25 - MOVD 80(RSP), R26 - MOVD 88(RSP), R27 - FMOVD 96(RSP), F8 - FMOVD 104(RSP), F9 - FMOVD 112(RSP), F10 - FMOVD 120(RSP), F11 - FMOVD 128(RSP), F12 - FMOVD 136(RSP), F13 - FMOVD 144(RSP), F14 - FMOVD 152(RSP), F15 - MOVD 160(RSP), g + RESTORE_R19_TO_R28(24) + RESTORE_F8_TO_F15(104) RET TEXT _rt0_arm64_linux_lib_go(SB),NOSPLIT,$0 diff --git a/src/runtime/rt0_netbsd_arm64.s b/src/runtime/rt0_netbsd_arm64.s index 2f3b5a5a87..691a8e4be7 100644 --- a/src/runtime/rt0_netbsd_arm64.s +++ b/src/runtime/rt0_netbsd_arm64.s @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. #include "textflag.h" +#include "cgo/abi_arm64.h" TEXT _rt0_arm64_netbsd(SB),NOSPLIT|NOFRAME,$0 MOVD 0(RSP), R0 // argc @@ -13,24 +14,8 @@ TEXT _rt0_arm64_netbsd(SB),NOSPLIT|NOFRAME,$0 // library is loaded. TEXT _rt0_arm64_netbsd_lib(SB),NOSPLIT,$184 // Preserve callee-save registers. - MOVD R19, 24(RSP) - MOVD R20, 32(RSP) - MOVD R21, 40(RSP) - MOVD R22, 48(RSP) - MOVD R23, 56(RSP) - MOVD R24, 64(RSP) - MOVD R25, 72(RSP) - MOVD R26, 80(RSP) - MOVD R27, 88(RSP) - FMOVD F8, 96(RSP) - FMOVD F9, 104(RSP) - FMOVD F10, 112(RSP) - FMOVD F11, 120(RSP) - FMOVD F12, 128(RSP) - FMOVD F13, 136(RSP) - FMOVD F14, 144(RSP) - FMOVD F15, 152(RSP) - MOVD g, 160(RSP) + SAVE_R19_TO_R28(24) + SAVE_F8_TO_F15(104) // Initialize g as null in case of using g later e.g. sigaction in cgo_sigaction.go MOVD ZR, g @@ -62,24 +47,8 @@ nocgo: restore: // Restore callee-save registers. - MOVD 24(RSP), R19 - MOVD 32(RSP), R20 - MOVD 40(RSP), R21 - MOVD 48(RSP), R22 - MOVD 56(RSP), R23 - MOVD 64(RSP), R24 - MOVD 72(RSP), R25 - MOVD 80(RSP), R26 - MOVD 88(RSP), R27 - FMOVD 96(RSP), F8 - FMOVD 104(RSP), F9 - FMOVD 112(RSP), F10 - FMOVD 120(RSP), F11 - FMOVD 128(RSP), F12 - FMOVD 136(RSP), F13 - FMOVD 144(RSP), F14 - FMOVD 152(RSP), F15 - MOVD 160(RSP), g + RESTORE_R19_TO_R28(24) + RESTORE_F8_TO_F15(104) RET TEXT _rt0_arm64_netbsd_lib_go(SB),NOSPLIT,$0 diff --git a/src/runtime/rt0_openbsd_arm64.s b/src/runtime/rt0_openbsd_arm64.s index 722fab6129..49d49b34ac 100644 --- a/src/runtime/rt0_openbsd_arm64.s +++ b/src/runtime/rt0_openbsd_arm64.s @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. #include "textflag.h" +#include "cgo/abi_arm64.h" // See comment in runtime/sys_openbsd_arm64.s re this construction. #define INVOKE_SYSCALL \ @@ -19,24 +20,8 @@ TEXT _rt0_arm64_openbsd(SB),NOSPLIT|NOFRAME,$0 // library is loaded. TEXT _rt0_arm64_openbsd_lib(SB),NOSPLIT,$184 // Preserve callee-save registers. - MOVD R19, 24(RSP) - MOVD R20, 32(RSP) - MOVD R21, 40(RSP) - MOVD R22, 48(RSP) - MOVD R23, 56(RSP) - MOVD R24, 64(RSP) - MOVD R25, 72(RSP) - MOVD R26, 80(RSP) - MOVD R27, 88(RSP) - FMOVD F8, 96(RSP) - FMOVD F9, 104(RSP) - FMOVD F10, 112(RSP) - FMOVD F11, 120(RSP) - FMOVD F12, 128(RSP) - FMOVD F13, 136(RSP) - FMOVD F14, 144(RSP) - FMOVD F15, 152(RSP) - MOVD g, 160(RSP) + SAVE_R19_TO_R28(24) + SAVE_F8_TO_F15(104) // Initialize g as null in case of using g later e.g. sigaction in cgo_sigaction.go MOVD ZR, g @@ -68,24 +53,8 @@ nocgo: restore: // Restore callee-save registers. - MOVD 24(RSP), R19 - MOVD 32(RSP), R20 - MOVD 40(RSP), R21 - MOVD 48(RSP), R22 - MOVD 56(RSP), R23 - MOVD 64(RSP), R24 - MOVD 72(RSP), R25 - MOVD 80(RSP), R26 - MOVD 88(RSP), R27 - FMOVD 96(RSP), F8 - FMOVD 104(RSP), F9 - FMOVD 112(RSP), F10 - FMOVD 120(RSP), F11 - FMOVD 128(RSP), F12 - FMOVD 136(RSP), F13 - FMOVD 144(RSP), F14 - FMOVD 152(RSP), F15 - MOVD 160(RSP), g + RESTORE_R19_TO_R28(24) + RESTORE_F8_TO_F15(104) RET TEXT _rt0_arm64_openbsd_lib_go(SB),NOSPLIT,$0 diff --git a/src/runtime/sys_darwin_arm64.s b/src/runtime/sys_darwin_arm64.s index e57ac53e10..dc7c9bffa8 100644 --- a/src/runtime/sys_darwin_arm64.s +++ b/src/runtime/sys_darwin_arm64.s @@ -9,6 +9,7 @@ #include "go_asm.h" #include "go_tls.h" #include "textflag.h" +#include "cgo/abi_arm64.h" #define CLOCK_REALTIME 0 @@ -175,28 +176,11 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 BL (R11) RET -TEXT runtime·sigtramp(SB),NOSPLIT,$192 +TEXT runtime·sigtramp(SB),NOSPLIT,$176 // Save callee-save registers in the case of signal forwarding. // Please refer to https://golang.org/issue/31827 . - MOVD R19, 8*4(RSP) - MOVD R20, 8*5(RSP) - MOVD R21, 8*6(RSP) - MOVD R22, 8*7(RSP) - MOVD R23, 8*8(RSP) - MOVD R24, 8*9(RSP) - MOVD R25, 8*10(RSP) - MOVD R26, 8*11(RSP) - MOVD R27, 8*12(RSP) - MOVD g, 8*13(RSP) - MOVD R29, 8*14(RSP) - FMOVD F8, 8*15(RSP) - FMOVD F9, 8*16(RSP) - FMOVD F10, 8*17(RSP) - FMOVD F11, 8*18(RSP) - FMOVD F12, 8*19(RSP) - FMOVD F13, 8*20(RSP) - FMOVD F14, 8*21(RSP) - FMOVD F15, 8*22(RSP) + SAVE_R19_TO_R28(8*4) + SAVE_F8_TO_F15(8*14) // Save arguments. MOVW R0, (8*1)(RSP) // sig @@ -249,25 +233,8 @@ nog: #endif // Restore callee-save registers. - MOVD (8*4)(RSP), R19 - MOVD (8*5)(RSP), R20 - MOVD (8*6)(RSP), R21 - MOVD (8*7)(RSP), R22 - MOVD (8*8)(RSP), R23 - MOVD (8*9)(RSP), R24 - MOVD (8*10)(RSP), R25 - MOVD (8*11)(RSP), R26 - MOVD (8*12)(RSP), R27 - MOVD (8*13)(RSP), g - MOVD (8*14)(RSP), R29 - FMOVD (8*15)(RSP), F8 - FMOVD (8*16)(RSP), F9 - FMOVD (8*17)(RSP), F10 - FMOVD (8*18)(RSP), F11 - FMOVD (8*19)(RSP), F12 - FMOVD (8*20)(RSP), F13 - FMOVD (8*21)(RSP), F14 - FMOVD (8*22)(RSP), F15 + RESTORE_R19_TO_R28(8*4) + RESTORE_F8_TO_F15(8*14) RET @@ -376,25 +343,8 @@ TEXT runtime·mstart_stub(SB),NOSPLIT,$160 // We are already on m's g0 stack. // Save callee-save registers. - MOVD R19, 8(RSP) - MOVD R20, 16(RSP) - MOVD R21, 24(RSP) - MOVD R22, 32(RSP) - MOVD R23, 40(RSP) - MOVD R24, 48(RSP) - MOVD R25, 56(RSP) - MOVD R26, 64(RSP) - MOVD R27, 72(RSP) - MOVD g, 80(RSP) - MOVD R29, 88(RSP) - FMOVD F8, 96(RSP) - FMOVD F9, 104(RSP) - FMOVD F10, 112(RSP) - FMOVD F11, 120(RSP) - FMOVD F12, 128(RSP) - FMOVD F13, 136(RSP) - FMOVD F14, 144(RSP) - FMOVD F15, 152(RSP) + SAVE_R19_TO_R28(8) + SAVE_F8_TO_F15(88) MOVD m_g0(R0), g BL ·save_g(SB) @@ -402,25 +352,8 @@ TEXT runtime·mstart_stub(SB),NOSPLIT,$160 BL runtime·mstart(SB) // Restore callee-save registers. - MOVD 8(RSP), R19 - MOVD 16(RSP), R20 - MOVD 24(RSP), R21 - MOVD 32(RSP), R22 - MOVD 40(RSP), R23 - MOVD 48(RSP), R24 - MOVD 56(RSP), R25 - MOVD 64(RSP), R26 - MOVD 72(RSP), R27 - MOVD 80(RSP), g - MOVD 88(RSP), R29 - FMOVD 96(RSP), F8 - FMOVD 104(RSP), F9 - FMOVD 112(RSP), F10 - FMOVD 120(RSP), F11 - FMOVD 128(RSP), F12 - FMOVD 136(RSP), F13 - FMOVD 144(RSP), F14 - FMOVD 152(RSP), F15 + RESTORE_R19_TO_R28(8) + RESTORE_F8_TO_F15(88) // Go is all done with this OS thread. // Tell pthread everything is ok (we never join with this thread, so diff --git a/src/runtime/sys_freebsd_arm64.s b/src/runtime/sys_freebsd_arm64.s index 59adf4e5f3..7b05fb0900 100644 --- a/src/runtime/sys_freebsd_arm64.s +++ b/src/runtime/sys_freebsd_arm64.s @@ -10,6 +10,7 @@ #include "go_asm.h" #include "go_tls.h" #include "textflag.h" +#include "cgo/abi_arm64.h" #define CLOCK_REALTIME 0 #define CLOCK_MONOTONIC 4 @@ -279,28 +280,11 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 RET // func sigtramp() -TEXT runtime·sigtramp(SB),NOSPLIT,$192 +TEXT runtime·sigtramp(SB),NOSPLIT,$176 // Save callee-save registers in the case of signal forwarding. // Please refer to https://golang.org/issue/31827 . - MOVD R19, 8*4(RSP) - MOVD R20, 8*5(RSP) - MOVD R21, 8*6(RSP) - MOVD R22, 8*7(RSP) - MOVD R23, 8*8(RSP) - MOVD R24, 8*9(RSP) - MOVD R25, 8*10(RSP) - MOVD R26, 8*11(RSP) - MOVD R27, 8*12(RSP) - MOVD g, 8*13(RSP) - MOVD R29, 8*14(RSP) - FMOVD F8, 8*15(RSP) - FMOVD F9, 8*16(RSP) - FMOVD F10, 8*17(RSP) - FMOVD F11, 8*18(RSP) - FMOVD F12, 8*19(RSP) - FMOVD F13, 8*20(RSP) - FMOVD F14, 8*21(RSP) - FMOVD F15, 8*22(RSP) + SAVE_R19_TO_R28(8*4) + SAVE_F8_TO_F15(8*14) // this might be called in external code context, // where g is not set. @@ -317,25 +301,8 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$192 BL (R0) // Restore callee-save registers. - MOVD 8*4(RSP), R19 - MOVD 8*5(RSP), R20 - MOVD 8*6(RSP), R21 - MOVD 8*7(RSP), R22 - MOVD 8*8(RSP), R23 - MOVD 8*9(RSP), R24 - MOVD 8*10(RSP), R25 - MOVD 8*11(RSP), R26 - MOVD 8*12(RSP), R27 - MOVD 8*13(RSP), g - MOVD 8*14(RSP), R29 - FMOVD 8*15(RSP), F8 - FMOVD 8*16(RSP), F9 - FMOVD 8*17(RSP), F10 - FMOVD 8*18(RSP), F11 - FMOVD 8*19(RSP), F12 - FMOVD 8*20(RSP), F13 - FMOVD 8*21(RSP), F14 - FMOVD 8*22(RSP), F15 + RESTORE_R19_TO_R28(8*4) + RESTORE_F8_TO_F15(8*14) RET diff --git a/src/runtime/sys_linux_arm64.s b/src/runtime/sys_linux_arm64.s index ca362ed552..36ac014f03 100644 --- a/src/runtime/sys_linux_arm64.s +++ b/src/runtime/sys_linux_arm64.s @@ -9,6 +9,7 @@ #include "go_asm.h" #include "go_tls.h" #include "textflag.h" +#include "cgo/abi_arm64.h" #define AT_FDCWD -100 @@ -444,28 +445,11 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 RET // Called from c-abi, R0: sig, R1: info, R2: cxt -TEXT runtime·sigtramp(SB),NOSPLIT,$192 +TEXT runtime·sigtramp(SB),NOSPLIT,$176 // Save callee-save registers in the case of signal forwarding. // Please refer to https://golang.org/issue/31827 . - MOVD R19, 8*4(RSP) - MOVD R20, 8*5(RSP) - MOVD R21, 8*6(RSP) - MOVD R22, 8*7(RSP) - MOVD R23, 8*8(RSP) - MOVD R24, 8*9(RSP) - MOVD R25, 8*10(RSP) - MOVD R26, 8*11(RSP) - MOVD R27, 8*12(RSP) - MOVD g, 8*13(RSP) - MOVD R29, 8*14(RSP) - FMOVD F8, 8*15(RSP) - FMOVD F9, 8*16(RSP) - FMOVD F10, 8*17(RSP) - FMOVD F11, 8*18(RSP) - FMOVD F12, 8*19(RSP) - FMOVD F13, 8*20(RSP) - FMOVD F14, 8*21(RSP) - FMOVD F15, 8*22(RSP) + SAVE_R19_TO_R28(8*4) + SAVE_F8_TO_F15(8*14) // this might be called in external code context, // where g is not set. @@ -481,52 +465,16 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$192 BL (R0) // Restore callee-save registers. - MOVD 8*4(RSP), R19 - MOVD 8*5(RSP), R20 - MOVD 8*6(RSP), R21 - MOVD 8*7(RSP), R22 - MOVD 8*8(RSP), R23 - MOVD 8*9(RSP), R24 - MOVD 8*10(RSP), R25 - MOVD 8*11(RSP), R26 - MOVD 8*12(RSP), R27 - MOVD 8*13(RSP), g - MOVD 8*14(RSP), R29 - FMOVD 8*15(RSP), F8 - FMOVD 8*16(RSP), F9 - FMOVD 8*17(RSP), F10 - FMOVD 8*18(RSP), F11 - FMOVD 8*19(RSP), F12 - FMOVD 8*20(RSP), F13 - FMOVD 8*21(RSP), F14 - FMOVD 8*22(RSP), F15 + RESTORE_R19_TO_R28(8*4) + RESTORE_F8_TO_F15(8*14) RET // Called from c-abi, R0: sig, R1: info, R2: cxt -TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT,$192 - // TODO(eric): In multiple places we need to save and restore the - // callee-saved registers, we can define a macro for this. +TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT,$176 // Save callee-save registers because it's a callback from c code. - MOVD R19, 8*4(RSP) - MOVD R20, 8*5(RSP) - MOVD R21, 8*6(RSP) - MOVD R22, 8*7(RSP) - MOVD R23, 8*8(RSP) - MOVD R24, 8*9(RSP) - MOVD R25, 8*10(RSP) - MOVD R26, 8*11(RSP) - MOVD R27, 8*12(RSP) - MOVD g, 8*13(RSP) - MOVD R29, 8*14(RSP) - FMOVD F8, 8*15(RSP) - FMOVD F9, 8*16(RSP) - FMOVD F10, 8*17(RSP) - FMOVD F11, 8*18(RSP) - FMOVD F12, 8*19(RSP) - FMOVD F13, 8*20(RSP) - FMOVD F14, 8*21(RSP) - FMOVD F15, 8*22(RSP) + SAVE_R19_TO_R28(8*4) + SAVE_F8_TO_F15(8*14) MOVW R0, 8(RSP) // sig MOVD R1, 16(RSP) // info @@ -534,25 +482,8 @@ TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT,$192 CALL runtime·sigprofNonGo(SB) // Restore callee-save registers. - MOVD 8*4(RSP), R19 - MOVD 8*5(RSP), R20 - MOVD 8*6(RSP), R21 - MOVD 8*7(RSP), R22 - MOVD 8*8(RSP), R23 - MOVD 8*9(RSP), R24 - MOVD 8*10(RSP), R25 - MOVD 8*11(RSP), R26 - MOVD 8*12(RSP), R27 - MOVD 8*13(RSP), g - MOVD 8*14(RSP), R29 - FMOVD 8*15(RSP), F8 - FMOVD 8*16(RSP), F9 - FMOVD 8*17(RSP), F10 - FMOVD 8*18(RSP), F11 - FMOVD 8*19(RSP), F12 - FMOVD 8*20(RSP), F13 - FMOVD 8*21(RSP), F14 - FMOVD 8*22(RSP), F15 + RESTORE_R19_TO_R28(8*4) + RESTORE_F8_TO_F15(8*14) RET // Called from c-abi, R0: sig, R1: info, R2: cxt diff --git a/src/runtime/sys_netbsd_arm64.s b/src/runtime/sys_netbsd_arm64.s index f7cce57c2d..32e6740c52 100644 --- a/src/runtime/sys_netbsd_arm64.s +++ b/src/runtime/sys_netbsd_arm64.s @@ -9,6 +9,7 @@ #include "go_asm.h" #include "go_tls.h" #include "textflag.h" +#include "cgo/abi_arm64.h" #define CLOCK_REALTIME 0 #define CLOCK_MONOTONIC 3 @@ -294,34 +295,17 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 BL (R11) RET -TEXT runtime·sigtramp(SB),NOSPLIT,$192 +TEXT runtime·sigtramp(SB),NOSPLIT,$176 // Save callee-save registers in the case of signal forwarding. // Please refer to https://golang.org/issue/31827 . - MOVD R19, 8*4(RSP) - MOVD R20, 8*5(RSP) - MOVD R21, 8*6(RSP) - MOVD R22, 8*7(RSP) - MOVD R23, 8*8(RSP) - MOVD R24, 8*9(RSP) - MOVD R25, 8*10(RSP) - MOVD R26, 8*11(RSP) - MOVD R27, 8*12(RSP) - MOVD g, 8*13(RSP) + SAVE_R19_TO_R28(8*4) + SAVE_F8_TO_F15(8*14) // Unclobber g for now (kernel uses it as ucontext ptr) // See https://github.com/golang/go/issues/30824#issuecomment-492772426 // This is only correct in the non-cgo case. // XXX should use lwp_getprivate as suggested. // 8*36 is ucontext.uc_mcontext.__gregs[_REG_X28] MOVD 8*36(g), g - MOVD R29, 8*14(RSP) - FMOVD F8, 8*15(RSP) - FMOVD F9, 8*16(RSP) - FMOVD F10, 8*17(RSP) - FMOVD F11, 8*18(RSP) - FMOVD F12, 8*19(RSP) - FMOVD F13, 8*20(RSP) - FMOVD F14, 8*21(RSP) - FMOVD F15, 8*22(RSP) // this might be called in external code context, // where g is not set. @@ -338,25 +322,8 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$192 BL runtime·sigtrampgo(SB) // Restore callee-save registers. - MOVD 8*4(RSP), R19 - MOVD 8*5(RSP), R20 - MOVD 8*6(RSP), R21 - MOVD 8*7(RSP), R22 - MOVD 8*8(RSP), R23 - MOVD 8*9(RSP), R24 - MOVD 8*10(RSP), R25 - MOVD 8*11(RSP), R26 - MOVD 8*12(RSP), R27 - MOVD 8*13(RSP), g - MOVD 8*14(RSP), R29 - FMOVD 8*15(RSP), F8 - FMOVD 8*16(RSP), F9 - FMOVD 8*17(RSP), F10 - FMOVD 8*18(RSP), F11 - FMOVD 8*19(RSP), F12 - FMOVD 8*20(RSP), F13 - FMOVD 8*21(RSP), F14 - FMOVD 8*22(RSP), F15 + RESTORE_R19_TO_R28(8*4) + RESTORE_F8_TO_F15(8*14) RET diff --git a/src/runtime/sys_openbsd_arm64.s b/src/runtime/sys_openbsd_arm64.s index 3fa7e1ede2..7c1886e0a0 100644 --- a/src/runtime/sys_openbsd_arm64.s +++ b/src/runtime/sys_openbsd_arm64.s @@ -11,6 +11,7 @@ #include "go_asm.h" #include "go_tls.h" #include "textflag.h" +#include "cgo/abi_arm64.h" #define CLOCK_REALTIME $0 #define CLOCK_MONOTONIC $3 @@ -18,30 +19,13 @@ // mstart_stub is the first function executed on a new thread started by pthread_create. // It just does some low-level setup and then calls mstart. // Note: called with the C calling convention. -TEXT runtime·mstart_stub(SB),NOSPLIT,$160 +TEXT runtime·mstart_stub(SB),NOSPLIT,$144 // R0 points to the m. // We are already on m's g0 stack. // Save callee-save registers. - MOVD R19, 8(RSP) - MOVD R20, 16(RSP) - MOVD R21, 24(RSP) - MOVD R22, 32(RSP) - MOVD R23, 40(RSP) - MOVD R24, 48(RSP) - MOVD R25, 56(RSP) - MOVD R26, 64(RSP) - MOVD R27, 72(RSP) - MOVD g, 80(RSP) - MOVD R29, 88(RSP) - FMOVD F8, 96(RSP) - FMOVD F9, 104(RSP) - FMOVD F10, 112(RSP) - FMOVD F11, 120(RSP) - FMOVD F12, 128(RSP) - FMOVD F13, 136(RSP) - FMOVD F14, 144(RSP) - FMOVD F15, 152(RSP) + SAVE_R19_TO_R28(8) + SAVE_F8_TO_F15(88) MOVD m_g0(R0), g BL runtime·save_g(SB) @@ -49,25 +33,8 @@ TEXT runtime·mstart_stub(SB),NOSPLIT,$160 BL runtime·mstart(SB) // Restore callee-save registers. - MOVD 8(RSP), R19 - MOVD 16(RSP), R20 - MOVD 24(RSP), R21 - MOVD 32(RSP), R22 - MOVD 40(RSP), R23 - MOVD 48(RSP), R24 - MOVD 56(RSP), R25 - MOVD 64(RSP), R26 - MOVD 72(RSP), R27 - MOVD 80(RSP), g - MOVD 88(RSP), R29 - FMOVD 96(RSP), F8 - FMOVD 104(RSP), F9 - FMOVD 112(RSP), F10 - FMOVD 120(RSP), F11 - FMOVD 128(RSP), F12 - FMOVD 136(RSP), F13 - FMOVD 144(RSP), F14 - FMOVD 152(RSP), F15 + RESTORE_R19_TO_R28(8) + RESTORE_F8_TO_F15(88) // Go is all done with this OS thread. // Tell pthread everything is ok (we never join with this thread, so @@ -87,25 +54,8 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 TEXT runtime·sigtramp(SB),NOSPLIT,$192 // Save callee-save registers in the case of signal forwarding. // Please refer to https://golang.org/issue/31827 . - MOVD R19, 8*4(RSP) - MOVD R20, 8*5(RSP) - MOVD R21, 8*6(RSP) - MOVD R22, 8*7(RSP) - MOVD R23, 8*8(RSP) - MOVD R24, 8*9(RSP) - MOVD R25, 8*10(RSP) - MOVD R26, 8*11(RSP) - MOVD R27, 8*12(RSP) - MOVD g, 8*13(RSP) - MOVD R29, 8*14(RSP) - FMOVD F8, 8*15(RSP) - FMOVD F9, 8*16(RSP) - FMOVD F10, 8*17(RSP) - FMOVD F11, 8*18(RSP) - FMOVD F12, 8*19(RSP) - FMOVD F13, 8*20(RSP) - FMOVD F14, 8*21(RSP) - FMOVD F15, 8*22(RSP) + SAVE_R19_TO_R28(8*4) + SAVE_F8_TO_F15(8*14) // If called from an external code context, g will not be set. // Save R0, since runtime·load_g will clobber it. @@ -117,25 +67,8 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$192 BL runtime·sigtrampgo(SB) // Restore callee-save registers. - MOVD 8*4(RSP), R19 - MOVD 8*5(RSP), R20 - MOVD 8*6(RSP), R21 - MOVD 8*7(RSP), R22 - MOVD 8*8(RSP), R23 - MOVD 8*9(RSP), R24 - MOVD 8*10(RSP), R25 - MOVD 8*11(RSP), R26 - MOVD 8*12(RSP), R27 - MOVD 8*13(RSP), g - MOVD 8*14(RSP), R29 - FMOVD 8*15(RSP), F8 - FMOVD 8*16(RSP), F9 - FMOVD 8*17(RSP), F10 - FMOVD 8*18(RSP), F11 - FMOVD 8*19(RSP), F12 - FMOVD 8*20(RSP), F13 - FMOVD 8*21(RSP), F14 - FMOVD 8*22(RSP), F15 + RESTORE_R19_TO_R28(8*4) + RESTORE_F8_TO_F15(8*14) RET diff --git a/src/runtime/sys_windows_arm64.s b/src/runtime/sys_windows_arm64.s index 87f8f0d218..7b1514f552 100644 --- a/src/runtime/sys_windows_arm64.s +++ b/src/runtime/sys_windows_arm64.s @@ -7,6 +7,7 @@ #include "textflag.h" #include "funcdata.h" #include "time_windows.h" +#include "cgo/abi_arm64.h" // Offsets into Thread Environment Block (pointer in R18) #define TEB_error 0x68 @@ -128,30 +129,6 @@ TEXT runtime·getlasterror(SB),NOSPLIT|NOFRAME,$0 MOVD R0, ret+0(FP) RET -#define SAVE_R19_TO_R28(offset) \ - MOVD R19, savedR19+((offset)+0*8)(SP); \ - MOVD R20, savedR20+((offset)+1*8)(SP); \ - MOVD R21, savedR21+((offset)+2*8)(SP); \ - MOVD R22, savedR22+((offset)+3*8)(SP); \ - MOVD R23, savedR23+((offset)+4*8)(SP); \ - MOVD R24, savedR24+((offset)+5*8)(SP); \ - MOVD R25, savedR25+((offset)+6*8)(SP); \ - MOVD R26, savedR26+((offset)+7*8)(SP); \ - MOVD R27, savedR27+((offset)+8*8)(SP); \ - MOVD g, savedR28+((offset)+9*8)(SP); - -#define RESTORE_R19_TO_R28(offset) \ - MOVD savedR19+((offset)+0*8)(SP), R19; \ - MOVD savedR20+((offset)+1*8)(SP), R20; \ - MOVD savedR21+((offset)+2*8)(SP), R21; \ - MOVD savedR22+((offset)+3*8)(SP), R22; \ - MOVD savedR23+((offset)+4*8)(SP), R23; \ - MOVD savedR24+((offset)+5*8)(SP), R24; \ - MOVD savedR25+((offset)+6*8)(SP), R25; \ - MOVD savedR26+((offset)+7*8)(SP), R26; \ - MOVD savedR27+((offset)+8*8)(SP), R27; \ - MOVD savedR28+((offset)+9*8)(SP), g; /* R28 */ - // Called by Windows as a Vectored Exception Handler (VEH). // First argument is pointer to struct containing // exception record and context pointers. @@ -221,7 +198,8 @@ TEXT sigtramp_g0<>(SB),NOSPLIT,$128 NO_LOCAL_POINTERS // Push C callee-save registers R19-R28. LR, FP already saved. - SAVE_R19_TO_R28(-10*8) + // These registers will occupy the upper 10 words of the frame. + SAVE_R19_TO_R28(8*7) MOVD 0(R0), R5 // R5 = ExceptionPointers->ExceptionRecord MOVD 8(R0), R6 // R6 = ExceptionPointers->ContextRecord @@ -275,7 +253,7 @@ TEXT sigtramp_g0<>(SB),NOSPLIT,$128 MOVD R2, context_pc(R6) return: - RESTORE_R19_TO_R28(-10*8) // smashes g + RESTORE_R19_TO_R28(8*7) // smashes g RET // Trampoline to resume execution from exception handler. @@ -317,18 +295,14 @@ TEXT runtime·callbackasm1(SB),NOSPLIT,$208-0 // but we are not called from Go so that space is ours to use, // and we must to be contiguous with the stack arguments. MOVD $arg0-(7*8)(SP), R14 - MOVD R0, (0*8)(R14) - MOVD R1, (1*8)(R14) - MOVD R2, (2*8)(R14) - MOVD R3, (3*8)(R14) - MOVD R4, (4*8)(R14) - MOVD R5, (5*8)(R14) - MOVD R6, (6*8)(R14) - MOVD R7, (7*8)(R14) + STP (R0, R1), (0*8)(R14) + STP (R2, R3), (2*8)(R14) + STP (R4, R5), (4*8)(R14) + STP (R6, R7), (6*8)(R14) // Push C callee-save registers R19-R28. // LR, FP already saved. - SAVE_R19_TO_R28(-18*8) + SAVE_R19_TO_R28(8*9) // Create a struct callbackArgs on our stack. MOVD $cbargs-(18*8+callbackArgs__size)(SP), R13 @@ -342,8 +316,7 @@ TEXT runtime·callbackasm1(SB),NOSPLIT,$208-0 MOVD $·callbackWrap(SB), R0 // PC of function to call, cgocallback takes an ABIInternal entry-point MOVD R13, R1 // frame (&callbackArgs{...}) MOVD $0, R2 // context - MOVD R0, (1*8)(RSP) - MOVD R1, (2*8)(RSP) + STP (R0, R1), (1*8)(RSP) MOVD R2, (3*8)(RSP) BL runtime·cgocallback(SB) @@ -351,13 +324,13 @@ TEXT runtime·callbackasm1(SB),NOSPLIT,$208-0 MOVD $cbargs-(18*8+callbackArgs__size)(SP), R13 MOVD callbackArgs_result(R13), R0 - RESTORE_R19_TO_R28(-18*8) + RESTORE_R19_TO_R28(8*9) RET // uint32 tstart_stdcall(M *newm); TEXT runtime·tstart_stdcall(SB),NOSPLIT,$96-0 - SAVE_R19_TO_R28(-10*8) + SAVE_R19_TO_R28(8*3) MOVD m_g0(R0), g MOVD R0, g_m(g) @@ -374,7 +347,7 @@ TEXT runtime·tstart_stdcall(SB),NOSPLIT,$96-0 BL runtime·emptyfunc(SB) // fault if stack check is wrong BL runtime·mstart(SB) - RESTORE_R19_TO_R28(-10*8) + RESTORE_R19_TO_R28(8*3) // Exit the thread. MOVD $0, R0