Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "asm_support_arm64.S" |
| 18 | |
| 19 | #include "arch/quick_alloc_entrypoints.S" |
| 20 | |
| 21 | |
| 22 | /* |
| 23 | * Macro that sets up the callee save frame to conform with |
| 24 | * Runtime::CreateCalleeSaveMethod(kSaveAll) |
| 25 | */ |
| 26 | .macro SETUP_SAVE_ALL_CALLEE_SAVE_FRAME |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 27 | adrp xIP0, :got:_ZN3art7Runtime9instance_E |
| 28 | ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 29 | |
| 30 | // Our registers aren't intermixed - just spill in order. |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 31 | ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) . |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 32 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 33 | // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] . |
Hiroshi Yamauchi | ab08811 | 2014-07-14 13:00:14 -0700 | [diff] [blame] | 34 | THIS_LOAD_REQUIRES_READ_BARRIER |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 35 | ldr xIP0, [xIP0, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET ] |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 36 | |
| 37 | sub sp, sp, #176 |
| 38 | .cfi_adjust_cfa_offset 176 |
| 39 | |
| 40 | // Ugly compile-time check, but we only have the preprocessor. |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 41 | #if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 176) |
| 42 | #error "SAVE_ALL_CALLEE_SAVE_FRAME(ARM64) size not as expected." |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 43 | #endif |
| 44 | |
| 45 | // FP callee-saves |
| 46 | stp d8, d9, [sp, #8] |
| 47 | stp d10, d11, [sp, #24] |
| 48 | stp d12, d13, [sp, #40] |
| 49 | stp d14, d15, [sp, #56] |
| 50 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 51 | // Reserved registers |
| 52 | stp xSELF, xSUSPEND, [sp, #72] |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 53 | .cfi_rel_offset x18, 72 |
| 54 | .cfi_rel_offset x19, 80 |
| 55 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 56 | // callee-saves |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 57 | stp x20, x21, [sp, #88] |
| 58 | .cfi_rel_offset x20, 88 |
| 59 | .cfi_rel_offset x21, 96 |
| 60 | |
| 61 | stp x22, x23, [sp, #104] |
| 62 | .cfi_rel_offset x22, 104 |
| 63 | .cfi_rel_offset x23, 112 |
| 64 | |
| 65 | stp x24, x25, [sp, #120] |
| 66 | .cfi_rel_offset x24, 120 |
| 67 | .cfi_rel_offset x25, 128 |
| 68 | |
| 69 | stp x26, x27, [sp, #136] |
| 70 | .cfi_rel_offset x26, 136 |
| 71 | .cfi_rel_offset x27, 144 |
| 72 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 73 | stp x28, x29, [sp, #152] |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 74 | .cfi_rel_offset x28, 152 |
| 75 | .cfi_rel_offset x29, 160 |
| 76 | |
| 77 | str xLR, [sp, #168] |
| 78 | .cfi_rel_offset x30, 168 |
| 79 | |
| 80 | // Loads appropriate callee-save-method |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 81 | str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 82 | .endm |
| 83 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 84 | /* |
| 85 | * Macro that sets up the callee save frame to conform with |
| 86 | * Runtime::CreateCalleeSaveMethod(kRefsOnly). |
| 87 | */ |
| 88 | .macro SETUP_REF_ONLY_CALLEE_SAVE_FRAME |
| 89 | adrp xIP0, :got:_ZN3art7Runtime9instance_E |
| 90 | ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E] |
| 91 | |
| 92 | // Our registers aren't intermixed - just spill in order. |
| 93 | ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) . |
| 94 | |
| 95 | // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] . |
| 96 | THIS_LOAD_REQUIRES_READ_BARRIER |
| 97 | ldr xIP0, [xIP0, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET ] |
| 98 | |
| 99 | sub sp, sp, #96 |
| 100 | .cfi_adjust_cfa_offset 96 |
| 101 | |
| 102 | // Ugly compile-time check, but we only have the preprocessor. |
| 103 | #if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 96) |
| 104 | #error "REFS_ONLY_CALLEE_SAVE_FRAME(ARM64) size not as expected." |
| 105 | #endif |
| 106 | |
| 107 | // Callee-saves |
| 108 | stp x20, x21, [sp, #8] |
| 109 | .cfi_rel_offset x20, 8 |
| 110 | .cfi_rel_offset x21, 16 |
| 111 | |
| 112 | stp x22, x23, [sp, #24] |
| 113 | .cfi_rel_offset x22, 24 |
| 114 | .cfi_rel_offset x23, 32 |
| 115 | |
| 116 | stp x24, x25, [sp, #40] |
| 117 | .cfi_rel_offset x24, 40 |
| 118 | .cfi_rel_offset x25, 48 |
| 119 | |
| 120 | stp x26, x27, [sp, #56] |
| 121 | .cfi_rel_offset x26, 56 |
| 122 | .cfi_rel_offset x27, 64 |
| 123 | |
| 124 | stp x28, x29, [sp, #72] |
| 125 | .cfi_rel_offset x28, 72 |
| 126 | .cfi_rel_offset x29, 80 |
| 127 | |
| 128 | // LR |
| 129 | str xLR, [sp, #88] |
| 130 | .cfi_rel_offset x30, 88 |
| 131 | |
| 132 | // Save xSELF to xETR. |
| 133 | mov xETR, xSELF |
| 134 | |
| 135 | // Loads appropriate callee-save-method |
| 136 | str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs] |
| 137 | .endm |
| 138 | |
| 139 | // TODO: Probably no need to restore registers preserved by aapcs64. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 140 | .macro RESTORE_REF_ONLY_CALLEE_SAVE_FRAME |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 141 | // Restore xSELF. |
| 142 | mov xSELF, xETR |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 143 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 144 | // Callee-saves |
| 145 | ldp x20, x21, [sp, #8] |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 146 | .cfi_restore x20 |
| 147 | .cfi_restore x21 |
| 148 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 149 | ldp x22, x23, [sp, #24] |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 150 | .cfi_restore x22 |
| 151 | .cfi_restore x23 |
| 152 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 153 | ldp x24, x25, [sp, #40] |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 154 | .cfi_restore x24 |
| 155 | .cfi_restore x25 |
| 156 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 157 | ldp x26, x27, [sp, #56] |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 158 | .cfi_restore x26 |
| 159 | .cfi_restore x27 |
| 160 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 161 | ldp x28, x29, [sp, #72] |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 162 | .cfi_restore x28 |
| 163 | .cfi_restore x29 |
| 164 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 165 | // LR |
| 166 | ldr xLR, [sp, #88] |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 167 | .cfi_restore x30 |
| 168 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 169 | add sp, sp, #96 |
| 170 | .cfi_adjust_cfa_offset -96 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 171 | .endm |
| 172 | |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 173 | .macro POP_REF_ONLY_CALLEE_SAVE_FRAME |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 174 | // Restore xSELF as it might be scratched. |
| 175 | mov xSELF, xETR |
| 176 | // ETR |
| 177 | ldr xETR, [sp, #16] |
| 178 | .cfi_restore x21 |
| 179 | |
| 180 | add sp, sp, #96 |
| 181 | .cfi_adjust_cfa_offset -96 |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 182 | .endm |
| 183 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 184 | .macro RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 185 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME |
| 186 | ret |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 187 | .endm |
| 188 | |
| 189 | |
| 190 | .macro SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 191 | sub sp, sp, #224 |
| 192 | .cfi_adjust_cfa_offset 224 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 193 | |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 194 | // Ugly compile-time check, but we only have the preprocessor. |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 195 | #if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 224) |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 196 | #error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(ARM64) size not as expected." |
| 197 | #endif |
| 198 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 199 | // FP args |
| 200 | stp d0, d1, [sp, #16] |
| 201 | stp d2, d3, [sp, #32] |
| 202 | stp d4, d5, [sp, #48] |
| 203 | stp d6, d7, [sp, #64] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 204 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 205 | // args and x20(callee-save) |
| 206 | stp x1, x2, [sp, #80] |
| 207 | .cfi_rel_offset x1, 80 |
| 208 | .cfi_rel_offset x2, 88 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 209 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 210 | stp x3, x4, [sp, #96] |
| 211 | .cfi_rel_offset x3, 96 |
| 212 | .cfi_rel_offset x4, 104 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 213 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 214 | stp x5, x6, [sp, #112] |
| 215 | .cfi_rel_offset x5, 112 |
| 216 | .cfi_rel_offset x6, 120 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 217 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 218 | stp x7, x20, [sp, #128] |
| 219 | .cfi_rel_offset x7, 128 |
| 220 | .cfi_rel_offset x20, 136 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 221 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 222 | // Callee-saves. |
| 223 | stp x21, x22, [sp, #144] |
| 224 | .cfi_rel_offset x21, 144 |
| 225 | .cfi_rel_offset x22, 152 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 226 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 227 | stp x23, x24, [sp, #160] |
| 228 | .cfi_rel_offset x23, 160 |
| 229 | .cfi_rel_offset x24, 168 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 230 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 231 | stp x25, x26, [sp, #176] |
| 232 | .cfi_rel_offset x25, 176 |
| 233 | .cfi_rel_offset x26, 184 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 234 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 235 | stp x27, x28, [sp, #192] |
| 236 | .cfi_rel_offset x27, 192 |
| 237 | .cfi_rel_offset x28, 200 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 238 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 239 | // x29(callee-save) and LR |
| 240 | stp x29, xLR, [sp, #208] |
| 241 | .cfi_rel_offset x29, 208 |
| 242 | .cfi_rel_offset x30, 216 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 243 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 244 | // Save xSELF to xETR. |
| 245 | mov xETR, xSELF |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 246 | .endm |
| 247 | |
| 248 | /* |
| 249 | * Macro that sets up the callee save frame to conform with |
| 250 | * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). |
| 251 | * |
| 252 | * TODO This is probably too conservative - saving FP & LR. |
| 253 | */ |
| 254 | .macro SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 255 | adrp xIP0, :got:_ZN3art7Runtime9instance_E |
| 256 | ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 257 | |
| 258 | // Our registers aren't intermixed - just spill in order. |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 259 | ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) . |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 260 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 261 | // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] . |
Hiroshi Yamauchi | ab08811 | 2014-07-14 13:00:14 -0700 | [diff] [blame] | 262 | THIS_LOAD_REQUIRES_READ_BARRIER |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 263 | ldr xIP0, [xIP0, RUNTIME_REF_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET ] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 264 | |
| 265 | SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL |
| 266 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 267 | str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 268 | .endm |
| 269 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 270 | // TODO: Probably no need to restore registers preserved by aapcs64. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 271 | .macro RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 272 | // Restore xSELF. |
| 273 | mov xSELF, xETR |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 274 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 275 | // FP args |
| 276 | ldp d0, d1, [sp, #16] |
| 277 | ldp d2, d3, [sp, #32] |
| 278 | ldp d4, d5, [sp, #48] |
| 279 | ldp d6, d7, [sp, #64] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 280 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 281 | // args and x20(callee-save) |
| 282 | ldp x1, x2, [sp, #80] |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 283 | .cfi_restore x1 |
| 284 | .cfi_restore x2 |
| 285 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 286 | ldp x3, x4, [sp, #96] |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 287 | .cfi_restore x3 |
| 288 | .cfi_restore x4 |
| 289 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 290 | ldp x5, x6, [sp, #112] |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 291 | .cfi_restore x5 |
| 292 | .cfi_restore x6 |
| 293 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 294 | ldp x7, x20, [sp, #128] |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 295 | .cfi_restore x7 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 296 | .cfi_restore x20 |
| 297 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 298 | // Callee-saves. |
| 299 | ldp x21, x22, [sp, #144] |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 300 | .cfi_restore x21 |
| 301 | .cfi_restore x22 |
| 302 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 303 | ldp x23, x24, [sp, #160] |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 304 | .cfi_restore x23 |
| 305 | .cfi_restore x24 |
| 306 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 307 | ldp x25, x26, [sp, #176] |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 308 | .cfi_restore x25 |
| 309 | .cfi_restore x26 |
| 310 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 311 | ldp x27, x28, [sp, #192] |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 312 | .cfi_restore x27 |
| 313 | .cfi_restore x28 |
| 314 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 315 | // x29(callee-save) and LR |
| 316 | ldp x29, xLR, [sp, #208] |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 317 | .cfi_restore x29 |
| 318 | .cfi_restore x30 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 319 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 320 | add sp, sp, #224 |
| 321 | .cfi_adjust_cfa_offset -224 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 322 | .endm |
| 323 | |
| 324 | .macro RETURN_IF_RESULT_IS_ZERO |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 325 | cbnz x0, 1f // result non-zero branch over |
| 326 | ret // return |
| 327 | 1: |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 328 | .endm |
| 329 | |
| 330 | .macro RETURN_IF_RESULT_IS_NON_ZERO |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 331 | cbz x0, 1f // result zero branch over |
| 332 | ret // return |
| 333 | 1: |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 334 | .endm |
| 335 | |
| 336 | /* |
| 337 | * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending |
| 338 | * exception is Thread::Current()->exception_ |
| 339 | */ |
| 340 | .macro DELIVER_PENDING_EXCEPTION |
| 341 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME |
| 342 | mov x0, xSELF |
| 343 | mov x1, sp |
| 344 | |
| 345 | // Point of no return. |
| 346 | b artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*, SP) |
| 347 | brk 0 // Unreached |
| 348 | .endm |
| 349 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 350 | .macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg |
| 351 | ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field. |
| 352 | cbnz \reg, 1f |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 353 | ret |
| 354 | 1: |
| 355 | DELIVER_PENDING_EXCEPTION |
| 356 | .endm |
| 357 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 358 | .macro RETURN_OR_DELIVER_PENDING_EXCEPTION |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 359 | RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0 |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 360 | .endm |
| 361 | |
| 362 | // Same as above with x1. This is helpful in stubs that want to avoid clobbering another register. |
| 363 | .macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 364 | RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1 |
| 365 | .endm |
| 366 | |
| 367 | .macro RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 368 | cbnz w0, 1f // result non-zero branch over |
| 369 | ret // return |
| 370 | 1: |
| 371 | DELIVER_PENDING_EXCEPTION |
| 372 | .endm |
| 373 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 374 | .macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name |
| 375 | .extern \cxx_name |
| 376 | ENTRY \c_name |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 377 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 378 | mov x0, xSELF // pass Thread::Current |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 379 | mov x1, sp // pass SP |
| 380 | b \cxx_name // \cxx_name(Thread*, SP) |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 381 | END \c_name |
| 382 | .endm |
| 383 | |
| 384 | .macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name |
| 385 | .extern \cxx_name |
| 386 | ENTRY \c_name |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 387 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context. |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 388 | mov x1, xSELF // pass Thread::Current. |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 389 | mov x2, sp // pass SP. |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 390 | b \cxx_name // \cxx_name(arg, Thread*, SP). |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 391 | brk 0 |
| 392 | END \c_name |
| 393 | .endm |
| 394 | |
| 395 | .macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name |
| 396 | .extern \cxx_name |
| 397 | ENTRY \c_name |
| 398 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 399 | mov x2, xSELF // pass Thread::Current |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 400 | mov x3, sp // pass SP |
| 401 | b \cxx_name // \cxx_name(arg1, arg2, Thread*, SP) |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 402 | brk 0 |
| 403 | END \c_name |
| 404 | .endm |
| 405 | |
| 406 | /* |
| 407 | * Called by managed code, saves callee saves and then calls artThrowException |
| 408 | * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception. |
| 409 | */ |
| 410 | ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode |
| 411 | |
| 412 | /* |
| 413 | * Called by managed code to create and deliver a NullPointerException. |
| 414 | */ |
| 415 | NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode |
| 416 | |
| 417 | /* |
| 418 | * Called by managed code to create and deliver an ArithmeticException. |
| 419 | */ |
| 420 | NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode |
| 421 | |
| 422 | /* |
| 423 | * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds |
| 424 | * index, arg2 holds limit. |
| 425 | */ |
| 426 | TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode |
| 427 | |
| 428 | /* |
| 429 | * Called by managed code to create and deliver a StackOverflowError. |
| 430 | */ |
| 431 | NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode |
| 432 | |
| 433 | /* |
| 434 | * Called by managed code to create and deliver a NoSuchMethodError. |
| 435 | */ |
| 436 | ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode |
| 437 | |
Stuart Monteith | d5c78f4 | 2014-06-11 16:44:46 +0100 | [diff] [blame] | 438 | /* |
| 439 | * Invoke stack overflow exception from signal handler. |
| 440 | * On entry: |
| 441 | * xSELF: thread |
| 442 | * SP: address of last known frame |
| 443 | * IP0: address of next valid SP below protected region in stack |
| 444 | * |
| 445 | * This is deceptively simple but hides some complexity. It is called in the case of |
| 446 | * a stack overflow condition during implicit checks. The signal handler has been |
| 447 | * called by the kernel due to a load from the protected stack region. The handler |
| 448 | * works out the address of the previous frame and passes this in SP. However there |
| 449 | * is a piece of memory somewhere below the current SP that is not accessible (the |
| 450 | * memory that caused the signal). The signal handler works out the next |
| 451 | * accessible value of SP and passes this in x16/IP0. This code then sets up the SP |
| 452 | * to be this new value and calls the code to create and throw the stack overflow |
| 453 | * exception. |
| 454 | */ |
| 455 | ENTRY art_quick_throw_stack_overflow_from_signal |
| 456 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context |
| 457 | mov x0, xSELF // pass Thread::Current |
| 458 | mov x1, sp // pass SP |
| 459 | mov sp, xIP0 // move SP down to below protected region. |
| 460 | b artThrowStackOverflowFromCode // artThrowStackOverflowFromCode(Thread*, SP) |
| 461 | END art_quick_throw_stack_overflow_from_signal |
| 462 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 463 | /* |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 464 | * All generated callsites for interface invokes and invocation slow paths will load arguments |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 465 | * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain |
| 466 | * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 467 | * stack and call the appropriate C helper. |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 468 | * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 469 | * |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 470 | * The helper will attempt to locate the target and return a 128-bit result in x0/x1 consisting |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 471 | * of the target Method* in x0 and method->code_ in x1. |
| 472 | * |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 473 | * If unsuccessful, the helper will return NULL/????. There will be a pending exception in the |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 474 | * thread and we branch to another stub to deliver it. |
| 475 | * |
| 476 | * On success this wrapper will restore arguments and *jump* to the target, leaving the lr |
| 477 | * pointing back to the original caller. |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 478 | * |
| 479 | * Adapted from ARM32 code. |
| 480 | * |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 481 | * Clobbers xIP0. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 482 | */ |
| 483 | .macro INVOKE_TRAMPOLINE c_name, cxx_name |
| 484 | .extern \cxx_name |
| 485 | ENTRY \c_name |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 486 | SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save callee saves in case allocation triggers GC |
| 487 | // Helper signature is always |
| 488 | // (method_idx, *this_object, *caller_method, *self, sp) |
| 489 | |
Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 490 | ldr w2, [sp, #FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE] // pass caller Method* |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 491 | mov x3, xSELF // pass Thread::Current |
| 492 | mov x4, sp |
| 493 | bl \cxx_name // (method_idx, this, caller, Thread*, SP) |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 494 | mov xIP0, x1 // save Method*->code_ |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 495 | RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME |
| 496 | cbz x0, 1f // did we find the target? if not go to exception delivery |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 497 | br xIP0 // tail call to target |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 498 | 1: |
| 499 | DELIVER_PENDING_EXCEPTION |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 500 | END \c_name |
| 501 | .endm |
| 502 | |
| 503 | INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline |
| 504 | INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck |
| 505 | |
| 506 | INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck |
| 507 | INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck |
| 508 | INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck |
| 509 | INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck |
| 510 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 511 | |
| 512 | .macro INVOKE_STUB_CREATE_FRAME |
| 513 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 514 | SAVE_SIZE=6*8 // x4, x5, xSUSPEND, SP, LR & FP saved. |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 515 | SAVE_SIZE_AND_METHOD=SAVE_SIZE+STACK_REFERENCE_SIZE |
| 516 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 517 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 518 | mov x9, sp // Save stack pointer. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 519 | .cfi_register sp,x9 |
| 520 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 521 | add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame. |
| 522 | sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args |
| 523 | and x10, x10, # ~0xf // Enforce 16 byte stack alignment. |
| 524 | mov sp, x10 // Set new SP. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 525 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 526 | sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP |
| 527 | .cfi_def_cfa_register x10 // before this. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 528 | .cfi_adjust_cfa_offset SAVE_SIZE |
| 529 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 530 | stp x9, xSUSPEND, [x10, #32] // Save old stack pointer and xSUSPEND |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 531 | .cfi_rel_offset sp, 32 |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 532 | .cfi_rel_offset x19, 40 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 533 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 534 | stp x4, x5, [x10, #16] // Save result and shorty addresses. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 535 | .cfi_rel_offset x4, 16 |
| 536 | .cfi_rel_offset x5, 24 |
| 537 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 538 | stp xFP, xLR, [x10] // Store LR & FP. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 539 | .cfi_rel_offset x29, 0 |
| 540 | .cfi_rel_offset x30, 8 |
| 541 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 542 | mov xFP, x10 // Use xFP now, as it's callee-saved. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 543 | .cfi_def_cfa_register x29 |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 544 | mov xSELF, x3 // Move thread pointer into SELF register. |
| 545 | mov wSUSPEND, #SUSPEND_CHECK_INTERVAL // reset wSUSPEND to suspend check interval |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 546 | |
| 547 | // Copy arguments into stack frame. |
| 548 | // Use simple copy routine for now. |
| 549 | // 4 bytes per slot. |
| 550 | // X1 - source address |
| 551 | // W2 - args length |
| 552 | // X9 - destination address. |
| 553 | // W10 - temporary |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 554 | add x9, sp, #4 // Destination address is bottom of stack + NULL. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 555 | |
| 556 | // Use \@ to differentiate between macro invocations. |
| 557 | .LcopyParams\@: |
| 558 | cmp w2, #0 |
| 559 | beq .LendCopyParams\@ |
| 560 | sub w2, w2, #4 // Need 65536 bytes of range. |
| 561 | ldr w10, [x1, x2] |
| 562 | str w10, [x9, x2] |
| 563 | |
| 564 | b .LcopyParams\@ |
| 565 | |
| 566 | .LendCopyParams\@: |
| 567 | |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 568 | // Store NULL into StackReference<Method>* at bottom of frame. |
| 569 | str wzr, [sp] |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 570 | |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 571 | #if (STACK_REFERENCE_SIZE != 4) |
| 572 | #error "STACK_REFERENCE_SIZE(ARM64) size not as expected." |
| 573 | #endif |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 574 | .endm |
| 575 | |
| 576 | .macro INVOKE_STUB_CALL_AND_RETURN |
| 577 | |
| 578 | // load method-> METHOD_QUICK_CODE_OFFSET |
| 579 | ldr x9, [x0 , #METHOD_QUICK_CODE_OFFSET] |
| 580 | // Branch to method. |
| 581 | blr x9 |
| 582 | |
| 583 | // Restore return value address and shorty address. |
| 584 | ldp x4,x5, [xFP, #16] |
| 585 | .cfi_restore x4 |
| 586 | .cfi_restore x5 |
| 587 | |
| 588 | // Store result (w0/x0/s0/d0) appropriately, depending on resultType. |
| 589 | ldrb w10, [x5] |
| 590 | |
| 591 | // Don't set anything for a void type. |
| 592 | cmp w10, #'V' |
| 593 | beq .Lexit_art_quick_invoke_stub\@ |
| 594 | |
| 595 | cmp w10, #'D' |
| 596 | bne .Lreturn_is_float\@ |
| 597 | str d0, [x4] |
| 598 | b .Lexit_art_quick_invoke_stub\@ |
| 599 | |
| 600 | .Lreturn_is_float\@: |
| 601 | cmp w10, #'F' |
| 602 | bne .Lreturn_is_int\@ |
| 603 | str s0, [x4] |
| 604 | b .Lexit_art_quick_invoke_stub\@ |
| 605 | |
| 606 | // Just store x0. Doesn't matter if it is 64 or 32 bits. |
| 607 | .Lreturn_is_int\@: |
| 608 | str x0, [x4] |
| 609 | |
| 610 | .Lexit_art_quick_invoke_stub\@: |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 611 | ldp x2, xSUSPEND, [xFP, #32] // Restore stack pointer and xSUSPEND. |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 612 | .cfi_restore x19 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 613 | mov sp, x2 |
| 614 | .cfi_restore sp |
| 615 | |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 616 | ldp xFP, xLR, [xFP] // Restore old frame pointer and link register. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 617 | .cfi_restore x29 |
| 618 | .cfi_restore x30 |
| 619 | |
| 620 | ret |
| 621 | |
| 622 | .endm |
| 623 | |
| 624 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 625 | /* |
| 626 | * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0 |
| 627 | * uint32_t *args, x1 |
| 628 | * uint32_t argsize, w2 |
| 629 | * Thread *self, x3 |
| 630 | * JValue *result, x4 |
| 631 | * char *shorty); x5 |
| 632 | * +----------------------+ |
| 633 | * | | |
| 634 | * | C/C++ frame | |
| 635 | * | LR'' | |
| 636 | * | FP'' | <- SP' |
| 637 | * +----------------------+ |
| 638 | * +----------------------+ |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 639 | * | x19 | <- Used as wSUSPEND, won't be restored by managed code. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 640 | * | SP' | |
| 641 | * | X5 | |
| 642 | * | X4 | Saved registers |
| 643 | * | LR' | |
| 644 | * | FP' | <- FP |
| 645 | * +----------------------+ |
| 646 | * | uint32_t out[n-1] | |
| 647 | * | : : | Outs |
| 648 | * | uint32_t out[0] | |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 649 | * | StackRef<ArtMethod> | <- SP value=null |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 650 | * +----------------------+ |
| 651 | * |
| 652 | * Outgoing registers: |
| 653 | * x0 - Method* |
| 654 | * x1-x7 - integer parameters. |
| 655 | * d0-d7 - Floating point parameters. |
| 656 | * xSELF = self |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 657 | * wSUSPEND = suspend count |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 658 | * SP = & of ArtMethod* |
| 659 | * x1 = "this" pointer. |
| 660 | * |
| 661 | */ |
| 662 | ENTRY art_quick_invoke_stub |
| 663 | // Spill registers as per AACPS64 calling convention. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 664 | INVOKE_STUB_CREATE_FRAME |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 665 | |
| 666 | // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters. |
| 667 | // Parse the passed shorty to determine which register to load. |
| 668 | // Load addresses for routines that load WXSD registers. |
| 669 | adr x11, .LstoreW2 |
| 670 | adr x12, .LstoreX2 |
| 671 | adr x13, .LstoreS0 |
| 672 | adr x14, .LstoreD0 |
| 673 | |
| 674 | // Initialize routine offsets to 0 for integers and floats. |
| 675 | // x8 for integers, x15 for floating point. |
| 676 | mov x8, #0 |
| 677 | mov x15, #0 |
| 678 | |
| 679 | add x10, x5, #1 // Load shorty address, plus one to skip return value. |
| 680 | ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer. |
| 681 | |
| 682 | // Loop to fill registers. |
| 683 | .LfillRegisters: |
| 684 | ldrb w17, [x10], #1 // Load next character in signature, and increment. |
| 685 | cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated. |
| 686 | |
| 687 | cmp w17, #'F' // is this a float? |
| 688 | bne .LisDouble |
| 689 | |
| 690 | cmp x15, # 8*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 691 | beq .Ladvance4 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 692 | |
| 693 | add x17, x13, x15 // Calculate subroutine to jump to. |
| 694 | br x17 |
| 695 | |
| 696 | .LisDouble: |
| 697 | cmp w17, #'D' // is this a double? |
| 698 | bne .LisLong |
| 699 | |
| 700 | cmp x15, # 8*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 701 | beq .Ladvance8 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 702 | |
| 703 | add x17, x14, x15 // Calculate subroutine to jump to. |
| 704 | br x17 |
| 705 | |
| 706 | .LisLong: |
| 707 | cmp w17, #'J' // is this a long? |
| 708 | bne .LisOther |
| 709 | |
Andreas Gampe | 9de65ff | 2014-03-21 17:25:57 -0700 | [diff] [blame] | 710 | cmp x8, # 6*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 711 | beq .Ladvance8 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 712 | |
| 713 | add x17, x12, x8 // Calculate subroutine to jump to. |
| 714 | br x17 |
| 715 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 716 | .LisOther: // Everything else takes one vReg. |
Andreas Gampe | 9de65ff | 2014-03-21 17:25:57 -0700 | [diff] [blame] | 717 | cmp x8, # 6*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 718 | beq .Ladvance4 |
| 719 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 720 | add x17, x11, x8 // Calculate subroutine to jump to. |
| 721 | br x17 |
| 722 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 723 | .Ladvance4: |
| 724 | add x9, x9, #4 |
| 725 | b .LfillRegisters |
| 726 | |
| 727 | .Ladvance8: |
| 728 | add x9, x9, #8 |
| 729 | b .LfillRegisters |
| 730 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 731 | // Macro for loading a parameter into a register. |
| 732 | // counter - the register with offset into these tables |
| 733 | // size - the size of the register - 4 or 8 bytes. |
| 734 | // register - the name of the register to be loaded. |
| 735 | .macro LOADREG counter size register return |
| 736 | ldr \register , [x9], #\size |
| 737 | add \counter, \counter, 12 |
| 738 | b \return |
| 739 | .endm |
| 740 | |
| 741 | // Store ints. |
| 742 | .LstoreW2: |
| 743 | LOADREG x8 4 w2 .LfillRegisters |
| 744 | LOADREG x8 4 w3 .LfillRegisters |
| 745 | LOADREG x8 4 w4 .LfillRegisters |
| 746 | LOADREG x8 4 w5 .LfillRegisters |
| 747 | LOADREG x8 4 w6 .LfillRegisters |
| 748 | LOADREG x8 4 w7 .LfillRegisters |
| 749 | |
| 750 | // Store longs. |
| 751 | .LstoreX2: |
| 752 | LOADREG x8 8 x2 .LfillRegisters |
| 753 | LOADREG x8 8 x3 .LfillRegisters |
| 754 | LOADREG x8 8 x4 .LfillRegisters |
| 755 | LOADREG x8 8 x5 .LfillRegisters |
| 756 | LOADREG x8 8 x6 .LfillRegisters |
| 757 | LOADREG x8 8 x7 .LfillRegisters |
| 758 | |
| 759 | // Store singles. |
| 760 | .LstoreS0: |
| 761 | LOADREG x15 4 s0 .LfillRegisters |
| 762 | LOADREG x15 4 s1 .LfillRegisters |
| 763 | LOADREG x15 4 s2 .LfillRegisters |
| 764 | LOADREG x15 4 s3 .LfillRegisters |
| 765 | LOADREG x15 4 s4 .LfillRegisters |
| 766 | LOADREG x15 4 s5 .LfillRegisters |
| 767 | LOADREG x15 4 s6 .LfillRegisters |
| 768 | LOADREG x15 4 s7 .LfillRegisters |
| 769 | |
| 770 | // Store doubles. |
| 771 | .LstoreD0: |
| 772 | LOADREG x15 8 d0 .LfillRegisters |
| 773 | LOADREG x15 8 d1 .LfillRegisters |
| 774 | LOADREG x15 8 d2 .LfillRegisters |
| 775 | LOADREG x15 8 d3 .LfillRegisters |
| 776 | LOADREG x15 8 d4 .LfillRegisters |
| 777 | LOADREG x15 8 d5 .LfillRegisters |
| 778 | LOADREG x15 8 d6 .LfillRegisters |
| 779 | LOADREG x15 8 d7 .LfillRegisters |
| 780 | |
| 781 | |
| 782 | .LcallFunction: |
| 783 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 784 | INVOKE_STUB_CALL_AND_RETURN |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 785 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 786 | END art_quick_invoke_stub |
| 787 | |
| 788 | /* extern"C" |
| 789 | * void art_quick_invoke_static_stub(ArtMethod *method, x0 |
| 790 | * uint32_t *args, x1 |
| 791 | * uint32_t argsize, w2 |
| 792 | * Thread *self, x3 |
| 793 | * JValue *result, x4 |
| 794 | * char *shorty); x5 |
| 795 | */ |
| 796 | ENTRY art_quick_invoke_static_stub |
| 797 | // Spill registers as per AACPS64 calling convention. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 798 | INVOKE_STUB_CREATE_FRAME |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 799 | |
| 800 | // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters. |
| 801 | // Parse the passed shorty to determine which register to load. |
| 802 | // Load addresses for routines that load WXSD registers. |
| 803 | adr x11, .LstoreW1_2 |
| 804 | adr x12, .LstoreX1_2 |
| 805 | adr x13, .LstoreS0_2 |
| 806 | adr x14, .LstoreD0_2 |
| 807 | |
| 808 | // Initialize routine offsets to 0 for integers and floats. |
| 809 | // x8 for integers, x15 for floating point. |
| 810 | mov x8, #0 |
| 811 | mov x15, #0 |
| 812 | |
| 813 | add x10, x5, #1 // Load shorty address, plus one to skip return value. |
| 814 | |
| 815 | // Loop to fill registers. |
| 816 | .LfillRegisters2: |
| 817 | ldrb w17, [x10], #1 // Load next character in signature, and increment. |
| 818 | cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated. |
| 819 | |
| 820 | cmp w17, #'F' // is this a float? |
| 821 | bne .LisDouble2 |
| 822 | |
| 823 | cmp x15, # 8*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 824 | beq .Ladvance4_2 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 825 | |
| 826 | add x17, x13, x15 // Calculate subroutine to jump to. |
| 827 | br x17 |
| 828 | |
| 829 | .LisDouble2: |
| 830 | cmp w17, #'D' // is this a double? |
| 831 | bne .LisLong2 |
| 832 | |
| 833 | cmp x15, # 8*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 834 | beq .Ladvance8_2 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 835 | |
| 836 | add x17, x14, x15 // Calculate subroutine to jump to. |
| 837 | br x17 |
| 838 | |
| 839 | .LisLong2: |
| 840 | cmp w17, #'J' // is this a long? |
| 841 | bne .LisOther2 |
| 842 | |
| 843 | cmp x8, # 7*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 844 | beq .Ladvance8_2 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 845 | |
| 846 | add x17, x12, x8 // Calculate subroutine to jump to. |
| 847 | br x17 |
| 848 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 849 | .LisOther2: // Everything else takes one vReg. |
| 850 | cmp x8, # 7*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 851 | beq .Ladvance4_2 |
| 852 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 853 | add x17, x11, x8 // Calculate subroutine to jump to. |
| 854 | br x17 |
| 855 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 856 | .Ladvance4_2: |
| 857 | add x9, x9, #4 |
| 858 | b .LfillRegisters2 |
| 859 | |
| 860 | .Ladvance8_2: |
| 861 | add x9, x9, #8 |
| 862 | b .LfillRegisters2 |
| 863 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 864 | // Store ints. |
| 865 | .LstoreW1_2: |
| 866 | LOADREG x8 4 w1 .LfillRegisters2 |
| 867 | LOADREG x8 4 w2 .LfillRegisters2 |
| 868 | LOADREG x8 4 w3 .LfillRegisters2 |
| 869 | LOADREG x8 4 w4 .LfillRegisters2 |
| 870 | LOADREG x8 4 w5 .LfillRegisters2 |
| 871 | LOADREG x8 4 w6 .LfillRegisters2 |
| 872 | LOADREG x8 4 w7 .LfillRegisters2 |
| 873 | |
| 874 | // Store longs. |
| 875 | .LstoreX1_2: |
| 876 | LOADREG x8 8 x1 .LfillRegisters2 |
| 877 | LOADREG x8 8 x2 .LfillRegisters2 |
| 878 | LOADREG x8 8 x3 .LfillRegisters2 |
| 879 | LOADREG x8 8 x4 .LfillRegisters2 |
| 880 | LOADREG x8 8 x5 .LfillRegisters2 |
| 881 | LOADREG x8 8 x6 .LfillRegisters2 |
| 882 | LOADREG x8 8 x7 .LfillRegisters2 |
| 883 | |
| 884 | // Store singles. |
| 885 | .LstoreS0_2: |
| 886 | LOADREG x15 4 s0 .LfillRegisters2 |
| 887 | LOADREG x15 4 s1 .LfillRegisters2 |
| 888 | LOADREG x15 4 s2 .LfillRegisters2 |
| 889 | LOADREG x15 4 s3 .LfillRegisters2 |
| 890 | LOADREG x15 4 s4 .LfillRegisters2 |
| 891 | LOADREG x15 4 s5 .LfillRegisters2 |
| 892 | LOADREG x15 4 s6 .LfillRegisters2 |
| 893 | LOADREG x15 4 s7 .LfillRegisters2 |
| 894 | |
| 895 | // Store doubles. |
| 896 | .LstoreD0_2: |
| 897 | LOADREG x15 8 d0 .LfillRegisters2 |
| 898 | LOADREG x15 8 d1 .LfillRegisters2 |
| 899 | LOADREG x15 8 d2 .LfillRegisters2 |
| 900 | LOADREG x15 8 d3 .LfillRegisters2 |
| 901 | LOADREG x15 8 d4 .LfillRegisters2 |
| 902 | LOADREG x15 8 d5 .LfillRegisters2 |
| 903 | LOADREG x15 8 d6 .LfillRegisters2 |
| 904 | LOADREG x15 8 d7 .LfillRegisters2 |
| 905 | |
| 906 | |
| 907 | .LcallFunction2: |
| 908 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 909 | INVOKE_STUB_CALL_AND_RETURN |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 910 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 911 | END art_quick_invoke_static_stub |
| 912 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 913 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 914 | |
| 915 | /* |
| 916 | * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_ |
| 917 | */ |
| 918 | |
| 919 | ENTRY art_quick_do_long_jump |
| 920 | // Load FPRs |
| 921 | ldp d0, d1, [x1], #16 |
| 922 | ldp d2, d3, [x1], #16 |
| 923 | ldp d4, d5, [x1], #16 |
| 924 | ldp d6, d7, [x1], #16 |
| 925 | ldp d8, d9, [x1], #16 |
| 926 | ldp d10, d11, [x1], #16 |
| 927 | ldp d12, d13, [x1], #16 |
| 928 | ldp d14, d15, [x1], #16 |
| 929 | ldp d16, d17, [x1], #16 |
| 930 | ldp d18, d19, [x1], #16 |
| 931 | ldp d20, d21, [x1], #16 |
| 932 | ldp d22, d23, [x1], #16 |
| 933 | ldp d24, d25, [x1], #16 |
| 934 | ldp d26, d27, [x1], #16 |
| 935 | ldp d28, d29, [x1], #16 |
| 936 | ldp d30, d31, [x1] |
| 937 | |
| 938 | // Load GPRs |
| 939 | // TODO: lots of those are smashed, could optimize. |
| 940 | add x0, x0, #30*8 |
| 941 | ldp x30, x1, [x0], #-16 |
| 942 | ldp x28, x29, [x0], #-16 |
| 943 | ldp x26, x27, [x0], #-16 |
| 944 | ldp x24, x25, [x0], #-16 |
| 945 | ldp x22, x23, [x0], #-16 |
| 946 | ldp x20, x21, [x0], #-16 |
| 947 | ldp x18, x19, [x0], #-16 |
| 948 | ldp x16, x17, [x0], #-16 |
| 949 | ldp x14, x15, [x0], #-16 |
| 950 | ldp x12, x13, [x0], #-16 |
| 951 | ldp x10, x11, [x0], #-16 |
| 952 | ldp x8, x9, [x0], #-16 |
| 953 | ldp x6, x7, [x0], #-16 |
| 954 | ldp x4, x5, [x0], #-16 |
| 955 | ldp x2, x3, [x0], #-16 |
| 956 | mov sp, x1 |
| 957 | |
| 958 | // TODO: Is it really OK to use LR for the target PC? |
| 959 | mov x0, #0 |
| 960 | mov x1, #0 |
| 961 | br xLR |
| 962 | END art_quick_do_long_jump |
| 963 | |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 964 | /* |
| 965 | * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on |
| 966 | * failure. |
| 967 | */ |
| 968 | .extern artHandleFillArrayDataFromCode |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 969 | ENTRY art_quick_handle_fill_data |
| 970 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // Save callee saves in case exception allocation triggers GC. |
| 971 | mov x2, xSELF // Pass Thread::Current. |
| 972 | mov x3, sp // Pass SP. |
| 973 | bl artHandleFillArrayDataFromCode // (Array*, const DexFile::Payload*, Thread*, SP) |
| 974 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME |
| 975 | RETURN_IF_RESULT_IS_ZERO |
| 976 | DELIVER_PENDING_EXCEPTION |
| 977 | END art_quick_handle_fill_data |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 978 | |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 979 | /* |
| 980 | * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the |
| 981 | * possibly null object to lock. |
| 982 | * |
| 983 | * Derived from arm32 code. |
| 984 | */ |
| 985 | .extern artLockObjectFromCode |
| 986 | ENTRY art_quick_lock_object |
| 987 | cbz w0, .Lslow_lock |
| 988 | add x4, x0, #LOCK_WORD_OFFSET // exclusive load/store had no immediate anymore |
| 989 | .Lretry_lock: |
| 990 | ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop? |
| 991 | ldxr w1, [x4] |
| 992 | cbnz w1, .Lnot_unlocked // already thin locked |
| 993 | stxr w3, w2, [x4] |
| 994 | cbnz w3, .Lstrex_fail // store failed, retry |
Andreas Gampe | 675967d | 2014-05-14 16:28:34 -0700 | [diff] [blame] | 995 | dmb ishld // full (LoadLoad|LoadStore) memory barrier |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 996 | ret |
| 997 | .Lstrex_fail: |
| 998 | b .Lretry_lock // unlikely forward branch, need to reload and recheck r1/r2 |
| 999 | .Lnot_unlocked: |
| 1000 | lsr w3, w1, 30 |
| 1001 | cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path |
| 1002 | eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId() |
| 1003 | uxth w2, w2 // zero top 16 bits |
| 1004 | cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock |
| 1005 | // else contention, go to slow path |
| 1006 | add w2, w1, #65536 // increment count in lock word placing in w2 for storing |
| 1007 | lsr w1, w2, 30 // if either of the top two bits are set, we overflowed. |
| 1008 | cbnz w1, .Lslow_lock // if we overflow the count go slow path |
| 1009 | str w2, [x0, #LOCK_WORD_OFFSET]// no need for stxr as we hold the lock |
| 1010 | ret |
| 1011 | .Lslow_lock: |
| 1012 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case we block |
| 1013 | mov x1, xSELF // pass Thread::Current |
| 1014 | mov x2, sp // pass SP |
| 1015 | bl artLockObjectFromCode // (Object* obj, Thread*, SP) |
| 1016 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME |
| 1017 | RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1018 | END art_quick_lock_object |
| 1019 | |
| 1020 | /* |
| 1021 | * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure. |
| 1022 | * x0 holds the possibly null object to lock. |
| 1023 | * |
| 1024 | * Derived from arm32 code. |
| 1025 | */ |
| 1026 | .extern artUnlockObjectFromCode |
| 1027 | ENTRY art_quick_unlock_object |
| 1028 | cbz x0, .Lslow_unlock |
| 1029 | ldr w1, [x0, #LOCK_WORD_OFFSET] |
| 1030 | lsr w2, w1, 30 |
| 1031 | cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path |
| 1032 | ldr w2, [xSELF, #THREAD_ID_OFFSET] |
| 1033 | eor w3, w1, w2 // lock_word.ThreadId() ^ self->ThreadId() |
| 1034 | uxth w3, w3 // zero top 16 bits |
| 1035 | cbnz w3, .Lslow_unlock // do lock word and self thread id's match? |
| 1036 | cmp w1, #65536 |
| 1037 | bpl .Lrecursive_thin_unlock |
| 1038 | // transition to unlocked, w3 holds 0 |
Andreas Gampe | 675967d | 2014-05-14 16:28:34 -0700 | [diff] [blame] | 1039 | dmb ish // full (LoadStore|StoreStore) memory barrier |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1040 | str w3, [x0, #LOCK_WORD_OFFSET] |
| 1041 | ret |
| 1042 | .Lrecursive_thin_unlock: |
| 1043 | sub w1, w1, #65536 |
| 1044 | str w1, [x0, #LOCK_WORD_OFFSET] |
| 1045 | ret |
| 1046 | .Lslow_unlock: |
| 1047 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case exception allocation triggers GC |
| 1048 | mov x1, xSELF // pass Thread::Current |
| 1049 | mov x2, sp // pass SP |
| 1050 | bl artUnlockObjectFromCode // (Object* obj, Thread*, SP) |
| 1051 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME |
| 1052 | RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1053 | END art_quick_unlock_object |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 1054 | |
| 1055 | /* |
| 1056 | * Entry from managed code that calls artIsAssignableFromCode and on failure calls |
| 1057 | * artThrowClassCastException. |
| 1058 | */ |
| 1059 | .extern artThrowClassCastException |
| 1060 | ENTRY art_quick_check_cast |
| 1061 | // Store arguments and link register |
| 1062 | sub sp, sp, #32 // Stack needs to be 16b aligned on calls |
| 1063 | .cfi_adjust_cfa_offset 32 |
| 1064 | stp x0, x1, [sp] |
| 1065 | .cfi_rel_offset x0, 0 |
| 1066 | .cfi_rel_offset x1, 8 |
| 1067 | stp xSELF, xLR, [sp, #16] |
| 1068 | .cfi_rel_offset x18, 16 |
| 1069 | .cfi_rel_offset x30, 24 |
| 1070 | |
| 1071 | // Call runtime code |
| 1072 | bl artIsAssignableFromCode |
| 1073 | |
| 1074 | // Check for exception |
| 1075 | cbz x0, .Lthrow_class_cast_exception |
| 1076 | |
| 1077 | // Restore and return |
| 1078 | ldp x0, x1, [sp] |
| 1079 | .cfi_restore x0 |
| 1080 | .cfi_restore x1 |
| 1081 | ldp xSELF, xLR, [sp, #16] |
| 1082 | .cfi_restore x18 |
| 1083 | .cfi_restore x30 |
| 1084 | add sp, sp, #32 |
| 1085 | .cfi_adjust_cfa_offset -32 |
| 1086 | ret |
| 1087 | |
| 1088 | .Lthrow_class_cast_exception: |
| 1089 | // Restore |
| 1090 | ldp x0, x1, [sp] |
| 1091 | .cfi_restore x0 |
| 1092 | .cfi_restore x1 |
| 1093 | ldp xSELF, xLR, [sp, #16] |
| 1094 | .cfi_restore x18 |
| 1095 | .cfi_restore x30 |
| 1096 | add sp, sp, #32 |
| 1097 | .cfi_adjust_cfa_offset -32 |
| 1098 | |
| 1099 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context |
| 1100 | mov x2, xSELF // pass Thread::Current |
| 1101 | mov x3, sp // pass SP |
| 1102 | b artThrowClassCastException // (Class*, Class*, Thread*, SP) |
| 1103 | brk 0 // We should not return here... |
| 1104 | END art_quick_check_cast |
| 1105 | |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1106 | /* |
| 1107 | * Entry from managed code for array put operations of objects where the value being stored |
| 1108 | * needs to be checked for compatibility. |
| 1109 | * x0 = array, x1 = index, x2 = value |
| 1110 | * |
| 1111 | * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We |
| 1112 | * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by |
| 1113 | * using index-zero-extension in load/stores. |
| 1114 | * |
| 1115 | * Temporaries: x3, x4 |
| 1116 | * TODO: x4 OK? ip seems wrong here. |
| 1117 | */ |
| 1118 | ENTRY art_quick_aput_obj_with_null_and_bound_check |
| 1119 | tst x0, x0 |
| 1120 | bne art_quick_aput_obj_with_bound_check |
| 1121 | b art_quick_throw_null_pointer_exception |
| 1122 | END art_quick_aput_obj_with_null_and_bound_check |
| 1123 | |
| 1124 | ENTRY art_quick_aput_obj_with_bound_check |
| 1125 | ldr w3, [x0, #ARRAY_LENGTH_OFFSET] |
| 1126 | cmp w3, w1 |
| 1127 | bhi art_quick_aput_obj |
| 1128 | mov x0, x1 |
| 1129 | mov x1, x3 |
| 1130 | b art_quick_throw_array_bounds |
| 1131 | END art_quick_aput_obj_with_bound_check |
| 1132 | |
| 1133 | ENTRY art_quick_aput_obj |
| 1134 | cbz x2, .Ldo_aput_null |
| 1135 | ldr w3, [x0, #CLASS_OFFSET] // Heap reference = 32b |
| 1136 | // This also zero-extends to x3 |
| 1137 | ldr w4, [x2, #CLASS_OFFSET] // Heap reference = 32b |
| 1138 | // This also zero-extends to x4 |
| 1139 | ldr w3, [x3, #CLASS_COMPONENT_TYPE_OFFSET] // Heap reference = 32b |
| 1140 | // This also zero-extends to x3 |
| 1141 | cmp w3, w4 // value's type == array's component type - trivial assignability |
| 1142 | bne .Lcheck_assignability |
| 1143 | .Ldo_aput: |
| 1144 | add x3, x0, #OBJECT_ARRAY_DATA_OFFSET |
| 1145 | // "Compress" = do nothing |
| 1146 | str w2, [x3, x1, lsl #2] // Heap reference = 32b |
| 1147 | ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET] |
| 1148 | lsr x0, x0, #7 |
| 1149 | strb w3, [x3, x0] |
| 1150 | ret |
| 1151 | .Ldo_aput_null: |
| 1152 | add x3, x0, #OBJECT_ARRAY_DATA_OFFSET |
| 1153 | // "Compress" = do nothing |
| 1154 | str w2, [x3, x1, lsl #2] // Heap reference = 32b |
| 1155 | ret |
| 1156 | .Lcheck_assignability: |
| 1157 | // Store arguments and link register |
| 1158 | sub sp, sp, #48 // Stack needs to be 16b aligned on calls |
| 1159 | .cfi_adjust_cfa_offset 48 |
| 1160 | stp x0, x1, [sp] |
| 1161 | .cfi_rel_offset x0, 0 |
| 1162 | .cfi_rel_offset x1, 8 |
| 1163 | stp x2, xSELF, [sp, #16] |
| 1164 | .cfi_rel_offset x2, 16 |
| 1165 | .cfi_rel_offset x18, 24 |
| 1166 | str xLR, [sp, #32] |
| 1167 | .cfi_rel_offset x30, 32 |
| 1168 | |
| 1169 | // Call runtime code |
| 1170 | mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended |
| 1171 | mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended |
| 1172 | bl artIsAssignableFromCode |
| 1173 | |
| 1174 | // Check for exception |
| 1175 | cbz x0, .Lthrow_array_store_exception |
| 1176 | |
| 1177 | // Restore |
| 1178 | ldp x0, x1, [sp] |
| 1179 | .cfi_restore x0 |
| 1180 | .cfi_restore x1 |
| 1181 | ldp x2, xSELF, [sp, #16] |
| 1182 | .cfi_restore x2 |
| 1183 | .cfi_restore x18 |
| 1184 | ldr xLR, [sp, #32] |
| 1185 | .cfi_restore x30 |
| 1186 | add sp, sp, #48 |
| 1187 | .cfi_adjust_cfa_offset -48 |
| 1188 | |
| 1189 | add x3, x0, #OBJECT_ARRAY_DATA_OFFSET |
| 1190 | // "Compress" = do nothing |
| 1191 | str w2, [x3, x1, lsl #2] // Heap reference = 32b |
| 1192 | ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET] |
| 1193 | lsr x0, x0, #7 |
| 1194 | strb w3, [x3, x0] |
| 1195 | ret |
| 1196 | .Lthrow_array_store_exception: |
| 1197 | ldp x0, x1, [sp] |
| 1198 | .cfi_restore x0 |
| 1199 | .cfi_restore x1 |
| 1200 | ldp x2, xSELF, [sp, #16] |
| 1201 | .cfi_restore x2 |
| 1202 | .cfi_restore x18 |
| 1203 | ldr xLR, [sp, #32] |
| 1204 | .cfi_restore x30 |
| 1205 | add sp, sp, #48 |
| 1206 | .cfi_adjust_cfa_offset -48 |
| 1207 | |
| 1208 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME |
| 1209 | mov x1, x2 // Pass value. |
| 1210 | mov x2, xSELF // Pass Thread::Current. |
| 1211 | mov x3, sp // Pass SP. |
| 1212 | b artThrowArrayStoreException // (Object*, Object*, Thread*, SP). |
| 1213 | brk 0 // Unreached. |
| 1214 | END art_quick_aput_obj |
| 1215 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1216 | // Macro to facilitate adding new allocation entrypoints. |
| 1217 | .macro TWO_ARG_DOWNCALL name, entrypoint, return |
| 1218 | .extern \entrypoint |
| 1219 | ENTRY \name |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1220 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC |
| 1221 | mov x2, xSELF // pass Thread::Current |
| 1222 | mov x3, sp // pass SP |
| 1223 | bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP) |
| 1224 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME |
| 1225 | \return |
| 1226 | DELIVER_PENDING_EXCEPTION |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1227 | END \name |
| 1228 | .endm |
| 1229 | |
| 1230 | // Macro to facilitate adding new array allocation entrypoints. |
| 1231 | .macro THREE_ARG_DOWNCALL name, entrypoint, return |
| 1232 | .extern \entrypoint |
| 1233 | ENTRY \name |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1234 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC |
| 1235 | mov x3, xSELF // pass Thread::Current |
| 1236 | mov x4, sp // pass SP |
| 1237 | bl \entrypoint |
| 1238 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME |
| 1239 | \return |
| 1240 | DELIVER_PENDING_EXCEPTION |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1241 | END \name |
| 1242 | .endm |
| 1243 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1244 | // Macros taking opportunity of code similarities for downcalls with referrer. |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1245 | .macro ONE_ARG_REF_DOWNCALL name, entrypoint, return |
| 1246 | .extern \entrypoint |
| 1247 | ENTRY \name |
| 1248 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 1249 | ldr w1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1250 | mov x2, xSELF // pass Thread::Current |
| 1251 | mov x3, sp // pass SP |
| 1252 | bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP) |
| 1253 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME |
| 1254 | \return |
| 1255 | END \name |
| 1256 | .endm |
| 1257 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1258 | .macro TWO_ARG_REF_DOWNCALL name, entrypoint, return |
| 1259 | .extern \entrypoint |
| 1260 | ENTRY \name |
| 1261 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 1262 | ldr w2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1263 | mov x3, xSELF // pass Thread::Current |
| 1264 | mov x4, sp // pass SP |
| 1265 | bl \entrypoint |
| 1266 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME |
| 1267 | \return |
| 1268 | END \name |
| 1269 | .endm |
| 1270 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1271 | .macro THREE_ARG_REF_DOWNCALL name, entrypoint, return |
| 1272 | .extern \entrypoint |
| 1273 | ENTRY \name |
| 1274 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 1275 | ldr w3, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1276 | mov x4, xSELF // pass Thread::Current |
| 1277 | mov x5, sp // pass SP |
| 1278 | bl \entrypoint |
| 1279 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME |
| 1280 | \return |
| 1281 | END \name |
| 1282 | .endm |
| 1283 | |
Matteo Franchin | dfd891a | 2014-04-30 12:17:17 +0100 | [diff] [blame] | 1284 | /* |
| 1285 | * Entry from managed code when uninitialized static storage, this stub will run the class |
| 1286 | * initializer and deliver the exception on error. On success the static storage base is |
| 1287 | * returned. |
| 1288 | */ |
| 1289 | TWO_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO |
| 1290 | |
Andreas Gampe | 6aac355 | 2014-06-09 14:55:53 -0700 | [diff] [blame] | 1291 | TWO_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO |
| 1292 | TWO_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO |
Matteo Franchin | dfd891a | 2014-04-30 12:17:17 +0100 | [diff] [blame] | 1293 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1294 | ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1295 | ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1296 | ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1297 | |
| 1298 | TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1299 | TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1300 | TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1301 | |
| 1302 | TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1303 | TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1304 | |
| 1305 | THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1306 | THREE_ARG_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1307 | THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1308 | |
| 1309 | // This is separated out as the argument order is different. |
| 1310 | .extern artSet64StaticFromCode |
| 1311 | ENTRY art_quick_set64_static |
| 1312 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC |
| 1313 | mov x3, x1 // Store value |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 1314 | ldr w1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1315 | mov x2, x3 // Put value param |
| 1316 | mov x3, xSELF // pass Thread::Current |
| 1317 | mov x4, sp // pass SP |
| 1318 | bl artSet64StaticFromCode |
| 1319 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME |
| 1320 | RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1321 | END art_quick_set64_static |
| 1322 | |
Matteo Franchin | dfd891a | 2014-04-30 12:17:17 +0100 | [diff] [blame] | 1323 | /* |
| 1324 | * Entry from managed code to resolve a string, this stub will allocate a String and deliver an |
| 1325 | * exception on error. On success the String is returned. x0 holds the referring method, |
| 1326 | * w1 holds the string index. The fast path check for hit in strings cache has already been |
| 1327 | * performed. |
| 1328 | */ |
| 1329 | TWO_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1330 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1331 | // Generate the allocation entrypoints for each allocator. |
| 1332 | GENERATE_ALL_ALLOC_ENTRYPOINTS |
| 1333 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 1334 | /* |
| 1335 | * Called by managed code when the value in wSUSPEND has been decremented to 0. |
| 1336 | */ |
| 1337 | .extern artTestSuspendFromCode |
| 1338 | ENTRY art_quick_test_suspend |
| 1339 | ldrh w0, [xSELF, #THREAD_FLAGS_OFFSET] // get xSELF->state_and_flags.as_struct.flags |
| 1340 | mov wSUSPEND, #SUSPEND_CHECK_INTERVAL // reset wSUSPEND to SUSPEND_CHECK_INTERVAL |
| 1341 | cbnz w0, .Lneed_suspend // check flags == 0 |
| 1342 | ret // return if flags == 0 |
| 1343 | .Lneed_suspend: |
| 1344 | mov x0, xSELF |
| 1345 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl |
| 1346 | mov x1, sp |
| 1347 | bl artTestSuspendFromCode // (Thread*, SP) |
| 1348 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN |
| 1349 | END art_quick_test_suspend |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1350 | |
Stuart Monteith | d5c78f4 | 2014-06-11 16:44:46 +0100 | [diff] [blame] | 1351 | ENTRY art_quick_implicit_suspend |
| 1352 | mov x0, xSELF |
| 1353 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl |
| 1354 | mov x1, sp |
| 1355 | bl artTestSuspendFromCode // (Thread*, SP) |
| 1356 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN |
| 1357 | END art_quick_implicit_suspend |
| 1358 | |
Andreas Gampe | e62a07e | 2014-03-26 14:53:21 -0700 | [diff] [blame] | 1359 | /* |
| 1360 | * Called by managed code that is attempting to call a method on a proxy class. On entry |
| 1361 | * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy |
| 1362 | * method agrees with a ref and args callee save frame. |
| 1363 | */ |
| 1364 | .extern artQuickProxyInvokeHandler |
| 1365 | ENTRY art_quick_proxy_invoke_handler |
| 1366 | SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME |
| 1367 | str x0, [sp, #0] // place proxy method at bottom of frame |
| 1368 | mov x2, xSELF // pass Thread::Current |
| 1369 | mov x3, sp // pass SP |
| 1370 | bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP) |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1371 | // Use xETR as xSELF might be scratched by native function above. |
| 1372 | ldr x2, [xETR, THREAD_EXCEPTION_OFFSET] |
Andreas Gampe | e62a07e | 2014-03-26 14:53:21 -0700 | [diff] [blame] | 1373 | cbnz x2, .Lexception_in_proxy // success if no exception is pending |
Andreas Gampe | d1e9167 | 2014-06-02 22:50:05 -0700 | [diff] [blame] | 1374 | RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME // Restore frame |
| 1375 | fmov d0, x0 // Store result in d0 in case it was float or double |
Andreas Gampe | e62a07e | 2014-03-26 14:53:21 -0700 | [diff] [blame] | 1376 | ret // return on success |
| 1377 | .Lexception_in_proxy: |
| 1378 | RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME |
| 1379 | DELIVER_PENDING_EXCEPTION |
| 1380 | END art_quick_proxy_invoke_handler |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1381 | |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 1382 | /* |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1383 | * Called to resolve an imt conflict. xIP1 is a hidden argument that holds the target method's |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 1384 | * dex method index. |
| 1385 | */ |
| 1386 | ENTRY art_quick_imt_conflict_trampoline |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 1387 | ldr w0, [sp, #0] // load caller Method* |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 1388 | ldr w0, [x0, #METHOD_DEX_CACHE_METHODS_OFFSET] // load dex_cache_resolved_methods |
| 1389 | add x0, x0, #OBJECT_ARRAY_DATA_OFFSET // get starting address of data |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1390 | ldr w0, [x0, xIP1, lsl 2] // load the target method |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 1391 | b art_quick_invoke_interface_trampoline |
| 1392 | END art_quick_imt_conflict_trampoline |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1393 | |
| 1394 | ENTRY art_quick_resolution_trampoline |
| 1395 | SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME |
| 1396 | mov x2, xSELF |
| 1397 | mov x3, sp |
| 1398 | bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP) |
Matteo Franchin | dfd891a | 2014-04-30 12:17:17 +0100 | [diff] [blame] | 1399 | cbz x0, 1f |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1400 | mov xIP0, x0 // Remember returned code pointer in xIP0. |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 1401 | ldr w0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1402 | RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1403 | br xIP0 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1404 | 1: |
| 1405 | RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME |
| 1406 | DELIVER_PENDING_EXCEPTION |
| 1407 | END art_quick_resolution_trampoline |
| 1408 | |
| 1409 | /* |
| 1410 | * Generic JNI frame layout: |
| 1411 | * |
| 1412 | * #-------------------# |
| 1413 | * | | |
| 1414 | * | caller method... | |
| 1415 | * #-------------------# <--- SP on entry |
| 1416 | * | Return X30/LR | |
| 1417 | * | X29/FP | callee save |
| 1418 | * | X28 | callee save |
| 1419 | * | X27 | callee save |
| 1420 | * | X26 | callee save |
| 1421 | * | X25 | callee save |
| 1422 | * | X24 | callee save |
| 1423 | * | X23 | callee save |
| 1424 | * | X22 | callee save |
| 1425 | * | X21 | callee save |
| 1426 | * | X20 | callee save |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1427 | * | X7 | arg7 |
| 1428 | * | X6 | arg6 |
| 1429 | * | X5 | arg5 |
| 1430 | * | X4 | arg4 |
| 1431 | * | X3 | arg3 |
| 1432 | * | X2 | arg2 |
| 1433 | * | X1 | arg1 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1434 | * | D7 | float arg 8 |
| 1435 | * | D6 | float arg 7 |
| 1436 | * | D5 | float arg 6 |
| 1437 | * | D4 | float arg 5 |
| 1438 | * | D3 | float arg 4 |
| 1439 | * | D2 | float arg 3 |
| 1440 | * | D1 | float arg 2 |
| 1441 | * | D0 | float arg 1 |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 1442 | * | Method* | <- X0 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1443 | * #-------------------# |
| 1444 | * | local ref cookie | // 4B |
Mathieu Chartier | 421c537 | 2014-05-14 14:11:40 -0700 | [diff] [blame] | 1445 | * | handle scope size | // 4B |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1446 | * #-------------------# |
| 1447 | * | JNI Call Stack | |
| 1448 | * #-------------------# <--- SP on native call |
| 1449 | * | | |
| 1450 | * | Stack for Regs | The trampoline assembly will pop these values |
| 1451 | * | | into registers for native call |
| 1452 | * #-------------------# |
| 1453 | * | Native code ptr | |
| 1454 | * #-------------------# |
| 1455 | * | Free scratch | |
| 1456 | * #-------------------# |
| 1457 | * | Ptr to (1) | <--- SP |
| 1458 | * #-------------------# |
| 1459 | */ |
| 1460 | /* |
| 1461 | * Called to do a generic JNI down-call |
| 1462 | */ |
| 1463 | ENTRY art_quick_generic_jni_trampoline |
| 1464 | SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL |
| 1465 | str x0, [sp, #0] // Store native ArtMethod* to bottom of stack. |
| 1466 | |
| 1467 | // Save SP , so we can have static CFI info. |
| 1468 | mov x28, sp |
| 1469 | .cfi_def_cfa_register x28 |
| 1470 | |
| 1471 | // This looks the same, but is different: this will be updated to point to the bottom |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1472 | // of the frame when the handle scope is inserted. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1473 | mov xFP, sp |
| 1474 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1475 | mov xIP0, #5120 |
| 1476 | sub sp, sp, xIP0 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1477 | |
| 1478 | // prepare for artQuickGenericJniTrampoline call |
| 1479 | // (Thread*, SP) |
| 1480 | // x0 x1 <= C calling convention |
| 1481 | // xSELF xFP <= where they are |
| 1482 | |
| 1483 | mov x0, xSELF // Thread* |
| 1484 | mov x1, xFP |
| 1485 | bl artQuickGenericJniTrampoline // (Thread*, sp) |
| 1486 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1487 | // The C call will have registered the complete save-frame on success. |
| 1488 | // The result of the call is: |
| 1489 | // x0: pointer to native code, 0 on error. |
| 1490 | // x1: pointer to the bottom of the used area of the alloca, can restore stack till there. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1491 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1492 | // Check for error = 0. |
| 1493 | cbz x0, .Lentry_error |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1494 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1495 | // Release part of the alloca. |
| 1496 | mov sp, x1 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1497 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1498 | // Save the code pointer |
| 1499 | mov xIP0, x0 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1500 | |
| 1501 | // Load parameters from frame into registers. |
| 1502 | // TODO Check with artQuickGenericJniTrampoline. |
| 1503 | // Also, check again APPCS64 - the stack arguments are interleaved. |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1504 | ldp x0, x1, [sp] |
| 1505 | ldp x2, x3, [sp, #16] |
| 1506 | ldp x4, x5, [sp, #32] |
| 1507 | ldp x6, x7, [sp, #48] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1508 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1509 | ldp d0, d1, [sp, #64] |
| 1510 | ldp d2, d3, [sp, #80] |
| 1511 | ldp d4, d5, [sp, #96] |
| 1512 | ldp d6, d7, [sp, #112] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1513 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1514 | add sp, sp, #128 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1515 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1516 | blr xIP0 // native call. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1517 | |
| 1518 | // result sign extension is handled in C code |
| 1519 | // prepare for artQuickGenericJniEndTrampoline call |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1520 | // (Thread*, result, result_f) |
| 1521 | // x0 x1 x2 <= C calling convention |
| 1522 | mov x1, x0 // Result (from saved) |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1523 | mov x0, xETR // Thread register, original xSELF might be scratched by native code. |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1524 | fmov x2, d0 // d0 will contain floating point result, but needs to go into x2 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1525 | |
| 1526 | bl artQuickGenericJniEndTrampoline |
| 1527 | |
| 1528 | // Tear down the alloca. |
| 1529 | mov sp, x28 |
| 1530 | .cfi_def_cfa_register sp |
| 1531 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1532 | // Pending exceptions possible. |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1533 | // Use xETR as xSELF might be scratched by native code |
| 1534 | ldr x1, [xETR, THREAD_EXCEPTION_OFFSET] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1535 | cbnz x1, .Lexception_in_native |
| 1536 | |
| 1537 | // Tear down the callee-save frame. |
| 1538 | RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME |
| 1539 | |
| 1540 | // store into fpr, for when it's a fpr return... |
| 1541 | fmov d0, x0 |
| 1542 | ret |
| 1543 | |
| 1544 | .Lentry_error: |
| 1545 | mov sp, x28 |
| 1546 | .cfi_def_cfa_register sp |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1547 | .Lexception_in_native: |
| 1548 | RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME |
| 1549 | DELIVER_PENDING_EXCEPTION |
| 1550 | |
| 1551 | END art_quick_generic_jni_trampoline |
| 1552 | |
| 1553 | /* |
| 1554 | * Called to bridge from the quick to interpreter ABI. On entry the arguments match those |
| 1555 | * of a quick call: |
| 1556 | * x0 = method being called/to bridge to. |
| 1557 | * x1..x7, d0..d7 = arguments to that method. |
| 1558 | */ |
| 1559 | ENTRY art_quick_to_interpreter_bridge |
| 1560 | SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // Set up frame and save arguments. |
| 1561 | |
| 1562 | // x0 will contain mirror::ArtMethod* method. |
| 1563 | mov x1, xSELF // How to get Thread::Current() ??? |
| 1564 | mov x2, sp |
| 1565 | |
| 1566 | // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self, |
| 1567 | // mirror::ArtMethod** sp) |
| 1568 | bl artQuickToInterpreterBridge |
| 1569 | |
| 1570 | RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME // TODO: no need to restore arguments in this case. |
| 1571 | |
| 1572 | fmov d0, x0 |
| 1573 | |
| 1574 | RETURN_OR_DELIVER_PENDING_EXCEPTION |
| 1575 | END art_quick_to_interpreter_bridge |
| 1576 | |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1577 | |
| 1578 | // |
| 1579 | // Instrumentation-related stubs |
| 1580 | // |
| 1581 | .extern artInstrumentationMethodEntryFromCode |
| 1582 | ENTRY art_quick_instrumentation_entry |
| 1583 | SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME |
| 1584 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1585 | mov x20, x0 // Preserve method reference in a callee-save. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1586 | |
| 1587 | mov x2, xSELF |
| 1588 | mov x3, sp |
| 1589 | mov x4, xLR |
| 1590 | bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, SP, LR) |
| 1591 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1592 | mov xIP0, x0 // x0 = result of call. |
| 1593 | mov x0, x20 // Reload method reference. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1594 | |
| 1595 | RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME // Note: will restore xSELF |
| 1596 | adr xLR, art_quick_instrumentation_exit |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1597 | br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1598 | END art_quick_instrumentation_entry |
| 1599 | |
| 1600 | .extern artInstrumentationMethodExitFromCode |
| 1601 | ENTRY art_quick_instrumentation_exit |
| 1602 | mov xLR, #0 // Clobber LR for later checks. |
| 1603 | |
| 1604 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME |
| 1605 | |
| 1606 | // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then |
| 1607 | // we would need to fully restore it. As there are a lot of callee-save registers, it seems |
| 1608 | // easier to have an extra small stack area. |
| 1609 | |
Sebastien Hertz | 70f8d4b | 2014-06-19 11:51:41 +0200 | [diff] [blame] | 1610 | str x0, [sp, #-16]! // Save integer result. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1611 | .cfi_adjust_cfa_offset 16 |
| 1612 | str d0, [sp, #8] // Save floating-point result. |
| 1613 | |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1614 | add x1, sp, #16 // Pass SP. |
| 1615 | mov x2, x0 // Pass integer result. |
| 1616 | fmov x3, d0 // Pass floating-point result. |
Sebastien Hertz | 70f8d4b | 2014-06-19 11:51:41 +0200 | [diff] [blame] | 1617 | mov x0, xSELF // Pass Thread. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1618 | bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res, fpr_res) |
| 1619 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1620 | mov xIP0, x0 // Return address from instrumentation call. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1621 | mov xLR, x1 // r1 is holding link register if we're to bounce to deoptimize |
| 1622 | |
| 1623 | ldr d0, [sp, #8] // Restore floating-point result. |
| 1624 | ldr x0, [sp], 16 // Restore integer result, and drop stack area. |
| 1625 | .cfi_adjust_cfa_offset 16 |
| 1626 | |
| 1627 | POP_REF_ONLY_CALLEE_SAVE_FRAME |
| 1628 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1629 | br xIP0 // Tail-call out. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1630 | END art_quick_instrumentation_exit |
| 1631 | |
| 1632 | /* |
| 1633 | * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization |
| 1634 | * will long jump to the upcall with a special exception of -1. |
| 1635 | */ |
| 1636 | .extern artDeoptimize |
| 1637 | ENTRY art_quick_deoptimize |
| 1638 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME |
| 1639 | mov x0, xSELF // Pass thread. |
| 1640 | mov x1, sp // Pass SP. |
| 1641 | bl artDeoptimize // artDeoptimize(Thread*, SP) |
Serban Constantinescu | 86797a7 | 2014-06-19 16:17:56 +0100 | [diff] [blame] | 1642 | brk 0 |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1643 | END art_quick_deoptimize |
| 1644 | |
| 1645 | |
Serban Constantinescu | 169489b | 2014-06-11 16:43:35 +0100 | [diff] [blame] | 1646 | /* |
| 1647 | * String's indexOf. |
| 1648 | * |
| 1649 | * TODO: Not very optimized. |
| 1650 | * On entry: |
| 1651 | * x0: string object (known non-null) |
| 1652 | * w1: char to match (known <= 0xFFFF) |
| 1653 | * w2: Starting offset in string data |
| 1654 | */ |
| 1655 | ENTRY art_quick_indexof |
| 1656 | ldr w3, [x0, #STRING_COUNT_OFFSET] |
| 1657 | ldr w4, [x0, #STRING_OFFSET_OFFSET] |
| 1658 | ldr w0, [x0, #STRING_VALUE_OFFSET] // x0 ? |
| 1659 | |
| 1660 | /* Clamp start to [0..count] */ |
| 1661 | cmp w2, #0 |
| 1662 | csel w2, wzr, w2, lt |
| 1663 | cmp w2, w3 |
| 1664 | csel w2, w3, w2, gt |
| 1665 | |
| 1666 | /* Build a pointer to the start of the string data */ |
| 1667 | add x0, x0, #STRING_DATA_OFFSET |
| 1668 | add x0, x0, x4, lsl #1 |
| 1669 | |
| 1670 | /* Save a copy to compute result */ |
| 1671 | mov x5, x0 |
| 1672 | |
| 1673 | /* Build pointer to start of data to compare and pre-bias */ |
| 1674 | add x0, x0, x2, lsl #1 |
| 1675 | sub x0, x0, #2 |
| 1676 | |
| 1677 | /* Compute iteration count */ |
| 1678 | sub w2, w3, w2 |
| 1679 | |
| 1680 | /* |
| 1681 | * At this point we have: |
| 1682 | * x0: start of the data to test |
| 1683 | * w1: char to compare |
| 1684 | * w2: iteration count |
| 1685 | * x5: original start of string data |
| 1686 | */ |
| 1687 | |
| 1688 | subs w2, w2, #4 |
| 1689 | b.lt .Lindexof_remainder |
| 1690 | |
| 1691 | .Lindexof_loop4: |
| 1692 | ldrh w6, [x0, #2]! |
| 1693 | ldrh w7, [x0, #2]! |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1694 | ldrh wIP0, [x0, #2]! |
| 1695 | ldrh wIP1, [x0, #2]! |
Serban Constantinescu | 169489b | 2014-06-11 16:43:35 +0100 | [diff] [blame] | 1696 | cmp w6, w1 |
| 1697 | b.eq .Lmatch_0 |
| 1698 | cmp w7, w1 |
| 1699 | b.eq .Lmatch_1 |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1700 | cmp wIP0, w1 |
Serban Constantinescu | 169489b | 2014-06-11 16:43:35 +0100 | [diff] [blame] | 1701 | b.eq .Lmatch_2 |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 1702 | cmp wIP1, w1 |
Serban Constantinescu | 169489b | 2014-06-11 16:43:35 +0100 | [diff] [blame] | 1703 | b.eq .Lmatch_3 |
| 1704 | subs w2, w2, #4 |
| 1705 | b.ge .Lindexof_loop4 |
| 1706 | |
| 1707 | .Lindexof_remainder: |
| 1708 | adds w2, w2, #4 |
| 1709 | b.eq .Lindexof_nomatch |
| 1710 | |
| 1711 | .Lindexof_loop1: |
| 1712 | ldrh w6, [x0, #2]! |
| 1713 | cmp w6, w1 |
| 1714 | b.eq .Lmatch_3 |
| 1715 | subs w2, w2, #1 |
| 1716 | b.ne .Lindexof_loop1 |
| 1717 | |
| 1718 | .Lindexof_nomatch: |
| 1719 | mov x0, #-1 |
| 1720 | ret |
| 1721 | |
| 1722 | .Lmatch_0: |
| 1723 | sub x0, x0, #6 |
| 1724 | sub x0, x0, x5 |
| 1725 | asr x0, x0, #1 |
| 1726 | ret |
| 1727 | .Lmatch_1: |
| 1728 | sub x0, x0, #4 |
| 1729 | sub x0, x0, x5 |
| 1730 | asr x0, x0, #1 |
| 1731 | ret |
| 1732 | .Lmatch_2: |
| 1733 | sub x0, x0, #2 |
| 1734 | sub x0, x0, x5 |
| 1735 | asr x0, x0, #1 |
| 1736 | ret |
| 1737 | .Lmatch_3: |
| 1738 | sub x0, x0, x5 |
| 1739 | asr x0, x0, #1 |
| 1740 | ret |
| 1741 | END art_quick_indexof |
Andreas Gampe | 266340d | 2014-05-02 07:55:24 -0700 | [diff] [blame] | 1742 | |
| 1743 | /* |
| 1744 | * String's compareTo. |
| 1745 | * |
| 1746 | * TODO: Not very optimized. |
| 1747 | * |
| 1748 | * On entry: |
| 1749 | * x0: this object pointer |
| 1750 | * x1: comp object pointer |
| 1751 | * |
| 1752 | */ |
Serban Constantinescu | 86797a7 | 2014-06-19 16:17:56 +0100 | [diff] [blame] | 1753 | .extern __memcmp16 |
Andreas Gampe | 266340d | 2014-05-02 07:55:24 -0700 | [diff] [blame] | 1754 | ENTRY art_quick_string_compareto |
| 1755 | mov x2, x0 // x0 is return, use x2 for first input. |
| 1756 | sub x0, x2, x1 // Same string object? |
| 1757 | cbnz x0,1f |
| 1758 | ret |
| 1759 | 1: // Different string objects. |
| 1760 | |
| 1761 | ldr w6, [x2, #STRING_OFFSET_OFFSET] |
| 1762 | ldr w5, [x1, #STRING_OFFSET_OFFSET] |
| 1763 | ldr w4, [x2, #STRING_COUNT_OFFSET] |
| 1764 | ldr w3, [x1, #STRING_COUNT_OFFSET] |
| 1765 | ldr w2, [x2, #STRING_VALUE_OFFSET] |
| 1766 | ldr w1, [x1, #STRING_VALUE_OFFSET] |
| 1767 | |
| 1768 | /* |
| 1769 | * Now: CharArray* Offset Count |
| 1770 | * first arg x2 w6 w4 |
| 1771 | * second arg x1 w5 w3 |
| 1772 | */ |
| 1773 | |
| 1774 | // x0 := str1.length(w4) - str2.length(w3). ldr zero-extended w3/w4 into x3/x4. |
| 1775 | subs x0, x4, x3 |
| 1776 | // Min(count1, count2) into w3. |
| 1777 | csel x3, x3, x4, ge |
| 1778 | |
| 1779 | // Build pointer into string data. |
| 1780 | |
| 1781 | // Add offset in array (substr etc.) (sign extend and << 1). |
| 1782 | add x2, x2, w6, sxtw #1 |
| 1783 | add x1, x1, w5, sxtw #1 |
| 1784 | |
| 1785 | // Add offset in CharArray to array. |
| 1786 | add x2, x2, #STRING_DATA_OFFSET |
| 1787 | add x1, x1, #STRING_DATA_OFFSET |
| 1788 | |
Serban Constantinescu | 169489b | 2014-06-11 16:43:35 +0100 | [diff] [blame] | 1789 | // TODO: Tune this value. |
Andreas Gampe | 266340d | 2014-05-02 07:55:24 -0700 | [diff] [blame] | 1790 | // Check for long string, do memcmp16 for them. |
| 1791 | cmp w3, #28 // Constant from arm32. |
| 1792 | bgt .Ldo_memcmp16 |
| 1793 | |
| 1794 | /* |
| 1795 | * Now: |
| 1796 | * x2: *first string data |
| 1797 | * x1: *second string data |
| 1798 | * w3: iteration count |
| 1799 | * x0: return value if comparison equal |
| 1800 | * x4, x5, x6, x7: free |
| 1801 | */ |
| 1802 | |
| 1803 | // Do a simple unrolled loop. |
| 1804 | .Lloop: |
| 1805 | // At least two more elements? |
| 1806 | subs w3, w3, #2 |
| 1807 | b.lt .Lremainder_or_done |
| 1808 | |
| 1809 | ldrh w4, [x2], #2 |
| 1810 | ldrh w5, [x1], #2 |
| 1811 | |
| 1812 | ldrh w6, [x2], #2 |
| 1813 | ldrh w7, [x1], #2 |
| 1814 | |
| 1815 | subs w4, w4, w5 |
| 1816 | b.ne .Lw4_result |
| 1817 | |
| 1818 | subs w6, w6, w7 |
| 1819 | b.ne .Lw6_result |
| 1820 | |
| 1821 | b .Lloop |
| 1822 | |
| 1823 | .Lremainder_or_done: |
| 1824 | adds w3, w3, #1 |
| 1825 | b.eq .Lremainder |
| 1826 | ret |
| 1827 | |
| 1828 | .Lremainder: |
| 1829 | ldrh w4, [x2], #2 |
| 1830 | ldrh w5, [x1], #2 |
| 1831 | subs w4, w4, w5 |
| 1832 | b.ne .Lw4_result |
| 1833 | ret |
| 1834 | |
| 1835 | // Result is in w4 |
| 1836 | .Lw4_result: |
| 1837 | sxtw x0, w4 |
| 1838 | ret |
| 1839 | |
| 1840 | // Result is in w6 |
| 1841 | .Lw6_result: |
| 1842 | sxtw x0, w6 |
| 1843 | ret |
| 1844 | |
| 1845 | .Ldo_memcmp16: |
Zheng Xu | 62ddb32 | 2014-08-12 17:19:12 +0800 | [diff] [blame^] | 1846 | mov x14, x0 // Save x0 and LR. __memcmp16 does not use these temps. |
| 1847 | mov x15, xLR // TODO: Codify and check that? |
Andreas Gampe | 266340d | 2014-05-02 07:55:24 -0700 | [diff] [blame] | 1848 | |
| 1849 | mov x0, x2 |
| 1850 | uxtw x2, w3 |
Serban Constantinescu | 86797a7 | 2014-06-19 16:17:56 +0100 | [diff] [blame] | 1851 | bl __memcmp16 |
Andreas Gampe | 266340d | 2014-05-02 07:55:24 -0700 | [diff] [blame] | 1852 | |
Zheng Xu | 62ddb32 | 2014-08-12 17:19:12 +0800 | [diff] [blame^] | 1853 | mov xLR, x15 // Restore LR. |
Andreas Gampe | 266340d | 2014-05-02 07:55:24 -0700 | [diff] [blame] | 1854 | |
Serban Constantinescu | 86797a7 | 2014-06-19 16:17:56 +0100 | [diff] [blame] | 1855 | cmp x0, #0 // Check the memcmp difference. |
Zheng Xu | 62ddb32 | 2014-08-12 17:19:12 +0800 | [diff] [blame^] | 1856 | csel x0, x0, x14, ne // x0 := x0 != 0 ? x14(prev x0=length diff) : x1. |
Andreas Gampe | 266340d | 2014-05-02 07:55:24 -0700 | [diff] [blame] | 1857 | ret |
| 1858 | END art_quick_string_compareto |
Zheng Xu | 0210d11 | 2014-06-17 12:25:48 +0800 | [diff] [blame] | 1859 | |
| 1860 | // Macro to facilitate adding new entrypoints which call to native function directly. |
| 1861 | // Currently, xSELF is the only thing we need to take care of between managed code and AAPCS. |
| 1862 | // But we might introduce more differences. |
| 1863 | .macro NATIVE_DOWNCALL name, entrypoint |
| 1864 | .extern \entrypoint |
| 1865 | ENTRY \name |
Serban Constantinescu | 86797a7 | 2014-06-19 16:17:56 +0100 | [diff] [blame] | 1866 | stp xSELF, xLR, [sp, #-16]! |
Zheng Xu | 0210d11 | 2014-06-17 12:25:48 +0800 | [diff] [blame] | 1867 | bl \entrypoint |
Serban Constantinescu | 86797a7 | 2014-06-19 16:17:56 +0100 | [diff] [blame] | 1868 | ldp xSELF, xLR, [sp], #16 |
Zheng Xu | 0210d11 | 2014-06-17 12:25:48 +0800 | [diff] [blame] | 1869 | ret |
| 1870 | END \name |
| 1871 | .endm |
| 1872 | |
| 1873 | NATIVE_DOWNCALL art_quick_fmod fmod |
| 1874 | NATIVE_DOWNCALL art_quick_fmodf fmodf |
| 1875 | NATIVE_DOWNCALL art_quick_memcpy memcpy |
Serban Constantinescu | 86797a7 | 2014-06-19 16:17:56 +0100 | [diff] [blame] | 1876 | NATIVE_DOWNCALL art_quick_assignable_from_code artIsAssignableFromCode |