blob: 5b70fb761059c19ef61d37ef7ebf724dde20d43b [file] [log] [blame]
#include "asm_support.h"
#if defined(__arm__)
.balign 4
/* Deliver the given exception */
.extern artDeliverExceptionFromCode
/* Deliver an exception pending on a thread */
.extern artDeliverPendingException
/*
* Macro that sets up the callee save frame to conform with
* Runtime::CreateCalleeSaveMethod(kSaveAll)
*/
.macro SETUP_CALLEE_SAVE_FRAME
push {r4-r11, lr} @ 9 words of callee saves
vpush {s0-s31}
sub sp, #12 @ 3 words of space, bottom word will hold Method*
.endm
/*
* Macro that sets up the callee save frame to conform with
* Runtime::CreateCalleeSaveMethod(kRefsOnly)
*/
.macro SETUP_REF_ONLY_CALLEE_SAVE_FRAME
push {r5-r8, r10-r11, lr} @ 7 words of callee saves
sub sp, #4 @ bottom word will hold Method*
.endm
.macro RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
add sp, #4
pop {r5-r8, r10-r11, lr} @ 7 words of callee saves
.endm
.macro RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
add sp, #4
pop {r5-r8, r10-r11, pc} @ 7 words of callee saves
.endm
/*
* Macro that sets up the callee save frame to conform with
* Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
*/
.macro SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
push {r1-r3, r5-r8, r10-r11, lr} @ 10 words of callee saves
sub sp, #8 @ 2 words of space, bottom word will hold Method*
.endm
.macro RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
add sp, #8
pop {r1-r3, r5-r8, r10-r11, lr} @ 10 words of callee saves
.endm
.global art_deliver_exception_from_code
/*
* Called by managed code, saves mosts registers (forms basis of long jump context) and passes
* the bottom of the stack. artDeliverExceptionFromCode will place the callee save Method* at
* the bottom of the thread. On entry r0 holds Throwable*
*/
art_deliver_exception_from_code:
SETUP_CALLEE_SAVE_FRAME
mov r1, r9 @ pass Thread::Current
mov r2, sp @ pass SP
b artDeliverExceptionFromCode @ artDeliverExceptionFromCode(Throwable*, Thread*, SP)
.global art_throw_null_pointer_exception_from_code
.extern artThrowNullPointerExceptionFromCode
/*
* Called by managed code to create and deliver a NullPointerException
*/
art_throw_null_pointer_exception_from_code:
SETUP_CALLEE_SAVE_FRAME
mov r0, r9 @ pass Thread::Current
mov r1, sp @ pass SP
b artThrowNullPointerExceptionFromCode @ artThrowNullPointerExceptionFromCode(Thread*, SP)
.global art_throw_div_zero_from_code
.extern artThrowDivZeroFromCode
/*
* Called by managed code to create and deliver an ArithmeticException
*/
art_throw_div_zero_from_code:
SETUP_CALLEE_SAVE_FRAME
mov r0, r9 @ pass Thread::Current
mov r1, sp @ pass SP
b artThrowDivZeroFromCode @ artThrowDivZeroFromCode(Thread*, SP)
.global art_throw_array_bounds_from_code
.extern artThrowArrayBoundsFromCode
/*
* Called by managed code to create and deliver an ArrayIndexOutOfBoundsException
*/
art_throw_array_bounds_from_code:
SETUP_CALLEE_SAVE_FRAME
mov r2, r9 @ pass Thread::Current
mov r3, sp @ pass SP
b artThrowArrayBoundsFromCode @ artThrowArrayBoundsFromCode(index, limit, Thread*, SP)
.global art_throw_stack_overflow_from_code
.extern artThrowStackOverflowFromCode
art_throw_stack_overflow_from_code:
SETUP_CALLEE_SAVE_FRAME
mov r1, r9 @ pass Thread::Current
mov r2, sp @ pass SP
b artThrowStackOverflowFromCode @ artThrowStackOverflowFromCode(method, Thread*, SP)
.global art_throw_neg_array_size_from_code
.extern artThrowNegArraySizeFromCode
art_throw_neg_array_size_from_code:
SETUP_CALLEE_SAVE_FRAME
mov r1, r9 @ pass Thread::Current
mov r2, sp @ pass SP
b artThrowNegArraySizeFromCode @ artThrowNegArraySizeFromCode(size, Thread*, SP)
.global art_throw_no_such_method_from_code
.extern artThrowNoSuchMethodFromCode
art_throw_no_such_method_from_code:
SETUP_CALLEE_SAVE_FRAME
mov r1, r9 @ pass Thread::Current
mov r2, sp @ pass SP
b artThrowNoSuchMethodFromCode @ artThrowNoSuchMethodFromCode(method_idx, Thread*, SP)
.global art_throw_verification_error_from_code
.extern artThrowVerificationErrorFromCode
art_throw_verification_error_from_code:
SETUP_CALLEE_SAVE_FRAME
mov r2, r9 @ pass Thread::Current
mov r3, sp @ pass SP
b artThrowVerificationErrorFromCode @ artThrowVerificationErrorFromCode(kind, ref, Thread*, SP)
.global art_invoke_interface_trampoline
.extern artFindInterfaceMethodInCacheFromCode
/*
* All generated callsites for interface invokes will load arguments as usual - except instead
* of loading arg0/r0 with the target Method*, arg0/r0 will contain the method_idx. This
* wrapper will save arg1-arg3, load the caller's Method*, align the stack and call the helper
* artFindInterfaceMethodInCacheFromCode(idx, this, method);
* NOTE: "this" is first visable argument of the target, and so can be found in arg1/r1.
*
* artFindInterfaceMethodInCacheFromCode will attempt to locate the target and return a 64-bit
* result in r0/r1 consisting of the target Method* in r0 and method->code_ in r1.
*
* If unsuccessful, artFindInterfaceMethodInCacheFromCode will return NULL/NULL. There will be
* a pending exception in the thread and we branch to another stub to deliver it.
*
* On success this wrapper will restore arguments and *jump* to the target, leaving the lr
* pointing back to the original caller.
*/
art_invoke_interface_trampoline:
SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME @ save callee saves in case allocation triggers GC
mov r2, r9 @ pass Thread::Current
mov r3, sp @ pass SP
bl artFindInterfaceMethodInCacheFromCode @ (method_idx, this, Thread*, SP)
mov r12, r1 @ save r0->code_
RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
cmp r0, #0 @ did we find the target?
bxne r12 @ tail call to target if so
SETUP_CALLEE_SAVE_FRAME @ set up for throwing exception
mov r0, r9 @ pass Thread::Current
mov r1, sp @ pass SP
b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
.global art_handle_fill_data_from_code
.extern artHandleFillArrayDataFromCode
/*
* Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
* failure.
*/
art_handle_fill_data_from_code:
SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case exception allocation triggers GC
mov r2, r9 @ pass Thread::Current
mov r3, sp @ pass SP
bl artHandleFillArrayDataFromCode @ (Array* array, const uint16_t* table, Thread*, SP)
RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
cmp r0, #0 @ success?
moveq pc, lr @ return on success
SETUP_CALLEE_SAVE_FRAME @ set up for throwing exception
mov r0, r9 @ pass Thread::Current
mov r1, sp @ pass SP
b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
.global art_lock_object_from_code
.extern artLockObjectFromCode
/*
* Entry from managed code that calls artLockObjectFromCode, may block for GC
*/
art_lock_object_from_code:
SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case we block
mov r1, r9 @ pass Thread::Current
mov r2, sp @ pass SP
bl artLockObjectFromCode @ (Object* obj, Thread*, SP)
RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
.global art_unlock_object_from_code
.extern artUnlockObjectFromCode
/*
* Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
*/
art_unlock_object_from_code:
SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case exception allocation triggers GC
mov r1, r9 @ pass Thread::Current
mov r2, sp @ pass SP
bl artUnlockObjectFromCode @ (Object* obj, Thread*, SP)
RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
cmp r0, #0 @ success?
moveq pc, lr @ return on success
SETUP_CALLEE_SAVE_FRAME @ set up for throwing exception
mov r0, r9 @ pass Thread::Current
mov r1, sp @ pass SP
b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
.global art_check_cast_from_code
.extern artCheckCastFromCode
/*
* Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
*/
art_check_cast_from_code:
SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case exception allocation triggers GC
mov r2, r9 @ pass Thread::Current
mov r3, sp @ pass SP
bl artCheckCastFromCode @ (Class* a, Class* b, Thread*, SP)
RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
cmp r0, #0 @ success?
moveq pc, lr @ return on success
SETUP_CALLEE_SAVE_FRAME @ set up for throwing exception
mov r0, r9 @ pass Thread::Current
mov r1, sp @ pass SP
b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
.global art_can_put_array_element_from_code
.extern artCanPutArrayElementFromCode
/*
* Entry from managed code that calls artCanPutArrayElementFromCode and delivers exception on
* failure.
*/
art_can_put_array_element_from_code:
cmp r0, #0 @ return if element == NULL
moveq pc, lr
SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case exception allocation triggers GC
mov r2, r9 @ pass Thread::Current
mov r3, sp @ pass SP
bl artCanPutArrayElementFromCode @ (Object* element, Class* array_class, Thread*, SP)
RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
cmp r0, #0 @ success?
moveq pc, lr @ return on success
SETUP_CALLEE_SAVE_FRAME @ set up for throwing exception
mov r0, r9 @ pass Thread::Current
mov r1, sp @ pass SP
b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
.global art_initialize_static_storage_from_code
.extern artInitializeStaticStorageFromCode
/*
* Entry from managed code when uninitialized static storage, this stub will run the class
* initializer and deliver the exception on error. On success the static storage base is
* returned.
*/
art_initialize_static_storage_from_code:
SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
mov r2, r9 @ pass Thread::Current
mov r3, sp @ pass SP
@ ClassLinker::InitializeStaticStorageFromCode(uint32_t type_idx, Method* referrer, Thread*, SP)
bl artInitializeStaticStorageFromCode
RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
cmp r0, #0 @ success if result is non-null
movne pc, lr @ return on success
SETUP_CALLEE_SAVE_FRAME @ set up for throwing exception
mov r0, r9 @ pass Thread::Current
mov r1, sp @ pass SP
b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
.global art_alloc_object_from_code
.extern artAllocObjectFromCode
/*
* Called by managed code to allocate an object
*/
art_alloc_object_from_code:
SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
mov r2, r9 @ pass Thread::Current
mov r3, sp @ pass SP
bl artAllocObjectFromCode @ (uint32_t type_idx, Method* method, Thread*, SP)
RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
cmp r0, #0 @ success if result is non-null
movne pc, lr @ return on success
SETUP_CALLEE_SAVE_FRAME @ set up for throwing exception
mov r0, r9 @ pass Thread::Current
mov r1, sp @ pass SP
b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
.global art_alloc_array_from_code
.extern artAllocArrayFromCode
/*
* Called by managed code to allocate an array
*/
art_alloc_array_from_code:
SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
mov r3, r9 @ pass Thread::Current
str sp, [sp, #0] @ pass SP
@ artAllocArrayFromCode(uint32_t type_idx, Method* method, int32_t component_count, Thread*, SP)
bl artAllocArrayFromCode
RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
cmp r0, #0 @ success if result is non-null
movne pc, lr @ return on success
SETUP_CALLEE_SAVE_FRAME @ set up for throwing exception
mov r0, r9 @ pass Thread::Current
mov r1, sp @ pass SP
b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
.global art_check_and_alloc_array_from_code
.extern artCheckAndAllocArrayFromCode
/*
* Called by managed code to allocate an array
*/
art_check_and_alloc_array_from_code:
SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC
mov r3, r9 @ pass Thread::Current
str sp, [sp, #0] @ pass SP
@ artCheckAndAllocArrayFromCode(uint32_t type_idx, Method* method, int32_t count, Thread* , SP)
bl artCheckAndAllocArrayFromCode
RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
cmp r0, #0 @ success if result is non-null
movne pc, lr @ return on success
SETUP_CALLEE_SAVE_FRAME @ set up for throwing exception
mov r0, r9 @ pass Thread::Current
mov r1, sp @ pass SP
b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*, SP)
.global art_test_suspend
.extern artCheckSuspendFromCode
art_test_suspend:
ldr r0, [rSELF, #THREAD_SUSPEND_COUNT_OFFSET]
mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
cmp r0, #0 @ check Thread::Current()->suspend_count_ == 0
bxeq rLR @ return if suspend_count_ == 0
mov r0, rSELF
mov r1, sp
SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves for stack crawl
bl artCheckSuspendFromCode @ (Thread*, SP)
RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
.global art_shl_long
art_shl_long:
/*
* Long integer shift. This is different from the generic 32/64-bit
* binary operations because vAA/vBB are 64-bit but vCC (the shift
* distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
* 6 bits.
* On entry:
* r0: low word
* r1: high word
* r2: shift count
*/
/* shl-long vAA, vBB, vCC */
and r2, r2, #63 @ r2<- r2 & 0x3f
mov r1, r1, asl r2 @ r1<- r1 << r2
rsb r3, r2, #32 @ r3<- 32 - r2
orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
subs ip, r2, #32 @ ip<- r2 - 32
movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
mov r0, r0, asl r2 @ r0<- r0 << r2
bx lr
.balign 4
.global art_shr_long
art_shr_long:
/*
* Long integer shift. This is different from the generic 32/64-bit
* binary operations because vAA/vBB are 64-bit but vCC (the shift
* distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
* 6 bits.
* On entry:
* r0: low word
* r1: high word
* r2: shift count
*/
/* shr-long vAA, vBB, vCC */
and r2, r2, #63 @ r0<- r0 & 0x3f
mov r0, r0, lsr r2 @ r0<- r2 >> r2
rsb r3, r2, #32 @ r3<- 32 - r2
orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
subs ip, r2, #32 @ ip<- r2 - 32
movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
mov r1, r1, asr r2 @ r1<- r1 >> r2
bx lr
.balign 4
.global art_ushr_long
art_ushr_long:
/*
* Long integer shift. This is different from the generic 32/64-bit
* binary operations because vAA/vBB are 64-bit but vCC (the shift
* distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
* 6 bits.
* On entry:
* r0: low word
* r1: high word
* r2: shift count
*/
/* ushr-long vAA, vBB, vCC */
and r2, r2, #63 @ r0<- r0 & 0x3f
mov r0, r0, lsr r2 @ r0<- r2 >> r2
rsb r3, r2, #32 @ r3<- 32 - r2
orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
subs ip, r2, #32 @ ip<- r2 - 32
movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
mov r1, r1, lsr r2 @ r1<- r1 >>> r2
bx lr
#endif
#if defined(__i386__)
.global art_deliver_exception_from_code
.extern artDeliverExceptionFromCode
/*
* Called by managed code, saves callee saves and then calls artThrowException
* that will place a mock Method* at the bottom of the stack.
* EAX holds the exception.
*/
art_deliver_exception_from_code:
// Create frame
pushl %edi // Save callee saves
pushl %esi
pushl %ebp
pushl %ebx
pushl $0
pushl $0
pushl $0 // Will be clobbered to be Method*
mov %esp, %ecx
// Outgoing argument set up
pushl $0 // Alignment padding
pushl %ecx // pass SP
pushl %fs:THREAD_SELF_OFFSET // pass fs:offsetof(Thread,self_)
pushl %eax // pass Throwable*
call artDeliverExceptionFromCode // artDeliverExceptionFromCode(Throwable*, Thread*, SP)
int3
#endif