blob: 75e0037145f20cc006dff255d8d497e1b4cd58c0 [file] [log] [blame]
buzbee1452bee2015-03-06 14:43:04 -08001/*
2 * ===========================================================================
3 * Common subroutines and data
4 * ===========================================================================
5 */
6
7 .text
8 .align 2
9
10/*
11 * We've detected a condition that will result in an exception, but the exception
12 * has not yet been thrown. Just bail out to the reference interpreter to deal with it.
13 * TUNING: for consistency, we may want to just go ahead and handle these here.
14 */
15#define MTERP_LOGGING 0
16common_errDivideByZero:
17 EXPORT_PC
18#if MTERP_LOGGING
19 mov r0, rSELF
20 add r1, rFP, #OFF_FP_SHADOWFRAME
21 bl MterpLogDivideByZeroException
22#endif
23 b MterpCommonFallback
24
25common_errArrayIndex:
26 EXPORT_PC
27#if MTERP_LOGGING
28 mov r0, rSELF
29 add r1, rFP, #OFF_FP_SHADOWFRAME
30 bl MterpLogArrayIndexException
31#endif
32 b MterpCommonFallback
33
34common_errNegativeArraySize:
35 EXPORT_PC
36#if MTERP_LOGGING
37 mov r0, rSELF
38 add r1, rFP, #OFF_FP_SHADOWFRAME
39 bl MterpLogNegativeArraySizeException
40#endif
41 b MterpCommonFallback
42
43common_errNoSuchMethod:
44 EXPORT_PC
45#if MTERP_LOGGING
46 mov r0, rSELF
47 add r1, rFP, #OFF_FP_SHADOWFRAME
48 bl MterpLogNoSuchMethodException
49#endif
50 b MterpCommonFallback
51
52common_errNullObject:
53 EXPORT_PC
54#if MTERP_LOGGING
55 mov r0, rSELF
56 add r1, rFP, #OFF_FP_SHADOWFRAME
57 bl MterpLogNullObjectException
58#endif
59 b MterpCommonFallback
60
61common_exceptionThrown:
62 EXPORT_PC
63#if MTERP_LOGGING
64 mov r0, rSELF
65 add r1, rFP, #OFF_FP_SHADOWFRAME
66 bl MterpLogExceptionThrownException
67#endif
68 b MterpCommonFallback
69
70MterpSuspendFallback:
71 EXPORT_PC
72#if MTERP_LOGGING
73 mov r0, rSELF
74 add r1, rFP, #OFF_FP_SHADOWFRAME
75 ldr r2, [rSELF, #THREAD_FLAGS_OFFSET]
76 bl MterpLogSuspendFallback
77#endif
78 b MterpCommonFallback
79
80/*
81 * If we're here, something is out of the ordinary. If there is a pending
82 * exception, handle it. Otherwise, roll back and retry with the reference
83 * interpreter.
84 */
85MterpPossibleException:
86 ldr r0, [rSELF, #THREAD_EXCEPTION_OFFSET]
87 cmp r0, #0 @ Exception pending?
88 beq MterpFallback @ If not, fall back to reference interpreter.
89 /* intentional fallthrough - handle pending exception. */
90/*
91 * On return from a runtime helper routine, we've found a pending exception.
92 * Can we handle it here - or need to bail out to caller?
93 *
94 */
95MterpException:
96 mov r0, rSELF
97 add r1, rFP, #OFF_FP_SHADOWFRAME
98 bl MterpHandleException @ (self, shadow_frame)
99 cmp r0, #0
100 beq MterpExceptionReturn @ no local catch, back to caller.
101 ldr r0, [rFP, #OFF_FP_CODE_ITEM]
102 ldr r1, [rFP, #OFF_FP_DEX_PC]
103 ldr rIBASE, [rSELF, #THREAD_CURRENT_IBASE_OFFSET]
104 add rPC, r0, #CODEITEM_INSNS_OFFSET
105 add rPC, rPC, r1, lsl #1 @ generate new dex_pc_ptr
106 str rPC, [rFP, #OFF_FP_DEX_PC_PTR]
107 /* resume execution at catch block */
108 FETCH_INST
109 GET_INST_OPCODE ip
110 GOTO_OPCODE ip
111 /* NOTE: no fallthrough */
112
113/*
114 * Check for suspend check request. Assumes rINST already loaded, rPC advanced and
115 * still needs to get the opcode and branch to it, and flags are in lr.
116 */
117MterpCheckSuspendAndContinue:
118 ldr rIBASE, [rSELF, #THREAD_CURRENT_IBASE_OFFSET] @ refresh rIBASE
119 EXPORT_PC
120 mov r0, rSELF
121 ands lr, #(THREAD_SUSPEND_REQUEST | THREAD_CHECKPOINT_REQUEST)
122 blne MterpSuspendCheck @ (self)
123 GET_INST_OPCODE ip @ extract opcode from rINST
124 GOTO_OPCODE ip @ jump to next instruction
125
126/*
127 * Bail out to reference interpreter.
128 */
129MterpFallback:
130 EXPORT_PC
131 mov r0, rSELF
132 add r1, rFP, #OFF_FP_SHADOWFRAME
133 bl MterpLogFallback
134MterpCommonFallback:
135 mov r0, #0 @ signal retry with reference interpreter.
136 b MterpDone
137
138/*
139 * We pushed some registers on the stack in ExecuteMterpImpl, then saved
140 * SP and LR. Here we restore SP, restore the registers, and then restore
141 * LR to PC.
142 *
143 * On entry:
144 * uint32_t* rFP (should still be live, pointer to base of vregs)
145 */
146MterpExceptionReturn:
147 ldr r2, [rFP, #OFF_FP_RESULT_REGISTER]
148 str r0, [r2]
149 str r1, [r2, #4]
150 mov r0, #1 @ signal return to caller.
151 b MterpDone
152MterpReturn:
153 ldr r2, [rFP, #OFF_FP_RESULT_REGISTER]
154 ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
155 str r0, [r2]
156 str r1, [r2, #4]
157 mov r0, rSELF
158 ands lr, #(THREAD_SUSPEND_REQUEST | THREAD_CHECKPOINT_REQUEST)
159 blne MterpSuspendCheck @ (self)
160 mov r0, #1 @ signal return to caller.
161MterpDone:
162 add sp, sp, #4 @ un-align 64
163 ldmfd sp!, {r4-r10,fp,pc} @ restore 9 regs and return
164
165
166 .fnend
167 .size ExecuteMterpImpl, .-ExecuteMterpImpl
168