Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 28 | #include <limits.h> // For LONG_MIN, LONG_MAX. |
| 29 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 30 | #include "v8.h" |
| 31 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 32 | #if defined(V8_TARGET_ARCH_ARM) |
| 33 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | #include "bootstrapper.h" |
| 35 | #include "codegen-inl.h" |
| 36 | #include "debug.h" |
| 37 | #include "runtime.h" |
| 38 | |
| 39 | namespace v8 { |
| 40 | namespace internal { |
| 41 | |
| 42 | MacroAssembler::MacroAssembler(void* buffer, int size) |
| 43 | : Assembler(buffer, size), |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | generating_stub_(false), |
| 45 | allow_stub_calls_(true), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 46 | code_object_(HEAP->undefined_value()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | |
| 50 | // We always generate arm code, never thumb code, even if V8 is compiled to |
| 51 | // thumb, so we require inter-working support |
| 52 | #if defined(__thumb__) && !defined(USE_THUMB_INTERWORK) |
| 53 | #error "flag -mthumb-interwork missing" |
| 54 | #endif |
| 55 | |
| 56 | |
| 57 | // We do not support thumb inter-working with an arm architecture not supporting |
| 58 | // the blx instruction (below v5t). If you know what CPU you are compiling for |
| 59 | // you can use -march=armv7 or similar. |
| 60 | #if defined(USE_THUMB_INTERWORK) && !defined(CAN_USE_THUMB_INSTRUCTIONS) |
| 61 | # error "For thumb inter-working we require an architecture which supports blx" |
| 62 | #endif |
| 63 | |
| 64 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 65 | // Using bx does not yield better code, so use it only when required |
| 66 | #if defined(USE_THUMB_INTERWORK) |
| 67 | #define USE_BX 1 |
| 68 | #endif |
| 69 | |
| 70 | |
| 71 | void MacroAssembler::Jump(Register target, Condition cond) { |
| 72 | #if USE_BX |
| 73 | bx(target, cond); |
| 74 | #else |
| 75 | mov(pc, Operand(target), LeaveCC, cond); |
| 76 | #endif |
| 77 | } |
| 78 | |
| 79 | |
| 80 | void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode, |
| 81 | Condition cond) { |
| 82 | #if USE_BX |
| 83 | mov(ip, Operand(target, rmode), LeaveCC, cond); |
| 84 | bx(ip, cond); |
| 85 | #else |
| 86 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
| 87 | #endif |
| 88 | } |
| 89 | |
| 90 | |
| 91 | void MacroAssembler::Jump(byte* target, RelocInfo::Mode rmode, |
| 92 | Condition cond) { |
| 93 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
| 94 | Jump(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode, |
| 99 | Condition cond) { |
| 100 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
| 101 | // 'code' is always generated ARM code, never THUMB code |
| 102 | Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 103 | } |
| 104 | |
| 105 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 106 | int MacroAssembler::CallSize(Register target, Condition cond) { |
| 107 | #if USE_BLX |
| 108 | return kInstrSize; |
| 109 | #else |
| 110 | return 2 * kInstrSize; |
| 111 | #endif |
| 112 | } |
| 113 | |
| 114 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 115 | void MacroAssembler::Call(Register target, Condition cond) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 116 | // Block constant pool for the call instruction sequence. |
| 117 | BlockConstPoolScope block_const_pool(this); |
| 118 | #ifdef DEBUG |
| 119 | int pre_position = pc_offset(); |
| 120 | #endif |
| 121 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 122 | #if USE_BLX |
| 123 | blx(target, cond); |
| 124 | #else |
| 125 | // set lr for return at current pc + 8 |
| 126 | mov(lr, Operand(pc), LeaveCC, cond); |
| 127 | mov(pc, Operand(target), LeaveCC, cond); |
| 128 | #endif |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 129 | |
| 130 | #ifdef DEBUG |
| 131 | int post_position = pc_offset(); |
| 132 | CHECK_EQ(pre_position + CallSize(target, cond), post_position); |
| 133 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 137 | int MacroAssembler::CallSize( |
| 138 | intptr_t target, RelocInfo::Mode rmode, Condition cond) { |
| 139 | int size = 2 * kInstrSize; |
| 140 | Instr mov_instr = cond | MOV | LeaveCC; |
| 141 | if (!Operand(target, rmode).is_single_instruction(mov_instr)) { |
| 142 | size += kInstrSize; |
| 143 | } |
| 144 | return size; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | void MacroAssembler::Call( |
| 149 | intptr_t target, RelocInfo::Mode rmode, Condition cond) { |
| 150 | // Block constant pool for the call instruction sequence. |
| 151 | BlockConstPoolScope block_const_pool(this); |
| 152 | #ifdef DEBUG |
| 153 | int pre_position = pc_offset(); |
| 154 | #endif |
| 155 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 156 | #if USE_BLX |
| 157 | // On ARMv5 and after the recommended call sequence is: |
| 158 | // ldr ip, [pc, #...] |
| 159 | // blx ip |
| 160 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 161 | // Statement positions are expected to be recorded when the target |
| 162 | // address is loaded. The mov method will automatically record |
| 163 | // positions when pc is the target, since this is not the case here |
| 164 | // we have to do it explicitly. |
| 165 | positions_recorder()->WriteRecordedPositions(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 166 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 167 | mov(ip, Operand(target, rmode), LeaveCC, cond); |
| 168 | blx(ip, cond); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 169 | |
| 170 | ASSERT(kCallTargetAddressOffset == 2 * kInstrSize); |
| 171 | #else |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 172 | // Set lr for return at current pc + 8. |
| 173 | mov(lr, Operand(pc), LeaveCC, cond); |
| 174 | // Emit a ldr<cond> pc, [pc + offset of target in constant pool]. |
| 175 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 176 | ASSERT(kCallTargetAddressOffset == kInstrSize); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 177 | #endif |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 178 | |
| 179 | #ifdef DEBUG |
| 180 | int post_position = pc_offset(); |
| 181 | CHECK_EQ(pre_position + CallSize(target, rmode, cond), post_position); |
| 182 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 186 | int MacroAssembler::CallSize( |
| 187 | byte* target, RelocInfo::Mode rmode, Condition cond) { |
| 188 | return CallSize(reinterpret_cast<intptr_t>(target), rmode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 192 | void MacroAssembler::Call( |
| 193 | byte* target, RelocInfo::Mode rmode, Condition cond) { |
| 194 | #ifdef DEBUG |
| 195 | int pre_position = pc_offset(); |
| 196 | #endif |
| 197 | |
| 198 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
| 199 | Call(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 200 | |
| 201 | #ifdef DEBUG |
| 202 | int post_position = pc_offset(); |
| 203 | CHECK_EQ(pre_position + CallSize(target, rmode, cond), post_position); |
| 204 | #endif |
| 205 | } |
| 206 | |
| 207 | |
| 208 | int MacroAssembler::CallSize( |
| 209 | Handle<Code> code, RelocInfo::Mode rmode, Condition cond) { |
| 210 | return CallSize(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 211 | } |
| 212 | |
| 213 | |
| 214 | void MacroAssembler::Call( |
| 215 | Handle<Code> code, RelocInfo::Mode rmode, Condition cond) { |
| 216 | #ifdef DEBUG |
| 217 | int pre_position = pc_offset(); |
| 218 | #endif |
| 219 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 220 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
| 221 | // 'code' is always generated ARM code, never THUMB code |
| 222 | Call(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 223 | |
| 224 | #ifdef DEBUG |
| 225 | int post_position = pc_offset(); |
| 226 | CHECK_EQ(pre_position + CallSize(code, rmode, cond), post_position); |
| 227 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | |
| 231 | void MacroAssembler::Ret(Condition cond) { |
| 232 | #if USE_BX |
| 233 | bx(lr, cond); |
| 234 | #else |
| 235 | mov(pc, Operand(lr), LeaveCC, cond); |
| 236 | #endif |
| 237 | } |
| 238 | |
| 239 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 240 | void MacroAssembler::Drop(int count, Condition cond) { |
| 241 | if (count > 0) { |
| 242 | add(sp, sp, Operand(count * kPointerSize), LeaveCC, cond); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 247 | void MacroAssembler::Ret(int drop, Condition cond) { |
| 248 | Drop(drop, cond); |
| 249 | Ret(cond); |
| 250 | } |
| 251 | |
| 252 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 253 | void MacroAssembler::Swap(Register reg1, |
| 254 | Register reg2, |
| 255 | Register scratch, |
| 256 | Condition cond) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 257 | if (scratch.is(no_reg)) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 258 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
| 259 | eor(reg2, reg2, Operand(reg1), LeaveCC, cond); |
| 260 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 261 | } else { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 262 | mov(scratch, reg1, LeaveCC, cond); |
| 263 | mov(reg1, reg2, LeaveCC, cond); |
| 264 | mov(reg2, scratch, LeaveCC, cond); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
| 268 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 269 | void MacroAssembler::Call(Label* target) { |
| 270 | bl(target); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | void MacroAssembler::Move(Register dst, Handle<Object> value) { |
| 275 | mov(dst, Operand(value)); |
| 276 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 277 | |
| 278 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 279 | void MacroAssembler::Move(Register dst, Register src) { |
| 280 | if (!dst.is(src)) { |
| 281 | mov(dst, src); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 286 | void MacroAssembler::And(Register dst, Register src1, const Operand& src2, |
| 287 | Condition cond) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 288 | if (!src2.is_reg() && |
| 289 | !src2.must_use_constant_pool() && |
| 290 | src2.immediate() == 0) { |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 291 | mov(dst, Operand(0, RelocInfo::NONE), LeaveCC, cond); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 292 | |
| 293 | } else if (!src2.is_single_instruction() && |
| 294 | !src2.must_use_constant_pool() && |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 295 | Isolate::Current()->cpu_features()->IsSupported(ARMv7) && |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 296 | IsPowerOf2(src2.immediate() + 1)) { |
| 297 | ubfx(dst, src1, 0, WhichPowerOf2(src2.immediate() + 1), cond); |
| 298 | |
| 299 | } else { |
| 300 | and_(dst, src1, src2, LeaveCC, cond); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 301 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | |
| 305 | void MacroAssembler::Ubfx(Register dst, Register src1, int lsb, int width, |
| 306 | Condition cond) { |
| 307 | ASSERT(lsb < 32); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 308 | if (!Isolate::Current()->cpu_features()->IsSupported(ARMv7)) { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 309 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 310 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 311 | if (lsb != 0) { |
| 312 | mov(dst, Operand(dst, LSR, lsb), LeaveCC, cond); |
| 313 | } |
| 314 | } else { |
| 315 | ubfx(dst, src1, lsb, width, cond); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | |
| 320 | void MacroAssembler::Sbfx(Register dst, Register src1, int lsb, int width, |
| 321 | Condition cond) { |
| 322 | ASSERT(lsb < 32); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 323 | if (!Isolate::Current()->cpu_features()->IsSupported(ARMv7)) { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 324 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 325 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 326 | int shift_up = 32 - lsb - width; |
| 327 | int shift_down = lsb + shift_up; |
| 328 | if (shift_up != 0) { |
| 329 | mov(dst, Operand(dst, LSL, shift_up), LeaveCC, cond); |
| 330 | } |
| 331 | if (shift_down != 0) { |
| 332 | mov(dst, Operand(dst, ASR, shift_down), LeaveCC, cond); |
| 333 | } |
| 334 | } else { |
| 335 | sbfx(dst, src1, lsb, width, cond); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 340 | void MacroAssembler::Bfi(Register dst, |
| 341 | Register src, |
| 342 | Register scratch, |
| 343 | int lsb, |
| 344 | int width, |
| 345 | Condition cond) { |
| 346 | ASSERT(0 <= lsb && lsb < 32); |
| 347 | ASSERT(0 <= width && width < 32); |
| 348 | ASSERT(lsb + width < 32); |
| 349 | ASSERT(!scratch.is(dst)); |
| 350 | if (width == 0) return; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 351 | if (!Isolate::Current()->cpu_features()->IsSupported(ARMv7)) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 352 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 353 | bic(dst, dst, Operand(mask)); |
| 354 | and_(scratch, src, Operand((1 << width) - 1)); |
| 355 | mov(scratch, Operand(scratch, LSL, lsb)); |
| 356 | orr(dst, dst, scratch); |
| 357 | } else { |
| 358 | bfi(dst, src, lsb, width, cond); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 363 | void MacroAssembler::Bfc(Register dst, int lsb, int width, Condition cond) { |
| 364 | ASSERT(lsb < 32); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 365 | if (!Isolate::Current()->cpu_features()->IsSupported(ARMv7)) { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 366 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 367 | bic(dst, dst, Operand(mask)); |
| 368 | } else { |
| 369 | bfc(dst, lsb, width, cond); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 374 | void MacroAssembler::Usat(Register dst, int satpos, const Operand& src, |
| 375 | Condition cond) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 376 | if (!Isolate::Current()->cpu_features()->IsSupported(ARMv7)) { |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 377 | ASSERT(!dst.is(pc) && !src.rm().is(pc)); |
| 378 | ASSERT((satpos >= 0) && (satpos <= 31)); |
| 379 | |
| 380 | // These asserts are required to ensure compatibility with the ARMv7 |
| 381 | // implementation. |
| 382 | ASSERT((src.shift_op() == ASR) || (src.shift_op() == LSL)); |
| 383 | ASSERT(src.rs().is(no_reg)); |
| 384 | |
| 385 | Label done; |
| 386 | int satval = (1 << satpos) - 1; |
| 387 | |
| 388 | if (cond != al) { |
| 389 | b(NegateCondition(cond), &done); // Skip saturate if !condition. |
| 390 | } |
| 391 | if (!(src.is_reg() && dst.is(src.rm()))) { |
| 392 | mov(dst, src); |
| 393 | } |
| 394 | tst(dst, Operand(~satval)); |
| 395 | b(eq, &done); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 396 | mov(dst, Operand(0, RelocInfo::NONE), LeaveCC, mi); // 0 if negative. |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 397 | mov(dst, Operand(satval), LeaveCC, pl); // satval if positive. |
| 398 | bind(&done); |
| 399 | } else { |
| 400 | usat(dst, satpos, src, cond); |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 405 | void MacroAssembler::SmiJumpTable(Register index, Vector<Label*> targets) { |
| 406 | // Empty the const pool. |
| 407 | CheckConstPool(true, true); |
| 408 | add(pc, pc, Operand(index, |
| 409 | LSL, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 410 | Instruction::kInstrSizeLog2 - kSmiTagSize)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 411 | BlockConstPoolBefore(pc_offset() + (targets.length() + 1) * kInstrSize); |
| 412 | nop(); // Jump table alignment. |
| 413 | for (int i = 0; i < targets.length(); i++) { |
| 414 | b(targets[i]); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | |
| 419 | void MacroAssembler::LoadRoot(Register destination, |
| 420 | Heap::RootListIndex index, |
| 421 | Condition cond) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 422 | ldr(destination, MemOperand(roots, index << kPointerSizeLog2), cond); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 426 | void MacroAssembler::StoreRoot(Register source, |
| 427 | Heap::RootListIndex index, |
| 428 | Condition cond) { |
| 429 | str(source, MemOperand(roots, index << kPointerSizeLog2), cond); |
| 430 | } |
| 431 | |
| 432 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 433 | void MacroAssembler::RecordWriteHelper(Register object, |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 434 | Register address, |
| 435 | Register scratch) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 436 | if (emit_debug_code()) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 437 | // Check that the object is not in new space. |
| 438 | Label not_in_new_space; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 439 | InNewSpace(object, scratch, ne, ¬_in_new_space); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 440 | Abort("new-space object passed to RecordWriteHelper"); |
| 441 | bind(¬_in_new_space); |
| 442 | } |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 443 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 444 | // Calculate page address. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 445 | Bfc(object, 0, kPageSizeBits); |
| 446 | |
| 447 | // Calculate region number. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 448 | Ubfx(address, address, Page::kRegionSizeLog2, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 449 | kPageSizeBits - Page::kRegionSizeLog2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 450 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 451 | // Mark region dirty. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 452 | ldr(scratch, MemOperand(object, Page::kDirtyFlagOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 453 | mov(ip, Operand(1)); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 454 | orr(scratch, scratch, Operand(ip, LSL, address)); |
| 455 | str(scratch, MemOperand(object, Page::kDirtyFlagOffset)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | |
| 459 | void MacroAssembler::InNewSpace(Register object, |
| 460 | Register scratch, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 461 | Condition cond, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 462 | Label* branch) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 463 | ASSERT(cond == eq || cond == ne); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 464 | and_(scratch, object, Operand(ExternalReference::new_space_mask(isolate()))); |
| 465 | cmp(scratch, Operand(ExternalReference::new_space_start(isolate()))); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 466 | b(cond, branch); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | |
| 470 | // Will clobber 4 registers: object, offset, scratch, ip. The |
| 471 | // register 'object' contains a heap object pointer. The heap object |
| 472 | // tag is shifted away. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 473 | void MacroAssembler::RecordWrite(Register object, |
| 474 | Operand offset, |
| 475 | Register scratch0, |
| 476 | Register scratch1) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 477 | // The compiled code assumes that record write doesn't change the |
| 478 | // context register, so we check that none of the clobbered |
| 479 | // registers are cp. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 480 | ASSERT(!object.is(cp) && !scratch0.is(cp) && !scratch1.is(cp)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 481 | |
| 482 | Label done; |
| 483 | |
| 484 | // First, test that the object is not in the new space. We cannot set |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 485 | // region marks for new space pages. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 486 | InNewSpace(object, scratch0, eq, &done); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 487 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 488 | // Add offset into the object. |
| 489 | add(scratch0, object, offset); |
| 490 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 491 | // Record the actual write. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 492 | RecordWriteHelper(object, scratch0, scratch1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 493 | |
| 494 | bind(&done); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 495 | |
| 496 | // Clobber all input registers when running with the debug-code flag |
| 497 | // turned on to provoke errors. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 498 | if (emit_debug_code()) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 499 | mov(object, Operand(BitCast<int32_t>(kZapValue))); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 500 | mov(scratch0, Operand(BitCast<int32_t>(kZapValue))); |
| 501 | mov(scratch1, Operand(BitCast<int32_t>(kZapValue))); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 502 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 506 | // Will clobber 4 registers: object, address, scratch, ip. The |
| 507 | // register 'object' contains a heap object pointer. The heap object |
| 508 | // tag is shifted away. |
| 509 | void MacroAssembler::RecordWrite(Register object, |
| 510 | Register address, |
| 511 | Register scratch) { |
| 512 | // The compiled code assumes that record write doesn't change the |
| 513 | // context register, so we check that none of the clobbered |
| 514 | // registers are cp. |
| 515 | ASSERT(!object.is(cp) && !address.is(cp) && !scratch.is(cp)); |
| 516 | |
| 517 | Label done; |
| 518 | |
| 519 | // First, test that the object is not in the new space. We cannot set |
| 520 | // region marks for new space pages. |
| 521 | InNewSpace(object, scratch, eq, &done); |
| 522 | |
| 523 | // Record the actual write. |
| 524 | RecordWriteHelper(object, address, scratch); |
| 525 | |
| 526 | bind(&done); |
| 527 | |
| 528 | // Clobber all input registers when running with the debug-code flag |
| 529 | // turned on to provoke errors. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 530 | if (emit_debug_code()) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 531 | mov(object, Operand(BitCast<int32_t>(kZapValue))); |
| 532 | mov(address, Operand(BitCast<int32_t>(kZapValue))); |
| 533 | mov(scratch, Operand(BitCast<int32_t>(kZapValue))); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 538 | // Push and pop all registers that can hold pointers. |
| 539 | void MacroAssembler::PushSafepointRegisters() { |
| 540 | // Safepoints expect a block of contiguous register values starting with r0: |
| 541 | ASSERT(((1 << kNumSafepointSavedRegisters) - 1) == kSafepointSavedRegisters); |
| 542 | // Safepoints expect a block of kNumSafepointRegisters values on the |
| 543 | // stack, so adjust the stack for unsaved registers. |
| 544 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 545 | ASSERT(num_unsaved >= 0); |
| 546 | sub(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 547 | stm(db_w, sp, kSafepointSavedRegisters); |
| 548 | } |
| 549 | |
| 550 | |
| 551 | void MacroAssembler::PopSafepointRegisters() { |
| 552 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 553 | ldm(ia_w, sp, kSafepointSavedRegisters); |
| 554 | add(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 555 | } |
| 556 | |
| 557 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 558 | void MacroAssembler::PushSafepointRegistersAndDoubles() { |
| 559 | PushSafepointRegisters(); |
| 560 | sub(sp, sp, Operand(DwVfpRegister::kNumAllocatableRegisters * |
| 561 | kDoubleSize)); |
| 562 | for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; i++) { |
| 563 | vstr(DwVfpRegister::FromAllocationIndex(i), sp, i * kDoubleSize); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | |
| 568 | void MacroAssembler::PopSafepointRegistersAndDoubles() { |
| 569 | for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; i++) { |
| 570 | vldr(DwVfpRegister::FromAllocationIndex(i), sp, i * kDoubleSize); |
| 571 | } |
| 572 | add(sp, sp, Operand(DwVfpRegister::kNumAllocatableRegisters * |
| 573 | kDoubleSize)); |
| 574 | PopSafepointRegisters(); |
| 575 | } |
| 576 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 577 | void MacroAssembler::StoreToSafepointRegistersAndDoublesSlot(Register src, |
| 578 | Register dst) { |
| 579 | str(src, SafepointRegistersAndDoublesSlot(dst)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 583 | void MacroAssembler::StoreToSafepointRegisterSlot(Register src, Register dst) { |
| 584 | str(src, SafepointRegisterSlot(dst)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 588 | void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) { |
| 589 | ldr(dst, SafepointRegisterSlot(src)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 593 | int MacroAssembler::SafepointRegisterStackIndex(int reg_code) { |
| 594 | // The registers are pushed starting with the highest encoding, |
| 595 | // which means that lowest encodings are closest to the stack pointer. |
| 596 | ASSERT(reg_code >= 0 && reg_code < kNumSafepointRegisters); |
| 597 | return reg_code; |
| 598 | } |
| 599 | |
| 600 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 601 | MemOperand MacroAssembler::SafepointRegisterSlot(Register reg) { |
| 602 | return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kPointerSize); |
| 603 | } |
| 604 | |
| 605 | |
| 606 | MemOperand MacroAssembler::SafepointRegistersAndDoublesSlot(Register reg) { |
| 607 | // General purpose registers are pushed last on the stack. |
| 608 | int doubles_size = DwVfpRegister::kNumAllocatableRegisters * kDoubleSize; |
| 609 | int register_offset = SafepointRegisterStackIndex(reg.code()) * kPointerSize; |
| 610 | return MemOperand(sp, doubles_size + register_offset); |
| 611 | } |
| 612 | |
| 613 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 614 | void MacroAssembler::Ldrd(Register dst1, Register dst2, |
| 615 | const MemOperand& src, Condition cond) { |
| 616 | ASSERT(src.rm().is(no_reg)); |
| 617 | ASSERT(!dst1.is(lr)); // r14. |
| 618 | ASSERT_EQ(0, dst1.code() % 2); |
| 619 | ASSERT_EQ(dst1.code() + 1, dst2.code()); |
| 620 | |
| 621 | // Generate two ldr instructions if ldrd is not available. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 622 | if (Isolate::Current()->cpu_features()->IsSupported(ARMv7)) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 623 | CpuFeatures::Scope scope(ARMv7); |
| 624 | ldrd(dst1, dst2, src, cond); |
| 625 | } else { |
| 626 | MemOperand src2(src); |
| 627 | src2.set_offset(src2.offset() + 4); |
| 628 | if (dst1.is(src.rn())) { |
| 629 | ldr(dst2, src2, cond); |
| 630 | ldr(dst1, src, cond); |
| 631 | } else { |
| 632 | ldr(dst1, src, cond); |
| 633 | ldr(dst2, src2, cond); |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | |
| 639 | void MacroAssembler::Strd(Register src1, Register src2, |
| 640 | const MemOperand& dst, Condition cond) { |
| 641 | ASSERT(dst.rm().is(no_reg)); |
| 642 | ASSERT(!src1.is(lr)); // r14. |
| 643 | ASSERT_EQ(0, src1.code() % 2); |
| 644 | ASSERT_EQ(src1.code() + 1, src2.code()); |
| 645 | |
| 646 | // Generate two str instructions if strd is not available. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 647 | if (Isolate::Current()->cpu_features()->IsSupported(ARMv7)) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 648 | CpuFeatures::Scope scope(ARMv7); |
| 649 | strd(src1, src2, dst, cond); |
| 650 | } else { |
| 651 | MemOperand dst2(dst); |
| 652 | dst2.set_offset(dst2.offset() + 4); |
| 653 | str(src1, dst, cond); |
| 654 | str(src2, dst2, cond); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 659 | void MacroAssembler::ClearFPSCRBits(const uint32_t bits_to_clear, |
| 660 | const Register scratch, |
| 661 | const Condition cond) { |
| 662 | vmrs(scratch, cond); |
| 663 | bic(scratch, scratch, Operand(bits_to_clear), LeaveCC, cond); |
| 664 | vmsr(scratch, cond); |
| 665 | } |
| 666 | |
| 667 | |
| 668 | void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 669 | const DwVfpRegister src2, |
| 670 | const Condition cond) { |
| 671 | // Compare and move FPSCR flags to the normal condition flags. |
| 672 | VFPCompareAndLoadFlags(src1, src2, pc, cond); |
| 673 | } |
| 674 | |
| 675 | void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 676 | const double src2, |
| 677 | const Condition cond) { |
| 678 | // Compare and move FPSCR flags to the normal condition flags. |
| 679 | VFPCompareAndLoadFlags(src1, src2, pc, cond); |
| 680 | } |
| 681 | |
| 682 | |
| 683 | void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 684 | const DwVfpRegister src2, |
| 685 | const Register fpscr_flags, |
| 686 | const Condition cond) { |
| 687 | // Compare and load FPSCR. |
| 688 | vcmp(src1, src2, cond); |
| 689 | vmrs(fpscr_flags, cond); |
| 690 | } |
| 691 | |
| 692 | void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 693 | const double src2, |
| 694 | const Register fpscr_flags, |
| 695 | const Condition cond) { |
| 696 | // Compare and load FPSCR. |
| 697 | vcmp(src1, src2, cond); |
| 698 | vmrs(fpscr_flags, cond); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 702 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
| 703 | // r0-r3: preserved |
| 704 | stm(db_w, sp, cp.bit() | fp.bit() | lr.bit()); |
| 705 | mov(ip, Operand(Smi::FromInt(type))); |
| 706 | push(ip); |
| 707 | mov(ip, Operand(CodeObject())); |
| 708 | push(ip); |
| 709 | add(fp, sp, Operand(3 * kPointerSize)); // Adjust FP to point to saved FP. |
| 710 | } |
| 711 | |
| 712 | |
| 713 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
| 714 | // r0: preserved |
| 715 | // r1: preserved |
| 716 | // r2: preserved |
| 717 | |
| 718 | // Drop the execution stack down to the frame pointer and restore |
| 719 | // the caller frame pointer and return address. |
| 720 | mov(sp, fp); |
| 721 | ldm(ia_w, sp, fp.bit() | lr.bit()); |
| 722 | } |
| 723 | |
| 724 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 725 | void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space) { |
| 726 | // Setup the frame structure on the stack. |
| 727 | ASSERT_EQ(2 * kPointerSize, ExitFrameConstants::kCallerSPDisplacement); |
| 728 | ASSERT_EQ(1 * kPointerSize, ExitFrameConstants::kCallerPCOffset); |
| 729 | ASSERT_EQ(0 * kPointerSize, ExitFrameConstants::kCallerFPOffset); |
| 730 | Push(lr, fp); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 731 | mov(fp, Operand(sp)); // Setup new frame pointer. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 732 | // Reserve room for saved entry sp and code object. |
| 733 | sub(sp, sp, Operand(2 * kPointerSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 734 | if (emit_debug_code()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 735 | mov(ip, Operand(0)); |
| 736 | str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
| 737 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 738 | mov(ip, Operand(CodeObject())); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 739 | str(ip, MemOperand(fp, ExitFrameConstants::kCodeOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 740 | |
| 741 | // Save the frame pointer and the context in top. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 742 | mov(ip, Operand(ExternalReference(Isolate::k_c_entry_fp_address, isolate()))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 743 | str(fp, MemOperand(ip)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 744 | mov(ip, Operand(ExternalReference(Isolate::k_context_address, isolate()))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 745 | str(cp, MemOperand(ip)); |
| 746 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 747 | // Optionally save all double registers. |
| 748 | if (save_doubles) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 749 | sub(sp, sp, Operand(DwVfpRegister::kNumRegisters * kDoubleSize)); |
| 750 | const int offset = -2 * kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 751 | for (int i = 0; i < DwVfpRegister::kNumRegisters; i++) { |
| 752 | DwVfpRegister reg = DwVfpRegister::from_code(i); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 753 | vstr(reg, fp, offset - ((i + 1) * kDoubleSize)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 754 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 755 | // Note that d0 will be accessible at |
| 756 | // fp - 2 * kPointerSize - DwVfpRegister::kNumRegisters * kDoubleSize, |
| 757 | // since the sp slot and code slot were pushed after the fp. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 758 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 759 | |
| 760 | // Reserve place for the return address and stack space and align the frame |
| 761 | // preparing for calling the runtime function. |
| 762 | const int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
| 763 | sub(sp, sp, Operand((stack_space + 1) * kPointerSize)); |
| 764 | if (frame_alignment > 0) { |
| 765 | ASSERT(IsPowerOf2(frame_alignment)); |
| 766 | and_(sp, sp, Operand(-frame_alignment)); |
| 767 | } |
| 768 | |
| 769 | // Set the exit frame sp value to point just before the return address |
| 770 | // location. |
| 771 | add(ip, sp, Operand(kPointerSize)); |
| 772 | str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 776 | void MacroAssembler::InitializeNewString(Register string, |
| 777 | Register length, |
| 778 | Heap::RootListIndex map_index, |
| 779 | Register scratch1, |
| 780 | Register scratch2) { |
| 781 | mov(scratch1, Operand(length, LSL, kSmiTagSize)); |
| 782 | LoadRoot(scratch2, map_index); |
| 783 | str(scratch1, FieldMemOperand(string, String::kLengthOffset)); |
| 784 | mov(scratch1, Operand(String::kEmptyHashField)); |
| 785 | str(scratch2, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 786 | str(scratch1, FieldMemOperand(string, String::kHashFieldOffset)); |
| 787 | } |
| 788 | |
| 789 | |
| 790 | int MacroAssembler::ActivationFrameAlignment() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 791 | #if defined(V8_HOST_ARCH_ARM) |
| 792 | // Running on the real platform. Use the alignment as mandated by the local |
| 793 | // environment. |
| 794 | // Note: This will break if we ever start generating snapshots on one ARM |
| 795 | // platform for another ARM platform with a different alignment. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 796 | return OS::ActivationFrameAlignment(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 797 | #else // defined(V8_HOST_ARCH_ARM) |
| 798 | // If we are using the simulator then we should always align to the expected |
| 799 | // alignment. As the simulator is used to generate snapshots we do not know |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 800 | // if the target platform will need alignment, so this is controlled from a |
| 801 | // flag. |
| 802 | return FLAG_sim_stack_alignment; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 803 | #endif // defined(V8_HOST_ARCH_ARM) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 807 | void MacroAssembler::LeaveExitFrame(bool save_doubles, |
| 808 | Register argument_count) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 809 | // Optionally restore all double registers. |
| 810 | if (save_doubles) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 811 | for (int i = 0; i < DwVfpRegister::kNumRegisters; i++) { |
| 812 | DwVfpRegister reg = DwVfpRegister::from_code(i); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 813 | const int offset = -2 * kPointerSize; |
| 814 | vldr(reg, fp, offset - ((i + 1) * kDoubleSize)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 818 | // Clear top frame. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 819 | mov(r3, Operand(0, RelocInfo::NONE)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 820 | mov(ip, Operand(ExternalReference(Isolate::k_c_entry_fp_address, isolate()))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 821 | str(r3, MemOperand(ip)); |
| 822 | |
| 823 | // Restore current context from top and clear it in debug mode. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 824 | mov(ip, Operand(ExternalReference(Isolate::k_context_address, isolate()))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 825 | ldr(cp, MemOperand(ip)); |
| 826 | #ifdef DEBUG |
| 827 | str(r3, MemOperand(ip)); |
| 828 | #endif |
| 829 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 830 | // Tear down the exit frame, pop the arguments, and return. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 831 | mov(sp, Operand(fp)); |
| 832 | ldm(ia_w, sp, fp.bit() | lr.bit()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 833 | if (argument_count.is_valid()) { |
| 834 | add(sp, sp, Operand(argument_count, LSL, kPointerSizeLog2)); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | void MacroAssembler::GetCFunctionDoubleResult(const DoubleRegister dst) { |
| 839 | #if !defined(USE_ARM_EABI) |
| 840 | UNREACHABLE(); |
| 841 | #else |
| 842 | vmov(dst, r0, r1); |
| 843 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | |
| 847 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 848 | const ParameterCount& actual, |
| 849 | Handle<Code> code_constant, |
| 850 | Register code_reg, |
| 851 | Label* done, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 852 | InvokeFlag flag, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 853 | CallWrapper* call_wrapper) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 854 | bool definitely_matches = false; |
| 855 | Label regular_invoke; |
| 856 | |
| 857 | // Check whether the expected and actual arguments count match. If not, |
| 858 | // setup registers according to contract with ArgumentsAdaptorTrampoline: |
| 859 | // r0: actual arguments count |
| 860 | // r1: function (passed through to callee) |
| 861 | // r2: expected arguments count |
| 862 | // r3: callee code entry |
| 863 | |
| 864 | // The code below is made a lot easier because the calling code already sets |
| 865 | // up actual and expected registers according to the contract if values are |
| 866 | // passed in registers. |
| 867 | ASSERT(actual.is_immediate() || actual.reg().is(r0)); |
| 868 | ASSERT(expected.is_immediate() || expected.reg().is(r2)); |
| 869 | ASSERT((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(r3)); |
| 870 | |
| 871 | if (expected.is_immediate()) { |
| 872 | ASSERT(actual.is_immediate()); |
| 873 | if (expected.immediate() == actual.immediate()) { |
| 874 | definitely_matches = true; |
| 875 | } else { |
| 876 | mov(r0, Operand(actual.immediate())); |
| 877 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 878 | if (expected.immediate() == sentinel) { |
| 879 | // Don't worry about adapting arguments for builtins that |
| 880 | // don't want that done. Skip adaption code by making it look |
| 881 | // like we have a match between expected and actual number of |
| 882 | // arguments. |
| 883 | definitely_matches = true; |
| 884 | } else { |
| 885 | mov(r2, Operand(expected.immediate())); |
| 886 | } |
| 887 | } |
| 888 | } else { |
| 889 | if (actual.is_immediate()) { |
| 890 | cmp(expected.reg(), Operand(actual.immediate())); |
| 891 | b(eq, ®ular_invoke); |
| 892 | mov(r0, Operand(actual.immediate())); |
| 893 | } else { |
| 894 | cmp(expected.reg(), Operand(actual.reg())); |
| 895 | b(eq, ®ular_invoke); |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | if (!definitely_matches) { |
| 900 | if (!code_constant.is_null()) { |
| 901 | mov(r3, Operand(code_constant)); |
| 902 | add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 903 | } |
| 904 | |
| 905 | Handle<Code> adaptor = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 906 | isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 907 | if (flag == CALL_FUNCTION) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 908 | if (call_wrapper != NULL) { |
| 909 | call_wrapper->BeforeCall(CallSize(adaptor, RelocInfo::CODE_TARGET)); |
| 910 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 911 | Call(adaptor, RelocInfo::CODE_TARGET); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 912 | if (call_wrapper != NULL) call_wrapper->AfterCall(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 913 | b(done); |
| 914 | } else { |
| 915 | Jump(adaptor, RelocInfo::CODE_TARGET); |
| 916 | } |
| 917 | bind(®ular_invoke); |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | |
| 922 | void MacroAssembler::InvokeCode(Register code, |
| 923 | const ParameterCount& expected, |
| 924 | const ParameterCount& actual, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 925 | InvokeFlag flag, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 926 | CallWrapper* call_wrapper) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 927 | Label done; |
| 928 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 929 | InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 930 | call_wrapper); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 931 | if (flag == CALL_FUNCTION) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 932 | if (call_wrapper != NULL) call_wrapper->BeforeCall(CallSize(code)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 933 | Call(code); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 934 | if (call_wrapper != NULL) call_wrapper->AfterCall(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 935 | } else { |
| 936 | ASSERT(flag == JUMP_FUNCTION); |
| 937 | Jump(code); |
| 938 | } |
| 939 | |
| 940 | // Continue here if InvokePrologue does handle the invocation due to |
| 941 | // mismatched parameter counts. |
| 942 | bind(&done); |
| 943 | } |
| 944 | |
| 945 | |
| 946 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 947 | const ParameterCount& expected, |
| 948 | const ParameterCount& actual, |
| 949 | RelocInfo::Mode rmode, |
| 950 | InvokeFlag flag) { |
| 951 | Label done; |
| 952 | |
| 953 | InvokePrologue(expected, actual, code, no_reg, &done, flag); |
| 954 | if (flag == CALL_FUNCTION) { |
| 955 | Call(code, rmode); |
| 956 | } else { |
| 957 | Jump(code, rmode); |
| 958 | } |
| 959 | |
| 960 | // Continue here if InvokePrologue does handle the invocation due to |
| 961 | // mismatched parameter counts. |
| 962 | bind(&done); |
| 963 | } |
| 964 | |
| 965 | |
| 966 | void MacroAssembler::InvokeFunction(Register fun, |
| 967 | const ParameterCount& actual, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 968 | InvokeFlag flag, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 969 | CallWrapper* call_wrapper) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 970 | // Contract with called JS functions requires that function is passed in r1. |
| 971 | ASSERT(fun.is(r1)); |
| 972 | |
| 973 | Register expected_reg = r2; |
| 974 | Register code_reg = r3; |
| 975 | |
| 976 | ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 977 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 978 | ldr(expected_reg, |
| 979 | FieldMemOperand(code_reg, |
| 980 | SharedFunctionInfo::kFormalParameterCountOffset)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 981 | mov(expected_reg, Operand(expected_reg, ASR, kSmiTagSize)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 982 | ldr(code_reg, |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 983 | FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 984 | |
| 985 | ParameterCount expected(expected_reg); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 986 | InvokeCode(code_reg, expected, actual, flag, call_wrapper); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 990 | void MacroAssembler::InvokeFunction(JSFunction* function, |
| 991 | const ParameterCount& actual, |
| 992 | InvokeFlag flag) { |
| 993 | ASSERT(function->is_compiled()); |
| 994 | |
| 995 | // Get the function and setup the context. |
| 996 | mov(r1, Operand(Handle<JSFunction>(function))); |
| 997 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 998 | |
| 999 | // Invoke the cached code. |
| 1000 | Handle<Code> code(function->code()); |
| 1001 | ParameterCount expected(function->shared()->formal_parameter_count()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1002 | if (V8::UseCrankshaft()) { |
| 1003 | // TODO(kasperl): For now, we always call indirectly through the |
| 1004 | // code field in the function to allow recompilation to take effect |
| 1005 | // without changing any of the call sites. |
| 1006 | ldr(r3, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
| 1007 | InvokeCode(r3, expected, actual, flag); |
| 1008 | } else { |
| 1009 | InvokeCode(code, expected, actual, RelocInfo::CODE_TARGET, flag); |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | |
| 1014 | void MacroAssembler::IsObjectJSObjectType(Register heap_object, |
| 1015 | Register map, |
| 1016 | Register scratch, |
| 1017 | Label* fail) { |
| 1018 | ldr(map, FieldMemOperand(heap_object, HeapObject::kMapOffset)); |
| 1019 | IsInstanceJSObjectType(map, scratch, fail); |
| 1020 | } |
| 1021 | |
| 1022 | |
| 1023 | void MacroAssembler::IsInstanceJSObjectType(Register map, |
| 1024 | Register scratch, |
| 1025 | Label* fail) { |
| 1026 | ldrb(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1027 | cmp(scratch, Operand(FIRST_JS_OBJECT_TYPE)); |
| 1028 | b(lt, fail); |
| 1029 | cmp(scratch, Operand(LAST_JS_OBJECT_TYPE)); |
| 1030 | b(gt, fail); |
| 1031 | } |
| 1032 | |
| 1033 | |
| 1034 | void MacroAssembler::IsObjectJSStringType(Register object, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1035 | Register scratch, |
| 1036 | Label* fail) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1037 | ASSERT(kNotStringTag != 0); |
| 1038 | |
| 1039 | ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1040 | ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 1041 | tst(scratch, Operand(kIsNotStringMask)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1042 | b(ne, fail); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1045 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1046 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1047 | void MacroAssembler::DebugBreak() { |
| 1048 | ASSERT(allow_stub_calls()); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1049 | mov(r0, Operand(0, RelocInfo::NONE)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1050 | mov(r1, Operand(ExternalReference(Runtime::kDebugBreak, isolate()))); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1051 | CEntryStub ces(1); |
| 1052 | Call(ces.GetCode(), RelocInfo::DEBUG_BREAK); |
| 1053 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1054 | #endif |
| 1055 | |
| 1056 | |
| 1057 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
| 1058 | HandlerType type) { |
| 1059 | // Adjust this code if not the case. |
| 1060 | ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
| 1061 | // The pc (return address) is passed in register lr. |
| 1062 | if (try_location == IN_JAVASCRIPT) { |
| 1063 | if (type == TRY_CATCH_HANDLER) { |
| 1064 | mov(r3, Operand(StackHandler::TRY_CATCH)); |
| 1065 | } else { |
| 1066 | mov(r3, Operand(StackHandler::TRY_FINALLY)); |
| 1067 | } |
| 1068 | ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize |
| 1069 | && StackHandlerConstants::kFPOffset == 2 * kPointerSize |
| 1070 | && StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 1071 | stm(db_w, sp, r3.bit() | fp.bit() | lr.bit()); |
| 1072 | // Save the current handler as the next handler. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1073 | mov(r3, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1074 | ldr(r1, MemOperand(r3)); |
| 1075 | ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1076 | push(r1); |
| 1077 | // Link this handler as the new current one. |
| 1078 | str(sp, MemOperand(r3)); |
| 1079 | } else { |
| 1080 | // Must preserve r0-r4, r5-r7 are available. |
| 1081 | ASSERT(try_location == IN_JS_ENTRY); |
| 1082 | // The frame pointer does not point to a JS frame so we save NULL |
| 1083 | // for fp. We expect the code throwing an exception to check fp |
| 1084 | // before dereferencing it to restore the context. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1085 | mov(ip, Operand(0, RelocInfo::NONE)); // To save a NULL frame pointer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1086 | mov(r6, Operand(StackHandler::ENTRY)); |
| 1087 | ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize |
| 1088 | && StackHandlerConstants::kFPOffset == 2 * kPointerSize |
| 1089 | && StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 1090 | stm(db_w, sp, r6.bit() | ip.bit() | lr.bit()); |
| 1091 | // Save the current handler as the next handler. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1092 | mov(r7, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1093 | ldr(r6, MemOperand(r7)); |
| 1094 | ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1095 | push(r6); |
| 1096 | // Link this handler as the new current one. |
| 1097 | str(sp, MemOperand(r7)); |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1102 | void MacroAssembler::PopTryHandler() { |
| 1103 | ASSERT_EQ(0, StackHandlerConstants::kNextOffset); |
| 1104 | pop(r1); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1105 | mov(ip, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1106 | add(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize)); |
| 1107 | str(r1, MemOperand(ip)); |
| 1108 | } |
| 1109 | |
| 1110 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1111 | void MacroAssembler::Throw(Register value) { |
| 1112 | // r0 is expected to hold the exception. |
| 1113 | if (!value.is(r0)) { |
| 1114 | mov(r0, value); |
| 1115 | } |
| 1116 | |
| 1117 | // Adjust this code if not the case. |
| 1118 | STATIC_ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
| 1119 | |
| 1120 | // Drop the sp to the top of the handler. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1121 | mov(r3, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1122 | ldr(sp, MemOperand(r3)); |
| 1123 | |
| 1124 | // Restore the next handler and frame pointer, discard handler state. |
| 1125 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1126 | pop(r2); |
| 1127 | str(r2, MemOperand(r3)); |
| 1128 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 2 * kPointerSize); |
| 1129 | ldm(ia_w, sp, r3.bit() | fp.bit()); // r3: discarded state. |
| 1130 | |
| 1131 | // Before returning we restore the context from the frame pointer if |
| 1132 | // not NULL. The frame pointer is NULL in the exception handler of a |
| 1133 | // JS entry frame. |
| 1134 | cmp(fp, Operand(0, RelocInfo::NONE)); |
| 1135 | // Set cp to NULL if fp is NULL. |
| 1136 | mov(cp, Operand(0, RelocInfo::NONE), LeaveCC, eq); |
| 1137 | // Restore cp otherwise. |
| 1138 | ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne); |
| 1139 | #ifdef DEBUG |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1140 | if (emit_debug_code()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1141 | mov(lr, Operand(pc)); |
| 1142 | } |
| 1143 | #endif |
| 1144 | STATIC_ASSERT(StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 1145 | pop(pc); |
| 1146 | } |
| 1147 | |
| 1148 | |
| 1149 | void MacroAssembler::ThrowUncatchable(UncatchableExceptionType type, |
| 1150 | Register value) { |
| 1151 | // Adjust this code if not the case. |
| 1152 | STATIC_ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
| 1153 | |
| 1154 | // r0 is expected to hold the exception. |
| 1155 | if (!value.is(r0)) { |
| 1156 | mov(r0, value); |
| 1157 | } |
| 1158 | |
| 1159 | // Drop sp to the top stack handler. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1160 | mov(r3, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1161 | ldr(sp, MemOperand(r3)); |
| 1162 | |
| 1163 | // Unwind the handlers until the ENTRY handler is found. |
| 1164 | Label loop, done; |
| 1165 | bind(&loop); |
| 1166 | // Load the type of the current stack handler. |
| 1167 | const int kStateOffset = StackHandlerConstants::kStateOffset; |
| 1168 | ldr(r2, MemOperand(sp, kStateOffset)); |
| 1169 | cmp(r2, Operand(StackHandler::ENTRY)); |
| 1170 | b(eq, &done); |
| 1171 | // Fetch the next handler in the list. |
| 1172 | const int kNextOffset = StackHandlerConstants::kNextOffset; |
| 1173 | ldr(sp, MemOperand(sp, kNextOffset)); |
| 1174 | jmp(&loop); |
| 1175 | bind(&done); |
| 1176 | |
| 1177 | // Set the top handler address to next handler past the current ENTRY handler. |
| 1178 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1179 | pop(r2); |
| 1180 | str(r2, MemOperand(r3)); |
| 1181 | |
| 1182 | if (type == OUT_OF_MEMORY) { |
| 1183 | // Set external caught exception to false. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1184 | ExternalReference external_caught( |
| 1185 | Isolate::k_external_caught_exception_address, isolate()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1186 | mov(r0, Operand(false, RelocInfo::NONE)); |
| 1187 | mov(r2, Operand(external_caught)); |
| 1188 | str(r0, MemOperand(r2)); |
| 1189 | |
| 1190 | // Set pending exception and r0 to out of memory exception. |
| 1191 | Failure* out_of_memory = Failure::OutOfMemoryException(); |
| 1192 | mov(r0, Operand(reinterpret_cast<int32_t>(out_of_memory))); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1193 | mov(r2, Operand(ExternalReference(Isolate::k_pending_exception_address, |
| 1194 | isolate()))); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1195 | str(r0, MemOperand(r2)); |
| 1196 | } |
| 1197 | |
| 1198 | // Stack layout at this point. See also StackHandlerConstants. |
| 1199 | // sp -> state (ENTRY) |
| 1200 | // fp |
| 1201 | // lr |
| 1202 | |
| 1203 | // Discard handler state (r2 is not used) and restore frame pointer. |
| 1204 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 2 * kPointerSize); |
| 1205 | ldm(ia_w, sp, r2.bit() | fp.bit()); // r2: discarded state. |
| 1206 | // Before returning we restore the context from the frame pointer if |
| 1207 | // not NULL. The frame pointer is NULL in the exception handler of a |
| 1208 | // JS entry frame. |
| 1209 | cmp(fp, Operand(0, RelocInfo::NONE)); |
| 1210 | // Set cp to NULL if fp is NULL. |
| 1211 | mov(cp, Operand(0, RelocInfo::NONE), LeaveCC, eq); |
| 1212 | // Restore cp otherwise. |
| 1213 | ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne); |
| 1214 | #ifdef DEBUG |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1215 | if (emit_debug_code()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1216 | mov(lr, Operand(pc)); |
| 1217 | } |
| 1218 | #endif |
| 1219 | STATIC_ASSERT(StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 1220 | pop(pc); |
| 1221 | } |
| 1222 | |
| 1223 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1224 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
| 1225 | Register scratch, |
| 1226 | Label* miss) { |
| 1227 | Label same_contexts; |
| 1228 | |
| 1229 | ASSERT(!holder_reg.is(scratch)); |
| 1230 | ASSERT(!holder_reg.is(ip)); |
| 1231 | ASSERT(!scratch.is(ip)); |
| 1232 | |
| 1233 | // Load current lexical context from the stack frame. |
| 1234 | ldr(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 1235 | // In debug mode, make sure the lexical context is set. |
| 1236 | #ifdef DEBUG |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1237 | cmp(scratch, Operand(0, RelocInfo::NONE)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1238 | Check(ne, "we should not have an empty lexical context"); |
| 1239 | #endif |
| 1240 | |
| 1241 | // Load the global context of the current context. |
| 1242 | int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 1243 | ldr(scratch, FieldMemOperand(scratch, offset)); |
| 1244 | ldr(scratch, FieldMemOperand(scratch, GlobalObject::kGlobalContextOffset)); |
| 1245 | |
| 1246 | // Check the context is a global context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1247 | if (emit_debug_code()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1248 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 1249 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 1250 | // that ip is clobbered as part of cmp with an object Operand. |
| 1251 | push(holder_reg); // Temporarily save holder on the stack. |
| 1252 | // Read the first word and compare to the global_context_map. |
| 1253 | ldr(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
| 1254 | LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 1255 | cmp(holder_reg, ip); |
| 1256 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 1257 | pop(holder_reg); // Restore holder. |
| 1258 | } |
| 1259 | |
| 1260 | // Check if both contexts are the same. |
| 1261 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 1262 | cmp(scratch, Operand(ip)); |
| 1263 | b(eq, &same_contexts); |
| 1264 | |
| 1265 | // Check the context is a global context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1266 | if (emit_debug_code()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1267 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 1268 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 1269 | // that ip is clobbered as part of cmp with an object Operand. |
| 1270 | push(holder_reg); // Temporarily save holder on the stack. |
| 1271 | mov(holder_reg, ip); // Move ip to its holding place. |
| 1272 | LoadRoot(ip, Heap::kNullValueRootIndex); |
| 1273 | cmp(holder_reg, ip); |
| 1274 | Check(ne, "JSGlobalProxy::context() should not be null."); |
| 1275 | |
| 1276 | ldr(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset)); |
| 1277 | LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 1278 | cmp(holder_reg, ip); |
| 1279 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 1280 | // Restore ip is not needed. ip is reloaded below. |
| 1281 | pop(holder_reg); // Restore holder. |
| 1282 | // Restore ip to holder's context. |
| 1283 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 1284 | } |
| 1285 | |
| 1286 | // Check that the security token in the calling global object is |
| 1287 | // compatible with the security token in the receiving global |
| 1288 | // object. |
| 1289 | int token_offset = Context::kHeaderSize + |
| 1290 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 1291 | |
| 1292 | ldr(scratch, FieldMemOperand(scratch, token_offset)); |
| 1293 | ldr(ip, FieldMemOperand(ip, token_offset)); |
| 1294 | cmp(scratch, Operand(ip)); |
| 1295 | b(ne, miss); |
| 1296 | |
| 1297 | bind(&same_contexts); |
| 1298 | } |
| 1299 | |
| 1300 | |
| 1301 | void MacroAssembler::AllocateInNewSpace(int object_size, |
| 1302 | Register result, |
| 1303 | Register scratch1, |
| 1304 | Register scratch2, |
| 1305 | Label* gc_required, |
| 1306 | AllocationFlags flags) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1307 | if (!FLAG_inline_new) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1308 | if (emit_debug_code()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1309 | // Trash the registers to simulate an allocation failure. |
| 1310 | mov(result, Operand(0x7091)); |
| 1311 | mov(scratch1, Operand(0x7191)); |
| 1312 | mov(scratch2, Operand(0x7291)); |
| 1313 | } |
| 1314 | jmp(gc_required); |
| 1315 | return; |
| 1316 | } |
| 1317 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1318 | ASSERT(!result.is(scratch1)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1319 | ASSERT(!result.is(scratch2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1320 | ASSERT(!scratch1.is(scratch2)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1321 | ASSERT(!scratch1.is(ip)); |
| 1322 | ASSERT(!scratch2.is(ip)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1323 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1324 | // Make object size into bytes. |
| 1325 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 1326 | object_size *= kPointerSize; |
| 1327 | } |
| 1328 | ASSERT_EQ(0, object_size & kObjectAlignmentMask); |
| 1329 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1330 | // Check relative positions of allocation top and limit addresses. |
| 1331 | // The values must be adjacent in memory to allow the use of LDM. |
| 1332 | // Also, assert that the registers are numbered such that the values |
| 1333 | // are loaded in the correct order. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1334 | ExternalReference new_space_allocation_top = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1335 | ExternalReference::new_space_allocation_top_address(isolate()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1336 | ExternalReference new_space_allocation_limit = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1337 | ExternalReference::new_space_allocation_limit_address(isolate()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1338 | intptr_t top = |
| 1339 | reinterpret_cast<intptr_t>(new_space_allocation_top.address()); |
| 1340 | intptr_t limit = |
| 1341 | reinterpret_cast<intptr_t>(new_space_allocation_limit.address()); |
| 1342 | ASSERT((limit - top) == kPointerSize); |
| 1343 | ASSERT(result.code() < ip.code()); |
| 1344 | |
| 1345 | // Set up allocation top address and object size registers. |
| 1346 | Register topaddr = scratch1; |
| 1347 | Register obj_size_reg = scratch2; |
| 1348 | mov(topaddr, Operand(new_space_allocation_top)); |
| 1349 | mov(obj_size_reg, Operand(object_size)); |
| 1350 | |
| 1351 | // This code stores a temporary value in ip. This is OK, as the code below |
| 1352 | // does not need ip for implicit literal generation. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1353 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1354 | // Load allocation top into result and allocation limit into ip. |
| 1355 | ldm(ia, topaddr, result.bit() | ip.bit()); |
| 1356 | } else { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1357 | if (emit_debug_code()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1358 | // Assert that result actually contains top on entry. ip is used |
| 1359 | // immediately below so this use of ip does not cause difference with |
| 1360 | // respect to register content between debug and release mode. |
| 1361 | ldr(ip, MemOperand(topaddr)); |
| 1362 | cmp(result, ip); |
| 1363 | Check(eq, "Unexpected allocation top"); |
| 1364 | } |
| 1365 | // Load allocation limit into ip. Result already contains allocation top. |
| 1366 | ldr(ip, MemOperand(topaddr, limit - top)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | // Calculate new top and bail out if new space is exhausted. Use result |
| 1370 | // to calculate the new top. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1371 | add(scratch2, result, Operand(obj_size_reg), SetCC); |
| 1372 | b(cs, gc_required); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1373 | cmp(scratch2, Operand(ip)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1374 | b(hi, gc_required); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1375 | str(scratch2, MemOperand(topaddr)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1376 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1377 | // Tag object if requested. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1378 | if ((flags & TAG_OBJECT) != 0) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1379 | add(result, result, Operand(kHeapObjectTag)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | |
| 1384 | void MacroAssembler::AllocateInNewSpace(Register object_size, |
| 1385 | Register result, |
| 1386 | Register scratch1, |
| 1387 | Register scratch2, |
| 1388 | Label* gc_required, |
| 1389 | AllocationFlags flags) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1390 | if (!FLAG_inline_new) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1391 | if (emit_debug_code()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1392 | // Trash the registers to simulate an allocation failure. |
| 1393 | mov(result, Operand(0x7091)); |
| 1394 | mov(scratch1, Operand(0x7191)); |
| 1395 | mov(scratch2, Operand(0x7291)); |
| 1396 | } |
| 1397 | jmp(gc_required); |
| 1398 | return; |
| 1399 | } |
| 1400 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1401 | // Assert that the register arguments are different and that none of |
| 1402 | // them are ip. ip is used explicitly in the code generated below. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1403 | ASSERT(!result.is(scratch1)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1404 | ASSERT(!result.is(scratch2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1405 | ASSERT(!scratch1.is(scratch2)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1406 | ASSERT(!result.is(ip)); |
| 1407 | ASSERT(!scratch1.is(ip)); |
| 1408 | ASSERT(!scratch2.is(ip)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1409 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1410 | // Check relative positions of allocation top and limit addresses. |
| 1411 | // The values must be adjacent in memory to allow the use of LDM. |
| 1412 | // Also, assert that the registers are numbered such that the values |
| 1413 | // are loaded in the correct order. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1414 | ExternalReference new_space_allocation_top = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1415 | ExternalReference::new_space_allocation_top_address(isolate()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1416 | ExternalReference new_space_allocation_limit = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1417 | ExternalReference::new_space_allocation_limit_address(isolate()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1418 | intptr_t top = |
| 1419 | reinterpret_cast<intptr_t>(new_space_allocation_top.address()); |
| 1420 | intptr_t limit = |
| 1421 | reinterpret_cast<intptr_t>(new_space_allocation_limit.address()); |
| 1422 | ASSERT((limit - top) == kPointerSize); |
| 1423 | ASSERT(result.code() < ip.code()); |
| 1424 | |
| 1425 | // Set up allocation top address. |
| 1426 | Register topaddr = scratch1; |
| 1427 | mov(topaddr, Operand(new_space_allocation_top)); |
| 1428 | |
| 1429 | // This code stores a temporary value in ip. This is OK, as the code below |
| 1430 | // does not need ip for implicit literal generation. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1431 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1432 | // Load allocation top into result and allocation limit into ip. |
| 1433 | ldm(ia, topaddr, result.bit() | ip.bit()); |
| 1434 | } else { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1435 | if (emit_debug_code()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1436 | // Assert that result actually contains top on entry. ip is used |
| 1437 | // immediately below so this use of ip does not cause difference with |
| 1438 | // respect to register content between debug and release mode. |
| 1439 | ldr(ip, MemOperand(topaddr)); |
| 1440 | cmp(result, ip); |
| 1441 | Check(eq, "Unexpected allocation top"); |
| 1442 | } |
| 1443 | // Load allocation limit into ip. Result already contains allocation top. |
| 1444 | ldr(ip, MemOperand(topaddr, limit - top)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | // Calculate new top and bail out if new space is exhausted. Use result |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1448 | // to calculate the new top. Object size may be in words so a shift is |
| 1449 | // required to get the number of bytes. |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1450 | if ((flags & SIZE_IN_WORDS) != 0) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1451 | add(scratch2, result, Operand(object_size, LSL, kPointerSizeLog2), SetCC); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1452 | } else { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1453 | add(scratch2, result, Operand(object_size), SetCC); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1454 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1455 | b(cs, gc_required); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1456 | cmp(scratch2, Operand(ip)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1457 | b(hi, gc_required); |
| 1458 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1459 | // Update allocation top. result temporarily holds the new top. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1460 | if (emit_debug_code()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1461 | tst(scratch2, Operand(kObjectAlignmentMask)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1462 | Check(eq, "Unaligned allocation in new space"); |
| 1463 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1464 | str(scratch2, MemOperand(topaddr)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1465 | |
| 1466 | // Tag object if requested. |
| 1467 | if ((flags & TAG_OBJECT) != 0) { |
| 1468 | add(result, result, Operand(kHeapObjectTag)); |
| 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | |
| 1473 | void MacroAssembler::UndoAllocationInNewSpace(Register object, |
| 1474 | Register scratch) { |
| 1475 | ExternalReference new_space_allocation_top = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1476 | ExternalReference::new_space_allocation_top_address(isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1477 | |
| 1478 | // Make sure the object has no tag before resetting top. |
| 1479 | and_(object, object, Operand(~kHeapObjectTagMask)); |
| 1480 | #ifdef DEBUG |
| 1481 | // Check that the object un-allocated is below the current top. |
| 1482 | mov(scratch, Operand(new_space_allocation_top)); |
| 1483 | ldr(scratch, MemOperand(scratch)); |
| 1484 | cmp(object, scratch); |
| 1485 | Check(lt, "Undo allocation of non allocated memory"); |
| 1486 | #endif |
| 1487 | // Write the address of the object to un-allocate as the current top. |
| 1488 | mov(scratch, Operand(new_space_allocation_top)); |
| 1489 | str(object, MemOperand(scratch)); |
| 1490 | } |
| 1491 | |
| 1492 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1493 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 1494 | Register length, |
| 1495 | Register scratch1, |
| 1496 | Register scratch2, |
| 1497 | Register scratch3, |
| 1498 | Label* gc_required) { |
| 1499 | // Calculate the number of bytes needed for the characters in the string while |
| 1500 | // observing object alignment. |
| 1501 | ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1502 | mov(scratch1, Operand(length, LSL, 1)); // Length in bytes, not chars. |
| 1503 | add(scratch1, scratch1, |
| 1504 | Operand(kObjectAlignmentMask + SeqTwoByteString::kHeaderSize)); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1505 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1506 | |
| 1507 | // Allocate two-byte string in new space. |
| 1508 | AllocateInNewSpace(scratch1, |
| 1509 | result, |
| 1510 | scratch2, |
| 1511 | scratch3, |
| 1512 | gc_required, |
| 1513 | TAG_OBJECT); |
| 1514 | |
| 1515 | // Set the map, length and hash field. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1516 | InitializeNewString(result, |
| 1517 | length, |
| 1518 | Heap::kStringMapRootIndex, |
| 1519 | scratch1, |
| 1520 | scratch2); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | |
| 1524 | void MacroAssembler::AllocateAsciiString(Register result, |
| 1525 | Register length, |
| 1526 | Register scratch1, |
| 1527 | Register scratch2, |
| 1528 | Register scratch3, |
| 1529 | Label* gc_required) { |
| 1530 | // Calculate the number of bytes needed for the characters in the string while |
| 1531 | // observing object alignment. |
| 1532 | ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1533 | ASSERT(kCharSize == 1); |
| 1534 | add(scratch1, length, |
| 1535 | Operand(kObjectAlignmentMask + SeqAsciiString::kHeaderSize)); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1536 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1537 | |
| 1538 | // Allocate ASCII string in new space. |
| 1539 | AllocateInNewSpace(scratch1, |
| 1540 | result, |
| 1541 | scratch2, |
| 1542 | scratch3, |
| 1543 | gc_required, |
| 1544 | TAG_OBJECT); |
| 1545 | |
| 1546 | // Set the map, length and hash field. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1547 | InitializeNewString(result, |
| 1548 | length, |
| 1549 | Heap::kAsciiStringMapRootIndex, |
| 1550 | scratch1, |
| 1551 | scratch2); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | |
| 1555 | void MacroAssembler::AllocateTwoByteConsString(Register result, |
| 1556 | Register length, |
| 1557 | Register scratch1, |
| 1558 | Register scratch2, |
| 1559 | Label* gc_required) { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1560 | AllocateInNewSpace(ConsString::kSize, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1561 | result, |
| 1562 | scratch1, |
| 1563 | scratch2, |
| 1564 | gc_required, |
| 1565 | TAG_OBJECT); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1566 | |
| 1567 | InitializeNewString(result, |
| 1568 | length, |
| 1569 | Heap::kConsStringMapRootIndex, |
| 1570 | scratch1, |
| 1571 | scratch2); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | |
| 1575 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 1576 | Register length, |
| 1577 | Register scratch1, |
| 1578 | Register scratch2, |
| 1579 | Label* gc_required) { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1580 | AllocateInNewSpace(ConsString::kSize, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1581 | result, |
| 1582 | scratch1, |
| 1583 | scratch2, |
| 1584 | gc_required, |
| 1585 | TAG_OBJECT); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1586 | |
| 1587 | InitializeNewString(result, |
| 1588 | length, |
| 1589 | Heap::kConsAsciiStringMapRootIndex, |
| 1590 | scratch1, |
| 1591 | scratch2); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1595 | void MacroAssembler::CompareObjectType(Register object, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1596 | Register map, |
| 1597 | Register type_reg, |
| 1598 | InstanceType type) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1599 | ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1600 | CompareInstanceType(map, type_reg, type); |
| 1601 | } |
| 1602 | |
| 1603 | |
| 1604 | void MacroAssembler::CompareInstanceType(Register map, |
| 1605 | Register type_reg, |
| 1606 | InstanceType type) { |
| 1607 | ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1608 | cmp(type_reg, Operand(type)); |
| 1609 | } |
| 1610 | |
| 1611 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1612 | void MacroAssembler::CompareRoot(Register obj, |
| 1613 | Heap::RootListIndex index) { |
| 1614 | ASSERT(!obj.is(ip)); |
| 1615 | LoadRoot(ip, index); |
| 1616 | cmp(obj, ip); |
| 1617 | } |
| 1618 | |
| 1619 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1620 | void MacroAssembler::CheckMap(Register obj, |
| 1621 | Register scratch, |
| 1622 | Handle<Map> map, |
| 1623 | Label* fail, |
| 1624 | bool is_heap_object) { |
| 1625 | if (!is_heap_object) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1626 | JumpIfSmi(obj, fail); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1627 | } |
| 1628 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1629 | mov(ip, Operand(map)); |
| 1630 | cmp(scratch, ip); |
| 1631 | b(ne, fail); |
| 1632 | } |
| 1633 | |
| 1634 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1635 | void MacroAssembler::CheckMap(Register obj, |
| 1636 | Register scratch, |
| 1637 | Heap::RootListIndex index, |
| 1638 | Label* fail, |
| 1639 | bool is_heap_object) { |
| 1640 | if (!is_heap_object) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1641 | JumpIfSmi(obj, fail); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1642 | } |
| 1643 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1644 | LoadRoot(ip, index); |
| 1645 | cmp(scratch, ip); |
| 1646 | b(ne, fail); |
| 1647 | } |
| 1648 | |
| 1649 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1650 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 1651 | Register result, |
| 1652 | Register scratch, |
| 1653 | Label* miss) { |
| 1654 | // Check that the receiver isn't a smi. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1655 | JumpIfSmi(function, miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1656 | |
| 1657 | // Check that the function really is a function. Load map into result reg. |
| 1658 | CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE); |
| 1659 | b(ne, miss); |
| 1660 | |
| 1661 | // Make sure that the function has an instance prototype. |
| 1662 | Label non_instance; |
| 1663 | ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 1664 | tst(scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
| 1665 | b(ne, &non_instance); |
| 1666 | |
| 1667 | // Get the prototype or initial map from the function. |
| 1668 | ldr(result, |
| 1669 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1670 | |
| 1671 | // If the prototype or initial map is the hole, don't return it and |
| 1672 | // simply miss the cache instead. This will allow us to allocate a |
| 1673 | // prototype object on-demand in the runtime system. |
| 1674 | LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 1675 | cmp(result, ip); |
| 1676 | b(eq, miss); |
| 1677 | |
| 1678 | // If the function does not have an initial map, we're done. |
| 1679 | Label done; |
| 1680 | CompareObjectType(result, scratch, scratch, MAP_TYPE); |
| 1681 | b(ne, &done); |
| 1682 | |
| 1683 | // Get the prototype from the initial map. |
| 1684 | ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 1685 | jmp(&done); |
| 1686 | |
| 1687 | // Non-instance prototype: Fetch prototype from constructor field |
| 1688 | // in initial map. |
| 1689 | bind(&non_instance); |
| 1690 | ldr(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 1691 | |
| 1692 | // All done. |
| 1693 | bind(&done); |
| 1694 | } |
| 1695 | |
| 1696 | |
| 1697 | void MacroAssembler::CallStub(CodeStub* stub, Condition cond) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1698 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1699 | Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1700 | } |
| 1701 | |
| 1702 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1703 | void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1704 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1705 | Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1706 | } |
| 1707 | |
| 1708 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1709 | MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub, Condition cond) { |
| 1710 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
| 1711 | Object* result; |
| 1712 | { MaybeObject* maybe_result = stub->TryGetCode(); |
| 1713 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1714 | } |
| 1715 | Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1716 | return result; |
| 1717 | } |
| 1718 | |
| 1719 | |
| 1720 | static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { |
| 1721 | return ref0.address() - ref1.address(); |
| 1722 | } |
| 1723 | |
| 1724 | |
| 1725 | MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn( |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1726 | ExternalReference function, int stack_space) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1727 | ExternalReference next_address = |
| 1728 | ExternalReference::handle_scope_next_address(); |
| 1729 | const int kNextOffset = 0; |
| 1730 | const int kLimitOffset = AddressOffset( |
| 1731 | ExternalReference::handle_scope_limit_address(), |
| 1732 | next_address); |
| 1733 | const int kLevelOffset = AddressOffset( |
| 1734 | ExternalReference::handle_scope_level_address(), |
| 1735 | next_address); |
| 1736 | |
| 1737 | // Allocate HandleScope in callee-save registers. |
| 1738 | mov(r7, Operand(next_address)); |
| 1739 | ldr(r4, MemOperand(r7, kNextOffset)); |
| 1740 | ldr(r5, MemOperand(r7, kLimitOffset)); |
| 1741 | ldr(r6, MemOperand(r7, kLevelOffset)); |
| 1742 | add(r6, r6, Operand(1)); |
| 1743 | str(r6, MemOperand(r7, kLevelOffset)); |
| 1744 | |
| 1745 | // Native call returns to the DirectCEntry stub which redirects to the |
| 1746 | // return address pushed on stack (could have moved after GC). |
| 1747 | // DirectCEntry stub itself is generated early and never moves. |
| 1748 | DirectCEntryStub stub; |
| 1749 | stub.GenerateCall(this, function); |
| 1750 | |
| 1751 | Label promote_scheduled_exception; |
| 1752 | Label delete_allocated_handles; |
| 1753 | Label leave_exit_frame; |
| 1754 | |
| 1755 | // If result is non-zero, dereference to get the result value |
| 1756 | // otherwise set it to undefined. |
| 1757 | cmp(r0, Operand(0)); |
| 1758 | LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
| 1759 | ldr(r0, MemOperand(r0), ne); |
| 1760 | |
| 1761 | // No more valid handles (the result handle was the last one). Restore |
| 1762 | // previous handle scope. |
| 1763 | str(r4, MemOperand(r7, kNextOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1764 | if (emit_debug_code()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1765 | ldr(r1, MemOperand(r7, kLevelOffset)); |
| 1766 | cmp(r1, r6); |
| 1767 | Check(eq, "Unexpected level after return from api call"); |
| 1768 | } |
| 1769 | sub(r6, r6, Operand(1)); |
| 1770 | str(r6, MemOperand(r7, kLevelOffset)); |
| 1771 | ldr(ip, MemOperand(r7, kLimitOffset)); |
| 1772 | cmp(r5, ip); |
| 1773 | b(ne, &delete_allocated_handles); |
| 1774 | |
| 1775 | // Check if the function scheduled an exception. |
| 1776 | bind(&leave_exit_frame); |
| 1777 | LoadRoot(r4, Heap::kTheHoleValueRootIndex); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1778 | mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate()))); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1779 | ldr(r5, MemOperand(ip)); |
| 1780 | cmp(r4, r5); |
| 1781 | b(ne, &promote_scheduled_exception); |
| 1782 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1783 | // LeaveExitFrame expects unwind space to be in a register. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1784 | mov(r4, Operand(stack_space)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1785 | LeaveExitFrame(false, r4); |
| 1786 | mov(pc, lr); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1787 | |
| 1788 | bind(&promote_scheduled_exception); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1789 | MaybeObject* result |
| 1790 | = TryTailCallExternalReference( |
| 1791 | ExternalReference(Runtime::kPromoteScheduledException, isolate()), |
| 1792 | 0, |
| 1793 | 1); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1794 | if (result->IsFailure()) { |
| 1795 | return result; |
| 1796 | } |
| 1797 | |
| 1798 | // HandleScope limit has changed. Delete allocated extensions. |
| 1799 | bind(&delete_allocated_handles); |
| 1800 | str(r5, MemOperand(r7, kLimitOffset)); |
| 1801 | mov(r4, r0); |
| 1802 | PrepareCallCFunction(0, r5); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1803 | CallCFunction( |
| 1804 | ExternalReference::delete_handle_scope_extensions(isolate()), 0); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1805 | mov(r0, r4); |
| 1806 | jmp(&leave_exit_frame); |
| 1807 | |
| 1808 | return result; |
| 1809 | } |
| 1810 | |
| 1811 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1812 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 1813 | if (num_arguments > 0) { |
| 1814 | add(sp, sp, Operand(num_arguments * kPointerSize)); |
| 1815 | } |
| 1816 | LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
| 1817 | } |
| 1818 | |
| 1819 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1820 | void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 1821 | // If the hash field contains an array index pick it out. The assert checks |
| 1822 | // that the constants for the maximum number of digits for an array index |
| 1823 | // cached in the hash field and the number of bits reserved for it does not |
| 1824 | // conflict. |
| 1825 | ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < |
| 1826 | (1 << String::kArrayIndexValueBits)); |
| 1827 | // We want the smi-tagged index in key. kArrayIndexValueMask has zeros in |
| 1828 | // the low kHashShift bits. |
| 1829 | STATIC_ASSERT(kSmiTag == 0); |
| 1830 | Ubfx(hash, hash, String::kHashShift, String::kArrayIndexValueBits); |
| 1831 | mov(index, Operand(hash, LSL, kSmiTagSize)); |
| 1832 | } |
| 1833 | |
| 1834 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1835 | void MacroAssembler::IntegerToDoubleConversionWithVFP3(Register inReg, |
| 1836 | Register outHighReg, |
| 1837 | Register outLowReg) { |
| 1838 | // ARMv7 VFP3 instructions to implement integer to double conversion. |
| 1839 | mov(r7, Operand(inReg, ASR, kSmiTagSize)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1840 | vmov(s15, r7); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1841 | vcvt_f64_s32(d7, s15); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1842 | vmov(outLowReg, outHighReg, d7); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1846 | void MacroAssembler::ObjectToDoubleVFPRegister(Register object, |
| 1847 | DwVfpRegister result, |
| 1848 | Register scratch1, |
| 1849 | Register scratch2, |
| 1850 | Register heap_number_map, |
| 1851 | SwVfpRegister scratch3, |
| 1852 | Label* not_number, |
| 1853 | ObjectToDoubleFlags flags) { |
| 1854 | Label done; |
| 1855 | if ((flags & OBJECT_NOT_SMI) == 0) { |
| 1856 | Label not_smi; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1857 | JumpIfNotSmi(object, ¬_smi); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1858 | // Remove smi tag and convert to double. |
| 1859 | mov(scratch1, Operand(object, ASR, kSmiTagSize)); |
| 1860 | vmov(scratch3, scratch1); |
| 1861 | vcvt_f64_s32(result, scratch3); |
| 1862 | b(&done); |
| 1863 | bind(¬_smi); |
| 1864 | } |
| 1865 | // Check for heap number and load double value from it. |
| 1866 | ldr(scratch1, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1867 | sub(scratch2, object, Operand(kHeapObjectTag)); |
| 1868 | cmp(scratch1, heap_number_map); |
| 1869 | b(ne, not_number); |
| 1870 | if ((flags & AVOID_NANS_AND_INFINITIES) != 0) { |
| 1871 | // If exponent is all ones the number is either a NaN or +/-Infinity. |
| 1872 | ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 1873 | Sbfx(scratch1, |
| 1874 | scratch1, |
| 1875 | HeapNumber::kExponentShift, |
| 1876 | HeapNumber::kExponentBits); |
| 1877 | // All-one value sign extend to -1. |
| 1878 | cmp(scratch1, Operand(-1)); |
| 1879 | b(eq, not_number); |
| 1880 | } |
| 1881 | vldr(result, scratch2, HeapNumber::kValueOffset); |
| 1882 | bind(&done); |
| 1883 | } |
| 1884 | |
| 1885 | |
| 1886 | void MacroAssembler::SmiToDoubleVFPRegister(Register smi, |
| 1887 | DwVfpRegister value, |
| 1888 | Register scratch1, |
| 1889 | SwVfpRegister scratch2) { |
| 1890 | mov(scratch1, Operand(smi, ASR, kSmiTagSize)); |
| 1891 | vmov(scratch2, scratch1); |
| 1892 | vcvt_f64_s32(value, scratch2); |
| 1893 | } |
| 1894 | |
| 1895 | |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1896 | // Tries to get a signed int32 out of a double precision floating point heap |
| 1897 | // number. Rounds towards 0. Branch to 'not_int32' if the double is out of the |
| 1898 | // 32bits signed integer range. |
| 1899 | void MacroAssembler::ConvertToInt32(Register source, |
| 1900 | Register dest, |
| 1901 | Register scratch, |
| 1902 | Register scratch2, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1903 | DwVfpRegister double_scratch, |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1904 | Label *not_int32) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 1905 | if (Isolate::Current()->cpu_features()->IsSupported(VFP3)) { |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1906 | CpuFeatures::Scope scope(VFP3); |
| 1907 | sub(scratch, source, Operand(kHeapObjectTag)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1908 | vldr(double_scratch, scratch, HeapNumber::kValueOffset); |
| 1909 | vcvt_s32_f64(double_scratch.low(), double_scratch); |
| 1910 | vmov(dest, double_scratch.low()); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1911 | // Signed vcvt instruction will saturate to the minimum (0x80000000) or |
| 1912 | // maximun (0x7fffffff) signed 32bits integer when the double is out of |
| 1913 | // range. When substracting one, the minimum signed integer becomes the |
| 1914 | // maximun signed integer. |
| 1915 | sub(scratch, dest, Operand(1)); |
| 1916 | cmp(scratch, Operand(LONG_MAX - 1)); |
| 1917 | // If equal then dest was LONG_MAX, if greater dest was LONG_MIN. |
| 1918 | b(ge, not_int32); |
| 1919 | } else { |
| 1920 | // This code is faster for doubles that are in the ranges -0x7fffffff to |
| 1921 | // -0x40000000 or 0x40000000 to 0x7fffffff. This corresponds almost to |
| 1922 | // the range of signed int32 values that are not Smis. Jumps to the label |
| 1923 | // 'not_int32' if the double isn't in the range -0x80000000.0 to |
| 1924 | // 0x80000000.0 (excluding the endpoints). |
| 1925 | Label right_exponent, done; |
| 1926 | // Get exponent word. |
| 1927 | ldr(scratch, FieldMemOperand(source, HeapNumber::kExponentOffset)); |
| 1928 | // Get exponent alone in scratch2. |
| 1929 | Ubfx(scratch2, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1930 | scratch, |
| 1931 | HeapNumber::kExponentShift, |
| 1932 | HeapNumber::kExponentBits); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1933 | // Load dest with zero. We use this either for the final shift or |
| 1934 | // for the answer. |
| 1935 | mov(dest, Operand(0, RelocInfo::NONE)); |
| 1936 | // Check whether the exponent matches a 32 bit signed int that is not a Smi. |
| 1937 | // A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). This is |
| 1938 | // the exponent that we are fastest at and also the highest exponent we can |
| 1939 | // handle here. |
| 1940 | const uint32_t non_smi_exponent = HeapNumber::kExponentBias + 30; |
| 1941 | // The non_smi_exponent, 0x41d, is too big for ARM's immediate field so we |
| 1942 | // split it up to avoid a constant pool entry. You can't do that in general |
| 1943 | // for cmp because of the overflow flag, but we know the exponent is in the |
| 1944 | // range 0-2047 so there is no overflow. |
| 1945 | int fudge_factor = 0x400; |
| 1946 | sub(scratch2, scratch2, Operand(fudge_factor)); |
| 1947 | cmp(scratch2, Operand(non_smi_exponent - fudge_factor)); |
| 1948 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 1949 | // logic. |
| 1950 | b(eq, &right_exponent); |
| 1951 | // If the exponent is higher than that then go to slow case. This catches |
| 1952 | // numbers that don't fit in a signed int32, infinities and NaNs. |
| 1953 | b(gt, not_int32); |
| 1954 | |
| 1955 | // We know the exponent is smaller than 30 (biased). If it is less than |
| 1956 | // 0 (biased) then the number is smaller in magnitude than 1.0 * 2^0, ie |
| 1957 | // it rounds to zero. |
| 1958 | const uint32_t zero_exponent = HeapNumber::kExponentBias + 0; |
| 1959 | sub(scratch2, scratch2, Operand(zero_exponent - fudge_factor), SetCC); |
| 1960 | // Dest already has a Smi zero. |
| 1961 | b(lt, &done); |
| 1962 | |
| 1963 | // We have an exponent between 0 and 30 in scratch2. Subtract from 30 to |
| 1964 | // get how much to shift down. |
| 1965 | rsb(dest, scratch2, Operand(30)); |
| 1966 | |
| 1967 | bind(&right_exponent); |
| 1968 | // Get the top bits of the mantissa. |
| 1969 | and_(scratch2, scratch, Operand(HeapNumber::kMantissaMask)); |
| 1970 | // Put back the implicit 1. |
| 1971 | orr(scratch2, scratch2, Operand(1 << HeapNumber::kExponentShift)); |
| 1972 | // Shift up the mantissa bits to take up the space the exponent used to |
| 1973 | // take. We just orred in the implicit bit so that took care of one and |
| 1974 | // we want to leave the sign bit 0 so we subtract 2 bits from the shift |
| 1975 | // distance. |
| 1976 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 1977 | mov(scratch2, Operand(scratch2, LSL, shift_distance)); |
| 1978 | // Put sign in zero flag. |
| 1979 | tst(scratch, Operand(HeapNumber::kSignMask)); |
| 1980 | // Get the second half of the double. For some exponents we don't |
| 1981 | // actually need this because the bits get shifted out again, but |
| 1982 | // it's probably slower to test than just to do it. |
| 1983 | ldr(scratch, FieldMemOperand(source, HeapNumber::kMantissaOffset)); |
| 1984 | // Shift down 22 bits to get the last 10 bits. |
| 1985 | orr(scratch, scratch2, Operand(scratch, LSR, 32 - shift_distance)); |
| 1986 | // Move down according to the exponent. |
| 1987 | mov(dest, Operand(scratch, LSR, dest)); |
| 1988 | // Fix sign if sign bit was set. |
| 1989 | rsb(dest, dest, Operand(0, RelocInfo::NONE), LeaveCC, ne); |
| 1990 | bind(&done); |
| 1991 | } |
| 1992 | } |
| 1993 | |
| 1994 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1995 | void MacroAssembler::EmitVFPTruncate(VFPRoundingMode rounding_mode, |
| 1996 | SwVfpRegister result, |
| 1997 | DwVfpRegister double_input, |
| 1998 | Register scratch1, |
| 1999 | Register scratch2, |
| 2000 | CheckForInexactConversion check_inexact) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2001 | ASSERT(Isolate::Current()->cpu_features()->IsSupported(VFP3)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2002 | CpuFeatures::Scope scope(VFP3); |
| 2003 | Register prev_fpscr = scratch1; |
| 2004 | Register scratch = scratch2; |
| 2005 | |
| 2006 | int32_t check_inexact_conversion = |
| 2007 | (check_inexact == kCheckForInexactConversion) ? kVFPInexactExceptionBit : 0; |
| 2008 | |
| 2009 | // Set custom FPCSR: |
| 2010 | // - Set rounding mode. |
| 2011 | // - Clear vfp cumulative exception flags. |
| 2012 | // - Make sure Flush-to-zero mode control bit is unset. |
| 2013 | vmrs(prev_fpscr); |
| 2014 | bic(scratch, |
| 2015 | prev_fpscr, |
| 2016 | Operand(kVFPExceptionMask | |
| 2017 | check_inexact_conversion | |
| 2018 | kVFPRoundingModeMask | |
| 2019 | kVFPFlushToZeroMask)); |
| 2020 | // 'Round To Nearest' is encoded by 0b00 so no bits need to be set. |
| 2021 | if (rounding_mode != kRoundToNearest) { |
| 2022 | orr(scratch, scratch, Operand(rounding_mode)); |
| 2023 | } |
| 2024 | vmsr(scratch); |
| 2025 | |
| 2026 | // Convert the argument to an integer. |
| 2027 | vcvt_s32_f64(result, |
| 2028 | double_input, |
| 2029 | (rounding_mode == kRoundToZero) ? kDefaultRoundToZero |
| 2030 | : kFPSCRRounding); |
| 2031 | |
| 2032 | // Retrieve FPSCR. |
| 2033 | vmrs(scratch); |
| 2034 | // Restore FPSCR. |
| 2035 | vmsr(prev_fpscr); |
| 2036 | // Check for vfp exceptions. |
| 2037 | tst(scratch, Operand(kVFPExceptionMask | check_inexact_conversion)); |
| 2038 | } |
| 2039 | |
| 2040 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2041 | void MacroAssembler::EmitOutOfInt32RangeTruncate(Register result, |
| 2042 | Register input_high, |
| 2043 | Register input_low, |
| 2044 | Register scratch) { |
| 2045 | Label done, normal_exponent, restore_sign; |
| 2046 | |
| 2047 | // Extract the biased exponent in result. |
| 2048 | Ubfx(result, |
| 2049 | input_high, |
| 2050 | HeapNumber::kExponentShift, |
| 2051 | HeapNumber::kExponentBits); |
| 2052 | |
| 2053 | // Check for Infinity and NaNs, which should return 0. |
| 2054 | cmp(result, Operand(HeapNumber::kExponentMask)); |
| 2055 | mov(result, Operand(0), LeaveCC, eq); |
| 2056 | b(eq, &done); |
| 2057 | |
| 2058 | // Express exponent as delta to (number of mantissa bits + 31). |
| 2059 | sub(result, |
| 2060 | result, |
| 2061 | Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31), |
| 2062 | SetCC); |
| 2063 | |
| 2064 | // If the delta is strictly positive, all bits would be shifted away, |
| 2065 | // which means that we can return 0. |
| 2066 | b(le, &normal_exponent); |
| 2067 | mov(result, Operand(0)); |
| 2068 | b(&done); |
| 2069 | |
| 2070 | bind(&normal_exponent); |
| 2071 | const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 2072 | // Calculate shift. |
| 2073 | add(scratch, result, Operand(kShiftBase + HeapNumber::kMantissaBits), SetCC); |
| 2074 | |
| 2075 | // Save the sign. |
| 2076 | Register sign = result; |
| 2077 | result = no_reg; |
| 2078 | and_(sign, input_high, Operand(HeapNumber::kSignMask)); |
| 2079 | |
| 2080 | // Set the implicit 1 before the mantissa part in input_high. |
| 2081 | orr(input_high, |
| 2082 | input_high, |
| 2083 | Operand(1 << HeapNumber::kMantissaBitsInTopWord)); |
| 2084 | // Shift the mantissa bits to the correct position. |
| 2085 | // We don't need to clear non-mantissa bits as they will be shifted away. |
| 2086 | // If they weren't, it would mean that the answer is in the 32bit range. |
| 2087 | mov(input_high, Operand(input_high, LSL, scratch)); |
| 2088 | |
| 2089 | // Replace the shifted bits with bits from the lower mantissa word. |
| 2090 | Label pos_shift, shift_done; |
| 2091 | rsb(scratch, scratch, Operand(32), SetCC); |
| 2092 | b(&pos_shift, ge); |
| 2093 | |
| 2094 | // Negate scratch. |
| 2095 | rsb(scratch, scratch, Operand(0)); |
| 2096 | mov(input_low, Operand(input_low, LSL, scratch)); |
| 2097 | b(&shift_done); |
| 2098 | |
| 2099 | bind(&pos_shift); |
| 2100 | mov(input_low, Operand(input_low, LSR, scratch)); |
| 2101 | |
| 2102 | bind(&shift_done); |
| 2103 | orr(input_high, input_high, Operand(input_low)); |
| 2104 | // Restore sign if necessary. |
| 2105 | cmp(sign, Operand(0)); |
| 2106 | result = sign; |
| 2107 | sign = no_reg; |
| 2108 | rsb(result, input_high, Operand(0), LeaveCC, ne); |
| 2109 | mov(result, input_high, LeaveCC, eq); |
| 2110 | bind(&done); |
| 2111 | } |
| 2112 | |
| 2113 | |
| 2114 | void MacroAssembler::EmitECMATruncate(Register result, |
| 2115 | DwVfpRegister double_input, |
| 2116 | SwVfpRegister single_scratch, |
| 2117 | Register scratch, |
| 2118 | Register input_high, |
| 2119 | Register input_low) { |
| 2120 | CpuFeatures::Scope scope(VFP3); |
| 2121 | ASSERT(!input_high.is(result)); |
| 2122 | ASSERT(!input_low.is(result)); |
| 2123 | ASSERT(!input_low.is(input_high)); |
| 2124 | ASSERT(!scratch.is(result) && |
| 2125 | !scratch.is(input_high) && |
| 2126 | !scratch.is(input_low)); |
| 2127 | ASSERT(!single_scratch.is(double_input.low()) && |
| 2128 | !single_scratch.is(double_input.high())); |
| 2129 | |
| 2130 | Label done; |
| 2131 | |
| 2132 | // Clear cumulative exception flags. |
| 2133 | ClearFPSCRBits(kVFPExceptionMask, scratch); |
| 2134 | // Try a conversion to a signed integer. |
| 2135 | vcvt_s32_f64(single_scratch, double_input); |
| 2136 | vmov(result, single_scratch); |
| 2137 | // Retrieve he FPSCR. |
| 2138 | vmrs(scratch); |
| 2139 | // Check for overflow and NaNs. |
| 2140 | tst(scratch, Operand(kVFPOverflowExceptionBit | |
| 2141 | kVFPUnderflowExceptionBit | |
| 2142 | kVFPInvalidOpExceptionBit)); |
| 2143 | // If we had no exceptions we are done. |
| 2144 | b(eq, &done); |
| 2145 | |
| 2146 | // Load the double value and perform a manual truncation. |
| 2147 | vmov(input_low, input_high, double_input); |
| 2148 | EmitOutOfInt32RangeTruncate(result, |
| 2149 | input_high, |
| 2150 | input_low, |
| 2151 | scratch); |
| 2152 | bind(&done); |
| 2153 | } |
| 2154 | |
| 2155 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2156 | void MacroAssembler::GetLeastBitsFromSmi(Register dst, |
| 2157 | Register src, |
| 2158 | int num_least_bits) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2159 | if (Isolate::Current()->cpu_features()->IsSupported(ARMv7)) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2160 | ubfx(dst, src, kSmiTagSize, num_least_bits); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2161 | } else { |
| 2162 | mov(dst, Operand(src, ASR, kSmiTagSize)); |
| 2163 | and_(dst, dst, Operand((1 << num_least_bits) - 1)); |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2168 | void MacroAssembler::GetLeastBitsFromInt32(Register dst, |
| 2169 | Register src, |
| 2170 | int num_least_bits) { |
| 2171 | and_(dst, src, Operand((1 << num_least_bits) - 1)); |
| 2172 | } |
| 2173 | |
| 2174 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2175 | void MacroAssembler::CallRuntime(const Runtime::Function* f, |
| 2176 | int num_arguments) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2177 | // All parameters are on the stack. r0 has the return value after call. |
| 2178 | |
| 2179 | // If the expected number of arguments of the runtime function is |
| 2180 | // constant, we check that the actual number of arguments match the |
| 2181 | // expectation. |
| 2182 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 2183 | IllegalOperation(num_arguments); |
| 2184 | return; |
| 2185 | } |
| 2186 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 2187 | // TODO(1236192): Most runtime routines don't need the number of |
| 2188 | // arguments passed in because it is constant. At some point we |
| 2189 | // should remove this need and make the runtime routine entry code |
| 2190 | // smarter. |
| 2191 | mov(r0, Operand(num_arguments)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2192 | mov(r1, Operand(ExternalReference(f, isolate()))); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 2193 | CEntryStub stub(1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2194 | CallStub(&stub); |
| 2195 | } |
| 2196 | |
| 2197 | |
| 2198 | void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) { |
| 2199 | CallRuntime(Runtime::FunctionForId(fid), num_arguments); |
| 2200 | } |
| 2201 | |
| 2202 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2203 | void MacroAssembler::CallRuntimeSaveDoubles(Runtime::FunctionId id) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2204 | const Runtime::Function* function = Runtime::FunctionForId(id); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2205 | mov(r0, Operand(function->nargs)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2206 | mov(r1, Operand(ExternalReference(function, isolate()))); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2207 | CEntryStub stub(1); |
| 2208 | stub.SaveDoubles(); |
| 2209 | CallStub(&stub); |
| 2210 | } |
| 2211 | |
| 2212 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2213 | void MacroAssembler::CallExternalReference(const ExternalReference& ext, |
| 2214 | int num_arguments) { |
| 2215 | mov(r0, Operand(num_arguments)); |
| 2216 | mov(r1, Operand(ext)); |
| 2217 | |
| 2218 | CEntryStub stub(1); |
| 2219 | CallStub(&stub); |
| 2220 | } |
| 2221 | |
| 2222 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2223 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 2224 | int num_arguments, |
| 2225 | int result_size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2226 | // TODO(1236192): Most runtime routines don't need the number of |
| 2227 | // arguments passed in because it is constant. At some point we |
| 2228 | // should remove this need and make the runtime routine entry code |
| 2229 | // smarter. |
| 2230 | mov(r0, Operand(num_arguments)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2231 | JumpToExternalReference(ext); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2235 | MaybeObject* MacroAssembler::TryTailCallExternalReference( |
| 2236 | const ExternalReference& ext, int num_arguments, int result_size) { |
| 2237 | // TODO(1236192): Most runtime routines don't need the number of |
| 2238 | // arguments passed in because it is constant. At some point we |
| 2239 | // should remove this need and make the runtime routine entry code |
| 2240 | // smarter. |
| 2241 | mov(r0, Operand(num_arguments)); |
| 2242 | return TryJumpToExternalReference(ext); |
| 2243 | } |
| 2244 | |
| 2245 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2246 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 2247 | int num_arguments, |
| 2248 | int result_size) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2249 | TailCallExternalReference(ExternalReference(fid, isolate()), |
| 2250 | num_arguments, |
| 2251 | result_size); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | |
| 2255 | void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2256 | #if defined(__thumb__) |
| 2257 | // Thumb mode builtin. |
| 2258 | ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 2259 | #endif |
| 2260 | mov(r1, Operand(builtin)); |
| 2261 | CEntryStub stub(1); |
| 2262 | Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 2263 | } |
| 2264 | |
| 2265 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2266 | MaybeObject* MacroAssembler::TryJumpToExternalReference( |
| 2267 | const ExternalReference& builtin) { |
| 2268 | #if defined(__thumb__) |
| 2269 | // Thumb mode builtin. |
| 2270 | ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 2271 | #endif |
| 2272 | mov(r1, Operand(builtin)); |
| 2273 | CEntryStub stub(1); |
| 2274 | return TryTailCallStub(&stub); |
| 2275 | } |
| 2276 | |
| 2277 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2278 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2279 | InvokeJSFlags flags, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2280 | CallWrapper* call_wrapper) { |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2281 | GetBuiltinEntry(r2, id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2282 | if (flags == CALL_JS) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2283 | if (call_wrapper != NULL) call_wrapper->BeforeCall(CallSize(r2)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2284 | Call(r2); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2285 | if (call_wrapper != NULL) call_wrapper->AfterCall(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2286 | } else { |
| 2287 | ASSERT(flags == JUMP_JS); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2288 | Jump(r2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 2293 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 2294 | Builtins::JavaScript id) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2295 | // Load the builtins object into target register. |
| 2296 | ldr(target, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 2297 | ldr(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2298 | // Load the JavaScript builtin function from the builtins object. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2299 | ldr(target, FieldMemOperand(target, |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 2300 | JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
| 2301 | } |
| 2302 | |
| 2303 | |
| 2304 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
| 2305 | ASSERT(!target.is(r1)); |
| 2306 | GetBuiltinFunction(r1, id); |
| 2307 | // Load the code entry point from the builtins object. |
| 2308 | ldr(target, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | |
| 2312 | void MacroAssembler::SetCounter(StatsCounter* counter, int value, |
| 2313 | Register scratch1, Register scratch2) { |
| 2314 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2315 | mov(scratch1, Operand(value)); |
| 2316 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2317 | str(scratch1, MemOperand(scratch2)); |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | |
| 2322 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value, |
| 2323 | Register scratch1, Register scratch2) { |
| 2324 | ASSERT(value > 0); |
| 2325 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2326 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2327 | ldr(scratch1, MemOperand(scratch2)); |
| 2328 | add(scratch1, scratch1, Operand(value)); |
| 2329 | str(scratch1, MemOperand(scratch2)); |
| 2330 | } |
| 2331 | } |
| 2332 | |
| 2333 | |
| 2334 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value, |
| 2335 | Register scratch1, Register scratch2) { |
| 2336 | ASSERT(value > 0); |
| 2337 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2338 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2339 | ldr(scratch1, MemOperand(scratch2)); |
| 2340 | sub(scratch1, scratch1, Operand(value)); |
| 2341 | str(scratch1, MemOperand(scratch2)); |
| 2342 | } |
| 2343 | } |
| 2344 | |
| 2345 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2346 | void MacroAssembler::Assert(Condition cond, const char* msg) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2347 | if (emit_debug_code()) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2348 | Check(cond, msg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
| 2351 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2352 | void MacroAssembler::AssertRegisterIsRoot(Register reg, |
| 2353 | Heap::RootListIndex index) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2354 | if (emit_debug_code()) { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2355 | LoadRoot(ip, index); |
| 2356 | cmp(reg, ip); |
| 2357 | Check(eq, "Register did not match expected root"); |
| 2358 | } |
| 2359 | } |
| 2360 | |
| 2361 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2362 | void MacroAssembler::AssertFastElements(Register elements) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2363 | if (emit_debug_code()) { |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2364 | ASSERT(!elements.is(ip)); |
| 2365 | Label ok; |
| 2366 | push(elements); |
| 2367 | ldr(elements, FieldMemOperand(elements, HeapObject::kMapOffset)); |
| 2368 | LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 2369 | cmp(elements, ip); |
| 2370 | b(eq, &ok); |
| 2371 | LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex); |
| 2372 | cmp(elements, ip); |
| 2373 | b(eq, &ok); |
| 2374 | Abort("JSObject with fast elements map has slow elements"); |
| 2375 | bind(&ok); |
| 2376 | pop(elements); |
| 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2381 | void MacroAssembler::Check(Condition cond, const char* msg) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2382 | Label L; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2383 | b(cond, &L); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2384 | Abort(msg); |
| 2385 | // will not return here |
| 2386 | bind(&L); |
| 2387 | } |
| 2388 | |
| 2389 | |
| 2390 | void MacroAssembler::Abort(const char* msg) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2391 | Label abort_start; |
| 2392 | bind(&abort_start); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2393 | // We want to pass the msg string like a smi to avoid GC |
| 2394 | // problems, however msg is not guaranteed to be aligned |
| 2395 | // properly. Instead, we pass an aligned pointer that is |
| 2396 | // a proper v8 smi, but also pass the alignment difference |
| 2397 | // from the real pointer as a smi. |
| 2398 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 2399 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 2400 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 2401 | #ifdef DEBUG |
| 2402 | if (msg != NULL) { |
| 2403 | RecordComment("Abort message: "); |
| 2404 | RecordComment(msg); |
| 2405 | } |
| 2406 | #endif |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2407 | // Disable stub call restrictions to always allow calls to abort. |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2408 | AllowStubCallsScope allow_scope(this, true); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2409 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2410 | mov(r0, Operand(p0)); |
| 2411 | push(r0); |
| 2412 | mov(r0, Operand(Smi::FromInt(p1 - p0))); |
| 2413 | push(r0); |
| 2414 | CallRuntime(Runtime::kAbort, 2); |
| 2415 | // will not return here |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2416 | if (is_const_pool_blocked()) { |
| 2417 | // If the calling code cares about the exact number of |
| 2418 | // instructions generated, we insert padding here to keep the size |
| 2419 | // of the Abort macro constant. |
| 2420 | static const int kExpectedAbortInstructions = 10; |
| 2421 | int abort_instructions = InstructionsGeneratedSince(&abort_start); |
| 2422 | ASSERT(abort_instructions <= kExpectedAbortInstructions); |
| 2423 | while (abort_instructions++ < kExpectedAbortInstructions) { |
| 2424 | nop(); |
| 2425 | } |
| 2426 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2430 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 2431 | if (context_chain_length > 0) { |
| 2432 | // Move up the chain of contexts to the context containing the slot. |
| 2433 | ldr(dst, MemOperand(cp, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 2434 | // Load the function context (which is the incoming, outer context). |
| 2435 | ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset)); |
| 2436 | for (int i = 1; i < context_chain_length; i++) { |
| 2437 | ldr(dst, MemOperand(dst, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 2438 | ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset)); |
| 2439 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2440 | } else { |
| 2441 | // Slot is in the current function context. Move it into the |
| 2442 | // destination register in case we store into it (the write barrier |
| 2443 | // cannot be allowed to destroy the context in esi). |
| 2444 | mov(dst, cp); |
| 2445 | } |
| 2446 | |
| 2447 | // We should not have found a 'with' context by walking the context chain |
| 2448 | // (i.e., the static scope chain and runtime context chain do not agree). |
| 2449 | // A variable occurring in such a scope should have slot type LOOKUP and |
| 2450 | // not CONTEXT. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2451 | if (emit_debug_code()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2452 | ldr(ip, MemOperand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 2453 | cmp(dst, ip); |
| 2454 | Check(eq, "Yo dawg, I heard you liked function contexts " |
| 2455 | "so I put function contexts in all your contexts"); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2456 | } |
| 2457 | } |
| 2458 | |
| 2459 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2460 | void MacroAssembler::LoadGlobalFunction(int index, Register function) { |
| 2461 | // Load the global or builtins object from the current context. |
| 2462 | ldr(function, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 2463 | // Load the global context from the global or builtins object. |
| 2464 | ldr(function, FieldMemOperand(function, |
| 2465 | GlobalObject::kGlobalContextOffset)); |
| 2466 | // Load the function from the global context. |
| 2467 | ldr(function, MemOperand(function, Context::SlotOffset(index))); |
| 2468 | } |
| 2469 | |
| 2470 | |
| 2471 | void MacroAssembler::LoadGlobalFunctionInitialMap(Register function, |
| 2472 | Register map, |
| 2473 | Register scratch) { |
| 2474 | // Load the initial map. The global functions all have initial maps. |
| 2475 | ldr(map, FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2476 | if (emit_debug_code()) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2477 | Label ok, fail; |
| 2478 | CheckMap(map, scratch, Heap::kMetaMapRootIndex, &fail, false); |
| 2479 | b(&ok); |
| 2480 | bind(&fail); |
| 2481 | Abort("Global functions must have initial map"); |
| 2482 | bind(&ok); |
| 2483 | } |
| 2484 | } |
| 2485 | |
| 2486 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2487 | void MacroAssembler::JumpIfNotPowerOfTwoOrZero( |
| 2488 | Register reg, |
| 2489 | Register scratch, |
| 2490 | Label* not_power_of_two_or_zero) { |
| 2491 | sub(scratch, reg, Operand(1), SetCC); |
| 2492 | b(mi, not_power_of_two_or_zero); |
| 2493 | tst(scratch, reg); |
| 2494 | b(ne, not_power_of_two_or_zero); |
| 2495 | } |
| 2496 | |
| 2497 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2498 | void MacroAssembler::JumpIfNotPowerOfTwoOrZeroAndNeg( |
| 2499 | Register reg, |
| 2500 | Register scratch, |
| 2501 | Label* zero_and_neg, |
| 2502 | Label* not_power_of_two) { |
| 2503 | sub(scratch, reg, Operand(1), SetCC); |
| 2504 | b(mi, zero_and_neg); |
| 2505 | tst(scratch, reg); |
| 2506 | b(ne, not_power_of_two); |
| 2507 | } |
| 2508 | |
| 2509 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2510 | void MacroAssembler::JumpIfNotBothSmi(Register reg1, |
| 2511 | Register reg2, |
| 2512 | Label* on_not_both_smi) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2513 | STATIC_ASSERT(kSmiTag == 0); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2514 | tst(reg1, Operand(kSmiTagMask)); |
| 2515 | tst(reg2, Operand(kSmiTagMask), eq); |
| 2516 | b(ne, on_not_both_smi); |
| 2517 | } |
| 2518 | |
| 2519 | |
| 2520 | void MacroAssembler::JumpIfEitherSmi(Register reg1, |
| 2521 | Register reg2, |
| 2522 | Label* on_either_smi) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2523 | STATIC_ASSERT(kSmiTag == 0); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2524 | tst(reg1, Operand(kSmiTagMask)); |
| 2525 | tst(reg2, Operand(kSmiTagMask), ne); |
| 2526 | b(eq, on_either_smi); |
| 2527 | } |
| 2528 | |
| 2529 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2530 | void MacroAssembler::AbortIfSmi(Register object) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2531 | STATIC_ASSERT(kSmiTag == 0); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2532 | tst(object, Operand(kSmiTagMask)); |
| 2533 | Assert(ne, "Operand is a smi"); |
| 2534 | } |
| 2535 | |
| 2536 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2537 | void MacroAssembler::AbortIfNotSmi(Register object) { |
| 2538 | STATIC_ASSERT(kSmiTag == 0); |
| 2539 | tst(object, Operand(kSmiTagMask)); |
| 2540 | Assert(eq, "Operand is not smi"); |
| 2541 | } |
| 2542 | |
| 2543 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2544 | void MacroAssembler::AbortIfNotString(Register object) { |
| 2545 | STATIC_ASSERT(kSmiTag == 0); |
| 2546 | tst(object, Operand(kSmiTagMask)); |
| 2547 | Assert(ne, "Operand is not a string"); |
| 2548 | push(object); |
| 2549 | ldr(object, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2550 | CompareInstanceType(object, object, FIRST_NONSTRING_TYPE); |
| 2551 | pop(object); |
| 2552 | Assert(lo, "Operand is not a string"); |
| 2553 | } |
| 2554 | |
| 2555 | |
| 2556 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2557 | void MacroAssembler::AbortIfNotRootValue(Register src, |
| 2558 | Heap::RootListIndex root_value_index, |
| 2559 | const char* message) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2560 | CompareRoot(src, root_value_index); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2561 | Assert(eq, message); |
| 2562 | } |
| 2563 | |
| 2564 | |
| 2565 | void MacroAssembler::JumpIfNotHeapNumber(Register object, |
| 2566 | Register heap_number_map, |
| 2567 | Register scratch, |
| 2568 | Label* on_not_heap_number) { |
| 2569 | ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2570 | AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2571 | cmp(scratch, heap_number_map); |
| 2572 | b(ne, on_not_heap_number); |
| 2573 | } |
| 2574 | |
| 2575 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2576 | void MacroAssembler::JumpIfNonSmisNotBothSequentialAsciiStrings( |
| 2577 | Register first, |
| 2578 | Register second, |
| 2579 | Register scratch1, |
| 2580 | Register scratch2, |
| 2581 | Label* failure) { |
| 2582 | // Test that both first and second are sequential ASCII strings. |
| 2583 | // Assume that they are non-smis. |
| 2584 | ldr(scratch1, FieldMemOperand(first, HeapObject::kMapOffset)); |
| 2585 | ldr(scratch2, FieldMemOperand(second, HeapObject::kMapOffset)); |
| 2586 | ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); |
| 2587 | ldrb(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2588 | |
| 2589 | JumpIfBothInstanceTypesAreNotSequentialAscii(scratch1, |
| 2590 | scratch2, |
| 2591 | scratch1, |
| 2592 | scratch2, |
| 2593 | failure); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2594 | } |
| 2595 | |
| 2596 | void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register first, |
| 2597 | Register second, |
| 2598 | Register scratch1, |
| 2599 | Register scratch2, |
| 2600 | Label* failure) { |
| 2601 | // Check that neither is a smi. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2602 | STATIC_ASSERT(kSmiTag == 0); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2603 | and_(scratch1, first, Operand(second)); |
| 2604 | tst(scratch1, Operand(kSmiTagMask)); |
| 2605 | b(eq, failure); |
| 2606 | JumpIfNonSmisNotBothSequentialAsciiStrings(first, |
| 2607 | second, |
| 2608 | scratch1, |
| 2609 | scratch2, |
| 2610 | failure); |
| 2611 | } |
| 2612 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2613 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2614 | // Allocates a heap number or jumps to the need_gc label if the young space |
| 2615 | // is full and a scavenge is needed. |
| 2616 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 2617 | Register scratch1, |
| 2618 | Register scratch2, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2619 | Register heap_number_map, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2620 | Label* gc_required) { |
| 2621 | // Allocate an object in the heap for the heap number and tag it as a heap |
| 2622 | // object. |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 2623 | AllocateInNewSpace(HeapNumber::kSize, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2624 | result, |
| 2625 | scratch1, |
| 2626 | scratch2, |
| 2627 | gc_required, |
| 2628 | TAG_OBJECT); |
| 2629 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2630 | // Store heap number map in the allocated object. |
| 2631 | AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2632 | str(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2633 | } |
| 2634 | |
| 2635 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2636 | void MacroAssembler::AllocateHeapNumberWithValue(Register result, |
| 2637 | DwVfpRegister value, |
| 2638 | Register scratch1, |
| 2639 | Register scratch2, |
| 2640 | Register heap_number_map, |
| 2641 | Label* gc_required) { |
| 2642 | AllocateHeapNumber(result, scratch1, scratch2, heap_number_map, gc_required); |
| 2643 | sub(scratch1, result, Operand(kHeapObjectTag)); |
| 2644 | vstr(value, scratch1, HeapNumber::kValueOffset); |
| 2645 | } |
| 2646 | |
| 2647 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 2648 | // Copies a fixed number of fields of heap objects from src to dst. |
| 2649 | void MacroAssembler::CopyFields(Register dst, |
| 2650 | Register src, |
| 2651 | RegList temps, |
| 2652 | int field_count) { |
| 2653 | // At least one bit set in the first 15 registers. |
| 2654 | ASSERT((temps & ((1 << 15) - 1)) != 0); |
| 2655 | ASSERT((temps & dst.bit()) == 0); |
| 2656 | ASSERT((temps & src.bit()) == 0); |
| 2657 | // Primitive implementation using only one temporary register. |
| 2658 | |
| 2659 | Register tmp = no_reg; |
| 2660 | // Find a temp register in temps list. |
| 2661 | for (int i = 0; i < 15; i++) { |
| 2662 | if ((temps & (1 << i)) != 0) { |
| 2663 | tmp.set_code(i); |
| 2664 | break; |
| 2665 | } |
| 2666 | } |
| 2667 | ASSERT(!tmp.is(no_reg)); |
| 2668 | |
| 2669 | for (int i = 0; i < field_count; i++) { |
| 2670 | ldr(tmp, FieldMemOperand(src, i * kPointerSize)); |
| 2671 | str(tmp, FieldMemOperand(dst, i * kPointerSize)); |
| 2672 | } |
| 2673 | } |
| 2674 | |
| 2675 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2676 | void MacroAssembler::CopyBytes(Register src, |
| 2677 | Register dst, |
| 2678 | Register length, |
| 2679 | Register scratch) { |
| 2680 | Label align_loop, align_loop_1, word_loop, byte_loop, byte_loop_1, done; |
| 2681 | |
| 2682 | // Align src before copying in word size chunks. |
| 2683 | bind(&align_loop); |
| 2684 | cmp(length, Operand(0)); |
| 2685 | b(eq, &done); |
| 2686 | bind(&align_loop_1); |
| 2687 | tst(src, Operand(kPointerSize - 1)); |
| 2688 | b(eq, &word_loop); |
| 2689 | ldrb(scratch, MemOperand(src, 1, PostIndex)); |
| 2690 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2691 | sub(length, length, Operand(1), SetCC); |
| 2692 | b(ne, &byte_loop_1); |
| 2693 | |
| 2694 | // Copy bytes in word size chunks. |
| 2695 | bind(&word_loop); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2696 | if (emit_debug_code()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2697 | tst(src, Operand(kPointerSize - 1)); |
| 2698 | Assert(eq, "Expecting alignment for CopyBytes"); |
| 2699 | } |
| 2700 | cmp(length, Operand(kPointerSize)); |
| 2701 | b(lt, &byte_loop); |
| 2702 | ldr(scratch, MemOperand(src, kPointerSize, PostIndex)); |
| 2703 | #if CAN_USE_UNALIGNED_ACCESSES |
| 2704 | str(scratch, MemOperand(dst, kPointerSize, PostIndex)); |
| 2705 | #else |
| 2706 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2707 | mov(scratch, Operand(scratch, LSR, 8)); |
| 2708 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2709 | mov(scratch, Operand(scratch, LSR, 8)); |
| 2710 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2711 | mov(scratch, Operand(scratch, LSR, 8)); |
| 2712 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2713 | #endif |
| 2714 | sub(length, length, Operand(kPointerSize)); |
| 2715 | b(&word_loop); |
| 2716 | |
| 2717 | // Copy the last bytes if any left. |
| 2718 | bind(&byte_loop); |
| 2719 | cmp(length, Operand(0)); |
| 2720 | b(eq, &done); |
| 2721 | bind(&byte_loop_1); |
| 2722 | ldrb(scratch, MemOperand(src, 1, PostIndex)); |
| 2723 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2724 | sub(length, length, Operand(1), SetCC); |
| 2725 | b(ne, &byte_loop_1); |
| 2726 | bind(&done); |
| 2727 | } |
| 2728 | |
| 2729 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2730 | void MacroAssembler::CountLeadingZeros(Register zeros, // Answer. |
| 2731 | Register source, // Input. |
| 2732 | Register scratch) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2733 | ASSERT(!zeros.is(source) || !source.is(scratch)); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2734 | ASSERT(!zeros.is(scratch)); |
| 2735 | ASSERT(!scratch.is(ip)); |
| 2736 | ASSERT(!source.is(ip)); |
| 2737 | ASSERT(!zeros.is(ip)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2738 | #ifdef CAN_USE_ARMV5_INSTRUCTIONS |
| 2739 | clz(zeros, source); // This instruction is only supported after ARM5. |
| 2740 | #else |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 2741 | mov(zeros, Operand(0, RelocInfo::NONE)); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2742 | Move(scratch, source); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2743 | // Top 16. |
| 2744 | tst(scratch, Operand(0xffff0000)); |
| 2745 | add(zeros, zeros, Operand(16), LeaveCC, eq); |
| 2746 | mov(scratch, Operand(scratch, LSL, 16), LeaveCC, eq); |
| 2747 | // Top 8. |
| 2748 | tst(scratch, Operand(0xff000000)); |
| 2749 | add(zeros, zeros, Operand(8), LeaveCC, eq); |
| 2750 | mov(scratch, Operand(scratch, LSL, 8), LeaveCC, eq); |
| 2751 | // Top 4. |
| 2752 | tst(scratch, Operand(0xf0000000)); |
| 2753 | add(zeros, zeros, Operand(4), LeaveCC, eq); |
| 2754 | mov(scratch, Operand(scratch, LSL, 4), LeaveCC, eq); |
| 2755 | // Top 2. |
| 2756 | tst(scratch, Operand(0xc0000000)); |
| 2757 | add(zeros, zeros, Operand(2), LeaveCC, eq); |
| 2758 | mov(scratch, Operand(scratch, LSL, 2), LeaveCC, eq); |
| 2759 | // Top bit. |
| 2760 | tst(scratch, Operand(0x80000000u)); |
| 2761 | add(zeros, zeros, Operand(1), LeaveCC, eq); |
| 2762 | #endif |
| 2763 | } |
| 2764 | |
| 2765 | |
| 2766 | void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 2767 | Register first, |
| 2768 | Register second, |
| 2769 | Register scratch1, |
| 2770 | Register scratch2, |
| 2771 | Label* failure) { |
| 2772 | int kFlatAsciiStringMask = |
| 2773 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 2774 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 2775 | and_(scratch1, first, Operand(kFlatAsciiStringMask)); |
| 2776 | and_(scratch2, second, Operand(kFlatAsciiStringMask)); |
| 2777 | cmp(scratch1, Operand(kFlatAsciiStringTag)); |
| 2778 | // Ignore second test if first test failed. |
| 2779 | cmp(scratch2, Operand(kFlatAsciiStringTag), eq); |
| 2780 | b(ne, failure); |
| 2781 | } |
| 2782 | |
| 2783 | |
| 2784 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii(Register type, |
| 2785 | Register scratch, |
| 2786 | Label* failure) { |
| 2787 | int kFlatAsciiStringMask = |
| 2788 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 2789 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 2790 | and_(scratch, type, Operand(kFlatAsciiStringMask)); |
| 2791 | cmp(scratch, Operand(kFlatAsciiStringTag)); |
| 2792 | b(ne, failure); |
| 2793 | } |
| 2794 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2795 | static const int kRegisterPassedArguments = 4; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2796 | |
| 2797 | void MacroAssembler::PrepareCallCFunction(int num_arguments, Register scratch) { |
| 2798 | int frame_alignment = ActivationFrameAlignment(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2799 | |
| 2800 | // Reserve space for Isolate address which is always passed as last parameter |
| 2801 | num_arguments += 1; |
| 2802 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2803 | // Up to four simple arguments are passed in registers r0..r3. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2804 | int stack_passed_arguments = (num_arguments <= kRegisterPassedArguments) ? |
| 2805 | 0 : num_arguments - kRegisterPassedArguments; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2806 | if (frame_alignment > kPointerSize) { |
| 2807 | // Make stack end at alignment and make room for num_arguments - 4 words |
| 2808 | // and the original value of sp. |
| 2809 | mov(scratch, sp); |
| 2810 | sub(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize)); |
| 2811 | ASSERT(IsPowerOf2(frame_alignment)); |
| 2812 | and_(sp, sp, Operand(-frame_alignment)); |
| 2813 | str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 2814 | } else { |
| 2815 | sub(sp, sp, Operand(stack_passed_arguments * kPointerSize)); |
| 2816 | } |
| 2817 | } |
| 2818 | |
| 2819 | |
| 2820 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 2821 | int num_arguments) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2822 | CallCFunctionHelper(no_reg, function, ip, num_arguments); |
| 2823 | } |
| 2824 | |
| 2825 | void MacroAssembler::CallCFunction(Register function, |
| 2826 | Register scratch, |
| 2827 | int num_arguments) { |
| 2828 | CallCFunctionHelper(function, |
| 2829 | ExternalReference::the_hole_value_location(isolate()), |
| 2830 | scratch, |
| 2831 | num_arguments); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2835 | void MacroAssembler::CallCFunctionHelper(Register function, |
| 2836 | ExternalReference function_reference, |
| 2837 | Register scratch, |
| 2838 | int num_arguments) { |
| 2839 | // Push Isolate address as the last argument. |
| 2840 | if (num_arguments < kRegisterPassedArguments) { |
| 2841 | Register arg_to_reg[] = {r0, r1, r2, r3}; |
| 2842 | Register r = arg_to_reg[num_arguments]; |
| 2843 | mov(r, Operand(ExternalReference::isolate_address())); |
| 2844 | } else { |
| 2845 | int stack_passed_arguments = num_arguments - kRegisterPassedArguments; |
| 2846 | // Push Isolate address on the stack after the arguments. |
| 2847 | mov(scratch, Operand(ExternalReference::isolate_address())); |
| 2848 | str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 2849 | } |
| 2850 | num_arguments += 1; |
| 2851 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2852 | // Make sure that the stack is aligned before calling a C function unless |
| 2853 | // running in the simulator. The simulator has its own alignment check which |
| 2854 | // provides more information. |
| 2855 | #if defined(V8_HOST_ARCH_ARM) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2856 | if (emit_debug_code()) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2857 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 2858 | int frame_alignment_mask = frame_alignment - 1; |
| 2859 | if (frame_alignment > kPointerSize) { |
| 2860 | ASSERT(IsPowerOf2(frame_alignment)); |
| 2861 | Label alignment_as_expected; |
| 2862 | tst(sp, Operand(frame_alignment_mask)); |
| 2863 | b(eq, &alignment_as_expected); |
| 2864 | // Don't use Check here, as it will call Runtime_Abort possibly |
| 2865 | // re-entering here. |
| 2866 | stop("Unexpected alignment"); |
| 2867 | bind(&alignment_as_expected); |
| 2868 | } |
| 2869 | } |
| 2870 | #endif |
| 2871 | |
| 2872 | // Just call directly. The function called cannot cause a GC, or |
| 2873 | // allow preemption, so the return address in the link register |
| 2874 | // stays correct. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2875 | if (function.is(no_reg)) { |
| 2876 | mov(scratch, Operand(function_reference)); |
| 2877 | function = scratch; |
| 2878 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2879 | Call(function); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2880 | int stack_passed_arguments = (num_arguments <= kRegisterPassedArguments) ? |
| 2881 | 0 : num_arguments - kRegisterPassedArguments; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2882 | if (OS::ActivationFrameAlignment() > kPointerSize) { |
| 2883 | ldr(sp, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 2884 | } else { |
| 2885 | add(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize))); |
| 2886 | } |
| 2887 | } |
| 2888 | |
| 2889 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2890 | void MacroAssembler::GetRelocatedValueLocation(Register ldr_location, |
| 2891 | Register result) { |
| 2892 | const uint32_t kLdrOffsetMask = (1 << 12) - 1; |
| 2893 | const int32_t kPCRegOffset = 2 * kPointerSize; |
| 2894 | ldr(result, MemOperand(ldr_location)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 2895 | if (emit_debug_code()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2896 | // Check that the instruction is a ldr reg, [pc + offset] . |
| 2897 | and_(result, result, Operand(kLdrPCPattern)); |
| 2898 | cmp(result, Operand(kLdrPCPattern)); |
| 2899 | Check(eq, "The instruction to patch should be a load from pc."); |
| 2900 | // Result was clobbered. Restore it. |
| 2901 | ldr(result, MemOperand(ldr_location)); |
| 2902 | } |
| 2903 | // Get the address of the constant. |
| 2904 | and_(result, result, Operand(kLdrOffsetMask)); |
| 2905 | add(result, ldr_location, Operand(result)); |
| 2906 | add(result, result, Operand(kPCRegOffset)); |
| 2907 | } |
| 2908 | |
| 2909 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2910 | CodePatcher::CodePatcher(byte* address, int instructions) |
| 2911 | : address_(address), |
| 2912 | instructions_(instructions), |
| 2913 | size_(instructions * Assembler::kInstrSize), |
| 2914 | masm_(address, size_ + Assembler::kGap) { |
| 2915 | // Create a new macro assembler pointing to the address of the code to patch. |
| 2916 | // The size is adjusted with kGap on order for the assembler to generate size |
| 2917 | // bytes of instructions without failing with buffer size constraints. |
| 2918 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2919 | } |
| 2920 | |
| 2921 | |
| 2922 | CodePatcher::~CodePatcher() { |
| 2923 | // Indicate that code has changed. |
| 2924 | CPU::FlushICache(address_, size_); |
| 2925 | |
| 2926 | // Check that the code was patched as expected. |
| 2927 | ASSERT(masm_.pc_ == address_ + size_); |
| 2928 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2929 | } |
| 2930 | |
| 2931 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2932 | void CodePatcher::Emit(Instr instr) { |
| 2933 | masm()->emit(instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | |
| 2937 | void CodePatcher::Emit(Address addr) { |
| 2938 | masm()->emit(reinterpret_cast<Instr>(addr)); |
| 2939 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2940 | |
| 2941 | |
| 2942 | void CodePatcher::EmitCondition(Condition cond) { |
| 2943 | Instr instr = Assembler::instr_at(masm_.pc_); |
| 2944 | instr = (instr & ~kCondMask) | cond; |
| 2945 | masm_.emit(instr); |
| 2946 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2947 | |
| 2948 | |
| 2949 | } } // namespace v8::internal |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2950 | |
| 2951 | #endif // V8_TARGET_ARCH_ARM |