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