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
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.
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.
28 #ifndef V8_ARM_FRAMES_ARM_H_
29 #define V8_ARM_FRAMES_ARM_H_
31 namespace v8 { namespace internal {
34 // The ARM ABI does not specify the usage of register r9, which may be reserved
35 // as the static base or thread register on some platforms, in which case we
36 // leave it alone. Adjust the value of kR9Available accordingly:
37 static const int kR9Available = 1; // 1 if available to us, 0 if reserved
40 // Register list in load/store instructions
41 // Note that the bit values must match those used in actual instruction encoding
42 static const int kNumRegs = 16;
45 // Caller-saved/arguments registers
46 static const RegList kJSCallerSaved =
52 static const int kNumJSCallerSaved = 4;
54 typedef Object* JSCallerSavedBuffer[kNumJSCallerSaved];
56 // Return the code of the n-th caller-saved register available to JavaScript
57 // e.g. JSCallerSavedReg(0) returns r0.code() == 0
58 int JSCallerSavedCode(int n);
61 // Callee-saved registers preserved when switching from C to JavaScript
62 static const RegList kCalleeSaved =
67 1 << 8 | // r8 v5 (cp in JavaScript code)
70 1 << 10 | // r10 v7 (pp in JavaScript code)
71 1 << 11; // r11 v8 (fp in JavaScript code)
73 static const int kNumCalleeSaved = 7 + kR9Available;
76 // ----------------------------------------------------
79 class StackHandlerConstants : public AllStatic {
81 // TODO(1233780): Get rid of the code slot in stack handlers.
82 static const int kCodeOffset = 0 * kPointerSize;
83 static const int kNextOffset = 1 * kPointerSize;
84 static const int kStateOffset = 2 * kPointerSize;
85 static const int kPPOffset = 3 * kPointerSize;
86 static const int kFPOffset = 4 * kPointerSize;
87 static const int kPCOffset = 5 * kPointerSize;
89 static const int kAddressDisplacement = -1 * kPointerSize;
90 static const int kSize = kPCOffset + kPointerSize;
94 class EntryFrameConstants : public AllStatic {
96 static const int kCallerFPOffset = -3 * kPointerSize;
100 class ExitFrameConstants : public AllStatic {
102 // Exit frames have a debug marker on the stack.
103 static const int kSPDisplacement = -1 * kPointerSize;
105 // The debug marker is just above the frame pointer.
106 static const int kDebugMarkOffset = -1 * kPointerSize;
108 static const int kSavedRegistersOffset = 0 * kPointerSize;
110 // Let the parameters pointer for exit frames point just below the
111 // frame structure on the stack.
112 static const int kPPDisplacement = 3 * kPointerSize;
114 // The caller fields are below the frame pointer on the stack.
115 static const int kCallerFPOffset = +0 * kPointerSize;
116 static const int kCallerPPOffset = +1 * kPointerSize;
117 static const int kCallerPCOffset = +2 * kPointerSize;
121 class StandardFrameConstants : public AllStatic {
123 static const int kExpressionsOffset = -3 * kPointerSize;
124 static const int kMarkerOffset = -2 * kPointerSize;
125 static const int kContextOffset = -1 * kPointerSize;
126 static const int kCallerFPOffset = 0 * kPointerSize;
127 static const int kCallerPCOffset = +1 * kPointerSize;
128 static const int kCallerSPOffset = +2 * kPointerSize;
132 class JavaScriptFrameConstants : public AllStatic {
135 static const int kLocal0Offset = StandardFrameConstants::kExpressionsOffset;
136 static const int kSavedRegistersOffset = +2 * kPointerSize;
137 static const int kFunctionOffset = StandardFrameConstants::kMarkerOffset;
140 static const int kParam0Offset = -2 * kPointerSize;
141 static const int kReceiverOffset = -1 * kPointerSize;
145 class ArgumentsAdaptorFrameConstants : public AllStatic {
147 static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset;
151 class InternalFrameConstants : public AllStatic {
153 static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset;
157 inline Object* JavaScriptFrame::function_slot_object() const {
158 const int offset = JavaScriptFrameConstants::kFunctionOffset;
159 return Memory::Object_at(fp() + offset);
163 // ----------------------------------------------------
175 // ----------- +=============+ <--- sp (stack pointer)
186 // t +- - - - - - -+ <---
188 // v +-------------+ |
190 // t +-------------+ | kLocal0Offset
191 // i -2 | context | |
192 // o +-------------+ |
193 // n -1 | args_length | v
194 // +-------------+ <--- fp (frame pointer)
199 // m 2 | sp_on_exit | (pp if return, caller_sp if no return)
202 // +-------------+ <--- caller_sp (incl. parameters)
206 // +- - - - - - -+ <---
207 // -2 | parameter0 | ^
208 // +-------------+ | kParam0Offset
210 // ----------- +=============+ <--- pp (parameter pointer, r10)
214 // |caller-saved | (must be valid JS values, traversed during GC)
220 // higher | expressions |
227 // Handler frames (part of expressions of JS frames):
237 // l +-------------+ <--- handler sp
238 // e 0 | next_sp | link to next handler (next handler's sp)
249 // higher | expressions |
254 // JS entry frames: When calling from C to JS, we construct two extra
255 // frames: An entry frame (C) and a trampoline frame (JS). The
256 // following pictures shows the two frames:
265 // ----------- +=============+ <--- sp (stack pointer)
278 // -2 | NULL | context is always NULL
280 // f -1 | 0 | args_length is always zero
281 // r +-------------+ <--- fp (frame pointer)
282 // a 0 | NULL | caller pp is always NULL for entries
286 // 2 | sp_on_exit | (caller_sp)
289 // ----------- +=============+ <--- caller_sp == pp
291 // . | try-handler, fake, not GC'ed
293 // +-------------+ <---
294 // -2 | next top pp |
296 // -1 | next top fp |
297 // +-------------+ <--- fp
298 // | r4 | r4-r9 holding non-JS values must be preserved
300 // J | r5 | before being initialized not to confuse GC
308 // y [ | r9 | ] only if r9 available
317 // +-------------+ <--- caller_sp
318 // | argv | passed on stack from C code
322 // addresses | C frame |
325 // The first 4 args are passed from C in r0-r3 and are not spilled on entry:
333 // C entry frames: When calling from JS to C, we construct one extra
343 // ----------- +=============+ <--- sp (stack pointer)
345 // | parameters | (first 4 args are passed in r0-r3)
347 // +-------------+ <--- fp (frame pointer)
348 // f 4/5 | caller_fp |
350 // a 5/6 | sp_on_exit | (pp)
352 // e 6/7 | caller_pc |
353 // +-------------+ <--- caller_sp (incl. parameters)
357 // +- - - - - - -+ <---
358 // -2 | parameter0 | ^
359 // +-------------+ | kParam0Offset
361 // ----------- +=============+ <--- pp (parameter pointer, r10)
374 // addresses | JS frame |
377 } } // namespace v8::internal
379 #endif // V8_ARM_FRAMES_ARM_H_