1 | /* |
2 | * Copyright (C) 2013-2017 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | |
28 | #if ENABLE(ASSEMBLER) && CPU(MIPS) |
29 | #include "MacroAssembler.h" |
30 | |
31 | #include "ProbeContext.h" |
32 | #include <wtf/InlineASM.h> |
33 | #include <wtf/MathExtras.h> |
34 | |
35 | namespace JSC { |
36 | |
37 | #if ENABLE(MASM_PROBE) |
38 | |
39 | extern "C" void ctiMasmProbeTrampoline(); |
40 | |
41 | using namespace MIPSRegisters; |
42 | |
43 | #if COMPILER(GCC_COMPATIBLE) |
44 | |
45 | // The following are offsets for Probe::State fields accessed |
46 | // by the ctiMasmProbeTrampoline stub. |
47 | |
48 | #define PTR_SIZE 4 |
49 | #define PROBE_PROBE_FUNCTION_OFFSET (0 * PTR_SIZE) |
50 | #define PROBE_ARG_OFFSET (1 * PTR_SIZE) |
51 | #define PROBE_INIT_STACK_FUNCTION_OFFSET (2 * PTR_SIZE) |
52 | #define PROBE_INIT_STACK_ARG_OFFSET (3 * PTR_SIZE) |
53 | |
54 | #define PROBE_INSTRUCTIONS_AFTER_CALL 2 |
55 | |
56 | #define PROBE_FIRST_GPREG_OFFSET (4 * PTR_SIZE) |
57 | |
58 | #define GPREG_SIZE 4 |
59 | #define PROBE_CPU_ZR_OFFSET (PROBE_FIRST_GPREG_OFFSET + (0 * GPREG_SIZE)) |
60 | #define PROBE_CPU_AT_OFFSET (PROBE_FIRST_GPREG_OFFSET + (1 * GPREG_SIZE)) |
61 | #define PROBE_CPU_V0_OFFSET (PROBE_FIRST_GPREG_OFFSET + (2 * GPREG_SIZE)) |
62 | #define PROBE_CPU_V1_OFFSET (PROBE_FIRST_GPREG_OFFSET + (3 * GPREG_SIZE)) |
63 | #define PROBE_CPU_A0_OFFSET (PROBE_FIRST_GPREG_OFFSET + (4 * GPREG_SIZE)) |
64 | #define PROBE_CPU_A1_OFFSET (PROBE_FIRST_GPREG_OFFSET + (5 * GPREG_SIZE)) |
65 | #define PROBE_CPU_A2_OFFSET (PROBE_FIRST_GPREG_OFFSET + (6 * GPREG_SIZE)) |
66 | #define PROBE_CPU_A3_OFFSET (PROBE_FIRST_GPREG_OFFSET + (7 * GPREG_SIZE)) |
67 | #define PROBE_CPU_T0_OFFSET (PROBE_FIRST_GPREG_OFFSET + (8 * GPREG_SIZE)) |
68 | #define PROBE_CPU_T1_OFFSET (PROBE_FIRST_GPREG_OFFSET + (9 * GPREG_SIZE)) |
69 | #define PROBE_CPU_T2_OFFSET (PROBE_FIRST_GPREG_OFFSET + (10 * GPREG_SIZE)) |
70 | #define PROBE_CPU_T3_OFFSET (PROBE_FIRST_GPREG_OFFSET + (11 * GPREG_SIZE)) |
71 | #define PROBE_CPU_T4_OFFSET (PROBE_FIRST_GPREG_OFFSET + (12 * GPREG_SIZE)) |
72 | #define PROBE_CPU_T5_OFFSET (PROBE_FIRST_GPREG_OFFSET + (13 * GPREG_SIZE)) |
73 | #define PROBE_CPU_T6_OFFSET (PROBE_FIRST_GPREG_OFFSET + (14 * GPREG_SIZE)) |
74 | #define PROBE_CPU_T7_OFFSET (PROBE_FIRST_GPREG_OFFSET + (15 * GPREG_SIZE)) |
75 | #define PROBE_CPU_S0_OFFSET (PROBE_FIRST_GPREG_OFFSET + (16 * GPREG_SIZE)) |
76 | #define PROBE_CPU_S1_OFFSET (PROBE_FIRST_GPREG_OFFSET + (17 * GPREG_SIZE)) |
77 | #define PROBE_CPU_S2_OFFSET (PROBE_FIRST_GPREG_OFFSET + (18 * GPREG_SIZE)) |
78 | #define PROBE_CPU_S3_OFFSET (PROBE_FIRST_GPREG_OFFSET + (19 * GPREG_SIZE)) |
79 | #define PROBE_CPU_S4_OFFSET (PROBE_FIRST_GPREG_OFFSET + (20 * GPREG_SIZE)) |
80 | #define PROBE_CPU_S5_OFFSET (PROBE_FIRST_GPREG_OFFSET + (21 * GPREG_SIZE)) |
81 | #define PROBE_CPU_S6_OFFSET (PROBE_FIRST_GPREG_OFFSET + (22 * GPREG_SIZE)) |
82 | #define PROBE_CPU_S7_OFFSET (PROBE_FIRST_GPREG_OFFSET + (23 * GPREG_SIZE)) |
83 | #define PROBE_CPU_T8_OFFSET (PROBE_FIRST_GPREG_OFFSET + (24 * GPREG_SIZE)) |
84 | #define PROBE_CPU_T9_OFFSET (PROBE_FIRST_GPREG_OFFSET + (25 * GPREG_SIZE)) |
85 | #define PROBE_CPU_K0_OFFSET (PROBE_FIRST_GPREG_OFFSET + (26 * GPREG_SIZE)) |
86 | #define PROBE_CPU_K1_OFFSET (PROBE_FIRST_GPREG_OFFSET + (27 * GPREG_SIZE)) |
87 | #define PROBE_CPU_GP_OFFSET (PROBE_FIRST_GPREG_OFFSET + (28 * GPREG_SIZE)) |
88 | #define PROBE_CPU_SP_OFFSET (PROBE_FIRST_GPREG_OFFSET + (29 * GPREG_SIZE)) |
89 | #define PROBE_CPU_FP_OFFSET (PROBE_FIRST_GPREG_OFFSET + (30 * GPREG_SIZE)) |
90 | #define PROBE_CPU_RA_OFFSET (PROBE_FIRST_GPREG_OFFSET + (31 * GPREG_SIZE)) |
91 | |
92 | #define PROBE_FIRST_SPREG_OFFSET (PROBE_FIRST_GPREG_OFFSET + (32 * GPREG_SIZE)) |
93 | |
94 | #define PROBE_CPU_FIR_OFFSET (PROBE_FIRST_SPREG_OFFSET + (0 * GPREG_SIZE)) |
95 | #define PROBE_CPU_FCCR_OFFSET (PROBE_FIRST_SPREG_OFFSET + (25 * GPREG_SIZE)) |
96 | #define PROBE_CPU_FEXR_OFFSET (PROBE_FIRST_SPREG_OFFSET + (26 * GPREG_SIZE)) |
97 | #define PROBE_CPU_FENR_OFFSET (PROBE_FIRST_SPREG_OFFSET + (28 * GPREG_SIZE)) |
98 | #define PROBE_CPU_FCSR_OFFSET (PROBE_FIRST_SPREG_OFFSET + (31 * GPREG_SIZE)) |
99 | #define PROBE_CPU_PC_OFFSET (PROBE_FIRST_SPREG_OFFSET + (32 * GPREG_SIZE)) |
100 | |
101 | #define PROBE_FIRST_FPREG_OFFSET (PROBE_FIRST_SPREG_OFFSET + (34 * GPREG_SIZE)) |
102 | |
103 | #define FPREG_SIZE 8 |
104 | #define PROBE_CPU_F0_OFFSET (PROBE_FIRST_FPREG_OFFSET + (0 * FPREG_SIZE)) |
105 | #define PROBE_CPU_F1_OFFSET (PROBE_FIRST_FPREG_OFFSET + (1 * FPREG_SIZE)) |
106 | #define PROBE_CPU_F2_OFFSET (PROBE_FIRST_FPREG_OFFSET + (2 * FPREG_SIZE)) |
107 | #define PROBE_CPU_F3_OFFSET (PROBE_FIRST_FPREG_OFFSET + (3 * FPREG_SIZE)) |
108 | #define PROBE_CPU_F4_OFFSET (PROBE_FIRST_FPREG_OFFSET + (4 * FPREG_SIZE)) |
109 | #define PROBE_CPU_F5_OFFSET (PROBE_FIRST_FPREG_OFFSET + (5 * FPREG_SIZE)) |
110 | #define PROBE_CPU_F6_OFFSET (PROBE_FIRST_FPREG_OFFSET + (6 * FPREG_SIZE)) |
111 | #define PROBE_CPU_F7_OFFSET (PROBE_FIRST_FPREG_OFFSET + (7 * FPREG_SIZE)) |
112 | #define PROBE_CPU_F8_OFFSET (PROBE_FIRST_FPREG_OFFSET + (8 * FPREG_SIZE)) |
113 | #define PROBE_CPU_F9_OFFSET (PROBE_FIRST_FPREG_OFFSET + (9 * FPREG_SIZE)) |
114 | #define PROBE_CPU_F10_OFFSET (PROBE_FIRST_FPREG_OFFSET + (10 * FPREG_SIZE)) |
115 | #define PROBE_CPU_F11_OFFSET (PROBE_FIRST_FPREG_OFFSET + (11 * FPREG_SIZE)) |
116 | #define PROBE_CPU_F12_OFFSET (PROBE_FIRST_FPREG_OFFSET + (12 * FPREG_SIZE)) |
117 | #define PROBE_CPU_F13_OFFSET (PROBE_FIRST_FPREG_OFFSET + (13 * FPREG_SIZE)) |
118 | #define PROBE_CPU_F14_OFFSET (PROBE_FIRST_FPREG_OFFSET + (14 * FPREG_SIZE)) |
119 | #define PROBE_CPU_F15_OFFSET (PROBE_FIRST_FPREG_OFFSET + (15 * FPREG_SIZE)) |
120 | #define PROBE_CPU_F16_OFFSET (PROBE_FIRST_FPREG_OFFSET + (16 * FPREG_SIZE)) |
121 | #define PROBE_CPU_F17_OFFSET (PROBE_FIRST_FPREG_OFFSET + (17 * FPREG_SIZE)) |
122 | #define PROBE_CPU_F18_OFFSET (PROBE_FIRST_FPREG_OFFSET + (18 * FPREG_SIZE)) |
123 | #define PROBE_CPU_F19_OFFSET (PROBE_FIRST_FPREG_OFFSET + (19 * FPREG_SIZE)) |
124 | #define PROBE_CPU_F20_OFFSET (PROBE_FIRST_FPREG_OFFSET + (20 * FPREG_SIZE)) |
125 | #define PROBE_CPU_F21_OFFSET (PROBE_FIRST_FPREG_OFFSET + (21 * FPREG_SIZE)) |
126 | #define PROBE_CPU_F22_OFFSET (PROBE_FIRST_FPREG_OFFSET + (22 * FPREG_SIZE)) |
127 | #define PROBE_CPU_F23_OFFSET (PROBE_FIRST_FPREG_OFFSET + (23 * FPREG_SIZE)) |
128 | #define PROBE_CPU_F24_OFFSET (PROBE_FIRST_FPREG_OFFSET + (24 * FPREG_SIZE)) |
129 | #define PROBE_CPU_F25_OFFSET (PROBE_FIRST_FPREG_OFFSET + (25 * FPREG_SIZE)) |
130 | #define PROBE_CPU_F26_OFFSET (PROBE_FIRST_FPREG_OFFSET + (26 * FPREG_SIZE)) |
131 | #define PROBE_CPU_F27_OFFSET (PROBE_FIRST_FPREG_OFFSET + (27 * FPREG_SIZE)) |
132 | #define PROBE_CPU_F28_OFFSET (PROBE_FIRST_FPREG_OFFSET + (28 * FPREG_SIZE)) |
133 | #define PROBE_CPU_F29_OFFSET (PROBE_FIRST_FPREG_OFFSET + (29 * FPREG_SIZE)) |
134 | #define PROBE_CPU_F30_OFFSET (PROBE_FIRST_FPREG_OFFSET + (30 * FPREG_SIZE)) |
135 | #define PROBE_CPU_F31_OFFSET (PROBE_FIRST_FPREG_OFFSET + (31 * FPREG_SIZE)) |
136 | |
137 | #define PROBE_SIZE (PROBE_FIRST_FPREG_OFFSET + (32 * FPREG_SIZE)) |
138 | |
139 | #define SAVED_PROBE_RETURN_PC_OFFSET (PROBE_SIZE + (0 * PTR_SIZE)) |
140 | #define PROBE_SIZE_PLUS_EXTRAS (PROBE_SIZE + (2 * PTR_SIZE)) |
141 | // PROBE_SIZE_PLUS_EXTRAS = PROBE_SIZE + SAVED_PROBE_RETURN_PC + padding |
142 | |
143 | #define FIR 0 |
144 | #define FCCR 25 |
145 | #define FEXR 26 |
146 | #define FENR 28 |
147 | #define FCSR 31 |
148 | |
149 | // These ASSERTs remind you that if you change the layout of Probe::State, |
150 | // you need to change ctiMasmProbeTrampoline offsets above to match. |
151 | #define PROBE_OFFSETOF(x) offsetof(struct Probe::State, x) |
152 | static_assert(PROBE_OFFSETOF(probeFunction) == PROBE_PROBE_FUNCTION_OFFSET, "Probe::State::probeFunction's offset matches ctiMasmProbeTrampoline" ); |
153 | static_assert(PROBE_OFFSETOF(arg) == PROBE_ARG_OFFSET, "Probe::State::arg's offset matches ctiMasmProbeTrampoline" ); |
154 | static_assert(PROBE_OFFSETOF(initializeStackFunction) == PROBE_INIT_STACK_FUNCTION_OFFSET, "Probe::State::initializeStackFunction's offset matches ctiMasmProbeTrampoline" ); |
155 | static_assert(PROBE_OFFSETOF(initializeStackArg) == PROBE_INIT_STACK_ARG_OFFSET, "Probe::State::initializeStackArg's offset matches ctiMasmProbeTrampoline" ); |
156 | |
157 | static_assert(!(PROBE_CPU_ZR_OFFSET & 0x3), "Probe::State::cpu.gprs[zero]'s offset should be 4 byte aligned" ); |
158 | |
159 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::zero]) == PROBE_CPU_ZR_OFFSET, "Probe::State::cpu.gprs[zero]'s offset matches ctiMasmProbeTrampoline" ); |
160 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::at]) == PROBE_CPU_AT_OFFSET, "Probe::State::cpu.gprs[at]'s offset matches ctiMasmProbeTrampoline" ); |
161 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::v0]) == PROBE_CPU_V0_OFFSET, "Probe::State::cpu.gprs[v0]'s offset matches ctiMasmProbeTrampoline" ); |
162 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::v1]) == PROBE_CPU_V1_OFFSET, "Probe::State::cpu.gprs[v1]'s offset matches ctiMasmProbeTrampoline" ); |
163 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::a0]) == PROBE_CPU_A0_OFFSET, "Probe::State::cpu.gprs[a0]'s offset matches ctiMasmProbeTrampoline" ); |
164 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::a1]) == PROBE_CPU_A1_OFFSET, "Probe::State::cpu.gprs[a1]'s offset matches ctiMasmProbeTrampoline" ); |
165 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::a2]) == PROBE_CPU_A2_OFFSET, "Probe::State::cpu.gprs[a2]'s offset matches ctiMasmProbeTrampoline" ); |
166 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::a3]) == PROBE_CPU_A3_OFFSET, "Probe::State::cpu.gprs[a3]'s offset matches ctiMasmProbeTrampoline" ); |
167 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::t0]) == PROBE_CPU_T0_OFFSET, "Probe::State::cpu.gprs[t0]'s offset matches ctiMasmProbeTrampoline" ); |
168 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::t1]) == PROBE_CPU_T1_OFFSET, "Probe::State::cpu.gprs[t1]'s offset matches ctiMasmProbeTrampoline" ); |
169 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::t2]) == PROBE_CPU_T2_OFFSET, "Probe::State::cpu.gprs[t2]'s offset matches ctiMasmProbeTrampoline" ); |
170 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::t3]) == PROBE_CPU_T3_OFFSET, "Probe::State::cpu.gprs[t3]'s offset matches ctiMasmProbeTrampoline" ); |
171 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::t4]) == PROBE_CPU_T4_OFFSET, "Probe::State::cpu.gprs[t4]'s offset matches ctiMasmProbeTrampoline" ); |
172 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::t5]) == PROBE_CPU_T5_OFFSET, "Probe::State::cpu.gprs[t5]'s offset matches ctiMasmProbeTrampoline" ); |
173 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::t6]) == PROBE_CPU_T6_OFFSET, "Probe::State::cpu.gprs[t6]'s offset matches ctiMasmProbeTrampoline" ); |
174 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::t7]) == PROBE_CPU_T7_OFFSET, "Probe::State::cpu.gprs[t7]'s offset matches ctiMasmProbeTrampoline" ); |
175 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::s0]) == PROBE_CPU_S0_OFFSET, "Probe::State::cpu.gprs[s0]'s offset matches ctiMasmProbeTrampoline" ); |
176 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::s1]) == PROBE_CPU_S1_OFFSET, "Probe::State::cpu.gprs[s1]'s offset matches ctiMasmProbeTrampoline" ); |
177 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::s2]) == PROBE_CPU_S2_OFFSET, "Probe::State::cpu.gprs[s2]'s offset matches ctiMasmProbeTrampoline" ); |
178 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::s3]) == PROBE_CPU_S3_OFFSET, "Probe::State::cpu.gprs[s3]'s offset matches ctiMasmProbeTrampoline" ); |
179 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::s4]) == PROBE_CPU_S4_OFFSET, "Probe::State::cpu.gprs[s4]'s offset matches ctiMasmProbeTrampoline" ); |
180 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::s5]) == PROBE_CPU_S5_OFFSET, "Probe::State::cpu.gprs[s5]'s offset matches ctiMasmProbeTrampoline" ); |
181 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::s6]) == PROBE_CPU_S6_OFFSET, "Probe::State::cpu.gprs[s6]'s offset matches ctiMasmProbeTrampoline" ); |
182 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::s7]) == PROBE_CPU_S7_OFFSET, "Probe::State::cpu.gprs[s7]'s offset matches ctiMasmProbeTrampoline" ); |
183 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::t8]) == PROBE_CPU_T8_OFFSET, "Probe::State::cpu.gprs[t8]'s offset matches ctiMasmProbeTrampoline" ); |
184 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::t9]) == PROBE_CPU_T9_OFFSET, "Probe::State::cpu.gprs[t9]'s offset matches ctiMasmProbeTrampoline" ); |
185 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::k0]) == PROBE_CPU_K0_OFFSET, "Probe::State::cpu.gprs[k0]'s offset matches ctiMasmProbeTrampoline" ); |
186 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::k1]) == PROBE_CPU_K1_OFFSET, "Probe::State::cpu.gprs[k1]'s offset matches ctiMasmProbeTrampoline" ); |
187 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::gp]) == PROBE_CPU_GP_OFFSET, "Probe::State::cpu.gprs[gp]'s offset matches ctiMasmProbeTrampoline" ); |
188 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::sp]) == PROBE_CPU_SP_OFFSET, "Probe::State::cpu.gprs[sp]'s offset matches ctiMasmProbeTrampoline" ); |
189 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::fp]) == PROBE_CPU_FP_OFFSET, "Probe::State::cpu.gprs[fp]'s offset matches ctiMasmProbeTrampoline" ); |
190 | static_assert(PROBE_OFFSETOF(cpu.gprs[MIPSRegisters::ra]) == PROBE_CPU_RA_OFFSET, "Probe::State::cpu.gprs[ra]'s offset matches ctiMasmProbeTrampoline" ); |
191 | |
192 | static_assert(PROBE_OFFSETOF(cpu.sprs[MIPSRegisters::fir]) == PROBE_CPU_FIR_OFFSET, "Probe::State::cpu.sprs[fir]'s offset matches ctiMasmProbeTrampoline" ); |
193 | static_assert(PROBE_OFFSETOF(cpu.sprs[MIPSRegisters::fccr]) == PROBE_CPU_FCCR_OFFSET, "Probe::State::cpu.sprs[fccr]'s offset matches ctiMasmProbeTrampoline" ); |
194 | static_assert(PROBE_OFFSETOF(cpu.sprs[MIPSRegisters::fexr]) == PROBE_CPU_FEXR_OFFSET, "Probe::State::cpu.sprs[fexr]'s offset matches ctiMasmProbeTrampoline" ); |
195 | static_assert(PROBE_OFFSETOF(cpu.sprs[MIPSRegisters::fenr]) == PROBE_CPU_FENR_OFFSET, "Probe::State::cpu.sprs[fenr]'s offset matches ctiMasmProbeTrampoline" ); |
196 | static_assert(PROBE_OFFSETOF(cpu.sprs[MIPSRegisters::fcsr]) == PROBE_CPU_FCSR_OFFSET, "Probe::State::cpu.sprs[fcsr]'s offset matches ctiMasmProbeTrampoline" ); |
197 | static_assert(PROBE_OFFSETOF(cpu.sprs[MIPSRegisters::pc]) == PROBE_CPU_PC_OFFSET, "Probe::State::cpu.sprs[pc]'s offset matches ctiMasmProbeTrampoline" ); |
198 | |
199 | static_assert(!(PROBE_CPU_F0_OFFSET & 0x7), "Probe::State::cpu.fprs[f0]'s offset should be 8 byte aligned" ); |
200 | |
201 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f0]) == PROBE_CPU_F0_OFFSET, "Probe::State::cpu.fprs[f0]'s offset matches ctiMasmProbeTrampoline" ); |
202 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f1]) == PROBE_CPU_F1_OFFSET, "Probe::State::cpu.fprs[f1]'s offset matches ctiMasmProbeTrampoline" ); |
203 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f2]) == PROBE_CPU_F2_OFFSET, "Probe::State::cpu.fprs[f2]'s offset matches ctiMasmProbeTrampoline" ); |
204 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f3]) == PROBE_CPU_F3_OFFSET, "Probe::State::cpu.fprs[f3]'s offset matches ctiMasmProbeTrampoline" ); |
205 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f4]) == PROBE_CPU_F4_OFFSET, "Probe::State::cpu.fprs[f4]'s offset matches ctiMasmProbeTrampoline" ); |
206 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f5]) == PROBE_CPU_F5_OFFSET, "Probe::State::cpu.fprs[f5]'s offset matches ctiMasmProbeTrampoline" ); |
207 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f6]) == PROBE_CPU_F6_OFFSET, "Probe::State::cpu.fprs[f6]'s offset matches ctiMasmProbeTrampoline" ); |
208 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f7]) == PROBE_CPU_F7_OFFSET, "Probe::State::cpu.fprs[f7]'s offset matches ctiMasmProbeTrampoline" ); |
209 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f8]) == PROBE_CPU_F8_OFFSET, "Probe::State::cpu.fprs[f8]'s offset matches ctiMasmProbeTrampoline" ); |
210 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f9]) == PROBE_CPU_F9_OFFSET, "Probe::State::cpu.fprs[f9]'s offset matches ctiMasmProbeTrampoline" ); |
211 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f10]) == PROBE_CPU_F10_OFFSET, "Probe::State::cpu.fprs[f10]'s offset matches ctiMasmProbeTrampoline" ); |
212 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f11]) == PROBE_CPU_F11_OFFSET, "Probe::State::cpu.fprs[f11]'s offset matches ctiMasmProbeTrampoline" ); |
213 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f12]) == PROBE_CPU_F12_OFFSET, "Probe::State::cpu.fprs[f12]'s offset matches ctiMasmProbeTrampoline" ); |
214 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f13]) == PROBE_CPU_F13_OFFSET, "Probe::State::cpu.fprs[f13]'s offset matches ctiMasmProbeTrampoline" ); |
215 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f14]) == PROBE_CPU_F14_OFFSET, "Probe::State::cpu.fprs[f14]'s offset matches ctiMasmProbeTrampoline" ); |
216 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f15]) == PROBE_CPU_F15_OFFSET, "Probe::State::cpu.fprs[f15]'s offset matches ctiMasmProbeTrampoline" ); |
217 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f16]) == PROBE_CPU_F16_OFFSET, "Probe::State::cpu.fprs[f16]'s offset matches ctiMasmProbeTrampoline" ); |
218 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f17]) == PROBE_CPU_F17_OFFSET, "Probe::State::cpu.fprs[f17]'s offset matches ctiMasmProbeTrampoline" ); |
219 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f18]) == PROBE_CPU_F18_OFFSET, "Probe::State::cpu.fprs[f18]'s offset matches ctiMasmProbeTrampoline" ); |
220 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f19]) == PROBE_CPU_F19_OFFSET, "Probe::State::cpu.fprs[f19]'s offset matches ctiMasmProbeTrampoline" ); |
221 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f20]) == PROBE_CPU_F20_OFFSET, "Probe::State::cpu.fprs[f20]'s offset matches ctiMasmProbeTrampoline" ); |
222 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f21]) == PROBE_CPU_F21_OFFSET, "Probe::State::cpu.fprs[f21]'s offset matches ctiMasmProbeTrampoline" ); |
223 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f22]) == PROBE_CPU_F22_OFFSET, "Probe::State::cpu.fprs[f22]'s offset matches ctiMasmProbeTrampoline" ); |
224 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f23]) == PROBE_CPU_F23_OFFSET, "Probe::State::cpu.fprs[f23]'s offset matches ctiMasmProbeTrampoline" ); |
225 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f24]) == PROBE_CPU_F24_OFFSET, "Probe::State::cpu.fprs[f24]'s offset matches ctiMasmProbeTrampoline" ); |
226 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f25]) == PROBE_CPU_F25_OFFSET, "Probe::State::cpu.fprs[f25]'s offset matches ctiMasmProbeTrampoline" ); |
227 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f26]) == PROBE_CPU_F26_OFFSET, "Probe::State::cpu.fprs[f26]'s offset matches ctiMasmProbeTrampoline" ); |
228 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f27]) == PROBE_CPU_F27_OFFSET, "Probe::State::cpu.fprs[f27]'s offset matches ctiMasmProbeTrampoline" ); |
229 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f28]) == PROBE_CPU_F28_OFFSET, "Probe::State::cpu.fprs[f28]'s offset matches ctiMasmProbeTrampoline" ); |
230 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f29]) == PROBE_CPU_F29_OFFSET, "Probe::State::cpu.fprs[f29]'s offset matches ctiMasmProbeTrampoline" ); |
231 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f30]) == PROBE_CPU_F30_OFFSET, "Probe::State::cpu.fprs[f30]'s offset matches ctiMasmProbeTrampoline" ); |
232 | static_assert(PROBE_OFFSETOF(cpu.fprs[MIPSRegisters::f31]) == PROBE_CPU_F31_OFFSET, "Probe::State::cpu.fprs[f31]'s offset matches ctiMasmProbeTrampoline" ); |
233 | |
234 | static_assert(sizeof(Probe::State) == PROBE_SIZE, "Probe::State's size matches ctiMasmProbeTrampoline" ); |
235 | #undef PROBE_OFFSETOF |
236 | |
237 | static_assert(MIPSRegisters::fir == FIR, "FIR matches MIPSRegisters::fir" ); |
238 | static_assert(MIPSRegisters::fccr == FCCR, "FCCR matches MIPSRegisters::fccr" ); |
239 | static_assert(MIPSRegisters::fexr == FEXR, "FEXR matches MIPSRegisters::fexr" ); |
240 | static_assert(MIPSRegisters::fenr == FENR, "FENR matches MIPSRegisters::fenr" ); |
241 | static_assert(MIPSRegisters::fcsr == FCSR, "FCSR matches MIPSRegisters::fcsr" ); |
242 | |
243 | struct IncomingRecord { |
244 | uintptr_t a0; |
245 | uintptr_t a1; |
246 | uintptr_t a2; |
247 | uintptr_t s0; |
248 | uintptr_t s1; |
249 | uintptr_t ra; |
250 | }; |
251 | |
252 | #define IN_A0_OFFSET (0 * PTR_SIZE) |
253 | #define IN_A1_OFFSET (1 * PTR_SIZE) |
254 | #define IN_A2_OFFSET (2 * PTR_SIZE) |
255 | #define IN_S0_OFFSET (3 * PTR_SIZE) |
256 | #define IN_S1_OFFSET (4 * PTR_SIZE) |
257 | #define IN_RA_OFFSET (5 * PTR_SIZE) |
258 | #define IN_SIZE (6 * PTR_SIZE) |
259 | |
260 | static_assert(IN_A0_OFFSET == offsetof(IncomingRecord, a0), "IN_A0_OFFSET is incorrect" ); |
261 | static_assert(IN_A1_OFFSET == offsetof(IncomingRecord, a1), "IN_A1_OFFSET is incorrect" ); |
262 | static_assert(IN_A2_OFFSET == offsetof(IncomingRecord, a2), "IN_A2_OFFSET is incorrect" ); |
263 | static_assert(IN_S0_OFFSET == offsetof(IncomingRecord, s0), "IN_S0_OFFSET is incorrect" ); |
264 | static_assert(IN_S1_OFFSET == offsetof(IncomingRecord, s1), "IN_S1_OFFSET is incorrect" ); |
265 | static_assert(IN_RA_OFFSET == offsetof(IncomingRecord, ra), "IN_RA_OFFSET is incorrect" ); |
266 | static_assert(IN_SIZE == sizeof(IncomingRecord), "IN_SIZE is incorrect" ); |
267 | |
268 | struct OutgoingRecord { |
269 | uintptr_t fp; |
270 | uintptr_t ra; |
271 | }; |
272 | |
273 | #define OUT_FP_OFFSET (0 * PTR_SIZE) |
274 | #define OUT_RA_OFFSET (1 * PTR_SIZE) |
275 | #define OUT_SIZE (2 * PTR_SIZE) |
276 | |
277 | static_assert(OUT_FP_OFFSET == offsetof(OutgoingRecord, fp), "OUT_FP_OFFSET is incorrect" ); |
278 | static_assert(OUT_RA_OFFSET == offsetof(OutgoingRecord, ra), "OUT_RA_OFFSET is incorrect" ); |
279 | static_assert(OUT_SIZE == sizeof(OutgoingRecord), "OUT_SIZE is incorrect" ); |
280 | |
281 | struct RARestorationRecord { |
282 | uintptr_t ra; |
283 | uintptr_t padding; |
284 | }; |
285 | |
286 | #define RA_RESTORATION_RA_OFFSET (0 * PTR_SIZE) |
287 | #define RA_RESTORATION_SIZE (2 * PTR_SIZE) |
288 | |
289 | static_assert(RA_RESTORATION_RA_OFFSET == offsetof(RARestorationRecord, ra), "RA_RESTORATION_RA_OFFSET is incorrect" ); |
290 | static_assert(RA_RESTORATION_SIZE == sizeof(RARestorationRecord), "RA_RESTORATION_SIZE is incorrect" ); |
291 | static_assert(!(sizeof(RARestorationRecord) & 0x7), "RARestorationRecord must be 8-byte aligned" ); |
292 | |
293 | asm ( |
294 | ".text" "\n" |
295 | ".globl " SYMBOL_STRING(ctiMasmProbeTrampoline) "\n" |
296 | HIDE_SYMBOL(ctiMasmProbeTrampoline) "\n" |
297 | SYMBOL_STRING(ctiMasmProbeTrampoline) ":" "\n" |
298 | ".set push" "\n" |
299 | ".set noreorder" "\n" |
300 | ".set noat" "\n" |
301 | |
302 | // MacroAssemblerMIPS::probe() has already generated code to store some values in an |
303 | // IncomingProbeRecord. sp points to the IncomingProbeRecord. |
304 | // |
305 | // Incoming register values: |
306 | // a0: probe function |
307 | // a1: probe arg |
308 | // a2: Probe::executeProbe |
309 | // s0: scratch, was ctiMasmProbeTrampoline |
310 | // s1: scratch |
311 | // ra: return address |
312 | |
313 | "move $s0, $sp" "\n" |
314 | "addiu $sp, $sp, -" STRINGIZE_VALUE_OF((PROBE_SIZE_PLUS_EXTRAS + OUT_SIZE)) "\n" // Set the sp to protect the Probe::State from interrupts before we initialize it. |
315 | "move $s1, $sp" "\n" |
316 | |
317 | "sw $a0, " STRINGIZE_VALUE_OF(PROBE_PROBE_FUNCTION_OFFSET) "($sp)" "\n" // Store the probe handler function (preloaded into a0) |
318 | "sw $a1, " STRINGIZE_VALUE_OF(PROBE_ARG_OFFSET) "($sp)" "\n" // Store the probe handler arg (preloaded into a1) |
319 | |
320 | "sw $at, " STRINGIZE_VALUE_OF(PROBE_CPU_AT_OFFSET) "($sp)" "\n" |
321 | "sw $v0, " STRINGIZE_VALUE_OF(PROBE_CPU_V0_OFFSET) "($sp)" "\n" |
322 | "sw $v1, " STRINGIZE_VALUE_OF(PROBE_CPU_V1_OFFSET) "($sp)" "\n" |
323 | |
324 | "lw $v0, " STRINGIZE_VALUE_OF(IN_A0_OFFSET) "($s0)" "\n" // Load saved a0 |
325 | "lw $v1, " STRINGIZE_VALUE_OF(IN_A1_OFFSET) "($s0)" "\n" // Load saved a1 |
326 | "lw $at, " STRINGIZE_VALUE_OF(IN_A2_OFFSET) "($s0)" "\n" // Load saved a2 |
327 | "sw $v0, " STRINGIZE_VALUE_OF(PROBE_CPU_A0_OFFSET) "($sp)" "\n" // Store saved a0 |
328 | "sw $v1, " STRINGIZE_VALUE_OF(PROBE_CPU_A1_OFFSET) "($sp)" "\n" // Store saved a1 |
329 | "sw $at, " STRINGIZE_VALUE_OF(PROBE_CPU_A2_OFFSET) "($sp)" "\n" // Store saved a2 |
330 | |
331 | "sw $a3, " STRINGIZE_VALUE_OF(PROBE_CPU_A3_OFFSET) "($sp)" "\n" |
332 | "sw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_T0_OFFSET) "($sp)" "\n" |
333 | "sw $t1, " STRINGIZE_VALUE_OF(PROBE_CPU_T1_OFFSET) "($sp)" "\n" |
334 | "sw $t2, " STRINGIZE_VALUE_OF(PROBE_CPU_T2_OFFSET) "($sp)" "\n" |
335 | "sw $t3, " STRINGIZE_VALUE_OF(PROBE_CPU_T3_OFFSET) "($sp)" "\n" |
336 | "sw $t4, " STRINGIZE_VALUE_OF(PROBE_CPU_T4_OFFSET) "($sp)" "\n" |
337 | "sw $t5, " STRINGIZE_VALUE_OF(PROBE_CPU_T5_OFFSET) "($sp)" "\n" |
338 | "sw $t6, " STRINGIZE_VALUE_OF(PROBE_CPU_T6_OFFSET) "($sp)" "\n" |
339 | "sw $t7, " STRINGIZE_VALUE_OF(PROBE_CPU_T7_OFFSET) "($sp)" "\n" |
340 | |
341 | "lw $v0, " STRINGIZE_VALUE_OF(IN_S0_OFFSET) "($s0)" "\n" // Load saved s0 |
342 | "lw $v1, " STRINGIZE_VALUE_OF(IN_S1_OFFSET) "($s0)" "\n" // Load saved s1 |
343 | "sw $v0, " STRINGIZE_VALUE_OF(PROBE_CPU_S0_OFFSET) "($sp)" "\n" // Store saved s0 |
344 | "sw $v1, " STRINGIZE_VALUE_OF(PROBE_CPU_S1_OFFSET) "($sp)" "\n" // Store saved s1 |
345 | |
346 | "sw $s2, " STRINGIZE_VALUE_OF(PROBE_CPU_S2_OFFSET) "($sp)" "\n" |
347 | "sw $s3, " STRINGIZE_VALUE_OF(PROBE_CPU_S3_OFFSET) "($sp)" "\n" |
348 | "sw $s4, " STRINGIZE_VALUE_OF(PROBE_CPU_S4_OFFSET) "($sp)" "\n" |
349 | "sw $s5, " STRINGIZE_VALUE_OF(PROBE_CPU_S5_OFFSET) "($sp)" "\n" |
350 | "sw $s6, " STRINGIZE_VALUE_OF(PROBE_CPU_S6_OFFSET) "($sp)" "\n" |
351 | "sw $s7, " STRINGIZE_VALUE_OF(PROBE_CPU_S7_OFFSET) "($sp)" "\n" |
352 | "sw $t8, " STRINGIZE_VALUE_OF(PROBE_CPU_T8_OFFSET) "($sp)" "\n" |
353 | "sw $t9, " STRINGIZE_VALUE_OF(PROBE_CPU_T9_OFFSET) "($sp)" "\n" |
354 | "sw $k0, " STRINGIZE_VALUE_OF(PROBE_CPU_K0_OFFSET) "($sp)" "\n" |
355 | "sw $k1, " STRINGIZE_VALUE_OF(PROBE_CPU_K1_OFFSET) "($sp)" "\n" |
356 | "sw $gp, " STRINGIZE_VALUE_OF(PROBE_CPU_GP_OFFSET) "($sp)" "\n" |
357 | "sw $fp, " STRINGIZE_VALUE_OF(PROBE_CPU_FP_OFFSET) "($sp)" "\n" |
358 | |
359 | "lw $v0, " STRINGIZE_VALUE_OF(IN_RA_OFFSET) "($s0)" "\n" // Load saved ra |
360 | "addiu $s0, $s0, " STRINGIZE_VALUE_OF(IN_SIZE) "\n" // Compute the sp before the probe |
361 | "sw $v0, " STRINGIZE_VALUE_OF(PROBE_CPU_RA_OFFSET) "($sp)" "\n" // Store saved ra |
362 | "sw $s0, " STRINGIZE_VALUE_OF(PROBE_CPU_SP_OFFSET) "($sp)" "\n" // Store original sp computed into s0 |
363 | |
364 | "sw $ra, " STRINGIZE_VALUE_OF(SAVED_PROBE_RETURN_PC_OFFSET) "($sp)" "\n" // Save a duplicate copy of return pc (in ra) |
365 | "addiu $ra, $ra, " STRINGIZE_VALUE_OF(PROBE_INSTRUCTIONS_AFTER_CALL * PTR_SIZE) "\n" // The PC after the probe is at 2 instructions past the return point. |
366 | "sw $ra, " STRINGIZE_VALUE_OF(PROBE_CPU_PC_OFFSET) "($sp)" "\n" |
367 | |
368 | "cfc1 $t0, $" STRINGIZE_VALUE_OF(FIR) "\n" |
369 | "sw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_FIR_OFFSET) "($sp)" "\n" |
370 | "cfc1 $t0, $" STRINGIZE_VALUE_OF(FCCR) "\n" |
371 | "sw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_FCCR_OFFSET) "($sp)" "\n" |
372 | "cfc1 $t0, $" STRINGIZE_VALUE_OF(FEXR) "\n" |
373 | "sw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_FEXR_OFFSET) "($sp)" "\n" |
374 | "cfc1 $t0, $" STRINGIZE_VALUE_OF(FENR) "\n" |
375 | "sw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_FENR_OFFSET) "($sp)" "\n" |
376 | "cfc1 $t0, $" STRINGIZE_VALUE_OF(FCSR) "\n" |
377 | "sw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_FCSR_OFFSET) "($sp)" "\n" |
378 | |
379 | "sdc1 $f0, " STRINGIZE_VALUE_OF(PROBE_CPU_F0_OFFSET) "($sp)" "\n" |
380 | "sdc1 $f2, " STRINGIZE_VALUE_OF(PROBE_CPU_F2_OFFSET) "($sp)" "\n" |
381 | "sdc1 $f4, " STRINGIZE_VALUE_OF(PROBE_CPU_F4_OFFSET) "($sp)" "\n" |
382 | "sdc1 $f6, " STRINGIZE_VALUE_OF(PROBE_CPU_F6_OFFSET) "($sp)" "\n" |
383 | "sdc1 $f8, " STRINGIZE_VALUE_OF(PROBE_CPU_F8_OFFSET) "($sp)" "\n" |
384 | "sdc1 $f10, " STRINGIZE_VALUE_OF(PROBE_CPU_F10_OFFSET) "($sp)" "\n" |
385 | "sdc1 $f12, " STRINGIZE_VALUE_OF(PROBE_CPU_F12_OFFSET) "($sp)" "\n" |
386 | "sdc1 $f14, " STRINGIZE_VALUE_OF(PROBE_CPU_F14_OFFSET) "($sp)" "\n" |
387 | "sdc1 $f16, " STRINGIZE_VALUE_OF(PROBE_CPU_F16_OFFSET) "($sp)" "\n" |
388 | "sdc1 $f18, " STRINGIZE_VALUE_OF(PROBE_CPU_F18_OFFSET) "($sp)" "\n" |
389 | "sdc1 $f20, " STRINGIZE_VALUE_OF(PROBE_CPU_F20_OFFSET) "($sp)" "\n" |
390 | "sdc1 $f22, " STRINGIZE_VALUE_OF(PROBE_CPU_F22_OFFSET) "($sp)" "\n" |
391 | "sdc1 $f24, " STRINGIZE_VALUE_OF(PROBE_CPU_F24_OFFSET) "($sp)" "\n" |
392 | "sdc1 $f26, " STRINGIZE_VALUE_OF(PROBE_CPU_F26_OFFSET) "($sp)" "\n" |
393 | "sdc1 $f28, " STRINGIZE_VALUE_OF(PROBE_CPU_F28_OFFSET) "($sp)" "\n" |
394 | "sdc1 $f30, " STRINGIZE_VALUE_OF(PROBE_CPU_F30_OFFSET) "($sp)" "\n" |
395 | |
396 | "move $a0, $sp" "\n" // Set the Probe::State* arg. |
397 | "move $t9, $a2" "\n" // Probe::executeProbe() |
398 | "jalr $t9" "\n" // Call the probe handler. |
399 | "nop" "\n" |
400 | |
401 | // Make sure the Probe::State is entirely below the result stack pointer so |
402 | // that register values are still preserved when we call the initializeStack |
403 | // function. |
404 | "lw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_SP_OFFSET) "($s1)" "\n" // Result sp. |
405 | "addiu $t1, $s1, " STRINGIZE_VALUE_OF((PROBE_SIZE_PLUS_EXTRAS + OUT_SIZE)) "\n" // End of Probe::State + buffer. |
406 | "sltu $t2, $t0, $t1" "\n" |
407 | "beqz $t2, " LOCAL_LABEL_STRING(ctiMasmProbeTrampolineProbeStateIsSafe) "\n" |
408 | "nop" "\n" |
409 | |
410 | // Allocate a safe place on the stack below the result stack pointer to stash the Probe::State. |
411 | "addiu $sp, $t0, -" STRINGIZE_VALUE_OF((PROBE_SIZE_PLUS_EXTRAS + OUT_SIZE)) "\n" // Set the new sp to protect that memory from interrupts before we copy the Probe::State. |
412 | |
413 | // Copy the Probe::State to the safe place. |
414 | // Note: we have to copy from low address to higher address because we're moving the |
415 | // Probe::State to a lower address. |
416 | "move $t0, $s1" "\n" |
417 | "move $t1, $sp" "\n" |
418 | "addiu $t2, $s1, " STRINGIZE_VALUE_OF(PROBE_SIZE_PLUS_EXTRAS) "\n" |
419 | |
420 | LOCAL_LABEL_STRING(ctiMasmProbeTrampolineCopyLoop) ":" "\n" |
421 | "lw $t3, 0($t0)" "\n" |
422 | "lw $t4, 4($t0)" "\n" |
423 | "sw $t3, 0($t1)" "\n" |
424 | "sw $t4, 4($t1)" "\n" |
425 | "addiu $t0, $t0, 8" "\n" |
426 | "addiu $t1, $t1, 8" "\n" |
427 | "bne $t0, $t2, " LOCAL_LABEL_STRING(ctiMasmProbeTrampolineCopyLoop) "\n" |
428 | "nop" "\n" |
429 | |
430 | "move $s1, $sp" "\n" |
431 | |
432 | // Call initializeStackFunction if present. |
433 | LOCAL_LABEL_STRING(ctiMasmProbeTrampolineProbeStateIsSafe) ":" "\n" |
434 | "lw $t9, " STRINGIZE_VALUE_OF(PROBE_INIT_STACK_FUNCTION_OFFSET) "($s1)" "\n" |
435 | "beqz $t9, " LOCAL_LABEL_STRING(ctiMasmProbeTrampolineRestoreRegisters) "\n" |
436 | "nop" "\n" |
437 | |
438 | "move $a0, $s1" "\n" // Set the Probe::State* arg. |
439 | "jalr $t9" "\n" // Call the initializeStackFunction (loaded into t9 above). |
440 | "nop" "\n" |
441 | |
442 | LOCAL_LABEL_STRING(ctiMasmProbeTrampolineRestoreRegisters) ":" "\n" |
443 | |
444 | "move $sp, $s1" "\n" |
445 | |
446 | // To enable probes to modify register state, we copy all registers |
447 | // out of the Probe::State before returning, except for zero, k0 and k1. |
448 | |
449 | "lw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_FIR_OFFSET) "($sp)" "\n" |
450 | "ctc1 $t0, $" STRINGIZE_VALUE_OF(FIR) "\n" |
451 | "lw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_FCCR_OFFSET) "($sp)" "\n" |
452 | "ctc1 $t0, $" STRINGIZE_VALUE_OF(FCCR) "\n" |
453 | "lw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_FEXR_OFFSET) "($sp)" "\n" |
454 | "ctc1 $t0, $" STRINGIZE_VALUE_OF(FEXR) "\n" |
455 | "lw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_FENR_OFFSET) "($sp)" "\n" |
456 | "ctc1 $t0, $" STRINGIZE_VALUE_OF(FENR) "\n" |
457 | "lw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_FCSR_OFFSET) "($sp)" "\n" |
458 | "ctc1 $t0, $" STRINGIZE_VALUE_OF(FCSR) "\n" |
459 | |
460 | "ldc1 $f0, " STRINGIZE_VALUE_OF(PROBE_CPU_F0_OFFSET) "($sp)" "\n" |
461 | "ldc1 $f2, " STRINGIZE_VALUE_OF(PROBE_CPU_F2_OFFSET) "($sp)" "\n" |
462 | "ldc1 $f4, " STRINGIZE_VALUE_OF(PROBE_CPU_F4_OFFSET) "($sp)" "\n" |
463 | "ldc1 $f6, " STRINGIZE_VALUE_OF(PROBE_CPU_F6_OFFSET) "($sp)" "\n" |
464 | "ldc1 $f8, " STRINGIZE_VALUE_OF(PROBE_CPU_F8_OFFSET) "($sp)" "\n" |
465 | "ldc1 $f10, " STRINGIZE_VALUE_OF(PROBE_CPU_F10_OFFSET) "($sp)" "\n" |
466 | "ldc1 $f12, " STRINGIZE_VALUE_OF(PROBE_CPU_F12_OFFSET) "($sp)" "\n" |
467 | "ldc1 $f14, " STRINGIZE_VALUE_OF(PROBE_CPU_F14_OFFSET) "($sp)" "\n" |
468 | "ldc1 $f16, " STRINGIZE_VALUE_OF(PROBE_CPU_F16_OFFSET) "($sp)" "\n" |
469 | "ldc1 $f18, " STRINGIZE_VALUE_OF(PROBE_CPU_F18_OFFSET) "($sp)" "\n" |
470 | "ldc1 $f20, " STRINGIZE_VALUE_OF(PROBE_CPU_F20_OFFSET) "($sp)" "\n" |
471 | "ldc1 $f22, " STRINGIZE_VALUE_OF(PROBE_CPU_F22_OFFSET) "($sp)" "\n" |
472 | "ldc1 $f24, " STRINGIZE_VALUE_OF(PROBE_CPU_F24_OFFSET) "($sp)" "\n" |
473 | "ldc1 $f26, " STRINGIZE_VALUE_OF(PROBE_CPU_F26_OFFSET) "($sp)" "\n" |
474 | "ldc1 $f28, " STRINGIZE_VALUE_OF(PROBE_CPU_F28_OFFSET) "($sp)" "\n" |
475 | "ldc1 $f30, " STRINGIZE_VALUE_OF(PROBE_CPU_F30_OFFSET) "($sp)" "\n" |
476 | |
477 | "lw $at, " STRINGIZE_VALUE_OF(PROBE_CPU_AT_OFFSET) "($sp)" "\n" |
478 | "lw $v0, " STRINGIZE_VALUE_OF(PROBE_CPU_V0_OFFSET) "($sp)" "\n" |
479 | "lw $v1, " STRINGIZE_VALUE_OF(PROBE_CPU_V1_OFFSET) "($sp)" "\n" |
480 | "lw $a0, " STRINGIZE_VALUE_OF(PROBE_CPU_A0_OFFSET) "($sp)" "\n" |
481 | "lw $a1, " STRINGIZE_VALUE_OF(PROBE_CPU_A1_OFFSET) "($sp)" "\n" |
482 | "lw $a2, " STRINGIZE_VALUE_OF(PROBE_CPU_A2_OFFSET) "($sp)" "\n" |
483 | "lw $a3, " STRINGIZE_VALUE_OF(PROBE_CPU_A3_OFFSET) "($sp)" "\n" |
484 | "lw $t2, " STRINGIZE_VALUE_OF(PROBE_CPU_T2_OFFSET) "($sp)" "\n" |
485 | "lw $t3, " STRINGIZE_VALUE_OF(PROBE_CPU_T3_OFFSET) "($sp)" "\n" |
486 | "lw $t4, " STRINGIZE_VALUE_OF(PROBE_CPU_T4_OFFSET) "($sp)" "\n" |
487 | "lw $t5, " STRINGIZE_VALUE_OF(PROBE_CPU_T5_OFFSET) "($sp)" "\n" |
488 | "lw $t6, " STRINGIZE_VALUE_OF(PROBE_CPU_T6_OFFSET) "($sp)" "\n" |
489 | "lw $t7, " STRINGIZE_VALUE_OF(PROBE_CPU_T7_OFFSET) "($sp)" "\n" |
490 | "lw $s0, " STRINGIZE_VALUE_OF(PROBE_CPU_S0_OFFSET) "($sp)" "\n" |
491 | "lw $s1, " STRINGIZE_VALUE_OF(PROBE_CPU_S1_OFFSET) "($sp)" "\n" |
492 | "lw $s2, " STRINGIZE_VALUE_OF(PROBE_CPU_S2_OFFSET) "($sp)" "\n" |
493 | "lw $s3, " STRINGIZE_VALUE_OF(PROBE_CPU_S3_OFFSET) "($sp)" "\n" |
494 | "lw $s4, " STRINGIZE_VALUE_OF(PROBE_CPU_S4_OFFSET) "($sp)" "\n" |
495 | "lw $s5, " STRINGIZE_VALUE_OF(PROBE_CPU_S5_OFFSET) "($sp)" "\n" |
496 | "lw $s6, " STRINGIZE_VALUE_OF(PROBE_CPU_S6_OFFSET) "($sp)" "\n" |
497 | "lw $s7, " STRINGIZE_VALUE_OF(PROBE_CPU_S7_OFFSET) "($sp)" "\n" |
498 | "lw $t8, " STRINGIZE_VALUE_OF(PROBE_CPU_T8_OFFSET) "($sp)" "\n" |
499 | "lw $t9, " STRINGIZE_VALUE_OF(PROBE_CPU_T9_OFFSET) "($sp)" "\n" |
500 | "lw $gp, " STRINGIZE_VALUE_OF(PROBE_CPU_GP_OFFSET) "($sp)" "\n" |
501 | |
502 | // Remaining registers to restore are: t0, t1, fp, ra, sp, and pc. |
503 | |
504 | // The only way to set the pc on MIPS (from user space) is via an indirect branch |
505 | // which means we'll need a free register to do so. For our purposes, ra |
506 | // happens to be available in applications of the probe where we may want to |
507 | // continue executing at a different location (i.e. change the pc) after the probe |
508 | // returns. So, the MIPS probe implementation will allow the probe handler to |
509 | // either modify ra or pc, but not both in the same probe invocation. The probe |
510 | // mechanism ensures that we never try to modify both ra and pc with a RELEASE_ASSERT |
511 | // in Probe::executeProbe(). |
512 | |
513 | // Determine if the probe handler changed the pc. |
514 | "lw $ra, " STRINGIZE_VALUE_OF(PROBE_CPU_SP_OFFSET) "($sp)" "\n" // preload the target sp. |
515 | "lw $t0, " STRINGIZE_VALUE_OF(SAVED_PROBE_RETURN_PC_OFFSET) "($sp)" "\n" |
516 | "lw $t1, " STRINGIZE_VALUE_OF(PROBE_CPU_PC_OFFSET) "($sp)" "\n" |
517 | "addiu $t0, $t0, " STRINGIZE_VALUE_OF(PROBE_INSTRUCTIONS_AFTER_CALL * PTR_SIZE) "\n" |
518 | "bne $t0, $t1, " LOCAL_LABEL_STRING(ctiMasmProbeTrampolineEnd) "\n" |
519 | "nop" "\n" |
520 | |
521 | // We didn't change the PC. So, let's prepare for setting a potentially new ra value. |
522 | |
523 | // 1. Make room for the RARestorationRecord. The probe site will pop this off later. |
524 | "addiu $ra, $ra, -" STRINGIZE_VALUE_OF(RA_RESTORATION_SIZE) "\n" |
525 | // 2. Store the lp value to restore at the probe return site. |
526 | "lw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_RA_OFFSET) "($sp)" "\n" |
527 | "sw $t0, " STRINGIZE_VALUE_OF(RA_RESTORATION_RA_OFFSET) "($ra)" "\n" |
528 | // 3. Force the return ramp to return to the probe return site. |
529 | "lw $t0, " STRINGIZE_VALUE_OF(SAVED_PROBE_RETURN_PC_OFFSET) "($sp)" "\n" |
530 | "sw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_PC_OFFSET) "($sp)" "\n" |
531 | |
532 | LOCAL_LABEL_STRING(ctiMasmProbeTrampolineEnd) ":" "\n" |
533 | |
534 | // Fill in the OutgoingProbeRecord. |
535 | "addiu $ra, $ra, -" STRINGIZE_VALUE_OF(OUT_SIZE) "\n" |
536 | |
537 | "lw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_FP_OFFSET) "($sp)" "\n" |
538 | "lw $t1, " STRINGIZE_VALUE_OF(PROBE_CPU_PC_OFFSET) "($sp)" "\n" // Set up the outgoing record so that we'll jump to the new PC. |
539 | "sw $t0, " STRINGIZE_VALUE_OF(OUT_FP_OFFSET) "($ra)" "\n" |
540 | "sw $t1, " STRINGIZE_VALUE_OF(OUT_RA_OFFSET) "($ra)" "\n" |
541 | "lw $t0, " STRINGIZE_VALUE_OF(PROBE_CPU_T0_OFFSET) "($sp)" "\n" |
542 | "lw $t1, " STRINGIZE_VALUE_OF(PROBE_CPU_T1_OFFSET) "($sp)" "\n" |
543 | "move $sp, $ra" "\n" |
544 | |
545 | // Restore the remaining registers. |
546 | "lw $fp, " STRINGIZE_VALUE_OF(OUT_FP_OFFSET) "($sp)" "\n" |
547 | "lw $ra, " STRINGIZE_VALUE_OF(OUT_RA_OFFSET) "($sp)" "\n" |
548 | "addiu $sp, $sp, " STRINGIZE_VALUE_OF(OUT_SIZE) "\n" |
549 | "jr $ra" "\n" |
550 | "nop" "\n" |
551 | ".set pop" "\n" |
552 | ); |
553 | #endif // COMPILER(GCC_COMPATIBLE) |
554 | |
555 | void MacroAssembler::probe(Probe::Function function, void* arg) |
556 | { |
557 | sub32(TrustedImm32(sizeof(IncomingRecord)), sp); |
558 | store32(a0, Address(sp, offsetof(IncomingRecord, a0))); |
559 | store32(a1, Address(sp, offsetof(IncomingRecord, a1))); |
560 | store32(a2, Address(sp, offsetof(IncomingRecord, a2))); |
561 | store32(s0, Address(sp, offsetof(IncomingRecord, s0))); |
562 | store32(s1, Address(sp, offsetof(IncomingRecord, s1))); |
563 | store32(ra, Address(sp, offsetof(IncomingRecord, ra))); |
564 | move(TrustedImmPtr(reinterpret_cast<void*>(function)), a0); |
565 | move(TrustedImmPtr(arg), a1); |
566 | move(TrustedImmPtr(reinterpret_cast<void*>(Probe::executeProbe)), a2); |
567 | move(TrustedImmPtr(reinterpret_cast<void*>(ctiMasmProbeTrampoline)), s0); |
568 | m_assembler.jalr(s0); |
569 | m_assembler.nop(); |
570 | // If you change the following instructions, be sure to update PROBE_INSTRUCTIONS_AFTER_CALL as well |
571 | load32(Address(sp, offsetof(RARestorationRecord, ra)), ra); |
572 | add32(TrustedImm32(sizeof(RARestorationRecord)), sp); |
573 | } |
574 | #endif // ENABLE(MASM_PROBE) |
575 | |
576 | } // namespace JSC |
577 | |
578 | #endif // ENABLE(ASSEMBLER) && CPU(MIPS) |
579 | |