• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
6 // are 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
14 // distribution.
15 //
16 // - Neither the name of Sun Microsystems or the names of contributors may
17 // be used to endorse or promote products derived from this software without
18 // specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 // OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 // The original source code covered by the above license above has been modified
34 // significantly by Google Inc.
35 // Copyright 2006-2008 the V8 project authors. All rights reserved.
36 
37 #ifndef V8_ARM_ASSEMBLER_ARM_INL_H_
38 #define V8_ARM_ASSEMBLER_ARM_INL_H_
39 
40 #include "arm/assembler-arm.h"
41 #include "cpu.h"
42 
43 
44 namespace v8 {
45 namespace internal {
46 
NegateCondition(Condition cc)47 Condition NegateCondition(Condition cc) {
48   ASSERT(cc != al);
49   return static_cast<Condition>(cc ^ ne);
50 }
51 
52 
apply(intptr_t delta)53 void RelocInfo::apply(intptr_t delta) {
54   if (RelocInfo::IsInternalReference(rmode_)) {
55     // absolute code pointer inside code object moves with the code object.
56     int32_t* p = reinterpret_cast<int32_t*>(pc_);
57     *p += delta;  // relocate entry
58   }
59   // We do not use pc relative addressing on ARM, so there is
60   // nothing else to do.
61 }
62 
63 
target_address()64 Address RelocInfo::target_address() {
65   ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY);
66   return Assembler::target_address_at(pc_);
67 }
68 
69 
target_address_address()70 Address RelocInfo::target_address_address() {
71   ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY);
72   return reinterpret_cast<Address>(Assembler::target_address_address_at(pc_));
73 }
74 
75 
set_target_address(Address target)76 void RelocInfo::set_target_address(Address target) {
77   ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY);
78   Assembler::set_target_address_at(pc_, target);
79 }
80 
81 
target_object()82 Object* RelocInfo::target_object() {
83   ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
84   return reinterpret_cast<Object*>(Assembler::target_address_at(pc_));
85 }
86 
87 
target_object_address()88 Object** RelocInfo::target_object_address() {
89   ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
90   return reinterpret_cast<Object**>(Assembler::target_address_address_at(pc_));
91 }
92 
93 
set_target_object(Object * target)94 void RelocInfo::set_target_object(Object* target) {
95   ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
96   Assembler::set_target_address_at(pc_, reinterpret_cast<Address>(target));
97 }
98 
99 
target_reference_address()100 Address* RelocInfo::target_reference_address() {
101   ASSERT(rmode_ == EXTERNAL_REFERENCE);
102   return reinterpret_cast<Address*>(Assembler::target_address_address_at(pc_));
103 }
104 
105 
call_address()106 Address RelocInfo::call_address() {
107   ASSERT(IsCallInstruction());
108   UNIMPLEMENTED();
109   return NULL;
110 }
111 
112 
set_call_address(Address target)113 void RelocInfo::set_call_address(Address target) {
114   ASSERT(IsCallInstruction());
115   UNIMPLEMENTED();
116 }
117 
118 
call_object()119 Object* RelocInfo::call_object() {
120   ASSERT(IsCallInstruction());
121   UNIMPLEMENTED();
122   return NULL;
123 }
124 
125 
call_object_address()126 Object** RelocInfo::call_object_address() {
127   ASSERT(IsCallInstruction());
128   UNIMPLEMENTED();
129   return NULL;
130 }
131 
132 
set_call_object(Object * target)133 void RelocInfo::set_call_object(Object* target) {
134   ASSERT(IsCallInstruction());
135   UNIMPLEMENTED();
136 }
137 
138 
IsCallInstruction()139 bool RelocInfo::IsCallInstruction() {
140   UNIMPLEMENTED();
141   return false;
142 }
143 
144 
Operand(int32_t immediate,RelocInfo::Mode rmode)145 Operand::Operand(int32_t immediate, RelocInfo::Mode rmode)  {
146   rm_ = no_reg;
147   imm32_ = immediate;
148   rmode_ = rmode;
149 }
150 
151 
Operand(const char * s)152 Operand::Operand(const char* s) {
153   rm_ = no_reg;
154   imm32_ = reinterpret_cast<int32_t>(s);
155   rmode_ = RelocInfo::EMBEDDED_STRING;
156 }
157 
158 
Operand(const ExternalReference & f)159 Operand::Operand(const ExternalReference& f)  {
160   rm_ = no_reg;
161   imm32_ = reinterpret_cast<int32_t>(f.address());
162   rmode_ = RelocInfo::EXTERNAL_REFERENCE;
163 }
164 
165 
Operand(Object ** opp)166 Operand::Operand(Object** opp) {
167   rm_ = no_reg;
168   imm32_ = reinterpret_cast<int32_t>(opp);
169   rmode_ = RelocInfo::NONE;
170 }
171 
172 
Operand(Context ** cpp)173 Operand::Operand(Context** cpp) {
174   rm_ = no_reg;
175   imm32_ = reinterpret_cast<int32_t>(cpp);
176   rmode_ = RelocInfo::NONE;
177 }
178 
179 
Operand(Smi * value)180 Operand::Operand(Smi* value) {
181   rm_ = no_reg;
182   imm32_ =  reinterpret_cast<intptr_t>(value);
183   rmode_ = RelocInfo::NONE;
184 }
185 
186 
Operand(Register rm)187 Operand::Operand(Register rm) {
188   rm_ = rm;
189   rs_ = no_reg;
190   shift_op_ = LSL;
191   shift_imm_ = 0;
192 }
193 
194 
is_reg()195 bool Operand::is_reg() const {
196   return rm_.is_valid() &&
197          rs_.is(no_reg) &&
198          shift_op_ == LSL &&
199          shift_imm_ == 0;
200 }
201 
202 
CheckBuffer()203 void Assembler::CheckBuffer() {
204   if (buffer_space() <= kGap) {
205     GrowBuffer();
206   }
207   if (pc_offset() >= next_buffer_check_) {
208     CheckConstPool(false, true);
209   }
210 }
211 
212 
emit(Instr x)213 void Assembler::emit(Instr x) {
214   CheckBuffer();
215   *reinterpret_cast<Instr*>(pc_) = x;
216   pc_ += kInstrSize;
217 }
218 
219 
target_address_address_at(Address pc)220 Address Assembler::target_address_address_at(Address pc) {
221   Instr instr = Memory::int32_at(pc);
222   // Verify that the instruction at pc is a ldr<cond> <Rd>, [pc +/- offset_12].
223   ASSERT((instr & 0x0f7f0000) == 0x051f0000);
224   int offset = instr & 0xfff;  // offset_12 is unsigned
225   if ((instr & (1 << 23)) == 0) offset = -offset;  // U bit defines offset sign
226   // Verify that the constant pool comes after the instruction referencing it.
227   ASSERT(offset >= -4);
228   return pc + offset + 8;
229 }
230 
231 
target_address_at(Address pc)232 Address Assembler::target_address_at(Address pc) {
233   return Memory::Address_at(target_address_address_at(pc));
234 }
235 
236 
set_target_address_at(Address pc,Address target)237 void Assembler::set_target_address_at(Address pc, Address target) {
238   Memory::Address_at(target_address_address_at(pc)) = target;
239   // Intuitively, we would think it is necessary to flush the instruction cache
240   // after patching a target address in the code as follows:
241   //   CPU::FlushICache(pc, sizeof(target));
242   // However, on ARM, no instruction was actually patched by the assignment
243   // above; the target address is not part of an instruction, it is patched in
244   // the constant pool and is read via a data access; the instruction accessing
245   // this address in the constant pool remains unchanged.
246 }
247 
248 } }  // namespace v8::internal
249 
250 #endif  // V8_ARM_ASSEMBLER_ARM_INL_H_
251