runtime/cgo: save and restore R31 for crosscall1 on loong64

According to the Loong64 procedure call standard [1], R31 is a static
register and therefore needs to be saved and restored.

Also, the R2 (thread pointer) register has been removed here, as it is
not involved in allocation.

[1]: https://github.com/loongson/la-abi-specs/blob/release/lapcs.adoc

Change-Id: I02e5d4bedf131e491f1a262aa3cbc0896cbc9488
Reviewed-on: https://go-review.googlesource.com/c/go/+/700817
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: sophie zhao <zhaoxiaolin@loongson.cn>
Reviewed-by: Meidan Li <limeidan@loongson.cn>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
Guoqi Chen
2025-09-04 17:02:01 +08:00
committed by abner chenc
parent d767064170
commit e8126bce9e

View File

@@ -8,23 +8,23 @@
* void crosscall1(void (*fn)(void), void (*setg_gcc)(void *g), void *g)
*
* Calling into the gc tool chain, where all registers are caller save.
* Called from standard lp64d ABI, where $r1, $r3, $r23-$r30, and $f24-$f31
* Called from standard lp64d ABI, where $r1, $r3, $r22-$r31, and $f24-$f31
* are callee-save, so they must be saved explicitly, along with $r1 (LR).
*/
.globl crosscall1
crosscall1:
addi.d $r3, $r3, -160
st.d $r1, $r3, 0
st.d $r23, $r3, 8
st.d $r24, $r3, 16
st.d $r25, $r3, 24
st.d $r26, $r3, 32
st.d $r27, $r3, 40
st.d $r28, $r3, 48
st.d $r29, $r3, 56
st.d $r30, $r3, 64
st.d $r2, $r3, 72
st.d $r22, $r3, 80
st.d $r22, $r3, 8
st.d $r23, $r3, 16
st.d $r24, $r3, 24
st.d $r25, $r3, 32
st.d $r26, $r3, 40
st.d $r27, $r3, 48
st.d $r28, $r3, 56
st.d $r29, $r3, 64
st.d $r30, $r3, 72
st.d $r31, $r3, 80
fst.d $f24, $r3, 88
fst.d $f25, $r3, 96
fst.d $f26, $r3, 104
@@ -40,16 +40,16 @@ crosscall1:
jirl $r1, $r5, 0 // call setg_gcc (clobbers R4)
jirl $r1, $r23, 0 // call fn
ld.d $r23, $r3, 8
ld.d $r24, $r3, 16
ld.d $r25, $r3, 24
ld.d $r26, $r3, 32
ld.d $r27, $r3, 40
ld.d $r28, $r3, 48
ld.d $r29, $r3, 56
ld.d $r30, $r3, 64
ld.d $r2, $r3, 72
ld.d $r22, $r3, 80
ld.d $r22, $r3, 8
ld.d $r23, $r3, 16
ld.d $r24, $r3, 24
ld.d $r25, $r3, 32
ld.d $r26, $r3, 40
ld.d $r27, $r3, 48
ld.d $r28, $r3, 56
ld.d $r29, $r3, 64
ld.d $r30, $r3, 72
ld.d $r31, $r3, 80
fld.d $f24, $r3, 88
fld.d $f25, $r3, 96
fld.d $f26, $r3, 104