blob: fe64761e3b1c709f2e07b5c564ee7c1706bc79ef [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
ager@chromium.org5ec48922009-05-05 07:25:34 +000037#ifndef V8_ARM_ASSEMBLER_ARM_INL_H_
38#define V8_ARM_ASSEMBLER_ARM_INL_H_
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000039
ager@chromium.org3a37e9b2009-04-27 09:26:21 +000040#include "arm/assembler-arm.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000041#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.org32912102009-01-16 10:38:43 +000064 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000065 return Assembler::target_address_at(pc_);
66}
67
68
ager@chromium.org32912102009-01-16 10:38:43 +000069Address RelocInfo::target_address_address() {
70 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY);
71 return reinterpret_cast<Address>(Assembler::target_address_address_at(pc_));
72}
73
74
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000075void RelocInfo::set_target_address(Address target) {
ager@chromium.org32912102009-01-16 10:38:43 +000076 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000077 Assembler::set_target_address_at(pc_, target);
78}
79
80
81Object* RelocInfo::target_object() {
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_at(pc_));
84}
85
86
87Object** RelocInfo::target_object_address() {
ager@chromium.org236ad962008-09-25 09:45:57 +000088 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000089 return reinterpret_cast<Object**>(Assembler::target_address_address_at(pc_));
90}
91
92
93void RelocInfo::set_target_object(Object* target) {
ager@chromium.org236ad962008-09-25 09:45:57 +000094 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000095 Assembler::set_target_address_at(pc_, reinterpret_cast<Address>(target));
96}
97
98
99Address* RelocInfo::target_reference_address() {
ager@chromium.org236ad962008-09-25 09:45:57 +0000100 ASSERT(rmode_ == EXTERNAL_REFERENCE);
ager@chromium.org32912102009-01-16 10:38:43 +0000101 return reinterpret_cast<Address*>(Assembler::target_address_address_at(pc_));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000102}
103
104
105Address RelocInfo::call_address() {
iposva@chromium.org245aa852009-02-10 00:49:54 +0000106 ASSERT(IsCallInstruction());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000107 UNIMPLEMENTED();
108 return NULL;
109}
110
111
112void RelocInfo::set_call_address(Address target) {
iposva@chromium.org245aa852009-02-10 00:49:54 +0000113 ASSERT(IsCallInstruction());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000114 UNIMPLEMENTED();
115}
116
117
118Object* RelocInfo::call_object() {
iposva@chromium.org245aa852009-02-10 00:49:54 +0000119 ASSERT(IsCallInstruction());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000120 UNIMPLEMENTED();
121 return NULL;
122}
123
124
125Object** RelocInfo::call_object_address() {
iposva@chromium.org245aa852009-02-10 00:49:54 +0000126 ASSERT(IsCallInstruction());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000127 UNIMPLEMENTED();
128 return NULL;
129}
130
131
132void RelocInfo::set_call_object(Object* target) {
iposva@chromium.org245aa852009-02-10 00:49:54 +0000133 ASSERT(IsCallInstruction());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000134 UNIMPLEMENTED();
135}
136
137
iposva@chromium.org245aa852009-02-10 00:49:54 +0000138bool RelocInfo::IsCallInstruction() {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000139 UNIMPLEMENTED();
140 return false;
141}
142
143
ager@chromium.org236ad962008-09-25 09:45:57 +0000144Operand::Operand(int32_t immediate, RelocInfo::Mode rmode) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000145 rm_ = no_reg;
146 imm32_ = immediate;
147 rmode_ = rmode;
148}
149
150
151Operand::Operand(const char* s) {
152 rm_ = no_reg;
153 imm32_ = reinterpret_cast<int32_t>(s);
ager@chromium.org236ad962008-09-25 09:45:57 +0000154 rmode_ = RelocInfo::EMBEDDED_STRING;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000155}
156
157
158Operand::Operand(const ExternalReference& f) {
159 rm_ = no_reg;
160 imm32_ = reinterpret_cast<int32_t>(f.address());
ager@chromium.org236ad962008-09-25 09:45:57 +0000161 rmode_ = RelocInfo::EXTERNAL_REFERENCE;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000162}
163
164
165Operand::Operand(Object** opp) {
166 rm_ = no_reg;
167 imm32_ = reinterpret_cast<int32_t>(opp);
ager@chromium.org236ad962008-09-25 09:45:57 +0000168 rmode_ = RelocInfo::NONE;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000169}
170
171
172Operand::Operand(Context** cpp) {
173 rm_ = no_reg;
174 imm32_ = reinterpret_cast<int32_t>(cpp);
ager@chromium.org236ad962008-09-25 09:45:57 +0000175 rmode_ = RelocInfo::NONE;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000176}
177
178
179Operand::Operand(Smi* value) {
180 rm_ = no_reg;
181 imm32_ = reinterpret_cast<intptr_t>(value);
ager@chromium.org236ad962008-09-25 09:45:57 +0000182 rmode_ = RelocInfo::NONE;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000183}
184
185
186Operand::Operand(Register rm) {
187 rm_ = rm;
188 rs_ = no_reg;
189 shift_op_ = LSL;
190 shift_imm_ = 0;
191}
192
193
mads.s.ager31e71382008-08-13 09:32:07 +0000194bool Operand::is_reg() const {
195 return rm_.is_valid() &&
196 rs_.is(no_reg) &&
197 shift_op_ == LSL &&
198 shift_imm_ == 0;
199}
200
201
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000202void Assembler::CheckBuffer() {
203 if (buffer_space() <= kGap) {
204 GrowBuffer();
205 }
206 if (pc_offset() > next_buffer_check_) {
207 CheckConstPool(false, true);
208 }
209}
210
211
212void Assembler::emit(Instr x) {
213 CheckBuffer();
214 *reinterpret_cast<Instr*>(pc_) = x;
215 pc_ += kInstrSize;
216}
217
218
219Address Assembler::target_address_address_at(Address pc) {
220 Instr instr = Memory::int32_at(pc);
221 // Verify that the instruction at pc is a ldr<cond> <Rd>, [pc +/- offset_12].
222 ASSERT((instr & 0x0f7f0000) == 0x051f0000);
223 int offset = instr & 0xfff; // offset_12 is unsigned
224 if ((instr & (1 << 23)) == 0) offset = -offset; // U bit defines offset sign
225 // Verify that the constant pool comes after the instruction referencing it.
226 ASSERT(offset >= -4);
227 return pc + offset + 8;
228}
229
230
231Address Assembler::target_address_at(Address pc) {
232 return Memory::Address_at(target_address_address_at(pc));
233}
234
235
236void Assembler::set_target_address_at(Address pc, Address target) {
237 Memory::Address_at(target_address_address_at(pc)) = target;
238 // Intuitively, we would think it is necessary to flush the instruction cache
239 // after patching a target address in the code as follows:
240 // CPU::FlushICache(pc, sizeof(target));
241 // However, on ARM, no instruction was actually patched by the assignment
242 // above; the target address is not part of an instruction, it is patched in
243 // the constant pool and is read via a data access; the instruction accessing
244 // this address in the constant pool remains unchanged.
245}
246
247} } // namespace v8::internal
248
ager@chromium.org5ec48922009-05-05 07:25:34 +0000249#endif // V8_ARM_ASSEMBLER_ARM_INL_H_