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