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_IA32_FRAMES_IA32_H_
29 #define V8_IA32_FRAMES_IA32_H_
36 // Note that the bit values must match those used in actual instruction encoding
37 static const int kNumRegs = 8;
40 // Caller-saved registers
41 static const RegList kJSCallerSaved =
45 1 << 3 | // ebx - used as a caller-saved register in JavaScript code
46 1 << 7; // edi - callee function
48 static const int kNumJSCallerSaved = 5;
50 typedef Object* JSCallerSavedBuffer[kNumJSCallerSaved];
52 // ----------------------------------------------------
55 class StackHandlerConstants : public AllStatic {
57 static const int kNextOffset = 0 * kPointerSize;
58 static const int kPPOffset = 1 * kPointerSize;
59 static const int kFPOffset = 2 * kPointerSize;
61 // TODO(1233780): Get rid of the code slot in stack handlers.
62 static const int kCodeOffset = 3 * kPointerSize;
64 static const int kStateOffset = 4 * kPointerSize;
65 static const int kPCOffset = 5 * kPointerSize;
67 static const int kAddressDisplacement = -1 * kPointerSize;
68 static const int kSize = kPCOffset + kPointerSize;
72 class EntryFrameConstants : public AllStatic {
74 static const int kCallerFPOffset = -6 * kPointerSize;
76 static const int kFunctionArgOffset = +3 * kPointerSize;
77 static const int kReceiverArgOffset = +4 * kPointerSize;
78 static const int kArgcOffset = +5 * kPointerSize;
79 static const int kArgvOffset = +6 * kPointerSize;
83 class ExitFrameConstants : public AllStatic {
85 static const int kDebugMarkOffset = -2 * kPointerSize;
86 static const int kSPOffset = -1 * kPointerSize;
88 // Let the parameters pointer for exit frames point just below the
89 // frame structure on the stack (frame pointer and return address).
90 static const int kPPDisplacement = +2 * kPointerSize;
92 static const int kCallerFPOffset = 0 * kPointerSize;
93 static const int kCallerPCOffset = +1 * kPointerSize;
97 class StandardFrameConstants : public AllStatic {
99 static const int kExpressionsOffset = -3 * kPointerSize;
100 static const int kMarkerOffset = -2 * kPointerSize;
101 static const int kContextOffset = -1 * kPointerSize;
102 static const int kCallerFPOffset = 0 * kPointerSize;
103 static const int kCallerPCOffset = +1 * kPointerSize;
104 static const int kCallerSPOffset = +2 * kPointerSize;
108 class JavaScriptFrameConstants : public AllStatic {
111 static const int kLocal0Offset = StandardFrameConstants::kExpressionsOffset;
112 static const int kSavedRegistersOffset = +2 * kPointerSize;
113 static const int kFunctionOffset = StandardFrameConstants::kMarkerOffset;
115 // CallerSP-relative (aka PP-relative)
116 static const int kParam0Offset = -2 * kPointerSize;
117 static const int kReceiverOffset = -1 * kPointerSize;
121 class ArgumentsAdaptorFrameConstants : public AllStatic {
123 static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset;
127 class InternalFrameConstants : public AllStatic {
129 static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset;
133 inline Object* JavaScriptFrame::function_slot_object() const {
134 const int offset = JavaScriptFrameConstants::kFunctionOffset;
135 return Memory::Object_at(fp() + offset);
139 // ----------------------------------------------------
152 // +-------------+ <--+ entry_sp
157 // -3 | entry_sp --+----+
159 // n -2 | C function |
161 // r -1 | caller_pp |
162 // y +-------------+ <--- fp (frame pointer, ebp)
166 // a +-------------+ <--- caller_sp (stack pointer, esp)
175 // higher | expressions |
185 // ----------- +=============+ <--- sp (stack pointer, esp)
195 // i +- - - - - - -+ <---
197 // a +-------------+ |
199 // i +-------------+ |
200 // o -2 | context | | kLocal0Offset
201 // n +-------------+ |
202 // -1 | caller_pp | v
203 // f +-------------+ <--- fp (frame pointer, ebp)
207 // e +-------------+ <--- caller_sp (incl. parameters)
211 // +- - - - - - -+ <---
212 // -2 | parameter0 | ^
213 // +-------------+ | kParam0Offset
215 // ----------- +=============+ <--- pp (parameter pointer, edi)
220 // higher | expressions |
224 // JS entry frames: When calling from C to JS, we construct two extra
225 // frames: An entry frame (C) and a trampoline frame (JS). The
226 // following pictures shows the two frames:
232 // ----------- +=============+ <--- sp (stack pointer, esp)
240 // o +-------------+ <---
242 // i +-------------+ |
243 // n -3 | code | | kLocal0Offset
245 // -2 | NULL | context is always NULL
247 // f -1 | NULL | caller pp is always NULL for entry frames
248 // r +-------------+ <--- fp (frame pointer, ebp)
252 // +-------------+ <--- caller_sp (incl. parameters)
254 // ----------- +=============+ <--- pp (parameter pointer, edi)
256 // +-------------+ <---
258 // . | try-handler (HandlerOffsets::kSize)
260 // +-------------+ <---
261 // -5 | next top pp |
263 // e -4 | next top fp |
264 // n +-------------+ <---
266 // r +-------------+ |
267 // y -2 | esi | | callee-saved registers
270 // f +-------------+ <--- fp
272 // a +-------------+ pp == NULL (parameter pointer)
274 // e +-------------+ <--- caller sp
275 // 2 | code entry | ^
278 // +-------------+ | arguments passed from C code
284 // +-------------+ <---
290 } } // namespace v8::internal
292 #endif // V8_IA32_FRAMES_IA32_H_