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