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 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 if (imm16 == 0) { | 1195 if (imm16 == 0) { |
1196 EMIT(0xC3); | 1196 EMIT(0xC3); |
1197 } else { | 1197 } else { |
1198 EMIT(0xC2); | 1198 EMIT(0xC2); |
1199 EMIT(imm16 & 0xFF); | 1199 EMIT(imm16 & 0xFF); |
1200 EMIT((imm16 >> 8) & 0xFF); | 1200 EMIT((imm16 >> 8) & 0xFF); |
1201 } | 1201 } |
1202 } | 1202 } |
1203 | 1203 |
1204 | 1204 |
| 1205 void Assembler::ud2() { |
| 1206 EnsureSpace ensure_space(this); |
| 1207 EMIT(0x0F); |
| 1208 EMIT(0x0B); |
| 1209 } |
| 1210 |
| 1211 |
1205 // Labels refer to positions in the (to be) generated code. | 1212 // Labels refer to positions in the (to be) generated code. |
1206 // There are bound, linked, and unused labels. | 1213 // There are bound, linked, and unused labels. |
1207 // | 1214 // |
1208 // Bound labels refer to known positions in the already | 1215 // Bound labels refer to known positions in the already |
1209 // generated code. pos() is the position the label refers to. | 1216 // generated code. pos() is the position the label refers to. |
1210 // | 1217 // |
1211 // Linked labels refer to unknown positions in the code | 1218 // Linked labels refer to unknown positions in the code |
1212 // to be generated; pos() is the position of the 32bit | 1219 // to be generated; pos() is the position of the 32bit |
1213 // Displacement of the last instruction using the label. | 1220 // Displacement of the last instruction using the label. |
1214 | 1221 |
(...skipping 18 matching lines...) Expand all Loading... |
1233 } | 1240 } |
1234 } | 1241 } |
1235 | 1242 |
1236 | 1243 |
1237 void Assembler::bind_to(Label* L, int pos) { | 1244 void Assembler::bind_to(Label* L, int pos) { |
1238 EnsureSpace ensure_space(this); | 1245 EnsureSpace ensure_space(this); |
1239 DCHECK(0 <= pos && pos <= pc_offset()); // must have a valid binding position | 1246 DCHECK(0 <= pos && pos <= pc_offset()); // must have a valid binding position |
1240 while (L->is_linked()) { | 1247 while (L->is_linked()) { |
1241 Displacement disp = disp_at(L); | 1248 Displacement disp = disp_at(L); |
1242 int fixup_pos = L->pos(); | 1249 int fixup_pos = L->pos(); |
1243 if (disp.type() == Displacement::CODE_RELATIVE) { | 1250 if (disp.type() == Displacement::CODE_ABSOLUTE) { |
| 1251 long_at_put(fixup_pos, reinterpret_cast<int>(buffer_ + pos)); |
| 1252 internal_reference_positions_.push_back(fixup_pos); |
| 1253 } else if (disp.type() == Displacement::CODE_RELATIVE) { |
1244 // Relative to Code* heap object pointer. | 1254 // Relative to Code* heap object pointer. |
1245 long_at_put(fixup_pos, pos + Code::kHeaderSize - kHeapObjectTag); | 1255 long_at_put(fixup_pos, pos + Code::kHeaderSize - kHeapObjectTag); |
1246 } else { | 1256 } else { |
1247 if (disp.type() == Displacement::UNCONDITIONAL_JUMP) { | 1257 if (disp.type() == Displacement::UNCONDITIONAL_JUMP) { |
1248 DCHECK(byte_at(fixup_pos - 1) == 0xE9); // jmp expected | 1258 DCHECK(byte_at(fixup_pos - 1) == 0xE9); // jmp expected |
1249 } | 1259 } |
1250 // Relative address, relative to point after address. | 1260 // Relative address, relative to point after address. |
1251 int imm32 = pos - (fixup_pos + sizeof(int32_t)); | 1261 int imm32 = pos - (fixup_pos + sizeof(int32_t)); |
1252 long_at_put(fixup_pos, imm32); | 1262 long_at_put(fixup_pos, imm32); |
1253 } | 1263 } |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 MemMove(rc_delta + reloc_info_writer.pos(), reloc_info_writer.pos(), | 1941 MemMove(rc_delta + reloc_info_writer.pos(), reloc_info_writer.pos(), |
1932 desc.reloc_size); | 1942 desc.reloc_size); |
1933 | 1943 |
1934 DeleteArray(buffer_); | 1944 DeleteArray(buffer_); |
1935 buffer_ = desc.buffer; | 1945 buffer_ = desc.buffer; |
1936 buffer_size_ = desc.buffer_size; | 1946 buffer_size_ = desc.buffer_size; |
1937 pc_ += pc_delta; | 1947 pc_ += pc_delta; |
1938 reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta, | 1948 reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta, |
1939 reloc_info_writer.last_pc() + pc_delta); | 1949 reloc_info_writer.last_pc() + pc_delta); |
1940 | 1950 |
1941 // Relocate runtime entries. | 1951 // Relocate internal references. |
1942 for (RelocIterator it(desc); !it.done(); it.next()) { | 1952 for (auto pos : internal_reference_positions_) { |
1943 RelocInfo::Mode rmode = it.rinfo()->rmode(); | 1953 int32_t* p = reinterpret_cast<int32_t*>(buffer_ + pos); |
1944 if (rmode == RelocInfo::INTERNAL_REFERENCE) { | 1954 *p += pc_delta; |
1945 int32_t* p = reinterpret_cast<int32_t*>(it.rinfo()->pc()); | |
1946 if (*p != 0) { // 0 means uninitialized. | |
1947 *p += pc_delta; | |
1948 } | |
1949 } | |
1950 } | 1955 } |
1951 | 1956 |
1952 DCHECK(!buffer_overflow()); | 1957 DCHECK(!buffer_overflow()); |
1953 } | 1958 } |
1954 | 1959 |
1955 | 1960 |
1956 void Assembler::emit_arith_b(int op1, int op2, Register dst, int imm8) { | 1961 void Assembler::emit_arith_b(int op1, int op2, Register dst, int imm8) { |
1957 DCHECK(is_uint8(op1) && is_uint8(op2)); // wrong opcode | 1962 DCHECK(is_uint8(op1) && is_uint8(op2)); // wrong opcode |
1958 DCHECK(is_uint8(imm8)); | 1963 DCHECK(is_uint8(imm8)); |
1959 DCHECK((op1 & 0x01) == 0); // should be 8bit operation | 1964 DCHECK((op1 & 0x01) == 0); // should be 8bit operation |
(...skipping 29 matching lines...) Expand all Loading... |
1989 pc_[0] = (adr.buf_[0] & ~0x38) | (reg.code() << 3); | 1994 pc_[0] = (adr.buf_[0] & ~0x38) | (reg.code() << 3); |
1990 | 1995 |
1991 // Emit the rest of the encoded operand. | 1996 // Emit the rest of the encoded operand. |
1992 for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i]; | 1997 for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i]; |
1993 pc_ += length; | 1998 pc_ += length; |
1994 | 1999 |
1995 // Emit relocation information if necessary. | 2000 // Emit relocation information if necessary. |
1996 if (length >= sizeof(int32_t) && !RelocInfo::IsNone(adr.rmode_)) { | 2001 if (length >= sizeof(int32_t) && !RelocInfo::IsNone(adr.rmode_)) { |
1997 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 | 2002 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 |
1998 RecordRelocInfo(adr.rmode_); | 2003 RecordRelocInfo(adr.rmode_); |
1999 pc_ += sizeof(int32_t); | 2004 if (adr.rmode_ == RelocInfo::INTERNAL_REFERENCE) { // Fixup for labels |
| 2005 emit_label(*reinterpret_cast<Label**>(pc_)); |
| 2006 } else { |
| 2007 pc_ += sizeof(int32_t); |
| 2008 } |
2000 } | 2009 } |
2001 } | 2010 } |
2002 | 2011 |
| 2012 |
| 2013 void Assembler::emit_label(Label* label) { |
| 2014 if (label->is_bound()) { |
| 2015 internal_reference_positions_.push_back(pc_offset()); |
| 2016 emit(reinterpret_cast<uint32_t>(buffer_ + label->pos())); |
| 2017 } else { |
| 2018 emit_disp(label, Displacement::CODE_ABSOLUTE); |
| 2019 } |
| 2020 } |
| 2021 |
2003 | 2022 |
2004 void Assembler::emit_farith(int b1, int b2, int i) { | 2023 void Assembler::emit_farith(int b1, int b2, int i) { |
2005 DCHECK(is_uint8(b1) && is_uint8(b2)); // wrong opcode | 2024 DCHECK(is_uint8(b1) && is_uint8(b2)); // wrong opcode |
2006 DCHECK(0 <= i && i < 8); // illegal stack offset | 2025 DCHECK(0 <= i && i < 8); // illegal stack offset |
2007 EMIT(b1); | 2026 EMIT(b1); |
2008 EMIT(b2 + i); | 2027 EMIT(b2 + i); |
2009 } | 2028 } |
2010 | 2029 |
2011 | 2030 |
2012 void Assembler::db(uint8_t data) { | 2031 void Assembler::db(uint8_t data) { |
2013 EnsureSpace ensure_space(this); | 2032 EnsureSpace ensure_space(this); |
2014 EMIT(data); | 2033 EMIT(data); |
2015 } | 2034 } |
2016 | 2035 |
2017 | 2036 |
2018 void Assembler::dd(uint32_t data) { | 2037 void Assembler::dd(uint32_t data) { |
2019 EnsureSpace ensure_space(this); | 2038 EnsureSpace ensure_space(this); |
2020 emit(data); | 2039 emit(data); |
2021 } | 2040 } |
2022 | 2041 |
2023 | 2042 |
| 2043 void Assembler::dd(Label* label) { |
| 2044 EnsureSpace ensure_space(this); |
| 2045 RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE); |
| 2046 emit_label(label); |
| 2047 } |
| 2048 |
| 2049 |
2024 void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { | 2050 void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { |
2025 DCHECK(!RelocInfo::IsNone(rmode)); | 2051 DCHECK(!RelocInfo::IsNone(rmode)); |
2026 // Don't record external references unless the heap will be serialized. | 2052 // Don't record external references unless the heap will be serialized. |
2027 if (rmode == RelocInfo::EXTERNAL_REFERENCE && | 2053 if (rmode == RelocInfo::EXTERNAL_REFERENCE && |
2028 !serializer_enabled() && !emit_debug_code()) { | 2054 !serializer_enabled() && !emit_debug_code()) { |
2029 return; | 2055 return; |
2030 } | 2056 } |
2031 RelocInfo rinfo(pc_, rmode, data, NULL); | 2057 RelocInfo rinfo(pc_, rmode, data, NULL); |
2032 reloc_info_writer.Write(&rinfo); | 2058 reloc_info_writer.Write(&rinfo); |
2033 } | 2059 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2068 fprintf(coverage_log, "%s\n", file_line); | 2094 fprintf(coverage_log, "%s\n", file_line); |
2069 fflush(coverage_log); | 2095 fflush(coverage_log); |
2070 } | 2096 } |
2071 } | 2097 } |
2072 | 2098 |
2073 #endif | 2099 #endif |
2074 | 2100 |
2075 } } // namespace v8::internal | 2101 } } // namespace v8::internal |
2076 | 2102 |
2077 #endif // V8_TARGET_ARCH_X87 | 2103 #endif // V8_TARGET_ARCH_X87 |
OLD | NEW |