My favorites | Sign in
v8
Project Home Downloads Wiki Issues Source Code Search
Checkout   Browse   Changes  
Changes to /trunk/src/assembler-ia32-inl.h
r0 vs. r9 Compare: vs.  Format:
Revision r9
Go to: 
Project members, sign in to write a code review
/trunk/src/assembler-ia32-inl.h /trunk/src/assembler-ia32-inl.h   r9
  1 // Copyright (c) 1994-2006 Sun Microsystems Inc.
  2 // All Rights Reserved.
  3 //
  4 // Redistribution and use in source and binary forms, with or without
  5 // modification, are permitted provided that the following conditions are
  6 // met:
  7 //
  8 // - Redistributions of source code must retain the above copyright notice,
  9 // this list of conditions and the following disclaimer.
  10 //
  11 // - Redistribution in binary form must reproduce the above copyright
  12 // notice, this list of conditions and the following disclaimer in the
  13 // documentation and/or other materials provided with the distribution.
  14 //
  15 // - Neither the name of Sun Microsystems or the names of contributors may
  16 // be used to endorse or promote products derived from this software without
  17 // specific prior written permission.
  18 //
  19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30
  31 // The original source code covered by the above license above has been
  32 // modified significantly by Google Inc.
  33 // Copyright 2006-2008 Google Inc. All Rights Reserved.
  34
  35 // A light-weight IA32 Assembler.
  36
  37 #ifndef V8_ASSEMBLER_IA32_INL_H_
  38 #define V8_ASSEMBLER_IA32_INL_H_
  39
  40 #include "cpu.h"
  41
  42 namespace v8 { namespace internal {
  43
  44 Condition NegateCondition(Condition cc) {
  45 return static_cast<Condition>(cc ^ 1);
  46 }
  47
  48
  49 // The modes possibly affected by apply must be in kApplyMask.
  50 void RelocInfo::apply(int delta) {
  51 if (rmode_ == runtime_entry || is_code_target(rmode_)) {
  52 int32_t* p = reinterpret_cast<int32_t*>(pc_);
  53 *p -= delta; // relocate entry
  54 } else if (rmode_ == js_return && is_call_instruction()) {
  55 // Special handling of js_return when a break point is set (call
  56 // instruction has been inserted).
  57 int32_t* p = reinterpret_cast<int32_t*>(pc_ + 1);
  58 *p -= delta; // relocate entry
  59 }
  60 }
  61
  62
  63 Address RelocInfo::target_address() {
  64 ASSERT(is_code_target(rmode_) || rmode_ == runtime_entry);
  65 return Assembler::target_address_at(pc_);
  66 }
  67
  68
  69 void RelocInfo::set_target_address(Address target) {
  70 ASSERT(is_code_target(rmode_) || rmode_ == runtime_entry);
  71 Assembler::set_target_address_at(pc_, target);
  72 }
  73
  74
  75 Object* RelocInfo::target_object() {
  76 ASSERT(is_code_target(rmode_) || rmode_ == embedded_object);
  77 return *reinterpret_cast<Object**>(pc_);
  78 }
  79
  80
  81 Object** RelocInfo::target_object_address() {
  82 ASSERT(is_code_target(rmode_) || rmode_ == embedded_object);
  83 return reinterpret_cast<Object**>(pc_);
  84 }
  85
  86
  87 void RelocInfo::set_target_object(Object* target) {
  88 ASSERT(is_code_target(rmode_) || rmode_ == embedded_object);
  89 *reinterpret_cast<Object**>(pc_) = target;
  90 }
  91
  92
  93 Address* RelocInfo::target_reference_address() {
  94 ASSERT(rmode_ == external_reference);
  95 return reinterpret_cast<Address*>(pc_);
  96 }
  97
  98
  99 Address RelocInfo::call_address() {
  100 ASSERT(is_call_instruction());
  101 return Assembler::target_address_at(pc_ + 1);
  102 }
  103
  104
  105 void RelocInfo::set_call_address(Address target) {
  106 ASSERT(is_call_instruction());
  107 Assembler::set_target_address_at(pc_ + 1, target);
  108 }
  109
  110
  111 Object* RelocInfo::call_object() {
  112 ASSERT(is_call_instruction());
  113 return *call_object_address();
  114 }
  115
  116
  117 Object** RelocInfo::call_object_address() {
  118 ASSERT(is_call_instruction());
  119 return reinterpret_cast<Object**>(pc_ + 1);
  120 }
  121
  122
  123 void RelocInfo::set_call_object(Object* target) {
  124 ASSERT(is_call_instruction());
  125 *call_object_address() = target;
  126 }
  127
  128
  129 bool RelocInfo::is_call_instruction() {
  130 return *pc_ == 0xE8;
  131 }
  132
  133
  134 Immediate::Immediate(int x) {
  135 x_ = x;
  136 rmode_ = no_reloc;
  137 }
  138
  139
  140 Immediate::Immediate(const ExternalReference& ext) {
  141 x_ = reinterpret_cast<int32_t>(ext.address());
  142 rmode_ = external_reference;
  143 }
  144
  145 Immediate::Immediate(const char* s) {
  146 x_ = reinterpret_cast<int32_t>(s);
  147 rmode_ = embedded_string;
  148 }
  149
  150
  151 Immediate::Immediate(Handle<Object> handle) {
  152 // Verify all Objects referred by code are NOT in new space.
  153 Object* obj = *handle;
  154 ASSERT(!Heap::InNewSpace(obj));
  155 if (obj->IsHeapObject()) {
  156 x_ = reinterpret_cast<intptr_t>(handle.location());
  157 rmode_ = embedded_object;
  158 } else {
  159 // no relocation needed
  160 x_ = reinterpret_cast<intptr_t>(obj);
  161 rmode_ = no_reloc;
  162 }
  163 }
  164
  165
  166 Immediate::Immediate(Smi* value) {
  167 x_ = reinterpret_cast<intptr_t>(value);
  168 rmode_ = no_reloc;
  169 }
  170
  171
  172 void Assembler::emit(uint32_t x) {
  173 *reinterpret_cast<uint32_t*>(pc_) = x;
  174 pc_ += sizeof(uint32_t);
  175 }
  176
  177
  178 void Assembler::emit(Handle<Object> handle) {
  179 // Verify all Objects referred by code are NOT in new space.
  180 Object* obj = *handle;
  181 ASSERT(!Heap::InNewSpace(obj));
  182 if (obj->IsHeapObject()) {
  183 emit(reinterpret_cast<intptr_t>(handle.location()), embedded_object);
  184 } else {
  185 // no relocation needed
  186 emit(reinterpret_cast<intptr_t>(obj));
  187 }
  188 }
  189
  190
  191 void Assembler::emit(uint32_t x, RelocMode rmode) {
  192 if (rmode != no_reloc) RecordRelocInfo(rmode);
  193 emit(x);
  194 }
  195
  196
  197 void Assembler::emit(const Immediate& x) {
  198 if (x.rmode_ != no_reloc) RecordRelocInfo(x.rmode_);
  199 emit(x.x_);
  200 }
  201
  202
  203 Address Assembler::target_address_at(Address pc) {
  204 return pc + sizeof(int32_t) + *reinterpret_cast<int32_t*>(pc);
  205 }
  206
  207
  208 void Assembler::set_target_address_at(Address pc, Address target) {
  209 int32_t* p = reinterpret_cast<int32_t*>(pc);
  210 *p = target - (pc + sizeof(int32_t));
  211 CPU::FlushICache(p, sizeof(int32_t));
  212 }
  213
  214
  215 Displacement Assembler::disp_at(Label* L) {
  216 return Displacement(long_at(L->pos()));
  217 }
  218
  219
  220 void Assembler::disp_at_put(Label* L, Displacement disp) {
  221 long_at_put(L->pos(), disp.data());
  222 }
  223
  224
  225 void Assembler::emit_disp(Label* L, Displacement::Type type) {
  226 Displacement disp(L, type);
  227 L->link_to(pc_offset());
  228 emit(static_cast<int>(disp.data()));
  229 }
  230
  231
  232 void Operand::set_modrm(int mod, // reg == 0
  233 Register rm) {
  234 ASSERT((mod & -4) == 0);
  235 buf_[0] = mod << 6 | rm.code();
  236 len_ = 1;
  237 }
  238
  239
  240 void Operand::set_dispr(int32_t disp, RelocMode rmode) {
  241 ASSERT(len_ == 1 || len_ == 2);
  242 *reinterpret_cast<int32_t*>(&buf_[len_]) = disp;
  243 len_ += sizeof(int32_t);
  244 rmode_ = rmode;
  245 }
  246
  247 Operand::Operand(Register reg) {
  248 // reg
  249 set_modrm(3, reg);
  250 }
  251
  252
  253 Operand::Operand(int32_t disp, RelocMode rmode) {
  254 // [disp/r]
  255 set_modrm(0, ebp);
  256 set_dispr(disp, rmode);
  257 }
  258
  259 } } // namespace v8::internal
  260
  261 #endif // V8_ASSEMBLER_IA32_INL_H_
Powered by Google Project Hosting