aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorMauri de Souza Meneguzzo <mauri870@gmail.com>2024-01-25 23:11:02 +0000
committerJoel Sing <joel@sing.id.au>2024-01-27 13:31:41 +0000
commitf719d5cffdb8298eff7a5ef533fe95290e8c869c (patch)
tree1ff53eb51213104caa496854d6f9e124be95aded /src/runtime
parent99efe7c39e80b92511bb06153da4d4d8db6138a6 (diff)
downloadgo-f719d5cffdb8298eff7a5ef533fe95290e8c869c.tar.xz
runtime: crash stack support for loong64
Change-Id: Icc2641b888440cc27444b5dfb2b8ff286e6a595d GitHub-Last-Rev: f5772e32e9190ab1eed94fcf2c9e58d6bc0d74d6 GitHub-Pull-Request: golang/go#63923 Reviewed-on: https://go-review.googlesource.com/c/go/+/539536 Reviewed-by: abner chenc <chenguoqi@loongson.cn> Run-TryBot: Joel Sing <joel@sing.id.au> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/asm.s2
-rw-r--r--src/runtime/asm_loong64.s37
-rw-r--r--src/runtime/proc.go2
3 files changed, 33 insertions, 8 deletions
diff --git a/src/runtime/asm.s b/src/runtime/asm.s
index 74ae8789ab..4833fae5e9 100644
--- a/src/runtime/asm.s
+++ b/src/runtime/asm.s
@@ -15,6 +15,7 @@ TEXT ·mapinitnoop<ABIInternal>(SB),NOSPLIT,$0-0
#ifndef GOARCH_amd64
#ifndef GOARCH_arm64
+#ifndef GOARCH_loong64
#ifndef GOARCH_mips64
#ifndef GOARCH_mips64le
#ifndef GOARCH_ppc64
@@ -34,3 +35,4 @@ TEXT ·switchToCrashStack0<ABIInternal>(SB),NOSPLIT,$0-0
#endif
#endif
#endif
+#endif
diff --git a/src/runtime/asm_loong64.s b/src/runtime/asm_loong64.s
index 586bd23ed4..7c5ecb8a01 100644
--- a/src/runtime/asm_loong64.s
+++ b/src/runtime/asm_loong64.s
@@ -213,6 +213,29 @@ noswitch:
ADDV $8, R3
JMP (R4)
+// func switchToCrashStack0(fn func())
+TEXT runtime·switchToCrashStack0(SB), NOSPLIT, $0-8
+ MOVV fn+0(FP), REGCTXT // context register
+ MOVV g_m(g), R4 // curm
+
+ // set g to gcrash
+ MOVV $runtime·gcrash(SB), g // g = &gcrash
+ JAL runtime·save_g(SB)
+ MOVV R4, g_m(g) // g.m = curm
+ MOVV g, m_g0(R4) // curm.g0 = g
+
+ // switch to crashstack
+ MOVV (g_stack+stack_hi)(g), R4
+ ADDV $(-4*8), R4, R3
+
+ // call target function
+ MOVV 0(REGCTXT), R6
+ JAL (R6)
+
+ // should never return
+ JAL runtime·abort(SB)
+ UNDEF
+
/*
* support for morestack
*/
@@ -226,6 +249,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 R3, (g_sched+gobuf_sp)(g)
+ MOVV R1, (g_sched+gobuf_pc)(g)
+ MOVV R31, (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
@@ -240,13 +270,6 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
JAL runtime·abort(SB)
// Called from f.
- // Set g->sched to context in f.
- MOVV R3, (g_sched+gobuf_sp)(g)
- MOVV R1, (g_sched+gobuf_pc)(g)
- MOVV R31, (g_sched+gobuf_lr)(g)
- MOVV REGCTXT, (g_sched+gobuf_ctxt)(g)
-
- // Called from f.
// Set m->morebuf to f's caller.
MOVV R31, (m_morebuf+gobuf_pc)(R7) // f's caller's PC
MOVV R3, (m_morebuf+gobuf_sp)(R7) // f's caller's SP
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index b3caeb9a7c..c1b3ce20d5 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -579,7 +579,7 @@ func switchToCrashStack(fn func()) {
// Disable crash stack on Windows for now. Apparently, throwing an exception
// on a non-system-allocated crash stack causes EXCEPTION_STACK_OVERFLOW and
// hangs the process (see issue 63938).
-const crashStackImplemented = (GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "mips64" || GOARCH == "mips64le" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64" || GOARCH == "s390x" || GOARCH == "wasm") && GOOS != "windows"
+const crashStackImplemented = (GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "loong64" || GOARCH == "mips64" || GOARCH == "mips64le" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64" || GOARCH == "s390x" || GOARCH == "wasm") && GOOS != "windows"
//go:noescape
func switchToCrashStack0(fn func()) // in assembly