blob: 185cdc2acc9062e68c3ff43be05fa891d298d101 [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 Rogerscbba6ac2011-09-22 16:28:37 -0700172 .global art_initialize_static_storage_from_code
173 .extern _ZN3art11ClassLinker31InitializeStaticStorageFromCodeEjPKNS_6MethodE
174 /*
175 * Entry from managed code when uninitialized static storage, this stub will run the class
176 * initializer and deliver the exception on error. On success the static storage base is
177 * returned.
178 */
179art_initialize_static_storage_from_code:
180 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
181 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
182 stmdb sp!, {lr} @ Save LR
183 sub sp, #12 @ Align stack
184 @ ClassLinker::InitializeStaticStorageFromCode(uint32_t type_idx, Method* referrer)
185 bl _ZN3art11ClassLinker31InitializeStaticStorageFromCodeEjPKNS_6MethodE
186 add sp, #12
187 ldmia sp!, {lr} @ restore LR
188 cmp r0, #0 @ success if result is non-null
189 movne 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
buzbee54330722011-08-23 16:46:55 -0700197 .global art_shl_long
198art_shl_long:
199 /*
200 * Long integer shift. This is different from the generic 32/64-bit
201 * binary operations because vAA/vBB are 64-bit but vCC (the shift
202 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
203 * 6 bits.
204 * On entry:
205 * r0: low word
206 * r1: high word
207 * r2: shift count
208 */
209 /* shl-long vAA, vBB, vCC */
210 and r2, r2, #63 @ r2<- r2 & 0x3f
211 mov r1, r1, asl r2 @ r1<- r1 << r2
212 rsb r3, r2, #32 @ r3<- 32 - r2
213 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
214 subs ip, r2, #32 @ ip<- r2 - 32
215 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
216 mov r0, r0, asl r2 @ r0<- r0 << r2
217 bx lr
218
219 .balign 4
220 .global art_shr_long
221art_shr_long:
222 /*
223 * Long integer shift. This is different from the generic 32/64-bit
224 * binary operations because vAA/vBB are 64-bit but vCC (the shift
225 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
226 * 6 bits.
227 * On entry:
228 * r0: low word
229 * r1: high word
230 * r2: shift count
231 */
232 /* shr-long vAA, vBB, vCC */
233 and r2, r2, #63 @ r0<- r0 & 0x3f
234 mov r0, r0, lsr r2 @ r0<- r2 >> r2
235 rsb r3, r2, #32 @ r3<- 32 - r2
236 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
237 subs ip, r2, #32 @ ip<- r2 - 32
238 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
239 mov r1, r1, asr r2 @ r1<- r1 >> r2
240 bx lr
241
242 .balign 4
243 .global art_ushr_long
244art_ushr_long:
245 /*
246 * Long integer shift. This is different from the generic 32/64-bit
247 * binary operations because vAA/vBB are 64-bit but vCC (the shift
248 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
249 * 6 bits.
250 * On entry:
251 * r0: low word
252 * r1: high word
253 * r2: shift count
254 */
255 /* ushr-long vAA, vBB, vCC */
256 and r2, r2, #63 @ r0<- r0 & 0x3f
257 mov r0, r0, lsr r2 @ r0<- r2 >> r2
258 rsb r3, r2, #32 @ r3<- 32 - r2
259 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
260 subs ip, r2, #32 @ ip<- r2 - 32
261 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
262 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
263 bx lr
264
buzbeec1f45042011-09-21 16:03:19 -0700265 .balign 4
266 .global art_test_suspend
267 .extern artCheckSuspendFromCode
268art_test_suspend:
269 /*
270 * Check to see if there's a pending suspend request on our thread.
271 * reset rSUSPEND to SUSPEND_CHECK_INTERVAL.
272 * On entry, rSUSPEND holds the suspend request value
273 * [TUNING: move load of suspend check value into this stub.
274 */
275 cmp rSUSPEND, #0
276 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL
277 bxeq rLR
278 mov r0, rSELF
279 b artCheckSuspendFromCode
280
281
buzbee54330722011-08-23 16:46:55 -0700282#endif
Ian Rogers67375ac2011-09-14 00:55:44 -0700283
284#if defined(__i386__)
285
Ian Rogersff1ed472011-09-20 13:46:24 -0700286 .global art_deliver_exception_from_code
287 .extern artDeliverExceptionFromCode
Ian Rogers67375ac2011-09-14 00:55:44 -0700288 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700289 * Called by managed code, saves callee saves and then calls artThrowException
Ian Rogers67375ac2011-09-14 00:55:44 -0700290 * that will place a mock Method* at the bottom of the stack.
291 * EAX holds the exception.
292 */
Ian Rogersff1ed472011-09-20 13:46:24 -0700293art_deliver_exception_from_code:
Ian Rogers67375ac2011-09-14 00:55:44 -0700294 // Create frame
295 pushl %edi // Save callee saves
296 pushl %esi
297 pushl %ebp
298 pushl %ebx
299 pushl $0
300 pushl $0
301 pushl $0 // Will be clobbered to be Method*
302 mov %esp, %ecx
303 // Outgoing argument set up
Ian Rogersff1ed472011-09-20 13:46:24 -0700304 pushl $0 // Alignment padding
305 pushl %ecx // pass SP
306 pushl %fs:THREAD_SELF_OFFSET // pass fs:offsetof(Thread,self_)
307 pushl %eax // pass Throwable*
308 call artDeliverExceptionFromCode // artDeliverExceptionFromCode(Throwable*, Thread*, SP)
Ian Rogers67375ac2011-09-14 00:55:44 -0700309 int3
310
311#endif