| OLD | NEW |
| 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. | 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 // All Rights Reserved. | 2 // All Rights Reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions | 5 // modification, are permitted provided that the following conditions |
| 6 // are met: | 6 // are met: |
| 7 // | 7 // |
| 8 // - Redistributions of source code must retain the above copyright notice, | 8 // - Redistributions of source code must retain the above copyright notice, |
| 9 // this list of conditions and the following disclaimer. | 9 // this list of conditions and the following disclaimer. |
| 10 // | 10 // |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 ASSERT(NextField::is_valid(Assembler::kMaximalBufferSize)); | 144 ASSERT(NextField::is_valid(Assembler::kMaximalBufferSize)); |
| 145 data_ = NextField::encode(next) | TypeField::encode(type); | 145 data_ = NextField::encode(next) | TypeField::encode(type); |
| 146 } | 146 } |
| 147 | 147 |
| 148 | 148 |
| 149 // ----------------------------------------------------------------------------- | 149 // ----------------------------------------------------------------------------- |
| 150 // Implementation of RelocInfo | 150 // Implementation of RelocInfo |
| 151 | 151 |
| 152 | 152 |
| 153 const int RelocInfo::kApplyMask = | 153 const int RelocInfo::kApplyMask = |
| 154 RelocInfo::kCodeTargetMask | 1 << runtime_entry | | 154 RelocInfo::kCodeTargetMask | 1 << RelocInfo::RUNTIME_ENTRY | |
| 155 1 << js_return | 1 << internal_reference; | 155 1 << RelocInfo::JS_RETURN | 1 << RelocInfo::INTERNAL_REFERENCE; |
| 156 | 156 |
| 157 | 157 |
| 158 void RelocInfo::patch_code(byte* instructions, int instruction_count) { | 158 void RelocInfo::patch_code(byte* instructions, int instruction_count) { |
| 159 // Patch the code at the current address with the supplied instructions. | 159 // Patch the code at the current address with the supplied instructions. |
| 160 for (int i = 0; i < instruction_count; i++) { | 160 for (int i = 0; i < instruction_count; i++) { |
| 161 *(pc_ + i) = *(instructions + i); | 161 *(pc_ + i) = *(instructions + i); |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 | 165 |
| 166 // Patch the code at the current PC with a call to the target address. | 166 // Patch the code at the current PC with a call to the target address. |
| 167 // Additional guard int3 instructions can be added if required. | 167 // Additional guard int3 instructions can be added if required. |
| 168 void RelocInfo::patch_code_with_call(Address target, int guard_bytes) { | 168 void RelocInfo::patch_code_with_call(Address target, int guard_bytes) { |
| 169 // Call instruction takes up 5 bytes and int3 takes up one byte. | 169 // Call instruction takes up 5 bytes and int3 takes up one byte. |
| 170 int code_size = 5 + guard_bytes; | 170 int code_size = 5 + guard_bytes; |
| 171 | 171 |
| 172 // Patch the code. | 172 // Patch the code. |
| 173 CodePatcher patcher(pc_, code_size); | 173 CodePatcher patcher(pc_, code_size); |
| 174 patcher.masm()->call(target, no_reloc); | 174 patcher.masm()->call(target, RelocInfo::NONE); |
| 175 | 175 |
| 176 // Add the requested number of int3 instructions after the call. | 176 // Add the requested number of int3 instructions after the call. |
| 177 for (int i = 0; i < guard_bytes; i++) { | 177 for (int i = 0; i < guard_bytes; i++) { |
| 178 patcher.masm()->int3(); | 178 patcher.masm()->int3(); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 | 182 |
| 183 // ----------------------------------------------------------------------------- | 183 // ----------------------------------------------------------------------------- |
| 184 // Implementation of Operand | 184 // Implementation of Operand |
| 185 | 185 |
| 186 Operand::Operand(Register base, int32_t disp, RelocMode rmode) { | 186 Operand::Operand(Register base, int32_t disp, RelocInfo::Mode rmode) { |
| 187 // [base + disp/r] | 187 // [base + disp/r] |
| 188 if (disp == 0 && rmode == no_reloc && !base.is(ebp)) { | 188 if (disp == 0 && rmode == RelocInfo::NONE && !base.is(ebp)) { |
| 189 // [base] | 189 // [base] |
| 190 set_modrm(0, base); | 190 set_modrm(0, base); |
| 191 if (base.is(esp)) set_sib(times_1, esp, base); | 191 if (base.is(esp)) set_sib(times_1, esp, base); |
| 192 } else if (is_int8(disp) && rmode == no_reloc) { | 192 } else if (is_int8(disp) && rmode == RelocInfo::NONE) { |
| 193 // [base + disp8] | 193 // [base + disp8] |
| 194 set_modrm(1, base); | 194 set_modrm(1, base); |
| 195 if (base.is(esp)) set_sib(times_1, esp, base); | 195 if (base.is(esp)) set_sib(times_1, esp, base); |
| 196 set_disp8(disp); | 196 set_disp8(disp); |
| 197 } else { | 197 } else { |
| 198 // [base + disp/r] | 198 // [base + disp/r] |
| 199 set_modrm(2, base); | 199 set_modrm(2, base); |
| 200 if (base.is(esp)) set_sib(times_1, esp, base); | 200 if (base.is(esp)) set_sib(times_1, esp, base); |
| 201 set_dispr(disp, rmode); | 201 set_dispr(disp, rmode); |
| 202 } | 202 } |
| 203 } | 203 } |
| 204 | 204 |
| 205 | 205 |
| 206 Operand::Operand(Register base, | 206 Operand::Operand(Register base, |
| 207 Register index, | 207 Register index, |
| 208 ScaleFactor scale, | 208 ScaleFactor scale, |
| 209 int32_t disp, | 209 int32_t disp, |
| 210 RelocMode rmode) { | 210 RelocInfo::Mode rmode) { |
| 211 ASSERT(!index.is(esp)); // illegal addressing mode | 211 ASSERT(!index.is(esp)); // illegal addressing mode |
| 212 // [base + index*scale + disp/r] | 212 // [base + index*scale + disp/r] |
| 213 if (disp == 0 && rmode == no_reloc && !base.is(ebp)) { | 213 if (disp == 0 && rmode == RelocInfo::NONE && !base.is(ebp)) { |
| 214 // [base + index*scale] | 214 // [base + index*scale] |
| 215 set_modrm(0, esp); | 215 set_modrm(0, esp); |
| 216 set_sib(scale, index, base); | 216 set_sib(scale, index, base); |
| 217 } else if (is_int8(disp) && rmode == no_reloc) { | 217 } else if (is_int8(disp) && rmode == RelocInfo::NONE) { |
| 218 // [base + index*scale + disp8] | 218 // [base + index*scale + disp8] |
| 219 set_modrm(1, esp); | 219 set_modrm(1, esp); |
| 220 set_sib(scale, index, base); | 220 set_sib(scale, index, base); |
| 221 set_disp8(disp); | 221 set_disp8(disp); |
| 222 } else { | 222 } else { |
| 223 // [base + index*scale + disp/r] | 223 // [base + index*scale + disp/r] |
| 224 set_modrm(2, esp); | 224 set_modrm(2, esp); |
| 225 set_sib(scale, index, base); | 225 set_sib(scale, index, base); |
| 226 set_dispr(disp, rmode); | 226 set_dispr(disp, rmode); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 | 230 |
| 231 Operand::Operand(Register index, | 231 Operand::Operand(Register index, |
| 232 ScaleFactor scale, | 232 ScaleFactor scale, |
| 233 int32_t disp, | 233 int32_t disp, |
| 234 RelocMode rmode) { | 234 RelocInfo::Mode rmode) { |
| 235 ASSERT(!index.is(esp)); // illegal addressing mode | 235 ASSERT(!index.is(esp)); // illegal addressing mode |
| 236 // [index*scale + disp/r] | 236 // [index*scale + disp/r] |
| 237 set_modrm(0, esp); | 237 set_modrm(0, esp); |
| 238 set_sib(scale, index, ebp); | 238 set_sib(scale, index, ebp); |
| 239 set_dispr(disp, rmode); | 239 set_dispr(disp, rmode); |
| 240 } | 240 } |
| 241 | 241 |
| 242 | 242 |
| 243 void Operand::set_sib(ScaleFactor scale, Register index, Register base) { | 243 void Operand::set_sib(ScaleFactor scale, Register index, Register base) { |
| 244 ASSERT(len_ == 1); | 244 ASSERT(len_ == 1); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 memset(buffer_, 0xCC, buffer_size); // int3 | 310 memset(buffer_, 0xCC, buffer_size); // int3 |
| 311 } | 311 } |
| 312 | 312 |
| 313 // setup buffer pointers | 313 // setup buffer pointers |
| 314 ASSERT(buffer_ != NULL); | 314 ASSERT(buffer_ != NULL); |
| 315 pc_ = buffer_; | 315 pc_ = buffer_; |
| 316 reloc_info_writer.Reposition(buffer_ + buffer_size, pc_); | 316 reloc_info_writer.Reposition(buffer_ + buffer_size, pc_); |
| 317 | 317 |
| 318 last_pc_ = NULL; | 318 last_pc_ = NULL; |
| 319 last_bound_pos_ = 0; | 319 last_bound_pos_ = 0; |
| 320 last_position_ = kNoPosition; | 320 last_position_ = RelocInfo::kNoPosition; |
| 321 last_statement_position_ = kNoPosition; | 321 last_statement_position_ = RelocInfo::kNoPosition; |
| 322 } | 322 } |
| 323 | 323 |
| 324 | 324 |
| 325 Assembler::~Assembler() { | 325 Assembler::~Assembler() { |
| 326 if (own_buffer_) { | 326 if (own_buffer_) { |
| 327 if (spare_buffer_ == NULL && buffer_size_ == kMinimalBufferSize) { | 327 if (spare_buffer_ == NULL && buffer_size_ == kMinimalBufferSize) { |
| 328 spare_buffer_ = buffer_; | 328 spare_buffer_ = buffer_; |
| 329 } else { | 329 } else { |
| 330 DeleteArray(buffer_); | 330 DeleteArray(buffer_); |
| 331 } | 331 } |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 EMIT(0x29); | 1004 EMIT(0x29); |
| 1005 emit_operand(dst, src); | 1005 emit_operand(dst, src); |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 | 1008 |
| 1009 void Assembler::test(Register reg, const Immediate& imm) { | 1009 void Assembler::test(Register reg, const Immediate& imm) { |
| 1010 EnsureSpace ensure_space(this); | 1010 EnsureSpace ensure_space(this); |
| 1011 last_pc_ = pc_; | 1011 last_pc_ = pc_; |
| 1012 // Only use test against byte for registers that have a byte | 1012 // Only use test against byte for registers that have a byte |
| 1013 // variant: eax, ebx, ecx, and edx. | 1013 // variant: eax, ebx, ecx, and edx. |
| 1014 if (imm.rmode_ == no_reloc && is_uint8(imm.x_) && reg.code() < 4) { | 1014 if (imm.rmode_ == RelocInfo::NONE && is_uint8(imm.x_) && reg.code() < 4) { |
| 1015 uint8_t imm8 = imm.x_; | 1015 uint8_t imm8 = imm.x_; |
| 1016 if (reg.is(eax)) { | 1016 if (reg.is(eax)) { |
| 1017 EMIT(0xA8); | 1017 EMIT(0xA8); |
| 1018 EMIT(imm8); | 1018 EMIT(imm8); |
| 1019 } else { | 1019 } else { |
| 1020 emit_arith_b(0xF6, 0xC0, reg, imm8); | 1020 emit_arith_b(0xF6, 0xC0, reg, imm8); |
| 1021 } | 1021 } |
| 1022 } else { | 1022 } else { |
| 1023 // This is not using emit_arith because test doesn't support | 1023 // This is not using emit_arith because test doesn't support |
| 1024 // sign-extension of 8-bit operands. | 1024 // sign-extension of 8-bit operands. |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1283 EMIT(0xE8); | 1283 EMIT(0xE8); |
| 1284 emit(offs - long_size); | 1284 emit(offs - long_size); |
| 1285 } else { | 1285 } else { |
| 1286 // 1110 1000 #32-bit disp | 1286 // 1110 1000 #32-bit disp |
| 1287 EMIT(0xE8); | 1287 EMIT(0xE8); |
| 1288 emit_disp(L, Displacement::OTHER); | 1288 emit_disp(L, Displacement::OTHER); |
| 1289 } | 1289 } |
| 1290 } | 1290 } |
| 1291 | 1291 |
| 1292 | 1292 |
| 1293 void Assembler::call(byte* entry, RelocMode rmode) { | 1293 void Assembler::call(byte* entry, RelocInfo::Mode rmode) { |
| 1294 EnsureSpace ensure_space(this); | 1294 EnsureSpace ensure_space(this); |
| 1295 last_pc_ = pc_; | 1295 last_pc_ = pc_; |
| 1296 ASSERT(!is_code_target(rmode)); | 1296 ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
| 1297 EMIT(0xE8); | 1297 EMIT(0xE8); |
| 1298 emit(entry - (pc_ + sizeof(int32_t)), rmode); | 1298 emit(entry - (pc_ + sizeof(int32_t)), rmode); |
| 1299 } | 1299 } |
| 1300 | 1300 |
| 1301 | 1301 |
| 1302 void Assembler::call(const Operand& adr) { | 1302 void Assembler::call(const Operand& adr) { |
| 1303 EnsureSpace ensure_space(this); | 1303 EnsureSpace ensure_space(this); |
| 1304 last_pc_ = pc_; | 1304 last_pc_ = pc_; |
| 1305 EMIT(0xFF); | 1305 EMIT(0xFF); |
| 1306 emit_operand(edx, adr); | 1306 emit_operand(edx, adr); |
| 1307 } | 1307 } |
| 1308 | 1308 |
| 1309 | 1309 |
| 1310 void Assembler::call(Handle<Code> code, RelocMode rmode) { | 1310 void Assembler::call(Handle<Code> code, RelocInfo::Mode rmode) { |
| 1311 WriteRecordedPositions(); | 1311 WriteRecordedPositions(); |
| 1312 EnsureSpace ensure_space(this); | 1312 EnsureSpace ensure_space(this); |
| 1313 last_pc_ = pc_; | 1313 last_pc_ = pc_; |
| 1314 ASSERT(is_code_target(rmode)); | 1314 ASSERT(RelocInfo::IsCodeTarget(rmode)); |
| 1315 EMIT(0xE8); | 1315 EMIT(0xE8); |
| 1316 emit(reinterpret_cast<intptr_t>(code.location()), rmode); | 1316 emit(reinterpret_cast<intptr_t>(code.location()), rmode); |
| 1317 } | 1317 } |
| 1318 | 1318 |
| 1319 | 1319 |
| 1320 void Assembler::jmp(Label* L) { | 1320 void Assembler::jmp(Label* L) { |
| 1321 EnsureSpace ensure_space(this); | 1321 EnsureSpace ensure_space(this); |
| 1322 last_pc_ = pc_; | 1322 last_pc_ = pc_; |
| 1323 if (L->is_bound()) { | 1323 if (L->is_bound()) { |
| 1324 const int short_size = 2; | 1324 const int short_size = 2; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1345 } | 1345 } |
| 1346 link_to(L, &unbound_label_); | 1346 link_to(L, &unbound_label_); |
| 1347 } | 1347 } |
| 1348 // 1110 1001 #32-bit disp | 1348 // 1110 1001 #32-bit disp |
| 1349 EMIT(0xE9); | 1349 EMIT(0xE9); |
| 1350 emit_disp(L, Displacement::UNCONDITIONAL_JUMP); | 1350 emit_disp(L, Displacement::UNCONDITIONAL_JUMP); |
| 1351 } | 1351 } |
| 1352 } | 1352 } |
| 1353 | 1353 |
| 1354 | 1354 |
| 1355 void Assembler::jmp(byte* entry, RelocMode rmode) { | 1355 void Assembler::jmp(byte* entry, RelocInfo::Mode rmode) { |
| 1356 EnsureSpace ensure_space(this); | 1356 EnsureSpace ensure_space(this); |
| 1357 last_pc_ = pc_; | 1357 last_pc_ = pc_; |
| 1358 ASSERT(!is_code_target(rmode)); | 1358 ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
| 1359 EMIT(0xE9); | 1359 EMIT(0xE9); |
| 1360 emit(entry - (pc_ + sizeof(int32_t)), rmode); | 1360 emit(entry - (pc_ + sizeof(int32_t)), rmode); |
| 1361 } | 1361 } |
| 1362 | 1362 |
| 1363 | 1363 |
| 1364 void Assembler::jmp(const Operand& adr) { | 1364 void Assembler::jmp(const Operand& adr) { |
| 1365 EnsureSpace ensure_space(this); | 1365 EnsureSpace ensure_space(this); |
| 1366 last_pc_ = pc_; | 1366 last_pc_ = pc_; |
| 1367 EMIT(0xFF); | 1367 EMIT(0xFF); |
| 1368 emit_operand(esp, adr); | 1368 emit_operand(esp, adr); |
| 1369 } | 1369 } |
| 1370 | 1370 |
| 1371 | 1371 |
| 1372 void Assembler::jmp(Handle<Code> code, RelocMode rmode) { | 1372 void Assembler::jmp(Handle<Code> code, RelocInfo::Mode rmode) { |
| 1373 EnsureSpace ensure_space(this); | 1373 EnsureSpace ensure_space(this); |
| 1374 last_pc_ = pc_; | 1374 last_pc_ = pc_; |
| 1375 ASSERT(is_code_target(rmode)); | 1375 ASSERT(RelocInfo::IsCodeTarget(rmode)); |
| 1376 EMIT(0xE9); | 1376 EMIT(0xE9); |
| 1377 emit(reinterpret_cast<intptr_t>(code.location()), rmode); | 1377 emit(reinterpret_cast<intptr_t>(code.location()), rmode); |
| 1378 } | 1378 } |
| 1379 | 1379 |
| 1380 | 1380 |
| 1381 | 1381 |
| 1382 void Assembler::j(Condition cc, Label* L, Hint hint) { | 1382 void Assembler::j(Condition cc, Label* L, Hint hint) { |
| 1383 EnsureSpace ensure_space(this); | 1383 EnsureSpace ensure_space(this); |
| 1384 last_pc_ = pc_; | 1384 last_pc_ = pc_; |
| 1385 ASSERT(0 <= cc && cc < 16); | 1385 ASSERT(0 <= cc && cc < 16); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1403 // 0000 1111 1000 tttn #32-bit disp | 1403 // 0000 1111 1000 tttn #32-bit disp |
| 1404 // Note: could eliminate cond. jumps to this jump if condition | 1404 // Note: could eliminate cond. jumps to this jump if condition |
| 1405 // is the same however, seems to be rather unlikely case. | 1405 // is the same however, seems to be rather unlikely case. |
| 1406 EMIT(0x0F); | 1406 EMIT(0x0F); |
| 1407 EMIT(0x80 | cc); | 1407 EMIT(0x80 | cc); |
| 1408 emit_disp(L, Displacement::OTHER); | 1408 emit_disp(L, Displacement::OTHER); |
| 1409 } | 1409 } |
| 1410 } | 1410 } |
| 1411 | 1411 |
| 1412 | 1412 |
| 1413 void Assembler::j(Condition cc, byte* entry, RelocMode rmode, Hint hint) { | 1413 void Assembler::j(Condition cc, byte* entry, RelocInfo::Mode rmode, Hint hint) { |
| 1414 EnsureSpace ensure_space(this); | 1414 EnsureSpace ensure_space(this); |
| 1415 last_pc_ = pc_; | 1415 last_pc_ = pc_; |
| 1416 ASSERT((0 <= cc) && (cc < 16)); | 1416 ASSERT((0 <= cc) && (cc < 16)); |
| 1417 if (FLAG_emit_branch_hints && hint != no_hint) EMIT(hint); | 1417 if (FLAG_emit_branch_hints && hint != no_hint) EMIT(hint); |
| 1418 // 0000 1111 1000 tttn #32-bit disp | 1418 // 0000 1111 1000 tttn #32-bit disp |
| 1419 EMIT(0x0F); | 1419 EMIT(0x0F); |
| 1420 EMIT(0x80 | cc); | 1420 EMIT(0x80 | cc); |
| 1421 emit(entry - (pc_ + sizeof(int32_t)), rmode); | 1421 emit(entry - (pc_ + sizeof(int32_t)), rmode); |
| 1422 } | 1422 } |
| 1423 | 1423 |
| 1424 | 1424 |
| 1425 void Assembler::j(Condition cc, Handle<Code> code, Hint hint) { | 1425 void Assembler::j(Condition cc, Handle<Code> code, Hint hint) { |
| 1426 EnsureSpace ensure_space(this); | 1426 EnsureSpace ensure_space(this); |
| 1427 last_pc_ = pc_; | 1427 last_pc_ = pc_; |
| 1428 if (FLAG_emit_branch_hints && hint != no_hint) EMIT(hint); | 1428 if (FLAG_emit_branch_hints && hint != no_hint) EMIT(hint); |
| 1429 // 0000 1111 1000 tttn #32-bit disp | 1429 // 0000 1111 1000 tttn #32-bit disp |
| 1430 EMIT(0x0F); | 1430 EMIT(0x0F); |
| 1431 EMIT(0x80 | cc); | 1431 EMIT(0x80 | cc); |
| 1432 emit(reinterpret_cast<intptr_t>(code.location()), code_target); | 1432 emit(reinterpret_cast<intptr_t>(code.location()), RelocInfo::CODE_TARGET); |
| 1433 } | 1433 } |
| 1434 | 1434 |
| 1435 | 1435 |
| 1436 // FPU instructions | 1436 // FPU instructions |
| 1437 | 1437 |
| 1438 | 1438 |
| 1439 void Assembler::fld(int i) { | 1439 void Assembler::fld(int i) { |
| 1440 EnsureSpace ensure_space(this); | 1440 EnsureSpace ensure_space(this); |
| 1441 last_pc_ = pc_; | 1441 last_pc_ = pc_; |
| 1442 emit_farith(0xD9, 0xC0, i); | 1442 emit_farith(0xD9, 0xC0, i); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 | 1842 |
| 1843 | 1843 |
| 1844 void Assembler::Print() { | 1844 void Assembler::Print() { |
| 1845 Disassembler::Decode(stdout, buffer_, pc_); | 1845 Disassembler::Decode(stdout, buffer_, pc_); |
| 1846 } | 1846 } |
| 1847 | 1847 |
| 1848 | 1848 |
| 1849 void Assembler::RecordJSReturn() { | 1849 void Assembler::RecordJSReturn() { |
| 1850 WriteRecordedPositions(); | 1850 WriteRecordedPositions(); |
| 1851 EnsureSpace ensure_space(this); | 1851 EnsureSpace ensure_space(this); |
| 1852 RecordRelocInfo(js_return); | 1852 RecordRelocInfo(RelocInfo::JS_RETURN); |
| 1853 } | 1853 } |
| 1854 | 1854 |
| 1855 | 1855 |
| 1856 void Assembler::RecordComment(const char* msg) { | 1856 void Assembler::RecordComment(const char* msg) { |
| 1857 if (FLAG_debug_code) { | 1857 if (FLAG_debug_code) { |
| 1858 EnsureSpace ensure_space(this); | 1858 EnsureSpace ensure_space(this); |
| 1859 RecordRelocInfo(comment, reinterpret_cast<intptr_t>(msg)); | 1859 RecordRelocInfo(RelocInfo::COMMENT, reinterpret_cast<intptr_t>(msg)); |
| 1860 } | 1860 } |
| 1861 } | 1861 } |
| 1862 | 1862 |
| 1863 | 1863 |
| 1864 void Assembler::RecordPosition(int pos) { | 1864 void Assembler::RecordPosition(int pos) { |
| 1865 if (pos == kNoPosition) return; | 1865 if (pos == RelocInfo::kNoPosition) return; |
| 1866 ASSERT(pos >= 0); | 1866 ASSERT(pos >= 0); |
| 1867 last_position_ = pos; | 1867 last_position_ = pos; |
| 1868 } | 1868 } |
| 1869 | 1869 |
| 1870 | 1870 |
| 1871 void Assembler::RecordStatementPosition(int pos) { | 1871 void Assembler::RecordStatementPosition(int pos) { |
| 1872 if (pos == kNoPosition) return; | 1872 if (pos == RelocInfo::kNoPosition) return; |
| 1873 ASSERT(pos >= 0); | 1873 ASSERT(pos >= 0); |
| 1874 last_statement_position_ = pos; | 1874 last_statement_position_ = pos; |
| 1875 } | 1875 } |
| 1876 | 1876 |
| 1877 | 1877 |
| 1878 void Assembler::WriteRecordedPositions() { | 1878 void Assembler::WriteRecordedPositions() { |
| 1879 if (last_statement_position_ != kNoPosition) { | 1879 if (last_statement_position_ != RelocInfo::kNoPosition) { |
| 1880 EnsureSpace ensure_space(this); | 1880 EnsureSpace ensure_space(this); |
| 1881 RecordRelocInfo(statement_position, last_statement_position_); | 1881 RecordRelocInfo(RelocInfo::STATEMENT_POSITION, last_statement_position_); |
| 1882 } | 1882 } |
| 1883 if ((last_position_ != kNoPosition) && | 1883 if ((last_position_ != RelocInfo::kNoPosition) && |
| 1884 (last_position_ != last_statement_position_)) { | 1884 (last_position_ != last_statement_position_)) { |
| 1885 EnsureSpace ensure_space(this); | 1885 EnsureSpace ensure_space(this); |
| 1886 RecordRelocInfo(position, last_position_); | 1886 RecordRelocInfo(RelocInfo::POSITION, last_position_); |
| 1887 } | 1887 } |
| 1888 last_statement_position_ = kNoPosition; | 1888 last_statement_position_ = RelocInfo::kNoPosition; |
| 1889 last_position_ = kNoPosition; | 1889 last_position_ = RelocInfo::kNoPosition; |
| 1890 } | 1890 } |
| 1891 | 1891 |
| 1892 | 1892 |
| 1893 void Assembler::GrowBuffer() { | 1893 void Assembler::GrowBuffer() { |
| 1894 ASSERT(overflow()); // should not call this otherwise | 1894 ASSERT(overflow()); // should not call this otherwise |
| 1895 if (!own_buffer_) FATAL("external code buffer is too small"); | 1895 if (!own_buffer_) FATAL("external code buffer is too small"); |
| 1896 | 1896 |
| 1897 // compute new buffer size | 1897 // compute new buffer size |
| 1898 CodeDesc desc; // the new buffer | 1898 CodeDesc desc; // the new buffer |
| 1899 if (buffer_size_ < 4*KB) { | 1899 if (buffer_size_ < 4*KB) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1936 buffer_size_ = desc.buffer_size; | 1936 buffer_size_ = desc.buffer_size; |
| 1937 pc_ += pc_delta; | 1937 pc_ += pc_delta; |
| 1938 if (last_pc_ != NULL) { | 1938 if (last_pc_ != NULL) { |
| 1939 last_pc_ += pc_delta; | 1939 last_pc_ += pc_delta; |
| 1940 } | 1940 } |
| 1941 reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta, | 1941 reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta, |
| 1942 reloc_info_writer.last_pc() + pc_delta); | 1942 reloc_info_writer.last_pc() + pc_delta); |
| 1943 | 1943 |
| 1944 // relocate runtime entries | 1944 // relocate runtime entries |
| 1945 for (RelocIterator it(desc); !it.done(); it.next()) { | 1945 for (RelocIterator it(desc); !it.done(); it.next()) { |
| 1946 RelocMode rmode = it.rinfo()->rmode(); | 1946 RelocInfo::Mode rmode = it.rinfo()->rmode(); |
| 1947 if (rmode == runtime_entry) { | 1947 if (rmode == RelocInfo::RUNTIME_ENTRY) { |
| 1948 int32_t* p = reinterpret_cast<int32_t*>(it.rinfo()->pc()); | 1948 int32_t* p = reinterpret_cast<int32_t*>(it.rinfo()->pc()); |
| 1949 *p -= pc_delta; // relocate entry | 1949 *p -= pc_delta; // relocate entry |
| 1950 } else if (rmode == internal_reference) { | 1950 } else if (rmode == RelocInfo::INTERNAL_REFERENCE) { |
| 1951 int32_t* p = reinterpret_cast<int32_t*>(it.rinfo()->pc()); | 1951 int32_t* p = reinterpret_cast<int32_t*>(it.rinfo()->pc()); |
| 1952 if (*p != 0) { // 0 means uninitialized. | 1952 if (*p != 0) { // 0 means uninitialized. |
| 1953 *p += pc_delta; | 1953 *p += pc_delta; |
| 1954 } | 1954 } |
| 1955 } | 1955 } |
| 1956 } | 1956 } |
| 1957 | 1957 |
| 1958 ASSERT(!overflow()); | 1958 ASSERT(!overflow()); |
| 1959 } | 1959 } |
| 1960 | 1960 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1984 emit_operand(ireg, dst); | 1984 emit_operand(ireg, dst); |
| 1985 emit(x); | 1985 emit(x); |
| 1986 } | 1986 } |
| 1987 } | 1987 } |
| 1988 | 1988 |
| 1989 | 1989 |
| 1990 void Assembler::emit_operand(Register reg, const Operand& adr) { | 1990 void Assembler::emit_operand(Register reg, const Operand& adr) { |
| 1991 adr.set_reg(reg); | 1991 adr.set_reg(reg); |
| 1992 memmove(pc_, adr.buf_, adr.len_); | 1992 memmove(pc_, adr.buf_, adr.len_); |
| 1993 pc_ += adr.len_; | 1993 pc_ += adr.len_; |
| 1994 if (adr.len_ >= sizeof(int32_t) && adr.rmode_ != no_reloc) { | 1994 if (adr.len_ >= sizeof(int32_t) && adr.rmode_ != RelocInfo::NONE) { |
| 1995 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 | 1995 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 |
| 1996 RecordRelocInfo(adr.rmode_); | 1996 RecordRelocInfo(adr.rmode_); |
| 1997 pc_ += sizeof(int32_t); | 1997 pc_ += sizeof(int32_t); |
| 1998 } | 1998 } |
| 1999 } | 1999 } |
| 2000 | 2000 |
| 2001 | 2001 |
| 2002 void Assembler::emit_operand(const Operand& adr, Register reg) { | 2002 void Assembler::emit_operand(const Operand& adr, Register reg) { |
| 2003 adr.set_reg(reg); | 2003 adr.set_reg(reg); |
| 2004 memmove(pc_, adr.buf_, adr.len_); | 2004 memmove(pc_, adr.buf_, adr.len_); |
| 2005 pc_ += adr.len_; | 2005 pc_ += adr.len_; |
| 2006 if (adr.len_ >= sizeof(int32_t) && adr.rmode_ != no_reloc) { | 2006 if (adr.len_ >= sizeof(int32_t) && adr.rmode_ != RelocInfo::NONE) { |
| 2007 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 | 2007 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 |
| 2008 RecordRelocInfo(adr.rmode_); | 2008 RecordRelocInfo(adr.rmode_); |
| 2009 pc_ += sizeof(int32_t); | 2009 pc_ += sizeof(int32_t); |
| 2010 } | 2010 } |
| 2011 } | 2011 } |
| 2012 | 2012 |
| 2013 | 2013 |
| 2014 void Assembler::emit_farith(int b1, int b2, int i) { | 2014 void Assembler::emit_farith(int b1, int b2, int i) { |
| 2015 ASSERT(is_uint8(b1) && is_uint8(b2)); // wrong opcode | 2015 ASSERT(is_uint8(b1) && is_uint8(b2)); // wrong opcode |
| 2016 ASSERT(0 <= i && i < 8); // illegal stack offset | 2016 ASSERT(0 <= i && i < 8); // illegal stack offset |
| 2017 EMIT(b1); | 2017 EMIT(b1); |
| 2018 EMIT(b2 + i); | 2018 EMIT(b2 + i); |
| 2019 } | 2019 } |
| 2020 | 2020 |
| 2021 | 2021 |
| 2022 void Assembler::dd(uint32_t data, RelocMode reloc_info) { | 2022 void Assembler::dd(uint32_t data, RelocInfo::Mode reloc_info) { |
| 2023 EnsureSpace ensure_space(this); | 2023 EnsureSpace ensure_space(this); |
| 2024 emit(data, reloc_info); | 2024 emit(data, reloc_info); |
| 2025 } | 2025 } |
| 2026 | 2026 |
| 2027 | 2027 |
| 2028 void Assembler::RecordRelocInfo(RelocMode rmode, intptr_t data) { | 2028 void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { |
| 2029 ASSERT(rmode != no_reloc); | 2029 ASSERT(rmode != RelocInfo::NONE); |
| 2030 // Don't record external references unless the heap will be serialized. | 2030 // Don't record external references unless the heap will be serialized. |
| 2031 if (rmode == external_reference && | 2031 if (rmode == RelocInfo::EXTERNAL_REFERENCE && |
| 2032 !Serializer::enabled() && | 2032 !Serializer::enabled() && |
| 2033 !FLAG_debug_code) { | 2033 !FLAG_debug_code) { |
| 2034 return; | 2034 return; |
| 2035 } | 2035 } |
| 2036 RelocInfo rinfo(pc_, rmode, data); | 2036 RelocInfo rinfo(pc_, rmode, data); |
| 2037 reloc_info_writer.Write(&rinfo); | 2037 reloc_info_writer.Write(&rinfo); |
| 2038 } | 2038 } |
| 2039 | 2039 |
| 2040 void Assembler::WriteInternalReference(int position, const Label& bound_label) { | 2040 void Assembler::WriteInternalReference(int position, const Label& bound_label) { |
| 2041 ASSERT(bound_label.is_bound()); | 2041 ASSERT(bound_label.is_bound()); |
| 2042 ASSERT(0 <= position); | 2042 ASSERT(0 <= position); |
| 2043 ASSERT(position + static_cast<int>(sizeof(uint32_t)) <= pc_offset()); | 2043 ASSERT(position + static_cast<int>(sizeof(uint32_t)) <= pc_offset()); |
| 2044 ASSERT(long_at(position) == 0); // only initialize once! | 2044 ASSERT(long_at(position) == 0); // only initialize once! |
| 2045 | 2045 |
| 2046 uint32_t label_loc = reinterpret_cast<uint32_t>(addr_at(bound_label.pos())); | 2046 uint32_t label_loc = reinterpret_cast<uint32_t>(addr_at(bound_label.pos())); |
| 2047 long_at_put(position, label_loc); | 2047 long_at_put(position, label_loc); |
| 2048 } | 2048 } |
| 2049 | 2049 |
| 2050 } } // namespace v8::internal | 2050 } } // namespace v8::internal |
| OLD | NEW |