blob: fbe37d7a20025376cfe04bc47970f7c36b8c0dc3 [file] [log] [blame]
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001// Copyright (c) 1994-2006 Sun Microsystems Inc.
2// All Rights Reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003//
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00004// 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.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000019//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000022// 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.
ager@chromium.org9258b6b2008-09-11 09:11:10 +000035// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000036
37#ifndef V8_ASSEMBLER_ARM_INL_H_
38#define V8_ASSEMBLER_ARM_INL_H_
39
40#include "assembler-arm.h"
41#include "cpu.h"
42
43
44namespace v8 { namespace internal {
45
46Condition NegateCondition(Condition cc) {
47 ASSERT(cc != al);
48 return static_cast<Condition>(cc ^ ne);
49}
50
51
52void RelocInfo::apply(int delta) {
ager@chromium.org236ad962008-09-25 09:45:57 +000053 if (RelocInfo::IsInternalReference(rmode_)) {
54 // absolute code pointer inside code object moves with the code object.
55 int32_t* p = reinterpret_cast<int32_t*>(pc_);
56 *p += delta; // relocate entry
57 }
58 // We do not use pc relative addressing on ARM, so there is
59 // nothing else to do.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000060}
61
62
63Address RelocInfo::target_address() {
ager@chromium.org236ad962008-09-25 09:45:57 +000064 ASSERT(IsCodeTarget(rmode_));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000065 return Assembler::target_address_at(pc_);
66}
67
68
69void RelocInfo::set_target_address(Address target) {
ager@chromium.org236ad962008-09-25 09:45:57 +000070 ASSERT(IsCodeTarget(rmode_));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000071 Assembler::set_target_address_at(pc_, target);
72}
73
74
75Object* RelocInfo::target_object() {
ager@chromium.org236ad962008-09-25 09:45:57 +000076 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000077 return reinterpret_cast<Object*>(Assembler::target_address_at(pc_));
78}
79
80
81Object** RelocInfo::target_object_address() {
ager@chromium.org236ad962008-09-25 09:45:57 +000082 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000083 return reinterpret_cast<Object**>(Assembler::target_address_address_at(pc_));
84}
85
86
87void RelocInfo::set_target_object(Object* target) {
ager@chromium.org236ad962008-09-25 09:45:57 +000088 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000089 Assembler::set_target_address_at(pc_, reinterpret_cast<Address>(target));
90}
91
92
93Address* RelocInfo::target_reference_address() {
ager@chromium.org236ad962008-09-25 09:45:57 +000094 ASSERT(rmode_ == EXTERNAL_REFERENCE);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000095 return reinterpret_cast<Address*>(pc_);
96}
97
98
99Address RelocInfo::call_address() {
100 ASSERT(is_call_instruction());
101 UNIMPLEMENTED();
102 return NULL;
103}
104
105
106void RelocInfo::set_call_address(Address target) {
107 ASSERT(is_call_instruction());
108 UNIMPLEMENTED();
109}
110
111
112Object* RelocInfo::call_object() {
113 ASSERT(is_call_instruction());
114 UNIMPLEMENTED();
115 return NULL;
116}
117
118
119Object** RelocInfo::call_object_address() {
120 ASSERT(is_call_instruction());
121 UNIMPLEMENTED();
122 return NULL;
123}
124
125
126void RelocInfo::set_call_object(Object* target) {
127 ASSERT(is_call_instruction());
128 UNIMPLEMENTED();
129}
130
131
132bool RelocInfo::is_call_instruction() {
133 UNIMPLEMENTED();
134 return false;
135}
136
137
ager@chromium.org236ad962008-09-25 09:45:57 +0000138Operand::Operand(int32_t immediate, RelocInfo::Mode rmode) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000139 rm_ = no_reg;
140 imm32_ = immediate;
141 rmode_ = rmode;
142}
143
144
145Operand::Operand(const char* s) {
146 rm_ = no_reg;
147 imm32_ = reinterpret_cast<int32_t>(s);
ager@chromium.org236ad962008-09-25 09:45:57 +0000148 rmode_ = RelocInfo::EMBEDDED_STRING;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000149}
150
151
152Operand::Operand(const ExternalReference& f) {
153 rm_ = no_reg;
154 imm32_ = reinterpret_cast<int32_t>(f.address());
ager@chromium.org236ad962008-09-25 09:45:57 +0000155 rmode_ = RelocInfo::EXTERNAL_REFERENCE;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000156}
157
158
159Operand::Operand(Object** opp) {
160 rm_ = no_reg;
161 imm32_ = reinterpret_cast<int32_t>(opp);
ager@chromium.org236ad962008-09-25 09:45:57 +0000162 rmode_ = RelocInfo::NONE;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000163}
164
165
166Operand::Operand(Context** cpp) {
167 rm_ = no_reg;
168 imm32_ = reinterpret_cast<int32_t>(cpp);
ager@chromium.org236ad962008-09-25 09:45:57 +0000169 rmode_ = RelocInfo::NONE;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000170}
171
172
173Operand::Operand(Smi* value) {
174 rm_ = no_reg;
175 imm32_ = reinterpret_cast<intptr_t>(value);
ager@chromium.org236ad962008-09-25 09:45:57 +0000176 rmode_ = RelocInfo::NONE;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000177}
178
179
180Operand::Operand(Register rm) {
181 rm_ = rm;
182 rs_ = no_reg;
183 shift_op_ = LSL;
184 shift_imm_ = 0;
185}
186
187
mads.s.ager31e71382008-08-13 09:32:07 +0000188bool Operand::is_reg() const {
189 return rm_.is_valid() &&
190 rs_.is(no_reg) &&
191 shift_op_ == LSL &&
192 shift_imm_ == 0;
193}
194
195
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000196void Assembler::CheckBuffer() {
197 if (buffer_space() <= kGap) {
198 GrowBuffer();
199 }
200 if (pc_offset() > next_buffer_check_) {
201 CheckConstPool(false, true);
202 }
203}
204
205
206void Assembler::emit(Instr x) {
207 CheckBuffer();
208 *reinterpret_cast<Instr*>(pc_) = x;
209 pc_ += kInstrSize;
210}
211
212
213Address Assembler::target_address_address_at(Address pc) {
214 Instr instr = Memory::int32_at(pc);
215 // Verify that the instruction at pc is a ldr<cond> <Rd>, [pc +/- offset_12].
216 ASSERT((instr & 0x0f7f0000) == 0x051f0000);
217 int offset = instr & 0xfff; // offset_12 is unsigned
218 if ((instr & (1 << 23)) == 0) offset = -offset; // U bit defines offset sign
219 // Verify that the constant pool comes after the instruction referencing it.
220 ASSERT(offset >= -4);
221 return pc + offset + 8;
222}
223
224
225Address Assembler::target_address_at(Address pc) {
226 return Memory::Address_at(target_address_address_at(pc));
227}
228
229
230void Assembler::set_target_address_at(Address pc, Address target) {
231 Memory::Address_at(target_address_address_at(pc)) = target;
232 // Intuitively, we would think it is necessary to flush the instruction cache
233 // after patching a target address in the code as follows:
234 // CPU::FlushICache(pc, sizeof(target));
235 // However, on ARM, no instruction was actually patched by the assignment
236 // above; the target address is not part of an instruction, it is patched in
237 // the constant pool and is read via a data access; the instruction accessing
238 // this address in the constant pool remains unchanged.
239}
240
241} } // namespace v8::internal
242
243#endif // V8_ASSEMBLER_ARM_INL_H_