Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: src/ia32/assembler-ia32.cc

Issue 900223006: [ia32] Assembler support for internal references. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ia32/assembler-ia32.h ('k') | src/ia32/disasm-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 if (imm16 == 0) { 1333 if (imm16 == 0) {
1334 EMIT(0xC3); 1334 EMIT(0xC3);
1335 } else { 1335 } else {
1336 EMIT(0xC2); 1336 EMIT(0xC2);
1337 EMIT(imm16 & 0xFF); 1337 EMIT(imm16 & 0xFF);
1338 EMIT((imm16 >> 8) & 0xFF); 1338 EMIT((imm16 >> 8) & 0xFF);
1339 } 1339 }
1340 } 1340 }
1341 1341
1342 1342
1343 void Assembler::ud2() {
1344 EnsureSpace ensure_space(this);
1345 EMIT(0x0F);
1346 EMIT(0x0B);
1347 }
1348
1349
1343 // Labels refer to positions in the (to be) generated code. 1350 // Labels refer to positions in the (to be) generated code.
1344 // There are bound, linked, and unused labels. 1351 // There are bound, linked, and unused labels.
1345 // 1352 //
1346 // Bound labels refer to known positions in the already 1353 // Bound labels refer to known positions in the already
1347 // generated code. pos() is the position the label refers to. 1354 // generated code. pos() is the position the label refers to.
1348 // 1355 //
1349 // Linked labels refer to unknown positions in the code 1356 // Linked labels refer to unknown positions in the code
1350 // to be generated; pos() is the position of the 32bit 1357 // to be generated; pos() is the position of the 32bit
1351 // Displacement of the last instruction using the label. 1358 // Displacement of the last instruction using the label.
1352 1359
(...skipping 18 matching lines...) Expand all
1371 } 1378 }
1372 } 1379 }
1373 1380
1374 1381
1375 void Assembler::bind_to(Label* L, int pos) { 1382 void Assembler::bind_to(Label* L, int pos) {
1376 EnsureSpace ensure_space(this); 1383 EnsureSpace ensure_space(this);
1377 DCHECK(0 <= pos && pos <= pc_offset()); // must have a valid binding position 1384 DCHECK(0 <= pos && pos <= pc_offset()); // must have a valid binding position
1378 while (L->is_linked()) { 1385 while (L->is_linked()) {
1379 Displacement disp = disp_at(L); 1386 Displacement disp = disp_at(L);
1380 int fixup_pos = L->pos(); 1387 int fixup_pos = L->pos();
1381 if (disp.type() == Displacement::CODE_RELATIVE) { 1388 if (disp.type() == Displacement::CODE_ABSOLUTE) {
1389 long_at_put(fixup_pos, reinterpret_cast<int>(buffer_ + pos));
1390 internal_reference_positions_.push_back(fixup_pos);
1391 } else if (disp.type() == Displacement::CODE_RELATIVE) {
1382 // Relative to Code* heap object pointer. 1392 // Relative to Code* heap object pointer.
1383 long_at_put(fixup_pos, pos + Code::kHeaderSize - kHeapObjectTag); 1393 long_at_put(fixup_pos, pos + Code::kHeaderSize - kHeapObjectTag);
1384 } else { 1394 } else {
1385 if (disp.type() == Displacement::UNCONDITIONAL_JUMP) { 1395 if (disp.type() == Displacement::UNCONDITIONAL_JUMP) {
1386 DCHECK(byte_at(fixup_pos - 1) == 0xE9); // jmp expected 1396 DCHECK(byte_at(fixup_pos - 1) == 0xE9); // jmp expected
1387 } 1397 }
1388 // Relative address, relative to point after address. 1398 // Relative address, relative to point after address.
1389 int imm32 = pos - (fixup_pos + sizeof(int32_t)); 1399 int imm32 = pos - (fixup_pos + sizeof(int32_t));
1390 long_at_put(fixup_pos, imm32); 1400 long_at_put(fixup_pos, imm32);
1391 } 1401 }
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after
2683 desc.reloc_size); 2693 desc.reloc_size);
2684 2694
2685 // Switch buffers. 2695 // Switch buffers.
2686 DeleteArray(buffer_); 2696 DeleteArray(buffer_);
2687 buffer_ = desc.buffer; 2697 buffer_ = desc.buffer;
2688 buffer_size_ = desc.buffer_size; 2698 buffer_size_ = desc.buffer_size;
2689 pc_ += pc_delta; 2699 pc_ += pc_delta;
2690 reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta, 2700 reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta,
2691 reloc_info_writer.last_pc() + pc_delta); 2701 reloc_info_writer.last_pc() + pc_delta);
2692 2702
2693 // Relocate runtime entries. 2703 // Relocate internal references.
2694 for (RelocIterator it(desc); !it.done(); it.next()) { 2704 for (auto pos : internal_reference_positions_) {
2695 RelocInfo::Mode rmode = it.rinfo()->rmode(); 2705 int32_t* p = reinterpret_cast<int32_t*>(buffer_ + pos);
2696 if (rmode == RelocInfo::INTERNAL_REFERENCE) { 2706 *p += pc_delta;
2697 int32_t* p = reinterpret_cast<int32_t*>(it.rinfo()->pc());
2698 if (*p != 0) { // 0 means uninitialized.
2699 *p += pc_delta;
2700 }
2701 }
2702 } 2707 }
2703 2708
2704 DCHECK(!buffer_overflow()); 2709 DCHECK(!buffer_overflow());
2705 } 2710 }
2706 2711
2707 2712
2708 void Assembler::emit_arith_b(int op1, int op2, Register dst, int imm8) { 2713 void Assembler::emit_arith_b(int op1, int op2, Register dst, int imm8) {
2709 DCHECK(is_uint8(op1) && is_uint8(op2)); // wrong opcode 2714 DCHECK(is_uint8(op1) && is_uint8(op2)); // wrong opcode
2710 DCHECK(is_uint8(imm8)); 2715 DCHECK(is_uint8(imm8));
2711 DCHECK((op1 & 0x01) == 0); // should be 8bit operation 2716 DCHECK((op1 & 0x01) == 0); // should be 8bit operation
(...skipping 29 matching lines...) Expand all
2741 pc_[0] = (adr.buf_[0] & ~0x38) | (reg.code() << 3); 2746 pc_[0] = (adr.buf_[0] & ~0x38) | (reg.code() << 3);
2742 2747
2743 // Emit the rest of the encoded operand. 2748 // Emit the rest of the encoded operand.
2744 for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i]; 2749 for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i];
2745 pc_ += length; 2750 pc_ += length;
2746 2751
2747 // Emit relocation information if necessary. 2752 // Emit relocation information if necessary.
2748 if (length >= sizeof(int32_t) && !RelocInfo::IsNone(adr.rmode_)) { 2753 if (length >= sizeof(int32_t) && !RelocInfo::IsNone(adr.rmode_)) {
2749 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 2754 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32
2750 RecordRelocInfo(adr.rmode_); 2755 RecordRelocInfo(adr.rmode_);
2751 pc_ += sizeof(int32_t); 2756 if (adr.rmode_ == RelocInfo::INTERNAL_REFERENCE) { // Fixup for labels
2757 emit_label(*reinterpret_cast<Label**>(pc_));
2758 } else {
2759 pc_ += sizeof(int32_t);
2760 }
2752 } 2761 }
2753 } 2762 }
2754 2763
2764
2765 void Assembler::emit_label(Label* label) {
2766 if (label->is_bound()) {
2767 internal_reference_positions_.push_back(pc_offset());
2768 emit(reinterpret_cast<uint32_t>(buffer_ + label->pos()));
2769 } else {
2770 emit_disp(label, Displacement::CODE_ABSOLUTE);
2771 }
2772 }
2773
2755 2774
2756 void Assembler::emit_farith(int b1, int b2, int i) { 2775 void Assembler::emit_farith(int b1, int b2, int i) {
2757 DCHECK(is_uint8(b1) && is_uint8(b2)); // wrong opcode 2776 DCHECK(is_uint8(b1) && is_uint8(b2)); // wrong opcode
2758 DCHECK(0 <= i && i < 8); // illegal stack offset 2777 DCHECK(0 <= i && i < 8); // illegal stack offset
2759 EMIT(b1); 2778 EMIT(b1);
2760 EMIT(b2 + i); 2779 EMIT(b2 + i);
2761 } 2780 }
2762 2781
2763 2782
2764 void Assembler::db(uint8_t data) { 2783 void Assembler::db(uint8_t data) {
2765 EnsureSpace ensure_space(this); 2784 EnsureSpace ensure_space(this);
2766 EMIT(data); 2785 EMIT(data);
2767 } 2786 }
2768 2787
2769 2788
2770 void Assembler::dd(uint32_t data) { 2789 void Assembler::dd(uint32_t data) {
2771 EnsureSpace ensure_space(this); 2790 EnsureSpace ensure_space(this);
2772 emit(data); 2791 emit(data);
2773 } 2792 }
2774 2793
2775 2794
2795 void Assembler::dd(Label* label) {
2796 EnsureSpace ensure_space(this);
2797 RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE);
2798 emit_label(label);
2799 }
2800
2801
2776 void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { 2802 void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
2777 DCHECK(!RelocInfo::IsNone(rmode)); 2803 DCHECK(!RelocInfo::IsNone(rmode));
2778 // Don't record external references unless the heap will be serialized. 2804 // Don't record external references unless the heap will be serialized.
2779 if (rmode == RelocInfo::EXTERNAL_REFERENCE && 2805 if (rmode == RelocInfo::EXTERNAL_REFERENCE &&
2780 !serializer_enabled() && !emit_debug_code()) { 2806 !serializer_enabled() && !emit_debug_code()) {
2781 return; 2807 return;
2782 } 2808 }
2783 RelocInfo rinfo(pc_, rmode, data, NULL); 2809 RelocInfo rinfo(pc_, rmode, data, NULL);
2784 reloc_info_writer.Write(&rinfo); 2810 reloc_info_writer.Write(&rinfo);
2785 } 2811 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2820 fprintf(coverage_log, "%s\n", file_line); 2846 fprintf(coverage_log, "%s\n", file_line);
2821 fflush(coverage_log); 2847 fflush(coverage_log);
2822 } 2848 }
2823 } 2849 }
2824 2850
2825 #endif 2851 #endif
2826 2852
2827 } } // namespace v8::internal 2853 } } // namespace v8::internal
2828 2854
2829 #endif // V8_TARGET_ARCH_IA32 2855 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/assembler-ia32.h ('k') | src/ia32/disasm-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698