aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMeng Zhuo <mzh@golangcn.org>2021-11-03 18:01:09 +0800
committermzh <mzh@golangcn.org>2022-04-01 01:41:42 +0000
commitbb2b16d15ead9c5b6b9e2b699aed8bdfcf7e9518 (patch)
tree3e58ba90314728de37aa6c9e2be927f4ba45a8f3 /src
parentecee4a32918c5e575303530abb9a504a235a1c71 (diff)
downloadgo-bb2b16d15ead9c5b6b9e2b699aed8bdfcf7e9518.tar.xz
reflect, runtime: add reflect support for regabi on riscv64
This CL adds regabi support needed for reflect and reimplement of CL 360994, which is reverted. Change-Id: I140673f09109dd9f72eff70aad64c0aa00d6857a Reviewed-on: https://go-review.googlesource.com/c/go/+/396077 Reviewed-by: Cherry Mui <cherryyz@google.com> Trust: mzh <mzh@golangcn.org>
Diffstat (limited to 'src')
-rw-r--r--src/reflect/asm_riscv64.s54
-rw-r--r--src/runtime/stack.go3
2 files changed, 48 insertions, 9 deletions
diff --git a/src/reflect/asm_riscv64.s b/src/reflect/asm_riscv64.s
index e707112277..1200b4d08e 100644
--- a/src/reflect/asm_riscv64.s
+++ b/src/reflect/asm_riscv64.s
@@ -5,34 +5,72 @@
#include "textflag.h"
#include "funcdata.h"
+// The frames of each of the two functions below contain two locals, at offsets
+// that are known to the runtime.
+//
+// The first local is a bool called retValid with a whole pointer-word reserved
+// for it on the stack. The purpose of this word is so that the runtime knows
+// whether the stack-allocated return space contains valid values for stack
+// scanning.
+//
+// The second local is an abi.RegArgs value whose offset is also known to the
+// runtime, so that a stack map for it can be constructed, since it contains
+// pointers visible to the GC.
+#define LOCAL_RETVALID 40
+#define LOCAL_REGARGS 48
+
+// The frame size of the functions below is
+// 32 (args of callReflect/callMethod) + (8 bool with padding) + 392 (abi.RegArgs) = 432.
+
// makeFuncStub is the code half of the function returned by MakeFunc.
// See the comment on the declaration of makeFuncStub in makefunc.go
// for more details.
// No arg size here, runtime pulls arg map out of the func value.
-TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$40
+TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$432
NO_LOCAL_POINTERS
+ ADD $LOCAL_REGARGS, SP, X25 // spillArgs using X25
+ CALL runtime·spillArgs(SB)
+ MOV CTXT, 32(SP) // save CTXT > args of moveMakeFuncArgPtrs < LOCAL_REGARGS
+ MOV CTXT, 8(SP)
+ MOV X25, 16(SP)
+ CALL ·moveMakeFuncArgPtrs(SB)
+ MOV 32(SP), CTXT // restore CTXT
+
MOV CTXT, 8(SP)
MOV $argframe+0(FP), T0
MOV T0, 16(SP)
- ADD $40, SP, T1
+ MOV ZERO, LOCAL_RETVALID(SP)
+ ADD $LOCAL_RETVALID, SP, T1
MOV T1, 24(SP)
- MOV ZERO, 32(SP)
- MOVB ZERO, 40(SP)
+ ADD $LOCAL_REGARGS, SP, T1
+ MOV T1, 32(SP)
CALL ·callReflect(SB)
+ ADD $LOCAL_REGARGS, SP, X25 // unspillArgs using X25
+ CALL runtime·unspillArgs(SB)
RET
// methodValueCall is the code half of the function returned by makeMethodValue.
// See the comment on the declaration of methodValueCall in makefunc.go
// for more details.
// No arg size here; runtime pulls arg map out of the func value.
-TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$40
+TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$432
NO_LOCAL_POINTERS
+ ADD $LOCAL_REGARGS, SP, X25 // spillArgs using X25
+ CALL runtime·spillArgs(SB)
+ MOV CTXT, 32(SP) // save CTXT
+ MOV CTXT, 8(SP)
+ MOV X25, 16(SP)
+ CALL ·moveMakeFuncArgPtrs(SB)
+ MOV 32(SP), CTXT // restore CTXT
MOV CTXT, 8(SP)
MOV $argframe+0(FP), T0
MOV T0, 16(SP)
- ADD $40, SP, T1
+ MOV ZERO, LOCAL_RETVALID(SP)
+ ADD $LOCAL_RETVALID, SP, T1
MOV T1, 24(SP)
- MOV ZERO, 32(SP)
- MOVB ZERO, 40(SP)
+ ADD $LOCAL_REGARGS, SP, T1
+ MOV T1, 32(SP) // frame size to 32+SP as callreflect args
CALL ·callMethod(SB)
+ ADD $LOCAL_REGARGS, SP, X25 // unspillArgs using X25
+ CALL runtime·unspillArgs(SB)
RET
diff --git a/src/runtime/stack.go b/src/runtime/stack.go
index edc37d4878..54a02173c3 100644
--- a/src/runtime/stack.go
+++ b/src/runtime/stack.go
@@ -1332,7 +1332,8 @@ func getStackMap(frame *stkframe, cache *pcvalueCache, debug bool) (locals, args
}
// stack objects.
- if (GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "ppc64" || GOARCH == "ppc64le") && unsafe.Sizeof(abi.RegArgs{}) > 0 && frame.argmap != nil {
+ if (GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64") &&
+ unsafe.Sizeof(abi.RegArgs{}) > 0 && frame.argmap != nil {
// argmap is set when the function is reflect.makeFuncStub or reflect.methodValueCall.
// We don't actually use argmap in this case, but we need to fake the stack object
// record for these frames which contain an internal/abi.RegArgs at a hard-coded offset.