buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 15 | common_errDivideByZero: |
| 16 | EXPORT_PC |
| 17 | #if MTERP_LOGGING |
| 18 | mov r0, rSELF |
| 19 | add r1, rFP, #OFF_FP_SHADOWFRAME |
| 20 | bl MterpLogDivideByZeroException |
| 21 | #endif |
| 22 | b MterpCommonFallback |
| 23 | |
| 24 | common_errArrayIndex: |
| 25 | EXPORT_PC |
| 26 | #if MTERP_LOGGING |
| 27 | mov r0, rSELF |
| 28 | add r1, rFP, #OFF_FP_SHADOWFRAME |
| 29 | bl MterpLogArrayIndexException |
| 30 | #endif |
| 31 | b MterpCommonFallback |
| 32 | |
| 33 | common_errNegativeArraySize: |
| 34 | EXPORT_PC |
| 35 | #if MTERP_LOGGING |
| 36 | mov r0, rSELF |
| 37 | add r1, rFP, #OFF_FP_SHADOWFRAME |
| 38 | bl MterpLogNegativeArraySizeException |
| 39 | #endif |
| 40 | b MterpCommonFallback |
| 41 | |
| 42 | common_errNoSuchMethod: |
| 43 | EXPORT_PC |
| 44 | #if MTERP_LOGGING |
| 45 | mov r0, rSELF |
| 46 | add r1, rFP, #OFF_FP_SHADOWFRAME |
| 47 | bl MterpLogNoSuchMethodException |
| 48 | #endif |
| 49 | b MterpCommonFallback |
| 50 | |
| 51 | common_errNullObject: |
| 52 | EXPORT_PC |
| 53 | #if MTERP_LOGGING |
| 54 | mov r0, rSELF |
| 55 | add r1, rFP, #OFF_FP_SHADOWFRAME |
| 56 | bl MterpLogNullObjectException |
| 57 | #endif |
| 58 | b MterpCommonFallback |
| 59 | |
| 60 | common_exceptionThrown: |
| 61 | EXPORT_PC |
| 62 | #if MTERP_LOGGING |
| 63 | mov r0, rSELF |
| 64 | add r1, rFP, #OFF_FP_SHADOWFRAME |
| 65 | bl MterpLogExceptionThrownException |
| 66 | #endif |
| 67 | b MterpCommonFallback |
| 68 | |
| 69 | MterpSuspendFallback: |
| 70 | EXPORT_PC |
| 71 | #if MTERP_LOGGING |
| 72 | mov r0, rSELF |
| 73 | add r1, rFP, #OFF_FP_SHADOWFRAME |
| 74 | ldr r2, [rSELF, #THREAD_FLAGS_OFFSET] |
| 75 | bl MterpLogSuspendFallback |
| 76 | #endif |
| 77 | b MterpCommonFallback |
| 78 | |
| 79 | /* |
| 80 | * If we're here, something is out of the ordinary. If there is a pending |
| 81 | * exception, handle it. Otherwise, roll back and retry with the reference |
| 82 | * interpreter. |
| 83 | */ |
| 84 | MterpPossibleException: |
| 85 | ldr r0, [rSELF, #THREAD_EXCEPTION_OFFSET] |
| 86 | cmp r0, #0 @ Exception pending? |
| 87 | beq MterpFallback @ If not, fall back to reference interpreter. |
| 88 | /* intentional fallthrough - handle pending exception. */ |
| 89 | /* |
| 90 | * On return from a runtime helper routine, we've found a pending exception. |
| 91 | * Can we handle it here - or need to bail out to caller? |
| 92 | * |
| 93 | */ |
| 94 | MterpException: |
| 95 | mov r0, rSELF |
| 96 | add r1, rFP, #OFF_FP_SHADOWFRAME |
| 97 | bl MterpHandleException @ (self, shadow_frame) |
| 98 | cmp r0, #0 |
| 99 | beq MterpExceptionReturn @ no local catch, back to caller. |
| 100 | ldr r0, [rFP, #OFF_FP_CODE_ITEM] |
| 101 | ldr r1, [rFP, #OFF_FP_DEX_PC] |
| 102 | ldr rIBASE, [rSELF, #THREAD_CURRENT_IBASE_OFFSET] |
| 103 | add rPC, r0, #CODEITEM_INSNS_OFFSET |
| 104 | add rPC, rPC, r1, lsl #1 @ generate new dex_pc_ptr |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame^] | 105 | /* Do we need to switch interpreters? */ |
| 106 | bl MterpShouldSwitchInterpreters |
| 107 | cmp r0, #0 |
| 108 | bne MterpFallback |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 109 | /* resume execution at catch block */ |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame^] | 110 | EXPORT_PC |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 111 | FETCH_INST |
| 112 | GET_INST_OPCODE ip |
| 113 | GOTO_OPCODE ip |
| 114 | /* NOTE: no fallthrough */ |
| 115 | |
| 116 | /* |
| 117 | * Check for suspend check request. Assumes rINST already loaded, rPC advanced and |
| 118 | * still needs to get the opcode and branch to it, and flags are in lr. |
| 119 | */ |
| 120 | MterpCheckSuspendAndContinue: |
| 121 | ldr rIBASE, [rSELF, #THREAD_CURRENT_IBASE_OFFSET] @ refresh rIBASE |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 122 | ands lr, #(THREAD_SUSPEND_REQUEST | THREAD_CHECKPOINT_REQUEST) |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame^] | 123 | bne 1f |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 124 | GET_INST_OPCODE ip @ extract opcode from rINST |
| 125 | GOTO_OPCODE ip @ jump to next instruction |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame^] | 126 | 1: |
| 127 | EXPORT_PC |
| 128 | mov r0, rSELF |
| 129 | bl MterpSuspendCheck @ (self) |
| 130 | cmp r0, #0 |
| 131 | bne MterpFallback |
| 132 | GET_INST_OPCODE ip @ extract opcode from rINST |
| 133 | GOTO_OPCODE ip @ jump to next instruction |
| 134 | |
| 135 | /* |
| 136 | * On-stack replacement has happened, and now we've returned from the compiled method. |
| 137 | */ |
| 138 | MterpOnStackReplacement: |
| 139 | #if MTERP_LOGGING |
| 140 | mov r0, rSELF |
| 141 | add r1, rFP, #OFF_FP_SHADOWFRAME |
| 142 | mov r2, rINST |
| 143 | bl MterpLogOSR |
| 144 | #endif |
| 145 | mov r0, #1 @ Signal normal return |
| 146 | b MterpDone |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 147 | |
| 148 | /* |
| 149 | * Bail out to reference interpreter. |
| 150 | */ |
| 151 | MterpFallback: |
| 152 | EXPORT_PC |
buzbee | 76833da | 2016-01-13 13:06:22 -0800 | [diff] [blame] | 153 | #if MTERP_LOGGING |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 154 | mov r0, rSELF |
| 155 | add r1, rFP, #OFF_FP_SHADOWFRAME |
| 156 | bl MterpLogFallback |
buzbee | 76833da | 2016-01-13 13:06:22 -0800 | [diff] [blame] | 157 | #endif |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 158 | MterpCommonFallback: |
| 159 | mov r0, #0 @ signal retry with reference interpreter. |
| 160 | b MterpDone |
| 161 | |
| 162 | /* |
| 163 | * We pushed some registers on the stack in ExecuteMterpImpl, then saved |
| 164 | * SP and LR. Here we restore SP, restore the registers, and then restore |
| 165 | * LR to PC. |
| 166 | * |
| 167 | * On entry: |
| 168 | * uint32_t* rFP (should still be live, pointer to base of vregs) |
| 169 | */ |
| 170 | MterpExceptionReturn: |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 171 | mov r0, #1 @ signal return to caller. |
| 172 | b MterpDone |
| 173 | MterpReturn: |
| 174 | ldr r2, [rFP, #OFF_FP_RESULT_REGISTER] |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 175 | str r0, [r2] |
| 176 | str r1, [r2, #4] |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 177 | mov r0, #1 @ signal return to caller. |
| 178 | MterpDone: |
| 179 | add sp, sp, #4 @ un-align 64 |
| 180 | ldmfd sp!, {r4-r10,fp,pc} @ restore 9 regs and return |
| 181 | |
| 182 | |
| 183 | .fnend |
| 184 | .size ExecuteMterpImpl, .-ExecuteMterpImpl |
| 185 | |