blob: 4a503443055c2bbb04e382059f62a0ce84f84dec [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 Rogers21d9e832011-09-23 17:05:09 -0700222 .global art_alloc_object_from_code
223 .extern artAllocObjectFromCode
224 /*
225 * Called by managed code to allocate an object
226 */
227art_alloc_object_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 artAllocObjectFromCode @ (uint32_t type_idx, Method* method)
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
Ian Rogersb886da82011-09-23 16:27:54 -0700244 .global art_array_alloc_from_code
245 .extern artArrayAllocFromCode
246 /*
247 * Called by managed code to allocate an array
248 */
249art_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 artArrayAllocFromCode @ (uint32_t type_idx, Method* method, int32_t component_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
266 .global art_check_and_array_alloc_from_code
267 .extern artCheckAndArrayAllocFromCode
268 /*
269 * Called by managed code to allocate an array
270 */
271art_check_and_array_alloc_from_code:
272 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
273 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
274 stmdb sp!, {lr} @ Save LR
275 sub sp, #12 @ Align stack
276 bl artCheckAndArrayAllocFromCode @ (uint32_t type_idx, Method* method, int32_t count)
277 add sp, #12
278 ldmia sp!, {lr} @ restore LR
279 cmp r0, #0 @ success if result is non-null
280 movne pc, lr @ return on success
281 @ set up for throwing exception
282 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
283 sub sp, #16 @ 4 words of space, bottom word will hold Method*
284 mov r0, r9 @ pass Thread::Current
285 mov r1, sp @ pass SP
286 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
287
buzbee54330722011-08-23 16:46:55 -0700288 .global art_shl_long
289art_shl_long:
290 /*
291 * Long integer shift. This is different from the generic 32/64-bit
292 * binary operations because vAA/vBB are 64-bit but vCC (the shift
293 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
294 * 6 bits.
295 * On entry:
296 * r0: low word
297 * r1: high word
298 * r2: shift count
299 */
300 /* shl-long vAA, vBB, vCC */
301 and r2, r2, #63 @ r2<- r2 & 0x3f
302 mov r1, r1, asl r2 @ r1<- r1 << r2
303 rsb r3, r2, #32 @ r3<- 32 - r2
304 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
305 subs ip, r2, #32 @ ip<- r2 - 32
306 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
307 mov r0, r0, asl r2 @ r0<- r0 << r2
308 bx lr
309
310 .balign 4
311 .global art_shr_long
312art_shr_long:
313 /*
314 * Long integer shift. This is different from the generic 32/64-bit
315 * binary operations because vAA/vBB are 64-bit but vCC (the shift
316 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
317 * 6 bits.
318 * On entry:
319 * r0: low word
320 * r1: high word
321 * r2: shift count
322 */
323 /* shr-long vAA, vBB, vCC */
324 and r2, r2, #63 @ r0<- r0 & 0x3f
325 mov r0, r0, lsr r2 @ r0<- r2 >> r2
326 rsb r3, r2, #32 @ r3<- 32 - r2
327 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
328 subs ip, r2, #32 @ ip<- r2 - 32
329 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
330 mov r1, r1, asr r2 @ r1<- r1 >> r2
331 bx lr
332
333 .balign 4
334 .global art_ushr_long
335art_ushr_long:
336 /*
337 * Long integer shift. This is different from the generic 32/64-bit
338 * binary operations because vAA/vBB are 64-bit but vCC (the shift
339 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
340 * 6 bits.
341 * On entry:
342 * r0: low word
343 * r1: high word
344 * r2: shift count
345 */
346 /* ushr-long vAA, vBB, vCC */
347 and r2, r2, #63 @ r0<- r0 & 0x3f
348 mov r0, r0, lsr r2 @ r0<- r2 >> r2
349 rsb r3, r2, #32 @ r3<- 32 - r2
350 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
351 subs ip, r2, #32 @ ip<- r2 - 32
352 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
353 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
354 bx lr
355
buzbeec1f45042011-09-21 16:03:19 -0700356 .balign 4
357 .global art_test_suspend
358 .extern artCheckSuspendFromCode
359art_test_suspend:
360 /*
361 * Check to see if there's a pending suspend request on our thread.
362 * reset rSUSPEND to SUSPEND_CHECK_INTERVAL.
363 * On entry, rSUSPEND holds the suspend request value
364 * [TUNING: move load of suspend check value into this stub.
365 */
366 cmp rSUSPEND, #0
367 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL
368 bxeq rLR
369 mov r0, rSELF
370 b artCheckSuspendFromCode
371
372
buzbee54330722011-08-23 16:46:55 -0700373#endif
Ian Rogers67375ac2011-09-14 00:55:44 -0700374
375#if defined(__i386__)
376
Ian Rogersff1ed472011-09-20 13:46:24 -0700377 .global art_deliver_exception_from_code
378 .extern artDeliverExceptionFromCode
Ian Rogers67375ac2011-09-14 00:55:44 -0700379 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700380 * Called by managed code, saves callee saves and then calls artThrowException
Ian Rogers67375ac2011-09-14 00:55:44 -0700381 * that will place a mock Method* at the bottom of the stack.
382 * EAX holds the exception.
383 */
Ian Rogersff1ed472011-09-20 13:46:24 -0700384art_deliver_exception_from_code:
Ian Rogers67375ac2011-09-14 00:55:44 -0700385 // Create frame
386 pushl %edi // Save callee saves
387 pushl %esi
388 pushl %ebp
389 pushl %ebx
390 pushl $0
391 pushl $0
392 pushl $0 // Will be clobbered to be Method*
393 mov %esp, %ecx
394 // Outgoing argument set up
Ian Rogersff1ed472011-09-20 13:46:24 -0700395 pushl $0 // Alignment padding
396 pushl %ecx // pass SP
397 pushl %fs:THREAD_SELF_OFFSET // pass fs:offsetof(Thread,self_)
398 pushl %eax // pass Throwable*
399 call artDeliverExceptionFromCode // artDeliverExceptionFromCode(Throwable*, Thread*, SP)
Ian Rogers67375ac2011-09-14 00:55:44 -0700400 int3
401
402#endif