blob: 963e1aafdb17d9a677e54fca56e4f8557c0800bc [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
buzbee54330722011-08-23 16:46:55 -0700222 .global art_shl_long
223art_shl_long:
224 /*
225 * Long integer shift. This is different from the generic 32/64-bit
226 * binary operations because vAA/vBB are 64-bit but vCC (the shift
227 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
228 * 6 bits.
229 * On entry:
230 * r0: low word
231 * r1: high word
232 * r2: shift count
233 */
234 /* shl-long vAA, vBB, vCC */
235 and r2, r2, #63 @ r2<- r2 & 0x3f
236 mov r1, r1, asl r2 @ r1<- r1 << r2
237 rsb r3, r2, #32 @ r3<- 32 - r2
238 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
239 subs ip, r2, #32 @ ip<- r2 - 32
240 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
241 mov r0, r0, asl r2 @ r0<- r0 << r2
242 bx lr
243
244 .balign 4
245 .global art_shr_long
246art_shr_long:
247 /*
248 * Long integer shift. This is different from the generic 32/64-bit
249 * binary operations because vAA/vBB are 64-bit but vCC (the shift
250 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
251 * 6 bits.
252 * On entry:
253 * r0: low word
254 * r1: high word
255 * r2: shift count
256 */
257 /* shr-long vAA, vBB, vCC */
258 and r2, r2, #63 @ r0<- r0 & 0x3f
259 mov r0, r0, lsr r2 @ r0<- r2 >> r2
260 rsb r3, r2, #32 @ r3<- 32 - r2
261 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
262 subs ip, r2, #32 @ ip<- r2 - 32
263 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
264 mov r1, r1, asr r2 @ r1<- r1 >> r2
265 bx lr
266
267 .balign 4
268 .global art_ushr_long
269art_ushr_long:
270 /*
271 * Long integer shift. This is different from the generic 32/64-bit
272 * binary operations because vAA/vBB are 64-bit but vCC (the shift
273 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
274 * 6 bits.
275 * On entry:
276 * r0: low word
277 * r1: high word
278 * r2: shift count
279 */
280 /* ushr-long vAA, vBB, vCC */
281 and r2, r2, #63 @ r0<- r0 & 0x3f
282 mov r0, r0, lsr r2 @ r0<- r2 >> r2
283 rsb r3, r2, #32 @ r3<- 32 - r2
284 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
285 subs ip, r2, #32 @ ip<- r2 - 32
286 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
287 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
288 bx lr
289
buzbeec1f45042011-09-21 16:03:19 -0700290 .balign 4
291 .global art_test_suspend
292 .extern artCheckSuspendFromCode
293art_test_suspend:
294 /*
295 * Check to see if there's a pending suspend request on our thread.
296 * reset rSUSPEND to SUSPEND_CHECK_INTERVAL.
297 * On entry, rSUSPEND holds the suspend request value
298 * [TUNING: move load of suspend check value into this stub.
299 */
300 cmp rSUSPEND, #0
301 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL
302 bxeq rLR
303 mov r0, rSELF
304 b artCheckSuspendFromCode
305
306
buzbee54330722011-08-23 16:46:55 -0700307#endif
Ian Rogers67375ac2011-09-14 00:55:44 -0700308
309#if defined(__i386__)
310
Ian Rogersff1ed472011-09-20 13:46:24 -0700311 .global art_deliver_exception_from_code
312 .extern artDeliverExceptionFromCode
Ian Rogers67375ac2011-09-14 00:55:44 -0700313 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700314 * Called by managed code, saves callee saves and then calls artThrowException
Ian Rogers67375ac2011-09-14 00:55:44 -0700315 * that will place a mock Method* at the bottom of the stack.
316 * EAX holds the exception.
317 */
Ian Rogersff1ed472011-09-20 13:46:24 -0700318art_deliver_exception_from_code:
Ian Rogers67375ac2011-09-14 00:55:44 -0700319 // Create frame
320 pushl %edi // Save callee saves
321 pushl %esi
322 pushl %ebp
323 pushl %ebx
324 pushl $0
325 pushl $0
326 pushl $0 // Will be clobbered to be Method*
327 mov %esp, %ecx
328 // Outgoing argument set up
Ian Rogersff1ed472011-09-20 13:46:24 -0700329 pushl $0 // Alignment padding
330 pushl %ecx // pass SP
331 pushl %fs:THREAD_SELF_OFFSET // pass fs:offsetof(Thread,self_)
332 pushl %eax // pass Throwable*
333 call artDeliverExceptionFromCode // artDeliverExceptionFromCode(Throwable*, Thread*, SP)
Ian Rogers67375ac2011-09-14 00:55:44 -0700334 int3
335
336#endif