blob: 9cfb3ab74cfc2c71a49f4f31c308c6022772f0ed [file] [log] [blame]
Ian Rogers9651f422011-09-19 20:26:07 -07001#include "asm_support.h"
2
buzbee54330722011-08-23 16:46:55 -07003#if defined(__arm__)
4
5 .balign 4
buzbee4a3164f2011-09-03 11:25:10 -07006
Ian Rogersff1ed472011-09-20 13:46:24 -07007 /* Deliver the given exception */
8 .extern artDeliverExceptionFromCode
9 /* Deliver an exception pending on a thread */
10 .extern artDeliverPendingException
11
12 .global art_deliver_exception_from_code
Ian Rogersbdb03912011-09-14 00:55:44 -070013 /*
Ian Rogersff1ed472011-09-20 13:46:24 -070014 * Called by managed code, saves mosts registers (forms basis of long jump context) and passes
15 * the bottom of the stack. artDeliverExceptionFromCode will place the callee save Method* at
16 * the bottom of the thread. On entry r0 holds Throwable*
Ian Rogersbdb03912011-09-14 00:55:44 -070017 */
Ian Rogersff1ed472011-09-20 13:46:24 -070018art_deliver_exception_from_code:
Ian Rogersbdb03912011-09-14 00:55:44 -070019 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
Ian Rogersff1ed472011-09-20 13:46:24 -070020 sub sp, #16 @ 4 words of space, bottom word will hold Method*
21 mov r1, r9 @ pass Thread::Current
22 mov r2, sp @ pass SP
23 b artDeliverExceptionFromCode @ artDeliverExceptionFromCode(Throwable*, Thread*, SP)
Ian Rogers9651f422011-09-19 20:26:07 -070024
25 .global art_throw_null_pointer_exception_from_code
Ian Rogersff1ed472011-09-20 13:46:24 -070026 .extern artThrowNullPointerExceptionFromCode
Ian Rogers9651f422011-09-19 20:26:07 -070027 /*
Ian Rogersff1ed472011-09-20 13:46:24 -070028 * Called by managed code to create and deliver a NullPointerException
Ian Rogers9651f422011-09-19 20:26:07 -070029 */
30art_throw_null_pointer_exception_from_code:
31 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
Ian Rogersff1ed472011-09-20 13:46:24 -070032 sub sp, #16 @ 4 words of space, bottom word will hold Method*
33 mov r0, r9 @ pass Thread::Current
34 mov r1, sp @ pass SP
35 b artThrowNullPointerExceptionFromCode @ artThrowNullPointerExceptionFromCode(Thread*, SP)
Ian Rogers9651f422011-09-19 20:26:07 -070036
37 .global art_throw_div_zero_from_code
Ian Rogersff1ed472011-09-20 13:46:24 -070038 .extern artThrowDivZeroFromCode
Ian Rogers9651f422011-09-19 20:26:07 -070039 /*
Ian Rogersff1ed472011-09-20 13:46:24 -070040 * Called by managed code to create and deliver an ArithmeticException
Ian Rogers9651f422011-09-19 20:26:07 -070041 */
42art_throw_div_zero_from_code:
43 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
Ian Rogersff1ed472011-09-20 13:46:24 -070044 sub sp, #16 @ 4 words of space, bottom word will hold Method*
45 mov r0, r9 @ pass Thread::Current
46 mov r1, sp @ pass SP
47 b artThrowDivZeroFromCode @ artThrowDivZeroFromCode(Thread*, SP)
Ian Rogers9651f422011-09-19 20:26:07 -070048
49 .global art_throw_array_bounds_from_code
Ian Rogersff1ed472011-09-20 13:46:24 -070050 .extern artThrowArrayBoundsFromCode
Ian Rogers9651f422011-09-19 20:26:07 -070051 /*
Ian Rogersff1ed472011-09-20 13:46:24 -070052 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException
Ian Rogers9651f422011-09-19 20:26:07 -070053 */
54art_throw_array_bounds_from_code:
55 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
Ian Rogersff1ed472011-09-20 13:46:24 -070056 sub sp, #16 @ 4 words of space, bottom word will hold Method*
57 mov r2, r9 @ pass Thread::Current
58 mov r3, sp @ pass SP
59 b artThrowArrayBoundsFromCode @ artThrowArrayBoundsFromCode(index, limit, Thread*, SP)
Ian Rogersbdb03912011-09-14 00:55:44 -070060
Ian Rogers932746a2011-09-22 18:57:50 -070061 .global art_throw_stack_overflow_from_code
62 .extern artThrowStackOverflowFromCode
63art_throw_stack_overflow_from_code:
64 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
65 sub sp, #16 @ 4 words of space, bottom word will hold Method*
66 mov r1, r9 @ pass Thread::Current
67 mov r2, sp @ pass SP
68 b artThrowStackOverflowFromCode @ artThrowStackOverflowFromCode(method, Thread*, SP)
69
buzbee4a3164f2011-09-03 11:25:10 -070070 .global art_invoke_interface_trampoline
Ian Rogersff1ed472011-09-20 13:46:24 -070071 .extern artFindInterfaceMethodInCacheFromCode
buzbee4a3164f2011-09-03 11:25:10 -070072 /*
Ian Rogersff1ed472011-09-20 13:46:24 -070073 * All generated callsites for interface invokes will load arguments as usual - except instead
74 * of loading arg0/r0 with the target Method*, arg0/r0 will contain the method_idx. This
75 * wrapper will save arg1-arg3, load the caller's Method*, align the stack and call the helper
76 * artFindInterfaceMethodInCacheFromCode(idx, this, method);
77 * NOTE: "this" is first visable argument of the target, and so can be found in arg1/r1.
buzbee4a3164f2011-09-03 11:25:10 -070078 *
Ian Rogersff1ed472011-09-20 13:46:24 -070079 * artFindInterfaceMethodInCacheFromCode will attempt to locate the target and return a 64-bit
80 * result in r0/r1 consisting of the target Method* in r0 and method->code_ in r1.
buzbee4a3164f2011-09-03 11:25:10 -070081 *
Ian Rogersff1ed472011-09-20 13:46:24 -070082 * If unsuccessful, artFindInterfaceMethodInCacheFromCode will return NULL/NULL. There will be
83 * a pending exception in the thread and we branch to another stub to deliver it.
buzbee4a3164f2011-09-03 11:25:10 -070084 *
Ian Rogersff1ed472011-09-20 13:46:24 -070085 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
86 * pointing back to the original caller.
buzbee4a3164f2011-09-03 11:25:10 -070087 */
Ian Rogersff1ed472011-09-20 13:46:24 -070088art_invoke_interface_trampoline:
89 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
90 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
buzbee4a3164f2011-09-03 11:25:10 -070091 stmdb sp!, {r1, r2, r3, lr}
Ian Rogersff1ed472011-09-20 13:46:24 -070092 ldr r2, [sp, #16] @ load caller's Method*
93 bl artFindInterfaceMethodInCacheFromCode @ (method_idx, this, callerMethod)
94 mov r12, r1 @ save r0->code_
95 ldmia sp!, {r1, r2, r3, lr} @ restore arguments
96 cmp r0, #0 @ did we find the target?
97 bxne r12 @ tail call to target if so
98 @ set up for throwing exception
99 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
100 sub sp, #16 @ 4 words of space, bottom word will hold Method*
101 mov r0, r9 @ pass Thread::Current
102 mov r1, sp @ pass SP
103 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
104
105 .global art_handle_fill_data_from_code
106 .extern artHandleFillArrayDataFromCode
107 /*
108 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
109 * failure.
110 */
111art_handle_fill_data_from_code:
112 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
113 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
114 stmdb sp!, {lr} @ Save LR
115 sub sp, #12 @ Align stack
116 bl artHandleFillArrayDataFromCode @ (Array* array, const uint16_t* table)
117 add sp, #12
118 ldmia sp!, {lr} @ restore LR
119 cmp r0, #0 @ success?
120 moveq pc, lr @ return on success
121 @ set up for throwing exception
122 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
123 sub sp, #16 @ 4 words of space, bottom word will hold Method*
124 mov r0, r9 @ pass Thread::Current
125 mov r1, sp @ pass SP
126 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
127
128 .global art_unlock_object_from_code
129 .extern artUnlockObjectFromCode
130 /*
131 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
132 */
133art_unlock_object_from_code:
134 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
135 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
136 stmdb sp!, {lr} @ Save LR
137 sub sp, #12 @ Align stack
138 bl artUnlockObjectFromCode @ (Thread* thread, Object* obj)
139 add sp, #12
140 ldmia sp!, {lr} @ restore LR
141 cmp r0, #0 @ success?
142 moveq pc, lr @ return on success
143 @ set up for throwing exception
144 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
145 sub sp, #16 @ 4 words of space, bottom word will hold Method*
146 mov r0, r9 @ pass Thread::Current
147 mov r1, sp @ pass SP
148 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
149
150 .global art_check_cast_from_code
151 .extern artCheckCastFromCode
152 /*
153 * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
154 */
155art_check_cast_from_code:
156 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
157 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
158 stmdb sp!, {lr} @ Save LR
159 sub sp, #12 @ Align stack
160 bl artCheckCastFromCode @ (Class* a, Class* b)
161 add sp, #12
162 ldmia sp!, {lr} @ restore LR
163 cmp r0, #0 @ success?
164 moveq pc, lr @ return on success
165 @ set up for throwing exception
166 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
167 sub sp, #16 @ 4 words of space, bottom word will hold Method*
168 mov r0, r9 @ pass Thread::Current
169 mov r1, sp @ pass SP
170 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
buzbee4a3164f2011-09-03 11:25:10 -0700171
Ian Rogerse51a5112011-09-23 14:16:35 -0700172 .global art_can_put_array_element_from_code
173 .extern artCanPutArrayElementFromCode
174 /*
175 * Entry from managed code that calls artCanPutArrayElementFromCode and delivers exception on
176 * failure.
177 */
178art_can_put_array_element_from_code:
179 cmp r0, #0 @ return if element == NULL
180 moveq pc, lr
181 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
182 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
183 stmdb sp!, {lr} @ Save LR
184 sub sp, #12 @ Align stack
185 bl artCanPutArrayElementFromCode @ (Object* element, Class* array_class)
186 add sp, #12
187 ldmia sp!, {lr} @ restore LR
188 cmp r0, #0 @ success?
189 moveq pc, lr @ return on success
190 @ set up for throwing exception
191 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
192 sub sp, #16 @ 4 words of space, bottom word will hold Method*
193 mov r0, r9 @ pass Thread::Current
194 mov r1, sp @ pass SP
195 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
196
Ian Rogerscbba6ac2011-09-22 16:28:37 -0700197 .global art_initialize_static_storage_from_code
198 .extern _ZN3art11ClassLinker31InitializeStaticStorageFromCodeEjPKNS_6MethodE
199 /*
200 * Entry from managed code when uninitialized static storage, this stub will run the class
201 * initializer and deliver the exception on error. On success the static storage base is
202 * returned.
203 */
204art_initialize_static_storage_from_code:
205 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
206 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
207 stmdb sp!, {lr} @ Save LR
208 sub sp, #12 @ Align stack
209 @ ClassLinker::InitializeStaticStorageFromCode(uint32_t type_idx, Method* referrer)
210 bl _ZN3art11ClassLinker31InitializeStaticStorageFromCodeEjPKNS_6MethodE
211 add sp, #12
212 ldmia sp!, {lr} @ restore LR
213 cmp r0, #0 @ success if result is non-null
214 movne pc, lr @ return on success
215 @ set up for throwing exception
216 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
217 sub sp, #16 @ 4 words of space, bottom word will hold Method*
218 mov r0, r9 @ pass Thread::Current
219 mov r1, sp @ pass SP
220 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
221
Ian Rogersb886da82011-09-23 16:27:54 -0700222 .global art_array_alloc_from_code
223 .extern artArrayAllocFromCode
224 /*
225 * Called by managed code to allocate an array
226 */
227art_array_alloc_from_code:
228 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
229 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
230 stmdb sp!, {lr} @ Save LR
231 sub sp, #12 @ Align stack
232 bl artArrayAllocFromCode @ (uint32_t type_idx, Method* method, int32_t component_count)
233 add sp, #12
234 ldmia sp!, {lr} @ restore LR
235 cmp r0, #0 @ success if result is non-null
236 movne pc, lr @ return on success
237 @ set up for throwing exception
238 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
239 sub sp, #16 @ 4 words of space, bottom word will hold Method*
240 mov r0, r9 @ pass Thread::Current
241 mov r1, sp @ pass SP
242 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
243
244 .global art_check_and_array_alloc_from_code
245 .extern artCheckAndArrayAllocFromCode
246 /*
247 * Called by managed code to allocate an array
248 */
249art_check_and_array_alloc_from_code:
250 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
251 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
252 stmdb sp!, {lr} @ Save LR
253 sub sp, #12 @ Align stack
254 bl artCheckAndArrayAllocFromCode @ (uint32_t type_idx, Method* method, int32_t count)
255 add sp, #12
256 ldmia sp!, {lr} @ restore LR
257 cmp r0, #0 @ success if result is non-null
258 movne pc, lr @ return on success
259 @ set up for throwing exception
260 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
261 sub sp, #16 @ 4 words of space, bottom word will hold Method*
262 mov r0, r9 @ pass Thread::Current
263 mov r1, sp @ pass SP
264 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
265
buzbee54330722011-08-23 16:46:55 -0700266 .global art_shl_long
267art_shl_long:
268 /*
269 * Long integer shift. This is different from the generic 32/64-bit
270 * binary operations because vAA/vBB are 64-bit but vCC (the shift
271 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
272 * 6 bits.
273 * On entry:
274 * r0: low word
275 * r1: high word
276 * r2: shift count
277 */
278 /* shl-long vAA, vBB, vCC */
279 and r2, r2, #63 @ r2<- r2 & 0x3f
280 mov r1, r1, asl r2 @ r1<- r1 << r2
281 rsb r3, r2, #32 @ r3<- 32 - r2
282 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
283 subs ip, r2, #32 @ ip<- r2 - 32
284 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
285 mov r0, r0, asl r2 @ r0<- r0 << r2
286 bx lr
287
288 .balign 4
289 .global art_shr_long
290art_shr_long:
291 /*
292 * Long integer shift. This is different from the generic 32/64-bit
293 * binary operations because vAA/vBB are 64-bit but vCC (the shift
294 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
295 * 6 bits.
296 * On entry:
297 * r0: low word
298 * r1: high word
299 * r2: shift count
300 */
301 /* shr-long vAA, vBB, vCC */
302 and r2, r2, #63 @ r0<- r0 & 0x3f
303 mov r0, r0, lsr r2 @ r0<- r2 >> r2
304 rsb r3, r2, #32 @ r3<- 32 - r2
305 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
306 subs ip, r2, #32 @ ip<- r2 - 32
307 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
308 mov r1, r1, asr r2 @ r1<- r1 >> r2
309 bx lr
310
311 .balign 4
312 .global art_ushr_long
313art_ushr_long:
314 /*
315 * Long integer shift. This is different from the generic 32/64-bit
316 * binary operations because vAA/vBB are 64-bit but vCC (the shift
317 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
318 * 6 bits.
319 * On entry:
320 * r0: low word
321 * r1: high word
322 * r2: shift count
323 */
324 /* ushr-long vAA, vBB, vCC */
325 and r2, r2, #63 @ r0<- r0 & 0x3f
326 mov r0, r0, lsr r2 @ r0<- r2 >> r2
327 rsb r3, r2, #32 @ r3<- 32 - r2
328 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
329 subs ip, r2, #32 @ ip<- r2 - 32
330 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
331 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
332 bx lr
333
buzbeec1f45042011-09-21 16:03:19 -0700334 .balign 4
335 .global art_test_suspend
336 .extern artCheckSuspendFromCode
337art_test_suspend:
338 /*
339 * Check to see if there's a pending suspend request on our thread.
340 * reset rSUSPEND to SUSPEND_CHECK_INTERVAL.
341 * On entry, rSUSPEND holds the suspend request value
342 * [TUNING: move load of suspend check value into this stub.
343 */
344 cmp rSUSPEND, #0
345 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL
346 bxeq rLR
347 mov r0, rSELF
348 b artCheckSuspendFromCode
349
350
buzbee54330722011-08-23 16:46:55 -0700351#endif
Ian Rogers67375ac2011-09-14 00:55:44 -0700352
353#if defined(__i386__)
354
Ian Rogersff1ed472011-09-20 13:46:24 -0700355 .global art_deliver_exception_from_code
356 .extern artDeliverExceptionFromCode
Ian Rogers67375ac2011-09-14 00:55:44 -0700357 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700358 * Called by managed code, saves callee saves and then calls artThrowException
Ian Rogers67375ac2011-09-14 00:55:44 -0700359 * that will place a mock Method* at the bottom of the stack.
360 * EAX holds the exception.
361 */
Ian Rogersff1ed472011-09-20 13:46:24 -0700362art_deliver_exception_from_code:
Ian Rogers67375ac2011-09-14 00:55:44 -0700363 // Create frame
364 pushl %edi // Save callee saves
365 pushl %esi
366 pushl %ebp
367 pushl %ebx
368 pushl $0
369 pushl $0
370 pushl $0 // Will be clobbered to be Method*
371 mov %esp, %ecx
372 // Outgoing argument set up
Ian Rogersff1ed472011-09-20 13:46:24 -0700373 pushl $0 // Alignment padding
374 pushl %ecx // pass SP
375 pushl %fs:THREAD_SELF_OFFSET // pass fs:offsetof(Thread,self_)
376 pushl %eax // pass Throwable*
377 call artDeliverExceptionFromCode // artDeliverExceptionFromCode(Throwable*, Thread*, SP)
Ian Rogers67375ac2011-09-14 00:55:44 -0700378 int3
379
380#endif