...
Source file
src/runtime/export_debug_ppc64le_test.go
Documentation: runtime
1
2
3
4
5
6
7 package runtime
8
9 import (
10 "internal/abi"
11 "internal/goarch"
12 "math"
13 "unsafe"
14 )
15
16 type sigContext struct {
17 savedRegs sigcontext
18 }
19
20 func sigctxtSetContextRegister(ctxt *sigctxt, x uint64) {
21 ctxt.regs().gpr[11] = x
22 }
23
24 func sigctxtAtTrapInstruction(ctxt *sigctxt) bool {
25 return *(*uint32)(unsafe.Pointer(ctxt.sigpc())) == 0x7fe00008
26 }
27
28 func sigctxtStatus(ctxt *sigctxt) uint64 {
29 return ctxt.r20()
30 }
31
32 func (h *debugCallHandler) saveSigContext(ctxt *sigctxt) {
33 sp := ctxt.sp()
34 sp -= 4 * goarch.PtrSize
35 ctxt.set_sp(sp)
36 *(*uint64)(unsafe.Pointer(uintptr(sp))) = ctxt.link()
37 ctxt.set_link(ctxt.pc())
38
39 *(*uintptr)(unsafe.Pointer(uintptr(sp - 32))) = h.argSize
40
41 h.sigCtxt.savedRegs = *ctxt.cregs()
42 }
43
44
45 func (h *debugCallHandler) debugCallRun(ctxt *sigctxt) {
46 sp := ctxt.sp()
47 memmove(unsafe.Pointer(uintptr(sp)+32), h.argp, h.argSize)
48 if h.regArgs != nil {
49 storeRegArgs(ctxt.cregs(), h.regArgs)
50 }
51
52
53 ctxt.set_link(ctxt.pc() + 4)
54
55 ctxt.set_pc(uint64(h.fv.fn))
56 sigctxtSetContextRegister(ctxt, uint64(uintptr(unsafe.Pointer(h.fv))))
57 }
58
59
60 func (h *debugCallHandler) debugCallReturn(ctxt *sigctxt) {
61 sp := ctxt.sp()
62 memmove(h.argp, unsafe.Pointer(uintptr(sp)+32), h.argSize)
63 if h.regArgs != nil {
64 loadRegArgs(h.regArgs, ctxt.cregs())
65 }
66
67 olr := *(*uint64)(unsafe.Pointer(uintptr(sp)))
68 ctxt.set_link(olr)
69 pc := ctxt.pc()
70 ctxt.set_pc(pc + 4)
71 }
72
73
74 func (h *debugCallHandler) debugCallPanicOut(ctxt *sigctxt) {
75 sp := ctxt.sp()
76 memmove(unsafe.Pointer(&h.panic), unsafe.Pointer(uintptr(sp)+32), 2*goarch.PtrSize)
77 ctxt.set_pc(ctxt.pc() + 4)
78 }
79
80
81 func (h *debugCallHandler) debugCallUnsafe(ctxt *sigctxt) {
82 sp := ctxt.sp()
83 reason := *(*string)(unsafe.Pointer(uintptr(sp) + 40))
84 h.err = plainError(reason)
85 ctxt.set_pc(ctxt.pc() + 4)
86 }
87
88
89 func (h *debugCallHandler) restoreSigContext(ctxt *sigctxt) {
90
91 pc, sp := ctxt.pc(), ctxt.sp()
92 *ctxt.cregs() = h.sigCtxt.savedRegs
93 ctxt.set_pc(pc + 4)
94 ctxt.set_sp(sp)
95 }
96
97
98
99
100
101 func storeRegArgs(dst *sigcontext, src *abi.RegArgs) {
102
103 for i := 0; i < 12; i++ {
104 if i > 7 {
105 dst.gp_regs[i+6] = uint64(src.Ints[i])
106 } else {
107 dst.gp_regs[i+3] = uint64(src.Ints[i])
108 }
109 }
110
111 for i := 0; i < 12; i++ {
112 dst.fp_regs[i+1] = math.Float64frombits(src.Floats[i])
113 }
114
115 }
116
117 func loadRegArgs(dst *abi.RegArgs, src *sigcontext) {
118
119 for i := range [12]int{} {
120 if i > 7 {
121 dst.Ints[i] = uintptr(src.gp_regs[i+6])
122 } else {
123 dst.Ints[i] = uintptr(src.gp_regs[i+3])
124 }
125 }
126
127 for i := range [12]int{} {
128 dst.Floats[i] = math.Float64bits(src.fp_regs[i+1])
129 }
130
131 }
132
View as plain text