blob: 112a1141a27b38ff80d4f8d7731750ed059336e8 [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
Ian Rogers4f0d07c2011-10-06 23:38:47 -070012 /*
13 * Macro that sets up the callee save frame to conform with
14 * Runtime::CreateCalleeSaveMethod(kSaveAll)
15 */
Ian Rogers15fdb8c2011-09-25 15:45:07 -070016.macro SETUP_CALLEE_SAVE_FRAME
Ian Rogers4f0d07c2011-10-06 23:38:47 -070017 push {r4-r11, lr} @ 9 words of callee saves
Ian Rogers15fdb8c2011-09-25 15:45:07 -070018 vpush {s0-s31}
Ian Rogers4f0d07c2011-10-06 23:38:47 -070019 sub sp, #12 @ 3 words of space, bottom word will hold Method*
20.endm
21
22 /*
23 * Macro that sets up the callee save frame to conform with
Ian Rogersdfcdf1a2011-10-10 17:50:35 -070024 * Runtime::CreateCalleeSaveMethod(kRefsOnly). Restoration assumes non-moving GC.
Ian Rogers4f0d07c2011-10-06 23:38:47 -070025 */
26.macro SETUP_REF_ONLY_CALLEE_SAVE_FRAME
27 push {r5-r8, r10-r11, lr} @ 7 words of callee saves
28 sub sp, #4 @ bottom word will hold Method*
29.endm
30
31.macro RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
Ian Rogersdfcdf1a2011-10-10 17:50:35 -070032 ldr lr, [sp, #28] @ restore lr for return
33 add sp, #32 @ unwind stack
Ian Rogers4f0d07c2011-10-06 23:38:47 -070034.endm
35
36.macro RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Ian Rogersdfcdf1a2011-10-10 17:50:35 -070037 ldr lr, [sp, #28] @ restore lr for return
38 add sp, #32 @ unwind stack
39 bx lr @ return
Ian Rogers4f0d07c2011-10-06 23:38:47 -070040.endm
41
42 /*
43 * Macro that sets up the callee save frame to conform with
Ian Rogersdfcdf1a2011-10-10 17:50:35 -070044 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). Restoration assumes non-moving GC.
Ian Rogers4f0d07c2011-10-06 23:38:47 -070045 */
46.macro SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogersdfcdf1a2011-10-10 17:50:35 -070047 push {r1-r3, r5-r8, r10-r11, lr} @ 10 words of callee saves
48 sub sp, #8 @ 2 words of space, bottom word will hold Method*
Ian Rogers4f0d07c2011-10-06 23:38:47 -070049.endm
50
51.macro RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogersdfcdf1a2011-10-10 17:50:35 -070052 ldr r1, [sp, #8] @ restore non-callee save r1
53 ldrd r2, [sp, #12] @ restore non-callee saves r2-r3
54 ldr lr, [sp, #44] @ restore lr
55 add sp, #48 @ rewind sp
Ian Rogers15fdb8c2011-09-25 15:45:07 -070056.endm
57
Ian Rogersce9eca62011-10-07 17:11:03 -070058 /*
59 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
60 * exception is Thread::Current()->exception_
61 */
62.macro DELIVER_PENDING_EXCEPTION
63 SETUP_CALLEE_SAVE_FRAME @ save callee saves for throw
64 mov r0, r9 @ pass Thread::Current
65 mov r1, sp @ pass SP
66 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
67.endm
68
Brian Carlstrom6f495f22011-10-10 15:05:03 -070069 .global art_do_long_jump
Brian Carlstrom6f495f22011-10-10 15:05:03 -070070 /*
71 * On entry r0 is uint32_t* gprs_ and r1 is uint32_t* fprs_
72 */
Ian Rogersdfcdf1a2011-10-10 17:50:35 -070073art_do_long_jump:
Brian Carlstrom6f495f22011-10-10 15:05:03 -070074 vldm r1, {s0-s31} @ load all fprs from argument fprs_
75 ldr r2, [r0, #60] @ r2 = r15 (PC from gprs_ 60=4*15)
76 add r0, r0, #12 @ increment r0 to skip gprs_[0..2] 12=4*3
77 ldm r0, {r3-r14} @ load remaining gprs from argument gprs_
78 mov r0, #0 @ clear result registers r0 and r1
79 mov r1, #0
80 bx r2 @ do long jump
81
Ian Rogersff1ed472011-09-20 13:46:24 -070082 .global art_deliver_exception_from_code
Ian Rogersbdb03912011-09-14 00:55:44 -070083 /*
Ian Rogersff1ed472011-09-20 13:46:24 -070084 * Called by managed code, saves mosts registers (forms basis of long jump context) and passes
85 * the bottom of the stack. artDeliverExceptionFromCode will place the callee save Method* at
86 * the bottom of the thread. On entry r0 holds Throwable*
Ian Rogersbdb03912011-09-14 00:55:44 -070087 */
Ian Rogersff1ed472011-09-20 13:46:24 -070088art_deliver_exception_from_code:
Ian Rogers15fdb8c2011-09-25 15:45:07 -070089 SETUP_CALLEE_SAVE_FRAME
Ian Rogersff1ed472011-09-20 13:46:24 -070090 mov r1, r9 @ pass Thread::Current
91 mov r2, sp @ pass SP
92 b artDeliverExceptionFromCode @ artDeliverExceptionFromCode(Throwable*, Thread*, SP)
Ian Rogers9651f422011-09-19 20:26:07 -070093
94 .global art_throw_null_pointer_exception_from_code
Ian Rogersff1ed472011-09-20 13:46:24 -070095 .extern artThrowNullPointerExceptionFromCode
Ian Rogers9651f422011-09-19 20:26:07 -070096 /*
Ian Rogersff1ed472011-09-20 13:46:24 -070097 * Called by managed code to create and deliver a NullPointerException
Ian Rogers9651f422011-09-19 20:26:07 -070098 */
99art_throw_null_pointer_exception_from_code:
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700100 SETUP_CALLEE_SAVE_FRAME
Ian Rogersff1ed472011-09-20 13:46:24 -0700101 mov r0, r9 @ pass Thread::Current
102 mov r1, sp @ pass SP
103 b artThrowNullPointerExceptionFromCode @ artThrowNullPointerExceptionFromCode(Thread*, SP)
Ian Rogers9651f422011-09-19 20:26:07 -0700104
105 .global art_throw_div_zero_from_code
Ian Rogersff1ed472011-09-20 13:46:24 -0700106 .extern artThrowDivZeroFromCode
Ian Rogers9651f422011-09-19 20:26:07 -0700107 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700108 * Called by managed code to create and deliver an ArithmeticException
Ian Rogers9651f422011-09-19 20:26:07 -0700109 */
110art_throw_div_zero_from_code:
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700111 SETUP_CALLEE_SAVE_FRAME
Ian Rogersff1ed472011-09-20 13:46:24 -0700112 mov r0, r9 @ pass Thread::Current
113 mov r1, sp @ pass SP
114 b artThrowDivZeroFromCode @ artThrowDivZeroFromCode(Thread*, SP)
Ian Rogers9651f422011-09-19 20:26:07 -0700115
116 .global art_throw_array_bounds_from_code
Ian Rogersff1ed472011-09-20 13:46:24 -0700117 .extern artThrowArrayBoundsFromCode
Ian Rogers9651f422011-09-19 20:26:07 -0700118 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700119 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException
Ian Rogers9651f422011-09-19 20:26:07 -0700120 */
121art_throw_array_bounds_from_code:
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700122 SETUP_CALLEE_SAVE_FRAME
Ian Rogersff1ed472011-09-20 13:46:24 -0700123 mov r2, r9 @ pass Thread::Current
124 mov r3, sp @ pass SP
125 b artThrowArrayBoundsFromCode @ artThrowArrayBoundsFromCode(index, limit, Thread*, SP)
Ian Rogersbdb03912011-09-14 00:55:44 -0700126
Ian Rogers932746a2011-09-22 18:57:50 -0700127 .global art_throw_stack_overflow_from_code
128 .extern artThrowStackOverflowFromCode
129art_throw_stack_overflow_from_code:
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700130 SETUP_CALLEE_SAVE_FRAME
Ian Rogers932746a2011-09-22 18:57:50 -0700131 mov r1, r9 @ pass Thread::Current
132 mov r2, sp @ pass SP
133 b artThrowStackOverflowFromCode @ artThrowStackOverflowFromCode(method, Thread*, SP)
134
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700135 .global art_throw_neg_array_size_from_code
136 .extern artThrowNegArraySizeFromCode
137art_throw_neg_array_size_from_code:
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700138 SETUP_CALLEE_SAVE_FRAME
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700139 mov r1, r9 @ pass Thread::Current
140 mov r2, sp @ pass SP
141 b artThrowNegArraySizeFromCode @ artThrowNegArraySizeFromCode(size, Thread*, SP)
142
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700143 .global art_throw_no_such_method_from_code
144 .extern artThrowNoSuchMethodFromCode
145art_throw_no_such_method_from_code:
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700146 SETUP_CALLEE_SAVE_FRAME
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700147 mov r1, r9 @ pass Thread::Current
148 mov r2, sp @ pass SP
149 b artThrowNoSuchMethodFromCode @ artThrowNoSuchMethodFromCode(method_idx, Thread*, SP)
150
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700151 .global art_throw_verification_error_from_code
152 .extern artThrowVerificationErrorFromCode
153art_throw_verification_error_from_code:
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700154 SETUP_CALLEE_SAVE_FRAME
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700155 mov r2, r9 @ pass Thread::Current
156 mov r3, sp @ pass SP
Elliott Hughes6c8867d2011-10-03 16:34:05 -0700157 b artThrowVerificationErrorFromCode @ artThrowVerificationErrorFromCode(kind, ref, Thread*, SP)
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700158
buzbee4a3164f2011-09-03 11:25:10 -0700159 .global art_invoke_interface_trampoline
Ian Rogersff1ed472011-09-20 13:46:24 -0700160 .extern artFindInterfaceMethodInCacheFromCode
buzbee4a3164f2011-09-03 11:25:10 -0700161 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700162 * All generated callsites for interface invokes will load arguments as usual - except instead
163 * of loading arg0/r0 with the target Method*, arg0/r0 will contain the method_idx. This
164 * wrapper will save arg1-arg3, load the caller's Method*, align the stack and call the helper
165 * artFindInterfaceMethodInCacheFromCode(idx, this, method);
166 * NOTE: "this" is first visable argument of the target, and so can be found in arg1/r1.
buzbee4a3164f2011-09-03 11:25:10 -0700167 *
Ian Rogersff1ed472011-09-20 13:46:24 -0700168 * artFindInterfaceMethodInCacheFromCode will attempt to locate the target and return a 64-bit
169 * result in r0/r1 consisting of the target Method* in r0 and method->code_ in r1.
buzbee4a3164f2011-09-03 11:25:10 -0700170 *
Ian Rogersff1ed472011-09-20 13:46:24 -0700171 * If unsuccessful, artFindInterfaceMethodInCacheFromCode will return NULL/NULL. There will be
172 * a pending exception in the thread and we branch to another stub to deliver it.
buzbee4a3164f2011-09-03 11:25:10 -0700173 *
Ian Rogersff1ed472011-09-20 13:46:24 -0700174 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
175 * pointing back to the original caller.
buzbee4a3164f2011-09-03 11:25:10 -0700176 */
Ian Rogersff1ed472011-09-20 13:46:24 -0700177art_invoke_interface_trampoline:
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700178 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME @ save callee saves in case allocation triggers GC
Ian Rogerscaab8c42011-10-12 12:11:18 -0700179 ldr r2, [sp, #48] @ pass caller Method*
180 mov r3, r9 @ pass Thread::Current
181 str sp, [sp, #0] @ pass SP
182 bl artFindInterfaceMethodInCacheFromCode @ (method_idx, this, caller, Thread*, SP)
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700183 mov r12, r1 @ save r0->code_
184 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
185 cmp r0, #0 @ did we find the target?
186 bxne r12 @ tail call to target if so
Ian Rogersce9eca62011-10-07 17:11:03 -0700187 DELIVER_PENDING_EXCEPTION
Ian Rogersff1ed472011-09-20 13:46:24 -0700188
189 .global art_handle_fill_data_from_code
190 .extern artHandleFillArrayDataFromCode
191 /*
192 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
193 * failure.
194 */
195art_handle_fill_data_from_code:
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700196 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case exception allocation triggers GC
197 mov r2, r9 @ pass Thread::Current
198 mov r3, sp @ pass SP
199 bl artHandleFillArrayDataFromCode @ (Array* array, const uint16_t* table, Thread*, SP)
200 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
201 cmp r0, #0 @ success?
Ian Rogersae675992011-10-09 17:10:22 -0700202 bxeq lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700203 DELIVER_PENDING_EXCEPTION
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700204
205 .global art_lock_object_from_code
206 .extern artLockObjectFromCode
207 /*
208 * Entry from managed code that calls artLockObjectFromCode, may block for GC
209 */
210art_lock_object_from_code:
211 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case we block
212 mov r1, r9 @ pass Thread::Current
213 mov r2, sp @ pass SP
214 bl artLockObjectFromCode @ (Object* obj, Thread*, SP)
215 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Ian Rogersff1ed472011-09-20 13:46:24 -0700216
217 .global art_unlock_object_from_code
218 .extern artUnlockObjectFromCode
219 /*
220 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
221 */
222art_unlock_object_from_code:
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700223 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case exception allocation triggers GC
224 mov r1, r9 @ pass Thread::Current
225 mov r2, sp @ pass SP
226 bl artUnlockObjectFromCode @ (Object* obj, Thread*, SP)
227 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
228 cmp r0, #0 @ success?
Ian Rogersae675992011-10-09 17:10:22 -0700229 bxeq lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700230 DELIVER_PENDING_EXCEPTION
Ian Rogersff1ed472011-09-20 13:46:24 -0700231
232 .global art_check_cast_from_code
233 .extern artCheckCastFromCode
234 /*
235 * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
236 */
237art_check_cast_from_code:
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700238 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case exception allocation triggers GC
239 mov r2, r9 @ pass Thread::Current
240 mov r3, sp @ pass SP
241 bl artCheckCastFromCode @ (Class* a, Class* b, Thread*, SP)
242 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
243 cmp r0, #0 @ success?
Ian Rogersae675992011-10-09 17:10:22 -0700244 bxeq lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700245 DELIVER_PENDING_EXCEPTION
buzbee4a3164f2011-09-03 11:25:10 -0700246
Ian Rogerse51a5112011-09-23 14:16:35 -0700247 .global art_can_put_array_element_from_code
248 .extern artCanPutArrayElementFromCode
249 /*
250 * Entry from managed code that calls artCanPutArrayElementFromCode and delivers exception on
251 * failure.
252 */
253art_can_put_array_element_from_code:
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700254 cmp r0, #0 @ return if element == NULL
Ian Rogersae675992011-10-09 17:10:22 -0700255 bxeq lr
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700256 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case exception allocation triggers GC
257 mov r2, r9 @ pass Thread::Current
258 mov r3, sp @ pass SP
259 bl artCanPutArrayElementFromCode @ (Object* element, Class* array_class, Thread*, SP)
260 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
261 cmp r0, #0 @ success?
Ian Rogersae675992011-10-09 17:10:22 -0700262 bxeq lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700263 DELIVER_PENDING_EXCEPTION
Ian Rogerse51a5112011-09-23 14:16:35 -0700264
Ian Rogerscbba6ac2011-09-22 16:28:37 -0700265 .global art_initialize_static_storage_from_code
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700266 .extern artInitializeStaticStorageFromCode
Ian Rogerscbba6ac2011-09-22 16:28:37 -0700267 /*
268 * Entry from managed code when uninitialized static storage, this stub will run the class
269 * initializer and deliver the exception on error. On success the static storage base is
270 * returned.
271 */
272art_initialize_static_storage_from_code:
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700273 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
274 mov r2, r9 @ pass Thread::Current
275 mov r3, sp @ pass SP
Brian Carlstromaded5f72011-10-07 17:15:04 -0700276 @ artInitializeStaticStorageFromCode(uint32_t type_idx, Method* referrer, Thread*, SP)
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700277 bl artInitializeStaticStorageFromCode
278 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
279 cmp r0, #0 @ success if result is non-null
Ian Rogersae675992011-10-09 17:10:22 -0700280 bxne lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700281 DELIVER_PENDING_EXCEPTION
282
Ian Rogers28ad40d2011-10-27 15:19:26 -0700283 .global art_initialize_type_from_code
284 .extern artInitializeTypeFromCode
285 /*
286 * Entry from managed code when dex cache misses for a type_idx
287 */
288art_initialize_type_from_code:
289 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
290 mov r2, r9 @ pass Thread::Current
291 mov r3, sp @ pass SP
292 @ artInitializeTypeFromCode(uint32_t type_idx, Method* referrer, Thread*, SP)
293 bl artInitializeTypeFromCode
294 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
295 cmp r0, #0 @ success if result is non-null
296 bxne lr @ return on success
297 DELIVER_PENDING_EXCEPTION
298
Ian Rogersce9eca62011-10-07 17:11:03 -0700299 .global art_find_instance_field_from_code
300 .extern artFindInstanceFieldFromCode
301 /*
302 * Called by managed code to resolve a field of an object
303 */
304art_find_instance_field_from_code:
305 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
306 mov r2, r9 @ pass Thread::Current
307 mov r3, sp @ pass SP
308 bl artFindInstanceFieldFromCode @ (uint32_t field_idx, const Method* referrer, Thread*, SP)
309 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
310 cmp r0, #0 @ success if result is non-null
Ian Rogersae675992011-10-09 17:10:22 -0700311 bxne lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700312 DELIVER_PENDING_EXCEPTION
313
314 .global art_get32_static_from_code
315 .extern artGet32StaticFromCode
316 /*
317 * Called by managed code to resolve a static field and load a 32-bit primitive value
318 */
319art_get32_static_from_code:
320 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
321 mov r2, r9 @ pass Thread::Current
322 mov r3, sp @ pass SP
323 bl artGet32StaticFromCode @ (uint32_t field_idx, const Method* referrer, Thread*, SP)
324 ldr r12, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
325 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
326 cmp r12, #0 @ success if no exception is pending
Ian Rogersae675992011-10-09 17:10:22 -0700327 bxeq lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700328 DELIVER_PENDING_EXCEPTION
329
330 .global art_get64_static_from_code
331 .extern artGet64StaticFromCode
332 /*
333 * Called by managed code to resolve a static field and load a 64-bit primitive value
334 */
335art_get64_static_from_code:
336 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
337 mov r2, r9 @ pass Thread::Current
338 mov r3, sp @ pass SP
339 bl artGet64StaticFromCode @ (uint32_t field_idx, const Method* referrer, Thread*, SP)
340 ldr r12, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
341 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
342 cmp r12, #0 @ success if no exception is pending
Ian Rogersae675992011-10-09 17:10:22 -0700343 bxeq lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700344 DELIVER_PENDING_EXCEPTION
345
346 .global art_get_obj_static_from_code
347 .extern artGetObjStaticFromCode
348 /*
349 * Called by managed code to resolve a static field and load an object reference
350 */
351art_get_obj_static_from_code:
352 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
353 mov r2, r9 @ pass Thread::Current
354 mov r3, sp @ pass SP
355 bl artGetObjStaticFromCode @ (uint32_t field_idx, const Method* referrer, Thread*, SP)
356 ldr r12, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
357 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
358 cmp r12, #0 @ success if no exception is pending
Ian Rogersae675992011-10-09 17:10:22 -0700359 bxeq lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700360 DELIVER_PENDING_EXCEPTION
361
362 .global art_set32_static_from_code
363 .extern artSet32StaticFromCode
364 /*
365 * Called by managed code to resolve a static field and store a 32-bit primitive value
366 */
367art_set32_static_from_code:
368 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
369 mov r3, r9 @ pass Thread::Current
370 str sp, [sp, #0] @ pass SP
371 bl artSet32StaticFromCode @ (field_idx, referrer, new_val, Thread*, SP)
372 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
373 cmp r0, #0 @ success if result is 0
Ian Rogersae675992011-10-09 17:10:22 -0700374 bxeq lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700375 DELIVER_PENDING_EXCEPTION
376
377 .global art_set64_static_from_code
378 .extern artSet32StaticFromCode
379 /*
380 * Called by managed code to resolve a static field and store a 64-bit primitive value
381 */
382art_set64_static_from_code:
383 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
384 mov r12, sp @ save SP
385 sub sp, #8 @ grow frame for alignment with stack args
386 push {r9, r12} @ pass Thread::Current and SP
387 bl artSet64StaticFromCode @ (field_idx, referrer, new_val, Thread*, SP)
388 add sp, #16 @ release out args
389 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
390 cmp r0, #0 @ success if result is 0
Ian Rogersae675992011-10-09 17:10:22 -0700391 bxeq lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700392 DELIVER_PENDING_EXCEPTION
393
394 .global art_set_obj_static_from_code
395 .extern artSetObjStaticFromCode
396 /*
397 * Called by managed code to resolve a static field and store an object reference
398 */
399art_set_obj_static_from_code:
400 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
401 mov r3, r9 @ pass Thread::Current
402 str sp, [sp, #0] @ pass SP
403 bl artSetObjStaticFromCode @ (field_idx, referrer, new_val, Thread*, SP)
404 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
405 cmp r0, #0 @ success if result is 0
Ian Rogersae675992011-10-09 17:10:22 -0700406 bxeq lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700407 DELIVER_PENDING_EXCEPTION
Ian Rogerscbba6ac2011-09-22 16:28:37 -0700408
Brian Carlstromaded5f72011-10-07 17:15:04 -0700409 .global art_resolve_string_from_code
410 .extern artResolveStringFromCode
411 /*
Ian Rogerscaab8c42011-10-12 12:11:18 -0700412 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
413 * exception on error. On success the String is returned. R0 holds the referring method,
414 * R1 holds the string index. The fast path check for hit in strings cache has already been
415 * performed.
Brian Carlstromaded5f72011-10-07 17:15:04 -0700416 */
Brian Carlstrom6f495f22011-10-10 15:05:03 -0700417art_resolve_string_from_code:
Ian Rogerscaab8c42011-10-12 12:11:18 -0700418 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
419 mov r2, r9 @ pass Thread::Current
420 mov r3, sp @ pass SP
421 @ artResolveStringFromCode(Method* referrer, uint32_t string_idx, Thread*, SP)
Brian Carlstromaded5f72011-10-07 17:15:04 -0700422 bl artResolveStringFromCode
423 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
Ian Rogerscaab8c42011-10-12 12:11:18 -0700424 cmp r0, #0 @ success if result is non-null
425 bxne lr @ return on success
Brian Carlstromaded5f72011-10-07 17:15:04 -0700426 DELIVER_PENDING_EXCEPTION
427
Brian Carlstrom6fd03fb2011-10-17 16:11:00 -0700428 .global art_object_init_from_code
429 .extern artObjectInitFromCode
430 /*
431 * Entry from managed code to perform Object.<init> string. R0 holds the object to initialize.
432 * On success, 0 is returned. Otherwise there is a pending exception to deliver.
433 */
434art_object_init_from_code:
435 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
436 mov r1, r9 @ pass Thread::Current
437 mov r2, sp @ pass SP
438 @ artObjectInitFromCode(Object* o, Thread*, SP)
439 bl artObjectInitFromCode
440 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
441 cmp r0, #0 @ success if result is zero
442 bxeq lr @ return on success
443 DELIVER_PENDING_EXCEPTION
444
Ian Rogers21d9e832011-09-23 17:05:09 -0700445 .global art_alloc_object_from_code
446 .extern artAllocObjectFromCode
447 /*
448 * Called by managed code to allocate an object
449 */
450art_alloc_object_from_code:
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700451 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
452 mov r2, r9 @ pass Thread::Current
453 mov r3, sp @ pass SP
454 bl artAllocObjectFromCode @ (uint32_t type_idx, Method* method, Thread*, SP)
455 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
456 cmp r0, #0 @ success if result is non-null
Ian Rogersae675992011-10-09 17:10:22 -0700457 bxne lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700458 DELIVER_PENDING_EXCEPTION
Ian Rogers21d9e832011-09-23 17:05:09 -0700459
Ian Rogers28ad40d2011-10-27 15:19:26 -0700460 .global art_alloc_object_from_code_with_access_check
461 .extern artAllocObjectFromCodeWithAccessCheck
buzbeecc4540e2011-10-27 13:06:03 -0700462 /*
Ian Rogers28ad40d2011-10-27 15:19:26 -0700463 * Called by managed code to allocate an object when the caller doesn't know whether it has
464 * access to the created type
buzbeecc4540e2011-10-27 13:06:03 -0700465 */
Ian Rogers28ad40d2011-10-27 15:19:26 -0700466art_alloc_object_from_code_with_access_check:
buzbeecc4540e2011-10-27 13:06:03 -0700467 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
468 mov r2, r9 @ pass Thread::Current
469 mov r3, sp @ pass SP
Ian Rogers28ad40d2011-10-27 15:19:26 -0700470 bl artAllocObjectFromCodeWithAccessCheck @ (uint32_t type_idx, Method* method, Thread*, SP)
buzbeecc4540e2011-10-27 13:06:03 -0700471 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
472 cmp r0, #0 @ success if result is non-null
473 bxne lr @ return on success
474 DELIVER_PENDING_EXCEPTION
475
Elliott Hughesb408de72011-10-04 14:35:05 -0700476 .global art_alloc_array_from_code
477 .extern artAllocArrayFromCode
Ian Rogersb886da82011-09-23 16:27:54 -0700478 /*
479 * Called by managed code to allocate an array
480 */
Elliott Hughesb408de72011-10-04 14:35:05 -0700481art_alloc_array_from_code:
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700482 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
483 mov r3, r9 @ pass Thread::Current
484 str sp, [sp, #0] @ pass SP
485 @ artAllocArrayFromCode(uint32_t type_idx, Method* method, int32_t component_count, Thread*, SP)
486 bl artAllocArrayFromCode
487 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
488 cmp r0, #0 @ success if result is non-null
Ian Rogersae675992011-10-09 17:10:22 -0700489 bxne lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700490 DELIVER_PENDING_EXCEPTION
Ian Rogersb886da82011-09-23 16:27:54 -0700491
Elliott Hughesb408de72011-10-04 14:35:05 -0700492 .global art_check_and_alloc_array_from_code
493 .extern artCheckAndAllocArrayFromCode
Ian Rogersb886da82011-09-23 16:27:54 -0700494 /*
495 * Called by managed code to allocate an array
496 */
Elliott Hughesb408de72011-10-04 14:35:05 -0700497art_check_and_alloc_array_from_code:
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700498 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
499 mov r3, r9 @ pass Thread::Current
500 str sp, [sp, #0] @ pass SP
501 @ artCheckAndAllocArrayFromCode(uint32_t type_idx, Method* method, int32_t count, Thread* , SP)
502 bl artCheckAndAllocArrayFromCode
503 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
Ian Rogersce9eca62011-10-07 17:11:03 -0700504 cmp r0, #0 @ success if result is non-null
Ian Rogersae675992011-10-09 17:10:22 -0700505 bxne lr @ return on success
Ian Rogersce9eca62011-10-07 17:11:03 -0700506 DELIVER_PENDING_EXCEPTION
Ian Rogersb886da82011-09-23 16:27:54 -0700507
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700508 .global art_test_suspend
Ian Rogers4a510d82011-10-09 14:30:24 -0700509 .extern artTestSuspendFromCode
Ian Rogersdfcdf1a2011-10-10 17:50:35 -0700510 /*
511 * Called by managed code when the value in rSUSPEND has been decremented to 0
512 */
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700513art_test_suspend:
514 ldr r0, [rSELF, #THREAD_SUSPEND_COUNT_OFFSET]
515 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
516 cmp r0, #0 @ check Thread::Current()->suspend_count_ == 0
517 bxeq rLR @ return if suspend_count_ == 0
518 mov r0, rSELF
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700519 SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves for stack crawl
buzbeec10717a2011-10-09 14:40:13 -0700520 mov r1, sp
Ian Rogers4a510d82011-10-09 14:30:24 -0700521 bl artTestSuspendFromCode @ (Thread*, SP)
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700522 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
523
Ian Rogersdfcdf1a2011-10-10 17:50:35 -0700524 .global art_proxy_invoke_handler
525 .extern artProxyInvokeHandler
526 /*
527 * Called by managed code that is attempting to call a method on a proxy class. On entry
528 * r0 holds the proxy method; r1, r2 and r3 may contain arguments
529 */
530art_proxy_invoke_handler:
531 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
532 str r0, [sp, #0] @ place proxy method at bottom of frame
533 mov r2, r9 @ pass Thread::Current
534 add r3, sp, #12 @ pointer to r2/r3/LR/caller's Method**/out-args as second arg
535 blx artProxyInvokeHandler @ (Method* proxy method, receiver, Thread*, args...)
536 ldr r12, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Ian Rogers466bb252011-10-14 03:29:56 -0700537 ldr lr, [sp, #44] @ restore lr
538 ldrd r0, [sp, #12] @ load r0/r1 from r2/r3 that were overwritten with the out args
539 add sp, #48 @ pop frame
Ian Rogersdfcdf1a2011-10-10 17:50:35 -0700540 cmp r12, #0 @ success if no exception is pending
541 bxeq lr @ return on success
542 DELIVER_PENDING_EXCEPTION
543
buzbee54330722011-08-23 16:46:55 -0700544 .global art_shl_long
545art_shl_long:
546 /*
547 * Long integer shift. This is different from the generic 32/64-bit
548 * binary operations because vAA/vBB are 64-bit but vCC (the shift
549 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
550 * 6 bits.
551 * On entry:
552 * r0: low word
553 * r1: high word
554 * r2: shift count
555 */
556 /* shl-long vAA, vBB, vCC */
557 and r2, r2, #63 @ r2<- r2 & 0x3f
558 mov r1, r1, asl r2 @ r1<- r1 << r2
559 rsb r3, r2, #32 @ r3<- 32 - r2
560 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
561 subs ip, r2, #32 @ ip<- r2 - 32
562 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
563 mov r0, r0, asl r2 @ r0<- r0 << r2
564 bx lr
565
566 .balign 4
567 .global art_shr_long
568art_shr_long:
569 /*
570 * Long integer shift. This is different from the generic 32/64-bit
571 * binary operations because vAA/vBB are 64-bit but vCC (the shift
572 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
573 * 6 bits.
574 * On entry:
575 * r0: low word
576 * r1: high word
577 * r2: shift count
578 */
579 /* shr-long vAA, vBB, vCC */
580 and r2, r2, #63 @ r0<- r0 & 0x3f
581 mov r0, r0, lsr r2 @ r0<- r2 >> r2
582 rsb r3, r2, #32 @ r3<- 32 - r2
583 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
584 subs ip, r2, #32 @ ip<- r2 - 32
585 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
586 mov r1, r1, asr r2 @ r1<- r1 >> r2
587 bx lr
588
589 .balign 4
590 .global art_ushr_long
591art_ushr_long:
592 /*
593 * Long integer shift. This is different from the generic 32/64-bit
594 * binary operations because vAA/vBB are 64-bit but vCC (the shift
595 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
596 * 6 bits.
597 * On entry:
598 * r0: low word
599 * r1: high word
600 * r2: shift count
601 */
602 /* ushr-long vAA, vBB, vCC */
603 and r2, r2, #63 @ r0<- r0 & 0x3f
604 mov r0, r0, lsr r2 @ r0<- r2 >> r2
605 rsb r3, r2, #32 @ r3<- 32 - r2
606 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
607 subs ip, r2, #32 @ ip<- r2 - 32
608 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
609 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
610 bx lr
611
612#endif
Ian Rogers67375ac2011-09-14 00:55:44 -0700613
614#if defined(__i386__)
615
Ian Rogersff1ed472011-09-20 13:46:24 -0700616 .global art_deliver_exception_from_code
617 .extern artDeliverExceptionFromCode
Ian Rogers67375ac2011-09-14 00:55:44 -0700618 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700619 * Called by managed code, saves callee saves and then calls artThrowException
Ian Rogers67375ac2011-09-14 00:55:44 -0700620 * that will place a mock Method* at the bottom of the stack.
621 * EAX holds the exception.
622 */
Ian Rogersff1ed472011-09-20 13:46:24 -0700623art_deliver_exception_from_code:
Ian Rogers67375ac2011-09-14 00:55:44 -0700624 // Create frame
625 pushl %edi // Save callee saves
626 pushl %esi
627 pushl %ebp
628 pushl %ebx
629 pushl $0
630 pushl $0
631 pushl $0 // Will be clobbered to be Method*
632 mov %esp, %ecx
633 // Outgoing argument set up
Ian Rogersff1ed472011-09-20 13:46:24 -0700634 pushl $0 // Alignment padding
635 pushl %ecx // pass SP
636 pushl %fs:THREAD_SELF_OFFSET // pass fs:offsetof(Thread,self_)
637 pushl %eax // pass Throwable*
638 call artDeliverExceptionFromCode // artDeliverExceptionFromCode(Throwable*, Thread*, SP)
Ian Rogers67375ac2011-09-14 00:55:44 -0700639 int3
640
Ian Rogers466bb252011-10-14 03:29:56 -0700641 // TODO
642 .global art_proxy_invoke_handler
643art_proxy_invoke_handler:
644 int3
645
Ian Rogers67375ac2011-09-14 00:55:44 -0700646#endif