The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / src / macro-assembler-arm.h @ 40c0f755

History | View | Annotate | Download (11.1 KB)

1
// Copyright 2006-2008 the V8 project authors. All rights reserved.
2
// 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

    
33
namespace v8 { namespace internal {
34

    
35

    
36
// Give alias names to registers
37
extern Register cp;  // JavaScript context pointer
38
extern Register pp;  // parameter pointer
39

    
40

    
41
// Helper types to make boolean flag easier to read at call-site.
42
enum InvokeFlag {
43
  CALL_FUNCTION,
44
  JUMP_FUNCTION
45
};
46

    
47
enum InvokeJSFlags {
48
  CALL_JS,
49
  JUMP_JS
50
};
51

    
52
enum ExitJSFlag {
53
  RETURN,
54
  DO_NOT_RETURN
55
};
56

    
57
enum CodeLocation {
58
  IN_JAVASCRIPT,
59
  IN_JS_ENTRY,
60
  IN_C_ENTRY
61
};
62

    
63
enum 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.
71
class 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:
80
  void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
81
  void Call(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
82
 public:
83
  void Jump(Register target, Condition cond = al);
84
  void Jump(byte* target, RelocInfo::Mode rmode, Condition cond = al);
85
  void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
86
  void Call(Register target, Condition cond = al);
87
  void Call(byte* target, RelocInfo::Mode rmode, Condition cond = al);
88
  void Call(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
89
  void Ret();
90
  // Jumps to the label at the index given by the Smi in "index".
91
  void SmiJumpTable(Register index, Vector<Label*> targets);
92

    
93
  // Sets the remembered set bit for [address+offset], where address is the
94
  // address of the heap object 'object'.  The address must be in the first 8K
95
  // of an allocated page. The 'scratch' register is used in the
96
  // implementation and all 3 registers are clobbered by the operation, as
97
  // well as the ip register.
98
  void RecordWrite(Register object, Register offset, Register scratch);
99

    
100
  // ---------------------------------------------------------------------------
101
  // Activation frames
102

    
103
  void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); }
104
  void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); }
105

    
106
  void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); }
107
  void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); }
108

    
109
  // Enter specific kind of exit frame; either EXIT or
110
  // EXIT_DEBUG. Expects the number of arguments in register r0 and
111
  // the builtin function to call in register r1. Exits with argc in
112
  // r4, argv in r6, and and the builtin function to call in r5.
113
  void EnterExitFrame(StackFrame::Type type);
114

    
115
  // Leave the current exit frame. Expects the return value in r0.
116
  void LeaveExitFrame(StackFrame::Type type);
117

    
118

    
119
  // ---------------------------------------------------------------------------
120
  // JavaScript invokes
121

    
122
  // Invoke the JavaScript function code by either calling or jumping.
123
  void InvokeCode(Register code,
124
                  const ParameterCount& expected,
125
                  const ParameterCount& actual,
126
                  InvokeFlag flag);
127

    
128
  void InvokeCode(Handle<Code> code,
129
                  const ParameterCount& expected,
130
                  const ParameterCount& actual,
131
                  RelocInfo::Mode rmode,
132
                  InvokeFlag flag);
133

    
134
  // Invoke the JavaScript function in the given register. Changes the
135
  // current context to the context in the function before invoking.
136
  void InvokeFunction(Register function,
137
                      const ParameterCount& actual,
138
                      InvokeFlag flag);
139

    
140

    
141
  // ---------------------------------------------------------------------------
142
  // Debugger Support
143

    
144
  void SaveRegistersToMemory(RegList regs);
145
  void RestoreRegistersFromMemory(RegList regs);
146
  void CopyRegistersFromMemoryToStack(Register base, RegList regs);
147
  void CopyRegistersFromStackToMemory(Register base,
148
                                      Register scratch,
149
                                      RegList regs);
150

    
151

    
152
  // ---------------------------------------------------------------------------
153
  // Exception handling
154

    
155
  // Push a new try handler and link into try handler chain.
156
  // The return address must be passed in register lr.
157
  // On exit, r0 contains TOS (code slot).
158
  void PushTryHandler(CodeLocation try_location, HandlerType type);
159

    
160

    
161
  // ---------------------------------------------------------------------------
162
  // Inline caching support
163

    
164
  // Generates code that verifies that the maps of objects in the
165
  // prototype chain of object hasn't changed since the code was
166
  // generated and branches to the miss label if any map has. If
167
  // necessary the function also generates code for security check
168
  // in case of global object holders. The scratch and holder
169
  // registers are always clobbered, but the object register is only
170
  // clobbered if it the same as the holder register. The function
171
  // returns a register containing the holder - either object_reg or
172
  // holder_reg.
173
  Register CheckMaps(JSObject* object, Register object_reg,
174
                     JSObject* holder, Register holder_reg,
175
                     Register scratch, Label* miss);
