blob: 7cc843fc3bf85513a0d8a8b2e68636b92dddf7a5 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_MACRO_ASSEMBLER_ARM_H_
29#define V8_MACRO_ASSEMBLER_ARM_H_
30
31#include "assembler.h"
32
33namespace v8 { namespace internal {
34
35
36// Give alias names to registers
37extern Register cp; // JavaScript context pointer
38extern Register pp; // parameter pointer
39
40
41// Helper types to make boolean flag easier to read at call-site.
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +000042enum InvokeFlag {
43 CALL_FUNCTION,
44 JUMP_FUNCTION
45};
46
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000047enum InvokeJSFlags {
48 CALL_JS,
49 JUMP_JS
50};
51
52enum ExitJSFlag {
53 RETURN,
54 DO_NOT_RETURN
55};
56
57enum CodeLocation {
58 IN_JAVASCRIPT,
59 IN_JS_ENTRY,
60 IN_C_ENTRY
61};
62
63enum HandlerType {
64 TRY_CATCH_HANDLER,
65 TRY_FINALLY_HANDLER,
66 JS_ENTRY_HANDLER
67};
68
69
70// MacroAssembler implements a collection of frequently used macros.
71class MacroAssembler: public Assembler {
72 public:
73 MacroAssembler(void* buffer, int size);
74
75 // ---------------------------------------------------------------------------
76 // Low-level helpers for compiler
77
78 // Jump, Call, and Ret pseudo instructions implementing inter-working
79 private:
ager@chromium.org236ad962008-09-25 09:45:57 +000080 void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
81 void Call(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000082 public:
83 void Jump(Register target, Condition cond = al);
ager@chromium.org236ad962008-09-25 09:45:57 +000084 void Jump(byte* target, RelocInfo::Mode rmode, Condition cond = al);
85 void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000086 void Call(Register target, Condition cond = al);
ager@chromium.org236ad962008-09-25 09:45:57 +000087 void Call(byte* target, RelocInfo::Mode rmode, Condition cond = al);
88 void Call(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000089 void Ret();
90
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000091
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000092 // Sets the remembered set bit for [address+offset], where address is the
93 // address of the heap object 'object'. The address must be in the first 8K
94 // of an allocated page. The 'scratch' register is used in the
95 // implementation and all 3 registers are clobbered by the operation, as
96 // well as the ip register.
97 void RecordWrite(Register object, Register offset, Register scratch);
98
99 // ---------------------------------------------------------------------------
100 // Activation frames
101
ager@chromium.org7c537e22008-10-16 08:43:32 +0000102 void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); }
103 void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); }
104
105 void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); }
106 void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); }
ager@chromium.org236ad962008-09-25 09:45:57 +0000107
108 // Enter specific kind of exit frame; either EXIT or
109 // EXIT_DEBUG. Expects the number of arguments in register r0 and
110 // the builtin function to call in register r1. Exits with argc in
111 // r4, argv in r6, and and the builtin function to call in r5.
112 void EnterExitFrame(StackFrame::Type type);
113
114 // Leave the current exit frame. Expects the return value in r0.
115 void LeaveExitFrame(StackFrame::Type type);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000116
117
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000118 // ---------------------------------------------------------------------------
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000119 // JavaScript invokes
120
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000121 // Invoke the JavaScript function code by either calling or jumping.
122 void InvokeCode(Register code,
123 const ParameterCount& expected,
124 const ParameterCount& actual,
125 InvokeFlag flag);
126
127 void InvokeCode(Handle<Code> code,
128 const ParameterCount& expected,
129 const ParameterCount& actual,
ager@chromium.org236ad962008-09-25 09:45:57 +0000130 RelocInfo::Mode rmode,
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000131 InvokeFlag flag);
132
133 // Invoke the JavaScript function in the given register. Changes the
134 // current context to the context in the function before invoking.
135 void InvokeFunction(Register function,
136 const ParameterCount& actual,
137 InvokeFlag flag);
138
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000139
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000140 // ---------------------------------------------------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000141 // Debugger Support
142
143 void SaveRegistersToMemory(RegList regs);
144 void RestoreRegistersFromMemory(RegList regs);
145 void CopyRegistersFromMemoryToStack(Register base, RegList regs);
146 void CopyRegistersFromStackToMemory(Register base,
147 Register scratch,
148 RegList regs);
149
150
151 // ---------------------------------------------------------------------------
152 // Exception handling
153
154 // Push a new try handler and link into try handler chain.
155 // The return address must be passed in register lr.
156 // On exit, r0 contains TOS (code slot).
157 void PushTryHandler(CodeLocation try_location, HandlerType type);
158
159
160 // ---------------------------------------------------------------------------
161 // Inline caching support
162
163 // Generates code that verifies that the maps of objects in the
164 // prototype chain of object hasn't changed since the code was
165 // generated and branches to the miss label if any map has. If
166 // necessary the function also generates code for security check
167 // in case of global object holders. The scratch and holder
168 // registers are always clobbered, but the object register is only
169 // clobbered if it the same as the holder register. The function
170 // returns a register containing the holder - either object_reg or
171 // holder_reg.
172 Register CheckMaps(JSObject* object, Register object_reg,
173 JSObject* holder, Register holder_reg,
174 Register scratch, Label* miss);
175
176 // Generate code for checking access rights - used for security checks
177 // on access to global objects across environments. The holder register
178 // is left untouched, whereas both scratch registers are clobbered.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000179 void CheckAccessGlobalProxy(Register holder_reg,
180 Register scratch,
181 Label* miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000182
183
184 // ---------------------------------------------------------------------------
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000185 // Support functions.
186
187 // Generates code for reporting that an illegal operation has
188 // occurred.
189 void IllegalOperation(int num_arguments);
190
191
192 // ---------------------------------------------------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000193 // Runtime calls
194
195 // Call a code stub.
196 void CallStub(CodeStub* stub);
197 void CallJSExitStub(CodeStub* stub);
198
199 // Return from a code stub after popping its arguments.
200 void StubReturn(int argc);
201
202 // Call a runtime routine.
203 // Eventually this should be used for all C calls.
204 void CallRuntime(Runtime::Function* f, int num_arguments);
205
206 // Convenience function: Same as above, but takes the fid instead.
207 void CallRuntime(Runtime::FunctionId fid, int num_arguments);
208
209 // Tail call of a runtime routine (jump).
210 // Like JumpToBuiltin, but also takes care of passing the number
mads.s.ager31e71382008-08-13 09:32:07 +0000211 // of parameters.
212 void TailCallRuntime(const ExternalReference& ext, int num_arguments);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000213
214 // Jump to the builtin routine.
215 void JumpToBuiltin(const ExternalReference& builtin);
216
217 // Invoke specified builtin JavaScript function. Adds an entry to
218 // the unresolved list if the name does not resolve.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000219 void InvokeBuiltin(Builtins::JavaScript id, InvokeJSFlags flags);
220
221 // Store the code object for the given builtin in the target register and
222 // setup the function in r1.
223 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000224
225 struct Unresolved {
226 int pc;
227 uint32_t flags; // see Bootstrapper::FixupFlags decoders/encoders.
228 const char* name;
229 };
230 List<Unresolved>* unresolved() { return &unresolved_; }
231
232
233 // ---------------------------------------------------------------------------
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000234 // StatsCounter support
235
236 void SetCounter(StatsCounter* counter, int value,
237 Register scratch1, Register scratch2);
238 void IncrementCounter(StatsCounter* counter, int value,
239 Register scratch1, Register scratch2);
240 void DecrementCounter(StatsCounter* counter, int value,
241 Register scratch1, Register scratch2);
242
243
244 // ---------------------------------------------------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000245 // Debugging
246
247 // Calls Abort(msg) if the condition cc is not satisfied.
248 // Use --debug_code to enable.
249 void Assert(Condition cc, const char* msg);
250
251 // Like Assert(), but always enabled.
252 void Check(Condition cc, const char* msg);
253
254 // Print a message to stdout and abort execution.
255 void Abort(const char* msg);
256
257 // Verify restrictions about code generated in stubs.
258 void set_generating_stub(bool value) { generating_stub_ = value; }
259 bool generating_stub() { return generating_stub_; }
kasper.lund7276f142008-07-30 08:49:36 +0000260 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
261 bool allow_stub_calls() { return allow_stub_calls_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000262
263 private:
264 List<Unresolved> unresolved_;
265 bool generating_stub_;
kasper.lund7276f142008-07-30 08:49:36 +0000266 bool allow_stub_calls_;
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000267
268 // Helper functions for generating invokes.
269 void InvokePrologue(const ParameterCount& expected,
270 const ParameterCount& actual,
271 Handle<Code> code_constant,
272 Register code_reg,
273 Label* done,
274 InvokeFlag flag);
275
276 // Get the code for the given builtin. Returns if able to resolve
277 // the function in the 'resolved' flag.
278 Handle<Code> ResolveBuiltin(Builtins::JavaScript id, bool* resolved);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000279
280 // Activation support.
281 void EnterFrame(StackFrame::Type type);
282 void LeaveFrame(StackFrame::Type type);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000283};
284
285
286// -----------------------------------------------------------------------------
287// Static helper functions.
288
289// Generate a MemOperand for loading a field from an object.
290static inline MemOperand FieldMemOperand(Register object, int offset) {
291 return MemOperand(object, offset - kHeapObjectTag);
292}
293
294
295
296} } // namespace v8::internal
297
298#endif // V8_MACRO_ASSEMBLER_ARM_H_