]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 2008, 2009, 2013 Apple Inc. All rights reserved. | |
3 | * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca> | |
4 | * Copyright (C) Research In Motion Limited 2010, 2011. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | |
9 | * | |
10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of | |
16 | * its contributors may be used to endorse or promote products derived | |
17 | * from this software without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
22 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 | */ | |
30 | ||
31 | #ifndef JITStubsARM_h | |
32 | #define JITStubsARM_h | |
33 | ||
34 | #if !CPU(ARM_TRADITIONAL) | |
35 | #error "JITStubsARM.h should only be #included if CPU(ARM_TRADITIONAL)" | |
36 | #endif | |
37 | ||
38 | #if !USE(JSVALUE32_64) | |
39 | #error "JITStubsARM.h only implements USE(JSVALUE32_64)" | |
40 | #endif | |
41 | ||
42 | namespace JSC { | |
43 | ||
44 | #if COMPILER(GCC) | |
45 | ||
46 | #if USE(MASM_PROBE) | |
47 | // The following are offsets for MacroAssembler::ProbeContext fields accessed | |
48 | // by the ctiMasmProbeTrampoline stub. | |
49 | ||
50 | #define PTR_SIZE 4 | |
51 | #define PROBE_PROBE_FUNCTION_OFFSET (0 * PTR_SIZE) | |
52 | #define PROBE_ARG1_OFFSET (1 * PTR_SIZE) | |
53 | #define PROBE_ARG2_OFFSET (2 * PTR_SIZE) | |
54 | ||
55 | #define PROBE_FIRST_GPREG_OFFSET (4 * PTR_SIZE) | |
56 | ||
57 | #define GPREG_SIZE 4 | |
58 | #define PROBE_CPU_R0_OFFSET (PROBE_FIRST_GPREG_OFFSET + (0 * GPREG_SIZE)) | |
59 | #define PROBE_CPU_R1_OFFSET (PROBE_FIRST_GPREG_OFFSET + (1 * GPREG_SIZE)) | |
60 | #define PROBE_CPU_R2_OFFSET (PROBE_FIRST_GPREG_OFFSET + (2 * GPREG_SIZE)) | |
61 | #define PROBE_CPU_R3_OFFSET (PROBE_FIRST_GPREG_OFFSET + (3 * GPREG_SIZE)) | |
62 | #define PROBE_CPU_R4_OFFSET (PROBE_FIRST_GPREG_OFFSET + (4 * GPREG_SIZE)) | |
63 | #define PROBE_CPU_R5_OFFSET (PROBE_FIRST_GPREG_OFFSET + (5 * GPREG_SIZE)) | |
64 | #define PROBE_CPU_R6_OFFSET (PROBE_FIRST_GPREG_OFFSET + (6 * GPREG_SIZE)) | |
65 | #define PROBE_CPU_R7_OFFSET (PROBE_FIRST_GPREG_OFFSET + (7 * GPREG_SIZE)) | |
66 | #define PROBE_CPU_R8_OFFSET (PROBE_FIRST_GPREG_OFFSET + (8 * GPREG_SIZE)) | |
67 | #define PROBE_CPU_R9_OFFSET (PROBE_FIRST_GPREG_OFFSET + (9 * GPREG_SIZE)) | |
68 | #define PROBE_CPU_R10_OFFSET (PROBE_FIRST_GPREG_OFFSET + (10 * GPREG_SIZE)) | |
69 | #define PROBE_CPU_R11_OFFSET (PROBE_FIRST_GPREG_OFFSET + (11 * GPREG_SIZE)) | |
70 | #define PROBE_CPU_IP_OFFSET (PROBE_FIRST_GPREG_OFFSET + (12 * GPREG_SIZE)) | |
71 | #define PROBE_CPU_SP_OFFSET (PROBE_FIRST_GPREG_OFFSET + (13 * GPREG_SIZE)) | |
72 | #define PROBE_CPU_LR_OFFSET (PROBE_FIRST_GPREG_OFFSET + (14 * GPREG_SIZE)) | |
73 | #define PROBE_CPU_PC_OFFSET (PROBE_FIRST_GPREG_OFFSET + (15 * GPREG_SIZE)) | |
74 | ||
75 | #define PROBE_CPU_APSR_OFFSET (PROBE_FIRST_GPREG_OFFSET + (16 * GPREG_SIZE)) | |
76 | #define PROBE_CPU_FPSCR_OFFSET (PROBE_FIRST_GPREG_OFFSET + (17 * GPREG_SIZE)) | |
77 | ||
78 | #define PROBE_FIRST_FPREG_OFFSET (PROBE_FIRST_GPREG_OFFSET + (18 * GPREG_SIZE)) | |
79 | ||
80 | #define FPREG_SIZE 8 | |
81 | #define PROBE_CPU_D0_OFFSET (PROBE_FIRST_FPREG_OFFSET + (0 * FPREG_SIZE)) | |
82 | #define PROBE_CPU_D1_OFFSET (PROBE_FIRST_FPREG_OFFSET + (1 * FPREG_SIZE)) | |
83 | #define PROBE_CPU_D2_OFFSET (PROBE_FIRST_FPREG_OFFSET + (2 * FPREG_SIZE)) | |
84 | #define PROBE_CPU_D3_OFFSET (PROBE_FIRST_FPREG_OFFSET + (3 * FPREG_SIZE)) | |
85 | #define PROBE_CPU_D4_OFFSET (PROBE_FIRST_FPREG_OFFSET + (4 * FPREG_SIZE)) | |
86 | #define PROBE_CPU_D5_OFFSET (PROBE_FIRST_FPREG_OFFSET + (5 * FPREG_SIZE)) | |
87 | #define PROBE_CPU_D6_OFFSET (PROBE_FIRST_FPREG_OFFSET + (6 * FPREG_SIZE)) | |
88 | #define PROBE_CPU_D7_OFFSET (PROBE_FIRST_FPREG_OFFSET + (7 * FPREG_SIZE)) | |
89 | #define PROBE_CPU_D8_OFFSET (PROBE_FIRST_FPREG_OFFSET + (8 * FPREG_SIZE)) | |
90 | #define PROBE_CPU_D9_OFFSET (PROBE_FIRST_FPREG_OFFSET + (9 * FPREG_SIZE)) | |
91 | #define PROBE_CPU_D10_OFFSET (PROBE_FIRST_FPREG_OFFSET + (10 * FPREG_SIZE)) | |
92 | #define PROBE_CPU_D11_OFFSET (PROBE_FIRST_FPREG_OFFSET + (11 * FPREG_SIZE)) | |
93 | #define PROBE_CPU_D12_OFFSET (PROBE_FIRST_FPREG_OFFSET + (12 * FPREG_SIZE)) | |
94 | #define PROBE_CPU_D13_OFFSET (PROBE_FIRST_FPREG_OFFSET + (13 * FPREG_SIZE)) | |
95 | #define PROBE_CPU_D14_OFFSET (PROBE_FIRST_FPREG_OFFSET + (14 * FPREG_SIZE)) | |
96 | #define PROBE_CPU_D15_OFFSET (PROBE_FIRST_FPREG_OFFSET + (15 * FPREG_SIZE)) | |
97 | ||
98 | #define PROBE_SIZE (PROBE_FIRST_FPREG_OFFSET + (16 * FPREG_SIZE)) | |
99 | ||
100 | // These ASSERTs remind you that if you change the layout of ProbeContext, | |
101 | // you need to change ctiMasmProbeTrampoline offsets above to match. | |
102 | #define PROBE_OFFSETOF(x) offsetof(struct MacroAssembler::ProbeContext, x) | |
103 | COMPILE_ASSERT(PROBE_OFFSETOF(probeFunction) == PROBE_PROBE_FUNCTION_OFFSET, ProbeContext_probeFunction_offset_matches_ctiMasmProbeTrampoline); | |
104 | COMPILE_ASSERT(PROBE_OFFSETOF(arg1) == PROBE_ARG1_OFFSET, ProbeContext_arg1_offset_matches_ctiMasmProbeTrampoline); | |
105 | COMPILE_ASSERT(PROBE_OFFSETOF(arg2) == PROBE_ARG2_OFFSET, ProbeContext_arg2_offset_matches_ctiMasmProbeTrampoline); | |
106 | ||
107 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.r0) == PROBE_CPU_R0_OFFSET, ProbeContext_cpu_r0_offset_matches_ctiMasmProbeTrampoline); | |
108 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.r1) == PROBE_CPU_R1_OFFSET, ProbeContext_cpu_r1_offset_matches_ctiMasmProbeTrampoline); | |
109 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.r2) == PROBE_CPU_R2_OFFSET, ProbeContext_cpu_r2_offset_matches_ctiMasmProbeTrampoline); | |
110 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.r3) == PROBE_CPU_R3_OFFSET, ProbeContext_cpu_r3_offset_matches_ctiMasmProbeTrampoline); | |
111 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.r4) == PROBE_CPU_R4_OFFSET, ProbeContext_cpu_r4_offset_matches_ctiMasmProbeTrampoline); | |
112 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.r5) == PROBE_CPU_R5_OFFSET, ProbeContext_cpu_r5_offset_matches_ctiMasmProbeTrampoline); | |
113 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.r6) == PROBE_CPU_R6_OFFSET, ProbeContext_cpu_r6_offset_matches_ctiMasmProbeTrampoline); | |
114 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.r7) == PROBE_CPU_R7_OFFSET, ProbeContext_cpu_r70_offset_matches_ctiMasmProbeTrampoline); | |
115 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.r8) == PROBE_CPU_R8_OFFSET, ProbeContext_cpu_r8_offset_matches_ctiMasmProbeTrampoline); | |
116 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.r9) == PROBE_CPU_R9_OFFSET, ProbeContext_cpu_r9_offset_matches_ctiMasmProbeTrampoline); | |
117 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.r10) == PROBE_CPU_R10_OFFSET, ProbeContext_cpu_r10_offset_matches_ctiMasmProbeTrampoline); | |
118 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.r11) == PROBE_CPU_R11_OFFSET, ProbeContext_cpu_r11_offset_matches_ctiMasmProbeTrampoline); | |
119 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.ip) == PROBE_CPU_IP_OFFSET, ProbeContext_cpu_ip_offset_matches_ctiMasmProbeTrampoline); | |
120 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.sp) == PROBE_CPU_SP_OFFSET, ProbeContext_cpu_sp_offset_matches_ctiMasmProbeTrampoline); | |
121 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.lr) == PROBE_CPU_LR_OFFSET, ProbeContext_cpu_lr_offset_matches_ctiMasmProbeTrampoline); | |
122 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.pc) == PROBE_CPU_PC_OFFSET, ProbeContext_cpu_pc_offset_matches_ctiMasmProbeTrampoline); | |
123 | ||
124 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.apsr) == PROBE_CPU_APSR_OFFSET, ProbeContext_cpu_apsr_offset_matches_ctiMasmProbeTrampoline); | |
125 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.fpscr) == PROBE_CPU_FPSCR_OFFSET, ProbeContext_cpu_fpscr_offset_matches_ctiMasmProbeTrampoline); | |
126 | ||
127 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d0) == PROBE_CPU_D0_OFFSET, ProbeContext_cpu_d0_offset_matches_ctiMasmProbeTrampoline); | |
128 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d1) == PROBE_CPU_D1_OFFSET, ProbeContext_cpu_d1_offset_matches_ctiMasmProbeTrampoline); | |
129 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d2) == PROBE_CPU_D2_OFFSET, ProbeContext_cpu_d2_offset_matches_ctiMasmProbeTrampoline); | |
130 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d3) == PROBE_CPU_D3_OFFSET, ProbeContext_cpu_d3_offset_matches_ctiMasmProbeTrampoline); | |
131 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d4) == PROBE_CPU_D4_OFFSET, ProbeContext_cpu_d4_offset_matches_ctiMasmProbeTrampoline); | |
132 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d5) == PROBE_CPU_D5_OFFSET, ProbeContext_cpu_d5_offset_matches_ctiMasmProbeTrampoline); | |
133 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d6) == PROBE_CPU_D6_OFFSET, ProbeContext_cpu_d6_offset_matches_ctiMasmProbeTrampoline); | |
134 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d7) == PROBE_CPU_D7_OFFSET, ProbeContext_cpu_d7_offset_matches_ctiMasmProbeTrampoline); | |
135 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d8) == PROBE_CPU_D8_OFFSET, ProbeContext_cpu_d8_offset_matches_ctiMasmProbeTrampoline); | |
136 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d9) == PROBE_CPU_D9_OFFSET, ProbeContext_cpu_d9_offset_matches_ctiMasmProbeTrampoline); | |
137 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d10) == PROBE_CPU_D10_OFFSET, ProbeContext_cpu_d10_offset_matches_ctiMasmProbeTrampoline); | |
138 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d11) == PROBE_CPU_D11_OFFSET, ProbeContext_cpu_d11_offset_matches_ctiMasmProbeTrampoline); | |
139 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d12) == PROBE_CPU_D12_OFFSET, ProbeContext_cpu_d12_offset_matches_ctiMasmProbeTrampoline); | |
140 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d13) == PROBE_CPU_D13_OFFSET, ProbeContext_cpu_d13_offset_matches_ctiMasmProbeTrampoline); | |
141 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d14) == PROBE_CPU_D14_OFFSET, ProbeContext_cpu_d14_offset_matches_ctiMasmProbeTrampoline); | |
142 | COMPILE_ASSERT(PROBE_OFFSETOF(cpu.d15) == PROBE_CPU_D15_OFFSET, ProbeContext_cpu_d15_offset_matches_ctiMasmProbeTrampoline); | |
143 | COMPILE_ASSERT(sizeof(MacroAssembler::ProbeContext) == PROBE_SIZE, ProbeContext_size_matches_ctiMasmProbeTrampoline); | |
144 | #undef PROBE_OFFSETOF | |
145 | ||
146 | #endif // USE(MASM_PROBE) | |
147 | ||
148 | ||
149 | #if USE(MASM_PROBE) | |
150 | asm ( | |
151 | ".text" "\n" | |
152 | ".globl " SYMBOL_STRING(ctiMasmProbeTrampoline) "\n" | |
153 | HIDE_SYMBOL(ctiMasmProbeTrampoline) "\n" | |
154 | INLINE_ARM_FUNCTION(ctiMasmProbeTrampoline) "\n" | |
155 | SYMBOL_STRING(ctiMasmProbeTrampoline) ":" "\n" | |
156 | ||
157 | // MacroAssembler::probe() has already generated code to store some values. | |
158 | // The top of stack now looks like this: | |
159 | // esp[0 * ptrSize]: probeFunction | |
160 | // esp[1 * ptrSize]: arg1 | |
161 | // esp[2 * ptrSize]: arg2 | |
162 | // esp[3 * ptrSize]: saved r3 / S0 | |
163 | // esp[4 * ptrSize]: saved ip | |
164 | // esp[5 * ptrSize]: saved lr | |
165 | // esp[6 * ptrSize]: saved sp | |
166 | ||
167 | "mov ip, sp" "\n" | |
168 | "mov r3, sp" "\n" | |
169 | "sub r3, r3, #" STRINGIZE_VALUE_OF(PROBE_SIZE) "\n" | |
170 | ||
171 | // The ARM EABI specifies that the stack needs to be 16 byte aligned. | |
172 | "bic r3, r3, #0xf" "\n" | |
173 | "mov sp, r3" "\n" | |
174 | ||
175 | "str lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_PC_OFFSET) "]" "\n" | |
176 | "add lr, sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_R0_OFFSET) "\n" | |
177 | "stmia lr, { r0-r11 }" "\n" | |
178 | "mrs lr, APSR" "\n" | |
179 | "str lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_APSR_OFFSET) "]" "\n" | |
180 | "vmrs lr, FPSCR" "\n" | |
181 | "str lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_FPSCR_OFFSET) "]" "\n" | |
182 | ||
183 | "ldr lr, [ip, #0 * " STRINGIZE_VALUE_OF(PTR_SIZE) "]" "\n" | |
184 | "str lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_PROBE_FUNCTION_OFFSET) "]" "\n" | |
185 | "ldr lr, [ip, #1 * " STRINGIZE_VALUE_OF(PTR_SIZE) "]" "\n" | |
186 | "str lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_ARG1_OFFSET) "]" "\n" | |
187 | "ldr lr, [ip, #2 * " STRINGIZE_VALUE_OF(PTR_SIZE) "]" "\n" | |
188 | "str lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_ARG2_OFFSET) "]" "\n" | |
189 | "ldr lr, [ip, #3 * " STRINGIZE_VALUE_OF(PTR_SIZE) "]" "\n" | |
190 | "str lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_R3_OFFSET) "]" "\n" | |
191 | "ldr lr, [ip, #4 * " STRINGIZE_VALUE_OF(PTR_SIZE) "]" "\n" | |
192 | "str lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_IP_OFFSET) "]" "\n" | |
193 | "ldr lr, [ip, #5 * " STRINGIZE_VALUE_OF(PTR_SIZE) "]" "\n" | |
194 | "str lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_LR_OFFSET) "]" "\n" | |
195 | "ldr lr, [ip, #6 * " STRINGIZE_VALUE_OF(PTR_SIZE) "]" "\n" | |
196 | "str lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_SP_OFFSET) "]" "\n" | |
197 | ||
198 | "ldr lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_PC_OFFSET) "]" "\n" | |
199 | ||
200 | "add ip, sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_D0_OFFSET) "\n" | |
201 | "vstmia.64 ip, { d0-d15 }" "\n" | |
202 | ||
203 | "mov fp, sp" "\n" // Save the ProbeContext*. | |
204 | ||
205 | "ldr ip, [sp, #" STRINGIZE_VALUE_OF(PROBE_PROBE_FUNCTION_OFFSET) "]" "\n" | |
206 | "mov r0, sp" "\n" // the ProbeContext* arg. | |
207 | "blx ip" "\n" | |
208 | ||
209 | "mov sp, fp" "\n" | |
210 | ||
211 | // To enable probes to modify register state, we copy all registers | |
212 | // out of the ProbeContext before returning. | |
213 | ||
214 | "add ip, sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_D15_OFFSET + FPREG_SIZE) "\n" | |
215 | "vldmdb.64 ip!, { d0-d15 }" "\n" | |
216 | "add ip, sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_R11_OFFSET + GPREG_SIZE) "\n" | |
217 | "ldmdb ip, { r0-r11 }" "\n" | |
218 | "ldr ip, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_FPSCR_OFFSET) "]" "\n" | |
219 | "vmsr FPSCR, ip" "\n" | |
220 | ||
221 | // There are 5 more registers left to restore: ip, sp, lr, pc, and apsr. | |
222 | // There are 2 issues that complicate the restoration of these last few | |
223 | // registers: | |
224 | // | |
225 | // 1. Normal ARM calling convention relies on moving lr to pc to return to | |
226 | // the caller. In our case, the address to return to is specified by | |
227 | // ProbeContext.cpu.pc. And at that moment, we won't have any available | |
228 | // scratch registers to hold the return address (lr needs to hold | |
229 | // ProbeContext.cpu.lr, not the return address). | |
230 | // | |
231 | // The solution is to store the return address on the stack and load the | |
232 | // pc from there. | |
233 | // | |
234 | // 2. Issue 1 means we will need to write to the stack location at | |
235 | // ProbeContext.cpu.sp - 4. But if the user probe function had modified | |
236 | // the value of ProbeContext.cpu.sp to point in the range between | |
237 | // &ProbeContext.cpu.ip thru &ProbeContext.cpu.aspr, then the action for | |
238 | // Issue 1 may trash the values to be restored before we can restore | |
239 | // them. | |
240 | // | |
241 | // The solution is to check if ProbeContext.cpu.sp contains a value in | |
242 | // the undesirable range. If so, we copy the remaining ProbeContext | |
243 | // register data to a safe range (at memory lower than where | |
244 | // ProbeContext.cpu.sp points) first, and restore the remaining register | |
245 | // from this new range. | |
246 | ||
247 | "add ip, sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_APSR_OFFSET) "\n" | |
248 | "ldr lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_SP_OFFSET) "]" "\n" | |
249 | "cmp lr, ip" "\n" | |
250 | "bgt " SYMBOL_STRING(ctiMasmProbeTrampolineEnd) "\n" | |
251 | ||
252 | // We get here because the new expected stack pointer location is lower | |
253 | // than where it's supposed to be. This means the safe range of stack | |
254 | // memory where we'll be copying the remaining register restore values to | |
255 | // might be in a region of memory below the sp i.e. unallocated stack | |
256 | // memory. This in turn makes it vulnerable to interrupts potentially | |
257 | // trashing the copied values. To prevent that, we must first allocate the | |
258 | // needed stack memory by adjusting the sp before the copying. | |
259 | ||
260 | "sub lr, lr, #(6 * " STRINGIZE_VALUE_OF(PTR_SIZE) | |
261 | " + " STRINGIZE_VALUE_OF(PROBE_CPU_IP_OFFSET) ")" "\n" | |
262 | ||
263 | "mov ip, sp" "\n" | |
264 | "mov sp, lr" "\n" | |
265 | "mov lr, ip" "\n" | |
266 | ||
267 | "ldr ip, [lr, #" STRINGIZE_VALUE_OF(PROBE_CPU_IP_OFFSET) "]" "\n" | |
268 | "str ip, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_IP_OFFSET) "]" "\n" | |
269 | "ldr ip, [lr, #" STRINGIZE_VALUE_OF(PROBE_CPU_SP_OFFSET) "]" "\n" | |
270 | "str ip, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_SP_OFFSET) "]" "\n" | |
271 | "ldr ip, [lr, #" STRINGIZE_VALUE_OF(PROBE_CPU_LR_OFFSET) "]" "\n" | |
272 | "str ip, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_LR_OFFSET) "]" "\n" | |
273 | "ldr ip, [lr, #" STRINGIZE_VALUE_OF(PROBE_CPU_PC_OFFSET) "]" "\n" | |
274 | "str ip, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_PC_OFFSET) "]" "\n" | |
275 | "ldr ip, [lr, #" STRINGIZE_VALUE_OF(PROBE_CPU_APSR_OFFSET) "]" "\n" | |
276 | "str ip, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_APSR_OFFSET) "]" "\n" | |
277 | ||
278 | SYMBOL_STRING(ctiMasmProbeTrampolineEnd) ":" "\n" | |
279 | "ldr ip, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_PC_OFFSET) "]" "\n" | |
280 | "ldr lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_SP_OFFSET) "]" "\n" | |
281 | "sub lr, lr, #" STRINGIZE_VALUE_OF(PTR_SIZE) "\n" | |
282 | "str ip, [lr]" "\n" | |
283 | "str lr, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_SP_OFFSET) "]" "\n" | |
284 | ||
285 | "ldr ip, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_APSR_OFFSET) "]" "\n" | |
286 | "msr APSR, ip" "\n" | |
287 | "ldr ip, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_LR_OFFSET) "]" "\n" | |
288 | "mov lr, ip" "\n" | |
289 | "ldr ip, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_IP_OFFSET) "]" "\n" | |
290 | "ldr sp, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_SP_OFFSET) "]" "\n" | |
291 | ||
292 | "pop { pc }" "\n" | |
293 | ); | |
294 | #endif // USE(MASM_PROBE) | |
295 | ||
296 | ||
297 | ||
298 | #endif // COMPILER(GCC) | |
299 | ||
300 | } // namespace JSC | |
301 | ||
302 | #endif // JITStubsARM_h |