176

    
177
  // Generate code for checking access rights - used for security checks
178
  // on access to global objects across environments. The holder register
179
  // is left untouched, whereas both scratch registers are clobbered.
180
  void CheckAccessGlobalProxy(Register holder_reg,
181
                              Register scratch,
182
                              Label* miss);
183

    
184

    
185
  // ---------------------------------------------------------------------------
186
  // Support functions.
187

    
188
  // Generates code for reporting that an illegal operation has
189
  // occurred.
190
  void IllegalOperation(int num_arguments);
191

    
192

    
193
  // ---------------------------------------------------------------------------
194
  // Runtime calls
195

    
196
  // Call a code stub.
197
  void CallStub(CodeStub* stub);
198
  void CallJSExitStub(CodeStub* stub);
199

    
200
  // Return from a code stub after popping its arguments.
201
  void StubReturn(int argc);
202

    
203
  // Call a runtime routine.
204
  // Eventually this should be used for all C calls.
205
  void CallRuntime(Runtime::Function* f, int num_arguments);
206

    
207
  // Convenience function: Same as above, but takes the fid instead.
208
  void CallRuntime(Runtime::FunctionId fid, int num_arguments);
209

    
210
  // Tail call of a runtime routine (jump).
211
  // Like JumpToBuiltin, but also takes care of passing the number
212
  // of parameters.
213
  void TailCallRuntime(const ExternalReference& ext, int num_arguments);
214

    
215
  // Jump to the builtin routine.
216
  void JumpToBuiltin(const ExternalReference& builtin);
217

    
218
  // Invoke specified builtin JavaScript function. Adds an entry to
219
  // the unresolved list if the name does not resolve.
220
  void InvokeBuiltin(Builtins::JavaScript id, InvokeJSFlags flags);
221

    
222
  // Store the code object for the given builtin in the target register and
223
  // setup the function in r1.
224
  void GetBuiltinEntry(Register target, Builtins::JavaScript id);
225

    
226
  struct Unresolved {
227
    int pc;
228
    uint32_t flags;  // see Bootstrapper::FixupFlags decoders/encoders.
229
    const char* name;
230
  };
231
  List<Unresolved>* unresolved() { return &unresolved_; }
232

    
233
  Handle<Object> CodeObject() { return code_object_; }
234

    
235

    
236
  // ---------------------------------------------------------------------------
237
  // StatsCounter support
238

    
239
  void SetCounter(StatsCounter* counter, int value,
240
                  Register scratch1, Register scratch2);
241
  void IncrementCounter(StatsCounter* counter, int value,
242
                        Register scratch1, Register scratch2);
243
  void DecrementCounter(StatsCounter* counter, int value,
244
                        Register scratch1, Register scratch2);
245

    
246

    
247
  // ---------------------------------------------------------------------------
248
  // Debugging
249

    
250
  // Calls Abort(msg) if the condition cc is not satisfied.
251
  // Use --debug_code to enable.
252
  void Assert(Condition cc, const char* msg);
253

    
254
  // Like Assert(), but always enabled.
255
  void Check(Condition cc, const char* msg);
256

    
257
  // Print a message to stdout and abort execution.
258
  void Abort(const char* msg);
259

    
260
  // Verify restrictions about code generated in stubs.
261
  void set_generating_stub(bool value) { generating_stub_ = value; }
262
  bool generating_stub() { return generating_stub_; }
263
  void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
264
  bool allow_stub_calls() { return allow_stub_calls_; }
265

    
266
 private:
267
  List<Unresolved> unresolved_;
268
  bool generating_stub_;
269
  bool allow_stub_calls_;
270
  Handle<Object> code_object_;  // This handle will be patched with the code
271
                                // object on installation.
272

    
273
  // Helper functions for generating invokes.
274
  void InvokePrologue(const ParameterCount& expected,
275
                      const ParameterCount& actual,
276
                      Handle<Code> code_constant,
277
                      Register code_reg,
278
                      Label* done,
279
                      InvokeFlag flag);
280

    
281
  // Get the code for the given builtin. Returns if able to resolve
282
  // the function in the 'resolved' flag.
283
  Handle<Code> ResolveBuiltin(Builtins::JavaScript id, bool* resolved);
284

    
285
  // Activation support.
286
  void EnterFrame(StackFrame::Type type);
287
  void LeaveFrame(StackFrame::Type type);
288
};
289

    
290

    
291
// -----------------------------------------------------------------------------
292
// Static helper functions.
293

    
294
// Generate a MemOperand for loading a field from an object.
295
static inline MemOperand FieldMemOperand(Register object, int offset) {
296
  return MemOperand(object, offset - kHeapObjectTag);
297
}
298

    
299

    
300

    
301
} }  // namespace v8::internal
302

    
303
#endif  // V8_MACRO_ASSEMBLER_ARM_H_