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_
31 namespace v8 { namespace internal {
35 // Note that the bit values must match those used in actual instruction encoding
36 static const int kNumRegs = 8;
39 // Caller-saved registers
40 static const RegList kJSCallerSaved =
44 1 << 3 | // ebx - used as a caller-saved register in JavaScript code
45 1 << 7; // edi - callee function
47 static const int kNumJSCallerSaved = 5;
49 typedef Object* JSCallerSavedBuffer[kNumJSCallerSaved];
51 // ----------------------------------------------------
54 class StackHandlerConstants : public AllStatic {
56 static const int kNextOffset = 0 * kPointerSize;
57 static const int kPPOffset = 1 * kPointerSize;
58 static const int kFPOffset = 2 * kPointerSize;
60 // TODO(1233780): Get rid of the code slot in stack handlers.
61 static const int kCodeOffset = 3 * kPointerSize;
63 static const int kStateOffset = 4 * kPointerSize;
64 static const int kPCOffset = 5 * kPointerSize;
66 static const int kAddressDisplacement = -1 * kPointerSize;
67 static const int kSize = kPCOffset + kPointerSize;
71 class EntryFrameConstants : public AllStatic {
73 static const int kCallerFPOffset = -6 * kPointerSize;
75 static const int kFunctionArgOffset = +3 * kPointerSize;
76 static const int kReceiverArgOffset = +4 * kPointerSize;
77 static const int kArgcOffset = +5 * kPointerSize;
78 static const int kArgvOffset = +6 * kPointerSize;
82 class ExitFrameConstants : public AllStatic {
84 static const int kDebugMarkOffset = -2 * kPointerSize;
85 static const int kSPOffset = -1 * kPointerSize;
87 // Let the parameters pointer for exit frames point just below the
88 // frame structure on the stack (frame pointer and return address).
89 static const int kPPDisplacement = +2 * kPointerSize;
91 static const int kCallerFPOffset = 0 * kPointerSize;
92 static const int kCallerPCOffset = +1 * kPointerSize;
96 class StandardFrameConstants : public AllStatic {
98 static const int kExpressionsOffset = -3 * kPointerSize;
99 static const int kMarkerOffset = -2 * kPointerSize;
100 static const int kContextOffset = -1 * kPointerSize;
101 static const int kCallerFPOffset = 0 * kPointerSize;
102 static const int kCallerPCOffset = +1 * kPointerSize;
103 static const int kCallerSPOffset = +2 * kPointerSize;
107 class JavaScriptFrameConstants : public AllStatic {
110 static const int kLocal0Offset = StandardFrameConstants::kExpressionsOffset;
111 static const int kSavedRegistersOffset = +2 * kPointerSize;
112 static const int kFunctionOffset = StandardFrameConstants::kMarkerOffset;
114 // CallerSP-relative (aka PP-relative)
115 static const int kParam0Offset = -2 * kPointerSize;
116 static const int kReceiverOffset = -1 * kPointerSize;
120 class ArgumentsAdaptorFrameConstants : public AllStatic {
122 static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset;
126 class InternalFrameConstants : public AllStatic {
128 static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset;
132 inline Object* JavaScriptFrame::function_slot_object() const {
133 const int offset = JavaScriptFrameConstants::kFunctionOffset;
134 return Memory::Object_at(fp() + offset);
138 // ----------------------------------------------------
151 // +-------------+ <--+ entry_sp
156 // -3 | entry_sp --+----+
158 // n -2 | C function |
160 // r -1 | caller_pp |
161 // y +-------------+ <--- fp (frame pointer, ebp)
165 // a +-------------+ <--- caller_sp (stack pointer, esp)
174 // higher | expressions |
184 // ----------- +=============+ <--- sp (stack pointer, esp)
194 // i +- - - - - - -+ <---
196 // a +-------------+ |
198 // i +-------------+ |
199 // o -2 | context | | kLocal0Offset
200 // n +-------------+ |
201 // -1 | caller_pp | v
202 // f +-------------+ <--- fp (frame pointer, ebp)
206 // e +-------------+ <--- caller_sp (incl. parameters)
210 // +- - - - - - -+ <---
211 // -2 | parameter0 | ^
212 // +-------------+ | kParam0Offset
214 // ----------- +=============+ <--- pp (parameter pointer, edi)
219 // higher | expressions |
223 // JS entry frames: When calling from C to JS, we construct two extra
224 // frames: An entry frame (C) and a trampoline frame (JS). The
225 // following pictures shows the two frames:
231 // ----------- +=============+ <--- sp (stack pointer, esp)
239 // o +-------------+ <---
241 // i +-------------+ |
242 // n -3 | code | | kLocal0Offset
244 // -2 | NULL | context is always NULL
246 // f -1 | NULL | caller pp is always NULL for entry frames
247 // r +-------------+ <--- fp (frame pointer, ebp)
251 // +-------------+ <--- caller_sp (incl. parameters)
253 // ----------- +=============+ <--- pp (parameter pointer, edi)
255 // +-------------+ <---
257 // . | try-handler (HandlerOffsets::kSize)
259 // +-------------+ <---
260 // -5 | next top pp |
262 // e -4 | next top fp |
263 // n +-------------+ <---
265 // r +-------------+ |
266 // y -2 | esi | | callee-saved registers
269 // f +-------------+ <--- fp
271 // a +-------------+ pp == NULL (parameter pointer)
273 // e +-------------+ <--- caller sp
274 // 2 | code entry | ^
277 // +-------------+ | arguments passed from C code
283 // +-------------+ <---
289 } } // namespace v8::internal
291 #endif // V8_IA32_FRAMES_IA32_H_