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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 len_ = 2; | 248 len_ = 2; |
249 } | 249 } |
250 | 250 |
251 | 251 |
252 void Operand::set_disp8(int8_t disp) { | 252 void Operand::set_disp8(int8_t disp) { |
253 ASSERT(len_ == 1 || len_ == 2); | 253 ASSERT(len_ == 1 || len_ == 2); |
254 *reinterpret_cast<int8_t*>(&buf_[len_++]) = disp; | 254 *reinterpret_cast<int8_t*>(&buf_[len_++]) = disp; |
255 } | 255 } |
256 | 256 |
257 | 257 |
258 void Operand::set_reg(Register reg) const { | |
259 ASSERT(len_ > 0); | |
260 buf_[0] = (buf_[0] & ~0x38) | static_cast<byte>(reg.code() << 3); | |
261 } | |
262 | |
263 | |
264 bool Operand::is_reg(Register reg) const { | 258 bool Operand::is_reg(Register reg) const { |
265 return ((buf_[0] & 0xF8) == 0xC0) // addressing mode is register only. | 259 return ((buf_[0] & 0xF8) == 0xC0) // addressing mode is register only. |
266 && ((buf_[0] & 0x07) == reg.code()); // register codes match. | 260 && ((buf_[0] & 0x07) == reg.code()); // register codes match. |
267 } | 261 } |
268 | 262 |
269 // ----------------------------------------------------------------------------- | 263 // ----------------------------------------------------------------------------- |
270 // Implementation of Assembler | 264 // Implementation of Assembler |
271 | 265 |
272 // Emit a single byte. Must always be inlined. | 266 // Emit a single byte. Must always be inlined. |
273 #define EMIT(x) \ | 267 #define EMIT(x) \ |
(...skipping 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2091 emit(x); | 2085 emit(x); |
2092 } else { | 2086 } else { |
2093 EMIT(0x81); // using a literal 32-bit immediate. | 2087 EMIT(0x81); // using a literal 32-bit immediate. |
2094 emit_operand(ireg, dst); | 2088 emit_operand(ireg, dst); |
2095 emit(x); | 2089 emit(x); |
2096 } | 2090 } |
2097 } | 2091 } |
2098 | 2092 |
2099 | 2093 |
2100 void Assembler::emit_operand(Register reg, const Operand& adr) { | 2094 void Assembler::emit_operand(Register reg, const Operand& adr) { |
2101 adr.set_reg(reg); | 2095 const unsigned length = adr.len_; |
2102 memmove(pc_, adr.buf_, adr.len_); | 2096 ASSERT(length > 0); |
2103 pc_ += adr.len_; | 2097 |
2104 if (adr.len_ >= sizeof(int32_t) && adr.rmode_ != RelocInfo::NONE) { | 2098 // Emit updated ModRM byte containing the given register. |
| 2099 pc_[0] = (adr.buf_[0] & ~0x38) | (reg.code() << 3); |
| 2100 |
| 2101 // Emit the rest of the encoded operand. |
| 2102 for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i]; |
| 2103 pc_ += length; |
| 2104 |
| 2105 // Emit relocation information if necessary. |
| 2106 if (length >= sizeof(int32_t) && adr.rmode_ != RelocInfo::NONE) { |
2105 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 | 2107 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 |
2106 RecordRelocInfo(adr.rmode_); | 2108 RecordRelocInfo(adr.rmode_); |
2107 pc_ += sizeof(int32_t); | 2109 pc_ += sizeof(int32_t); |
2108 } | 2110 } |
2109 } | 2111 } |
2110 | 2112 |
2111 | 2113 |
2112 void Assembler::emit_farith(int b1, int b2, int i) { | 2114 void Assembler::emit_farith(int b1, int b2, int i) { |
2113 ASSERT(is_uint8(b1) && is_uint8(b2)); // wrong opcode | 2115 ASSERT(is_uint8(b1) && is_uint8(b2)); // wrong opcode |
2114 ASSERT(0 <= i && i < 8); // illegal stack offset | 2116 ASSERT(0 <= i && i < 8); // illegal stack offset |
(...skipping 25 matching lines...) Expand all Loading... |
2140 ASSERT(bound_label.is_bound()); | 2142 ASSERT(bound_label.is_bound()); |
2141 ASSERT(0 <= position); | 2143 ASSERT(0 <= position); |
2142 ASSERT(position + static_cast<int>(sizeof(uint32_t)) <= pc_offset()); | 2144 ASSERT(position + static_cast<int>(sizeof(uint32_t)) <= pc_offset()); |
2143 ASSERT(long_at(position) == 0); // only initialize once! | 2145 ASSERT(long_at(position) == 0); // only initialize once! |
2144 | 2146 |
2145 uint32_t label_loc = reinterpret_cast<uint32_t>(addr_at(bound_label.pos())); | 2147 uint32_t label_loc = reinterpret_cast<uint32_t>(addr_at(bound_label.pos())); |
2146 long_at_put(position, label_loc); | 2148 long_at_put(position, label_loc); |
2147 } | 2149 } |
2148 | 2150 |
2149 } } // namespace v8::internal | 2151 } } // namespace v8::internal |
OLD | NEW |