blob: 0e575923ac580851dc949e7844d0da9f3e988915 [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
buzbee4a3164f2011-09-03 11:25:10 -070061 .global art_invoke_interface_trampoline
Ian Rogersff1ed472011-09-20 13:46:24 -070062 .extern artFindInterfaceMethodInCacheFromCode
buzbee4a3164f2011-09-03 11:25:10 -070063 /*
Ian Rogersff1ed472011-09-20 13:46:24 -070064 * All generated callsites for interface invokes will load arguments as usual - except instead
65 * of loading arg0/r0 with the target Method*, arg0/r0 will contain the method_idx. This
66 * wrapper will save arg1-arg3, load the caller's Method*, align the stack and call the helper
67 * artFindInterfaceMethodInCacheFromCode(idx, this, method);
68 * NOTE: "this" is first visable argument of the target, and so can be found in arg1/r1.
buzbee4a3164f2011-09-03 11:25:10 -070069 *
Ian Rogersff1ed472011-09-20 13:46:24 -070070 * artFindInterfaceMethodInCacheFromCode will attempt to locate the target and return a 64-bit
71 * result in r0/r1 consisting of the target Method* in r0 and method->code_ in r1.
buzbee4a3164f2011-09-03 11:25:10 -070072 *
Ian Rogersff1ed472011-09-20 13:46:24 -070073 * If unsuccessful, artFindInterfaceMethodInCacheFromCode will return NULL/NULL. There will be
74 * a pending exception in the thread and we branch to another stub to deliver it.
buzbee4a3164f2011-09-03 11:25:10 -070075 *
Ian Rogersff1ed472011-09-20 13:46:24 -070076 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
77 * pointing back to the original caller.
buzbee4a3164f2011-09-03 11:25:10 -070078 */
Ian Rogersff1ed472011-09-20 13:46:24 -070079art_invoke_interface_trampoline:
80 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
81 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
buzbee4a3164f2011-09-03 11:25:10 -070082 stmdb sp!, {r1, r2, r3, lr}
Ian Rogersff1ed472011-09-20 13:46:24 -070083 ldr r2, [sp, #16] @ load caller's Method*
84 bl artFindInterfaceMethodInCacheFromCode @ (method_idx, this, callerMethod)
85 mov r12, r1 @ save r0->code_
86 ldmia sp!, {r1, r2, r3, lr} @ restore arguments
87 cmp r0, #0 @ did we find the target?
88 bxne r12 @ tail call to target if so
89 @ set up for throwing exception
90 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
91 sub sp, #16 @ 4 words of space, bottom word will hold Method*
92 mov r0, r9 @ pass Thread::Current
93 mov r1, sp @ pass SP
94 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
95
96 .global art_handle_fill_data_from_code
97 .extern artHandleFillArrayDataFromCode
98 /*
99 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
100 * failure.
101 */
102art_handle_fill_data_from_code:
103 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
104 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
105 stmdb sp!, {lr} @ Save LR
106 sub sp, #12 @ Align stack
107 bl artHandleFillArrayDataFromCode @ (Array* array, const uint16_t* table)
108 add sp, #12
109 ldmia sp!, {lr} @ restore LR
110 cmp r0, #0 @ success?
111 moveq pc, lr @ return on success
112 @ set up for throwing exception
113 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
114 sub sp, #16 @ 4 words of space, bottom word will hold Method*
115 mov r0, r9 @ pass Thread::Current
116 mov r1, sp @ pass SP
117 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
118
119 .global art_unlock_object_from_code
120 .extern artUnlockObjectFromCode
121 /*
122 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
123 */
124art_unlock_object_from_code:
125 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
126 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
127 stmdb sp!, {lr} @ Save LR
128 sub sp, #12 @ Align stack
129 bl artUnlockObjectFromCode @ (Thread* thread, Object* obj)
130 add sp, #12
131 ldmia sp!, {lr} @ restore LR
132 cmp r0, #0 @ success?
133 moveq pc, lr @ return on success
134 @ set up for throwing exception
135 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
136 sub sp, #16 @ 4 words of space, bottom word will hold Method*
137 mov r0, r9 @ pass Thread::Current
138 mov r1, sp @ pass SP
139 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
140
141 .global art_check_cast_from_code
142 .extern artCheckCastFromCode
143 /*
144 * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
145 */
146art_check_cast_from_code:
147 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
148 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
149 stmdb sp!, {lr} @ Save LR
150 sub sp, #12 @ Align stack
151 bl artCheckCastFromCode @ (Class* a, Class* b)
152 add sp, #12
153 ldmia sp!, {lr} @ restore LR
154 cmp r0, #0 @ success?
155 moveq pc, lr @ return on success
156 @ set up for throwing exception
157 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
158 sub sp, #16 @ 4 words of space, bottom word will hold Method*
159 mov r0, r9 @ pass Thread::Current
160 mov r1, sp @ pass SP
161 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
buzbee4a3164f2011-09-03 11:25:10 -0700162
Ian Rogerscbba6ac2011-09-22 16:28:37 -0700163 .global art_initialize_static_storage_from_code
164 .extern _ZN3art11ClassLinker31InitializeStaticStorageFromCodeEjPKNS_6MethodE
165 /*
166 * Entry from managed code when uninitialized static storage, this stub will run the class
167 * initializer and deliver the exception on error. On success the static storage base is
168 * returned.
169 */
170art_initialize_static_storage_from_code:
171 str sp, [R9, #THREAD_TOP_OF_MANAGED_STACK_OFFSET] @ record top of stack and pc in case of
172 str lr, [R9, #THREAD_TOP_OF_MANAGED_STACK_PC_OFFSET] @ walking stack
173 stmdb sp!, {lr} @ Save LR
174 sub sp, #12 @ Align stack
175 @ ClassLinker::InitializeStaticStorageFromCode(uint32_t type_idx, Method* referrer)
176 bl _ZN3art11ClassLinker31InitializeStaticStorageFromCodeEjPKNS_6MethodE
177 add sp, #12
178 ldmia sp!, {lr} @ restore LR
179 cmp r0, #0 @ success if result is non-null
180 movne pc, lr @ return on success
181 @ set up for throwing exception
182 stmdb sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}
183 sub sp, #16 @ 4 words of space, bottom word will hold Method*
184 mov r0, r9 @ pass Thread::Current
185 mov r1, sp @ pass SP
186 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
187
buzbee54330722011-08-23 16:46:55 -0700188 .global art_shl_long
189art_shl_long:
190 /*
191 * Long integer shift. This is different from the generic 32/64-bit
192 * binary operations because vAA/vBB are 64-bit but vCC (the shift
193 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
194 * 6 bits.
195 * On entry:
196 * r0: low word
197 * r1: high word
198 * r2: shift count
199 */
200 /* shl-long vAA, vBB, vCC */
201 and r2, r2, #63 @ r2<- r2 & 0x3f
202 mov r1, r1, asl r2 @ r1<- r1 << r2
203 rsb r3, r2, #32 @ r3<- 32 - r2
204 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
205 subs ip, r2, #32 @ ip<- r2 - 32
206 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
207 mov r0, r0, asl r2 @ r0<- r0 << r2
208 bx lr
209
210 .balign 4
211 .global art_shr_long
212art_shr_long:
213 /*
214 * Long integer shift. This is different from the generic 32/64-bit
215 * binary operations because vAA/vBB are 64-bit but vCC (the shift
216 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
217 * 6 bits.
218 * On entry:
219 * r0: low word
220 * r1: high word
221 * r2: shift count
222 */
223 /* shr-long vAA, vBB, vCC */
224 and r2, r2, #63 @ r0<- r0 & 0x3f
225 mov r0, r0, lsr r2 @ r0<- r2 >> r2
226 rsb r3, r2, #32 @ r3<- 32 - r2
227 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
228 subs ip, r2, #32 @ ip<- r2 - 32
229 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
230 mov r1, r1, asr r2 @ r1<- r1 >> r2
231 bx lr
232
233 .balign 4
234 .global art_ushr_long
235art_ushr_long:
236 /*
237 * Long integer shift. This is different from the generic 32/64-bit
238 * binary operations because vAA/vBB are 64-bit but vCC (the shift
239 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
240 * 6 bits.
241 * On entry:
242 * r0: low word
243 * r1: high word
244 * r2: shift count
245 */
246 /* ushr-long vAA, vBB, vCC */
247 and r2, r2, #63 @ r0<- r0 & 0x3f
248 mov r0, r0, lsr r2 @ r0<- r2 >> r2
249 rsb r3, r2, #32 @ r3<- 32 - r2
250 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
251 subs ip, r2, #32 @ ip<- r2 - 32
252 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
253 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
254 bx lr
255
buzbeec1f45042011-09-21 16:03:19 -0700256 .balign 4
257 .global art_test_suspend
258 .extern artCheckSuspendFromCode
259art_test_suspend:
260 /*
261 * Check to see if there's a pending suspend request on our thread.
262 * reset rSUSPEND to SUSPEND_CHECK_INTERVAL.
263 * On entry, rSUSPEND holds the suspend request value
264 * [TUNING: move load of suspend check value into this stub.
265 */
266 cmp rSUSPEND, #0
267 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL
268 bxeq rLR
269 mov r0, rSELF
270 b artCheckSuspendFromCode
271
272
buzbee54330722011-08-23 16:46:55 -0700273#endif
Ian Rogers67375ac2011-09-14 00:55:44 -0700274
275#if defined(__i386__)
276
Ian Rogersff1ed472011-09-20 13:46:24 -0700277 .global art_deliver_exception_from_code
278 .extern artDeliverExceptionFromCode
Ian Rogers67375ac2011-09-14 00:55:44 -0700279 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700280 * Called by managed code, saves callee saves and then calls artThrowException
Ian Rogers67375ac2011-09-14 00:55:44 -0700281 * that will place a mock Method* at the bottom of the stack.
282 * EAX holds the exception.
283 */
Ian Rogersff1ed472011-09-20 13:46:24 -0700284art_deliver_exception_from_code:
Ian Rogers67375ac2011-09-14 00:55:44 -0700285 // Create frame
286 pushl %edi // Save callee saves
287 pushl %esi
288 pushl %ebp
289 pushl %ebx
290 pushl $0
291 pushl $0
292 pushl $0 // Will be clobbered to be Method*
293 mov %esp, %ecx
294 // Outgoing argument set up
Ian Rogersff1ed472011-09-20 13:46:24 -0700295 pushl $0 // Alignment padding
296 pushl %ecx // pass SP
297 pushl %fs:THREAD_SELF_OFFSET // pass fs:offsetof(Thread,self_)
298 pushl %eax // pass Throwable*
299 call artDeliverExceptionFromCode // artDeliverExceptionFromCode(Throwable*, Thread*, SP)
Ian Rogers67375ac2011-09-14 00:55:44 -0700300 int3
301
302#endif