blob: 574605902b55436dbc8933cbf9b514709a9bd137 [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
buzbee54330722011-08-23 16:46:55 -0700163 .global art_shl_long
164art_shl_long:
165 /*
166 * Long integer shift. This is different from the generic 32/64-bit
167 * binary operations because vAA/vBB are 64-bit but vCC (the shift
168 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
169 * 6 bits.
170 * On entry:
171 * r0: low word
172 * r1: high word
173 * r2: shift count
174 */
175 /* shl-long vAA, vBB, vCC */
176 and r2, r2, #63 @ r2<- r2 & 0x3f
177 mov r1, r1, asl r2 @ r1<- r1 << r2
178 rsb r3, r2, #32 @ r3<- 32 - r2
179 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
180 subs ip, r2, #32 @ ip<- r2 - 32
181 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
182 mov r0, r0, asl r2 @ r0<- r0 << r2
183 bx lr
184
185 .balign 4
186 .global art_shr_long
187art_shr_long:
188 /*
189 * Long integer shift. This is different from the generic 32/64-bit
190 * binary operations because vAA/vBB are 64-bit but vCC (the shift
191 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
192 * 6 bits.
193 * On entry:
194 * r0: low word
195 * r1: high word
196 * r2: shift count
197 */
198 /* shr-long vAA, vBB, vCC */
199 and r2, r2, #63 @ r0<- r0 & 0x3f
200 mov r0, r0, lsr r2 @ r0<- r2 >> r2
201 rsb r3, r2, #32 @ r3<- 32 - r2
202 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
203 subs ip, r2, #32 @ ip<- r2 - 32
204 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
205 mov r1, r1, asr r2 @ r1<- r1 >> r2
206 bx lr
207
208 .balign 4
209 .global art_ushr_long
210art_ushr_long:
211 /*
212 * Long integer shift. This is different from the generic 32/64-bit
213 * binary operations because vAA/vBB are 64-bit but vCC (the shift
214 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
215 * 6 bits.
216 * On entry:
217 * r0: low word
218 * r1: high word
219 * r2: shift count
220 */
221 /* ushr-long vAA, vBB, vCC */
222 and r2, r2, #63 @ r0<- r0 & 0x3f
223 mov r0, r0, lsr r2 @ r0<- r2 >> r2
224 rsb r3, r2, #32 @ r3<- 32 - r2
225 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
226 subs ip, r2, #32 @ ip<- r2 - 32
227 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
228 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
229 bx lr
230
buzbeec1f45042011-09-21 16:03:19 -0700231 .balign 4
232 .global art_test_suspend
233 .extern artCheckSuspendFromCode
234art_test_suspend:
235 /*
236 * Check to see if there's a pending suspend request on our thread.
237 * reset rSUSPEND to SUSPEND_CHECK_INTERVAL.
238 * On entry, rSUSPEND holds the suspend request value
239 * [TUNING: move load of suspend check value into this stub.
240 */
241 cmp rSUSPEND, #0
242 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL
243 bxeq rLR
244 mov r0, rSELF
245 b artCheckSuspendFromCode
246
247
buzbee54330722011-08-23 16:46:55 -0700248#endif
Ian Rogers67375ac2011-09-14 00:55:44 -0700249
250#if defined(__i386__)
251
Ian Rogersff1ed472011-09-20 13:46:24 -0700252 .global art_deliver_exception_from_code
253 .extern artDeliverExceptionFromCode
Ian Rogers67375ac2011-09-14 00:55:44 -0700254 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700255 * Called by managed code, saves callee saves and then calls artThrowException
Ian Rogers67375ac2011-09-14 00:55:44 -0700256 * that will place a mock Method* at the bottom of the stack.
257 * EAX holds the exception.
258 */
Ian Rogersff1ed472011-09-20 13:46:24 -0700259art_deliver_exception_from_code:
Ian Rogers67375ac2011-09-14 00:55:44 -0700260 // Create frame
261 pushl %edi // Save callee saves
262 pushl %esi
263 pushl %ebp
264 pushl %ebx
265 pushl $0
266 pushl $0
267 pushl $0 // Will be clobbered to be Method*
268 mov %esp, %ecx
269 // Outgoing argument set up
Ian Rogersff1ed472011-09-20 13:46:24 -0700270 pushl $0 // Alignment padding
271 pushl %ecx // pass SP
272 pushl %fs:THREAD_SELF_OFFSET // pass fs:offsetof(Thread,self_)
273 pushl %eax // pass Throwable*
274 call artDeliverExceptionFromCode // artDeliverExceptionFromCode(Throwable*, Thread*, SP)
Ian Rogers67375ac2011-09-14 00:55:44 -0700275 int3
276
277#endif