From: Mauri de Souza Meneguzzo Date: Thu, 2 Nov 2023 22:15:03 +0000 (+0000) Subject: runtime: add crash stack support for mips64x X-Git-Tag: go1.22rc1~424 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7dd94371339866b5809da2ad89b9c0b49b569ac5;p=gostls13.git runtime: add crash stack support for mips64x Change-Id: I240ea7dd6430f4c89cfdadbfa790e4a70a4fd79d GitHub-Last-Rev: 585742b5eebad7c03ec313b590e2171491b78b37 GitHub-Pull-Request: golang/go#63905 Reviewed-on: https://go-review.googlesource.com/c/go/+/539295 Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot Reviewed-by: Heschi Kreinick Run-TryBot: Mauri de Souza Meneguzzo --- diff --git a/src/runtime/asm.s b/src/runtime/asm.s index 81d3bfbb8a..012a6a095d 100644 --- a/src/runtime/asm.s +++ b/src/runtime/asm.s @@ -15,6 +15,8 @@ TEXT ·mapinitnoop(SB),NOSPLIT,$0-0 #ifndef GOARCH_amd64 #ifndef GOARCH_arm64 +#ifndef GOARCH_mips64 +#ifndef GOARCH_mips64le #ifndef GOARCH_riscv64 // stub to appease shared build mode. TEXT ·switchToCrashStack0(SB),NOSPLIT,$0-0 @@ -22,3 +24,5 @@ TEXT ·switchToCrashStack0(SB),NOSPLIT,$0-0 #endif #endif #endif +#endif +#endif diff --git a/src/runtime/asm_mips64x.s b/src/runtime/asm_mips64x.s index 19592b5695..80cd87c4af 100644 --- a/src/runtime/asm_mips64x.s +++ b/src/runtime/asm_mips64x.s @@ -205,6 +205,29 @@ noswitch: ADDV $8, R29 JMP (R4) +// func switchToCrashStack0(fn func()) +TEXT runtime·switchToCrashStack0(SB), NOSPLIT, $0-8 + MOVV fn+0(FP), REGCTXT // context register + MOVV g_m(g), R2 // curm + + // set g to gcrash + MOVV $runtime·gcrash(SB), g // g = &gcrash + CALL runtime·save_g(SB) + MOVV R2, g_m(g) // g.m = curm + MOVV g, m_g0(R2) // curm.g0 = g + + // switch to crashstack + MOVV (g_stack+stack_hi)(g), R2 + ADDV $(-4*8), R2, R29 + + // call target function + MOVV 0(REGCTXT), R25 + JAL (R25) + + // should never return + CALL runtime·abort(SB) + UNDEF + /* * support for morestack */ @@ -218,6 +241,13 @@ noswitch: // calling the scheduler calling newm calling gc), so we must // record an argument size. For that purpose, it has no arguments. TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0 + // Called from f. + // Set g->sched to context in f. + MOVV R29, (g_sched+gobuf_sp)(g) + MOVV R31, (g_sched+gobuf_pc)(g) + MOVV R3, (g_sched+gobuf_lr)(g) + MOVV REGCTXT, (g_sched+gobuf_ctxt)(g) + // Cannot grow scheduler stack (m->g0). MOVV g_m(g), R7 MOVV m_g0(R7), R8 @@ -231,13 +261,6 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0 JAL runtime·badmorestackgsignal(SB) JAL runtime·abort(SB) - // Called from f. - // Set g->sched to context in f. - MOVV R29, (g_sched+gobuf_sp)(g) - MOVV R31, (g_sched+gobuf_pc)(g) - MOVV R3, (g_sched+gobuf_lr)(g) - MOVV REGCTXT, (g_sched+gobuf_ctxt)(g) - // Called from f. // Set m->morebuf to f's caller. MOVV R3, (m_morebuf+gobuf_pc)(R7) // f's caller's PC diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 9b5f2e9a6d..7ed3068063 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -574,10 +574,10 @@ func switchToCrashStack(fn func()) { abort() } -const crashStackImplemented = GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "riscv64" +const crashStackImplemented = GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "mips64" || GOARCH == "mips64le" || GOARCH == "riscv64" //go:noescape -func switchToCrashStack0(func()) // in assembly +func switchToCrashStack0(fn func()) // in assembly func lockedOSThread() bool { gp := getg()