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_
35 // The ARM ABI does not specify the usage of register r9, which may be reserved
36 // as the static base or thread register on some platforms, in which case we
37 // leave it alone. Adjust the value of kR9Available accordingly:
38 static const int kR9Available = 1; // 1 if available to us, 0 if reserved
41 // Register list in load/store instructions
42 // Note that the bit values must match those used in actual instruction encoding
43 static const int kNumRegs = 16;
46 // Caller-saved/arguments registers
47 static const RegList kJSCallerSaved =
53 static const int kNumJSCallerSaved = 4;
55 typedef Object* JSCallerSavedBuffer[kNumJSCallerSaved];
57 // Return the code of the n-th caller-saved register available to JavaScript
58 // e.g. JSCallerSavedReg(0) returns r0.code() == 0
59 int JSCallerSavedCode(int n);
62 // Callee-saved registers preserved when switching from C to JavaScript
63 static const RegList kCalleeSaved =
68 1 << 8 | // r8 v5 (cp in JavaScript code)
71 1 << 10 | // r10 v7 (pp in JavaScript code)
72 1 << 11; // r11 v8 (fp in JavaScript code)
74 static const int kNumCalleeSaved = 7 + kR9Available;
77 // ----------------------------------------------------
80 class StackHandlerConstants : public AllStatic {
82 // TODO(1233780): Get rid of the code slot in stack handlers.
83 static const int kCodeOffset = 0 * kPointerSize;
84 static const int kNextOffset = 1 * kPointerSize;
85 static const int kStateOffset = 2 * kPointerSize;
86 static const int kPPOffset = 3 * kPointerSize;
87 static const int kFPOffset = 4 * kPointerSize;
88 static const int kPCOffset = 5 * kPointerSize;
90 static const int kAddressDisplacement = -1 * kPointerSize;
91 static const int kSize = kPCOffset + kPointerSize;
95 class EntryFrameConstants : public AllStatic {
97 static const int kCallerFPOffset = -3 * kPointerSize;
101 class ExitFrameConstants : public AllStatic {
103 // Exit frames have a debug marker on the stack.
104 static const int kSPDisplacement = -1 * kPointerSize;
106 // The debug marker is just above the frame pointer.
107 static const int kDebugMarkOffset = -1 * kPointerSize;
109 static const int kSavedRegistersOffset = 0 * kPointerSize;
111 // Let the parameters pointer for exit frames point just below the
112 // frame structure on the stack.
113 static const int kPPDisplacement = 3 * kPointerSize;
115 // The caller fields are below the frame pointer on the stack.
116 static const int kCallerFPOffset = +0 * kPointerSize;
117 static const int kCallerPPOffset = +1 * kPointerSize;
118 static const int kCallerPCOffset = +2 * kPointerSize;
122 class StandardFrameConstants : public AllStatic {
124 static const int kExpressionsOffset = -3 * kPointerSize;
125 static const int kMarkerOffset = -2 * kPointerSize;
126 static const int kContextOffset = -1 * kPointerSize;
127 static const int kCallerFPOffset = 0 * kPointerSize;
128 static const int kCallerPCOffset = +1 * kPointerSize;
129 static const int kCallerSPOffset = +2 * kPointerSize;
133 class JavaScriptFrameConstants : public AllStatic {
136 static const int kLocal0Offset = StandardFrameConstants::kExpressionsOffset;
137 static const int kSavedRegistersOffset = +2 * kPointerSize;
138 static const int kFunctionOffset = StandardFrameConstants::kMarkerOffset;
141 static const int kParam0Offset = -2 * kPointerSize;
142 static const int kReceiverOffset = -1 * kPointerSize;
146 class ArgumentsAdaptorFrameConstants : public AllStatic {
148 static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset;
152 class InternalFrameConstants : public AllStatic {
154 static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset;
158 inline Object* JavaScriptFrame::function_slot_object() const {
159 const int offset = JavaScriptFrameConstants::kFunctionOffset;
160 return Memory::Object_at(fp() + offset);
164 // ----------------------------------------------------
176 // ----------- +=============+ <--- sp (stack pointer)
187 // t +- - - - - - -+ <---
189 // v +-------------+ |
191 // t +-------------+ | kLocal0Offset
192 // i -2 | context | |
193 // o +-------------+ |
194 // n -1 | args_length | v
195 // +-------------+ <--- fp (frame pointer)
200 // m 2 | sp_on_exit | (pp if return, caller_sp if no return)
203 // +-------------+ <--- caller_sp (incl. parameters)
207 // +- - - - - - -+ <---
208 // -2 | parameter0 | ^
209 // +-------------+ | kParam0Offset
211 // ----------- +=============+ <--- pp (parameter pointer, r10)
215 // |caller-saved | (must be valid JS values, traversed during GC)
221 // higher | expressions |
228 // Handler frames (part of expressions of JS frames):
238 // l +-------------+ <--- handler sp
239 // e 0 | next_sp | link to next handler (next handler's sp)
250 // higher | expressions |
255 // JS entry frames: When calling from C to JS, we construct two extra
256 // frames: An entry frame (C) and a trampoline frame (JS). The
257 // following pictures shows the two frames:
266 // ----------- +=============+ <--- sp (stack pointer)
279 // -2 | NULL | context is always NULL
281 // f -1 | 0 | args_length is always zero
282 // r +-------------+ <--- fp (frame pointer)
283 // a 0 | NULL | caller pp is always NULL for entries
287 // 2 | sp_on_exit | (caller_sp)
290 // ----------- +=============+ <--- caller_sp == pp
292 // . | try-handler, fake, not GC'ed
294 // +-------------+ <---
295 // -2 | next top pp |
297 // -1 | next top fp |
298 // +-------------+ <--- fp
299 // | r4 | r4-r9 holding non-JS values must be preserved
301 // J | r5 | before being initialized not to confuse GC
309 // y [ | r9 | ] only if r9 available
318 // +-------------+ <--- caller_sp
319 // | argv | passed on stack from C code
323 // addresses | C frame |
326 // The first 4 args are passed from C in r0-r3 and are not spilled on entry:
334 // C entry frames: When calling from JS to C, we construct one extra
344 // ----------- +=============+ <--- sp (stack pointer)
346 // | parameters | (first 4 args are passed in r0-r3)
348 // +-------------+ <--- fp (frame pointer)
349 // f 4/5 | caller_fp |
351 // a 5/6 | sp_on_exit | (pp)
353 // e 6/7 | caller_pc |
354 // +-------------+ <--- caller_sp (incl. parameters)
358 // +- - - - - - -+ <---
359 // -2 | parameter0 | ^
360 // +-------------+ | kParam0Offset
362 // ----------- +=============+ <--- pp (parameter pointer, r10)
375 // addresses | JS frame |
378 } } // namespace v8::internal
380 #endif // V8_ARM_FRAMES_ARM_H_