| 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 1731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2005 void Assembler::WriteRecordedPositions() { | 1999 void Assembler::WriteRecordedPositions() { |
| 2006 // Write the statement position if it is different from what was written last | 2000 // Write the statement position if it is different from what was written last |
| 2007 // time. | 2001 // time. |
| 2008 if (current_statement_position_ != written_statement_position_) { | 2002 if (current_statement_position_ != written_statement_position_) { |
| 2009 EnsureSpace ensure_space(this); | 2003 EnsureSpace ensure_space(this); |
| 2010 RecordRelocInfo(RelocInfo::STATEMENT_POSITION, current_statement_position_); | 2004 RecordRelocInfo(RelocInfo::STATEMENT_POSITION, current_statement_position_); |
| 2011 written_statement_position_ = current_statement_position_; | 2005 written_statement_position_ = current_statement_position_; |
| 2012 } | 2006 } |
| 2013 | 2007 |
| 2014 // Write the position if it is different from what was written last time and | 2008 // Write the position if it is different from what was written last time and |
| 2015 // also diferent from the written statement position. | 2009 // also different from the written statement position. |
| 2016 if (current_position_ != written_position_ && | 2010 if (current_position_ != written_position_ && |
| 2017 current_position_ != written_statement_position_) { | 2011 current_position_ != written_statement_position_) { |
| 2018 EnsureSpace ensure_space(this); | 2012 EnsureSpace ensure_space(this); |
| 2019 RecordRelocInfo(RelocInfo::POSITION, current_position_); | 2013 RecordRelocInfo(RelocInfo::POSITION, current_position_); |
| 2020 written_position_ = current_position_; | 2014 written_position_ = current_position_; |
| 2021 } | 2015 } |
| 2022 } | 2016 } |
| 2023 | 2017 |
| 2024 | 2018 |
| 2025 void Assembler::GrowBuffer() { | 2019 void Assembler::GrowBuffer() { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2113 emit(x); | 2107 emit(x); |
| 2114 } else { | 2108 } else { |
| 2115 EMIT(0x81); // using a literal 32-bit immediate. | 2109 EMIT(0x81); // using a literal 32-bit immediate. |
| 2116 emit_operand(ireg, dst); | 2110 emit_operand(ireg, dst); |
| 2117 emit(x); | 2111 emit(x); |
| 2118 } | 2112 } |
| 2119 } | 2113 } |
| 2120 | 2114 |
| 2121 | 2115 |
| 2122 void Assembler::emit_operand(Register reg, const Operand& adr) { | 2116 void Assembler::emit_operand(Register reg, const Operand& adr) { |
| 2123 adr.set_reg(reg); | 2117 const unsigned length = adr.len_; |
| 2124 memmove(pc_, adr.buf_, adr.len_); | 2118 ASSERT(length > 0); |
| 2125 pc_ += adr.len_; | 2119 |
| 2126 if (adr.len_ >= sizeof(int32_t) && adr.rmode_ != RelocInfo::NONE) { | 2120 // Emit updated ModRM byte containing the given register. |
| 2121 pc_[0] = (adr.buf_[0] & ~0x38) | (reg.code() << 3); |
| 2122 |
| 2123 // Emit the rest of the encoded operand. |
| 2124 for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i]; |
| 2125 pc_ += length; |
| 2126 |
| 2127 // Emit relocation information if necessary. |
| 2128 if (length >= sizeof(int32_t) && adr.rmode_ != RelocInfo::NONE) { |
| 2127 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 | 2129 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 |
| 2128 RecordRelocInfo(adr.rmode_); | 2130 RecordRelocInfo(adr.rmode_); |
| 2129 pc_ += sizeof(int32_t); | 2131 pc_ += sizeof(int32_t); |
| 2130 } | 2132 } |
| 2131 } | 2133 } |
| 2132 | 2134 |
| 2133 | 2135 |
| 2134 void Assembler::emit_farith(int b1, int b2, int i) { | 2136 void Assembler::emit_farith(int b1, int b2, int i) { |
| 2135 ASSERT(is_uint8(b1) && is_uint8(b2)); // wrong opcode | 2137 ASSERT(is_uint8(b1) && is_uint8(b2)); // wrong opcode |
| 2136 ASSERT(0 <= i && i < 8); // illegal stack offset | 2138 ASSERT(0 <= i && i < 8); // illegal stack offset |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2162 ASSERT(bound_label.is_bound()); | 2164 ASSERT(bound_label.is_bound()); |
| 2163 ASSERT(0 <= position); | 2165 ASSERT(0 <= position); |
| 2164 ASSERT(position + static_cast<int>(sizeof(uint32_t)) <= pc_offset()); | 2166 ASSERT(position + static_cast<int>(sizeof(uint32_t)) <= pc_offset()); |
| 2165 ASSERT(long_at(position) == 0); // only initialize once! | 2167 ASSERT(long_at(position) == 0); // only initialize once! |
| 2166 | 2168 |
| 2167 uint32_t label_loc = reinterpret_cast<uint32_t>(addr_at(bound_label.pos())); | 2169 uint32_t label_loc = reinterpret_cast<uint32_t>(addr_at(bound_label.pos())); |
| 2168 long_at_put(position, label_loc); | 2170 long_at_put(position, label_loc); |
| 2169 } | 2171 } |
| 2170 | 2172 |
| 2171 } } // namespace v8::internal | 2173 } } // namespace v8::internal |
| OLD | NEW |