blob: e31906de3b82eb9425cd40a6ee8b5a1d61c23990 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// 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_FRAMES_IA32_H_
29#define V8_FRAMES_IA32_H_
30
31namespace v8 { namespace internal {
32
33
34// Register lists
35// Note that the bit values must match those used in actual instruction encoding
36static const int kNumRegs = 8;
37
38
39// Caller-saved registers
40static const RegList kJSCallerSaved =
41 1 << 0 | // eax
42 1 << 1 | // ecx
43 1 << 2 | // edx
44 1 << 3 | // ebx - used as a caller-saved register in JavaScript code
45 1 << 7; // edi - callee function
46
47static const int kNumJSCallerSaved = 5;
48
49typedef Object* JSCallerSavedBuffer[kNumJSCallerSaved];
50
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000051// ----------------------------------------------------
52
53
54class StackHandlerConstants : public AllStatic {
55 public:
56 static const int kNextOffset = 0 * kPointerSize;
57 static const int kPPOffset = 1 * kPointerSize;
58 static const int kFPOffset = 2 * kPointerSize;
59
60 // TODO(1233780): Get rid of the code slot in stack handlers.
61 static const int kCodeOffset = 3 * kPointerSize;
62
63 static const int kStateOffset = 4 * kPointerSize;
64 static const int kPCOffset = 5 * kPointerSize;
65
66 static const int kAddressDisplacement = -1 * kPointerSize;
67 static const int kSize = kPCOffset + kPointerSize;
68};
69
70
71class EntryFrameConstants : public AllStatic {
72 public:
73 static const int kCallerFPOffset = -6 * kPointerSize;
74
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;
79};
80
81
82class ExitFrameConstants : public AllStatic {
83 public:
ager@chromium.org236ad962008-09-25 09:45:57 +000084 static const int kDebugMarkOffset = -2 * kPointerSize;
85 static const int kSPOffset = -1 * kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000086
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;
90
91 static const int kCallerFPOffset = 0 * kPointerSize;
92 static const int kCallerPCOffset = +1 * kPointerSize;
93};
94
95
96class StandardFrameConstants : public AllStatic {
97 public:
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;
104};
105
106
107class JavaScriptFrameConstants : public AllStatic {
108 public:
109 // FP-relative.
110 static const int kLocal0Offset = StandardFrameConstants::kExpressionsOffset;
111 static const int kSavedRegistersOffset = +2 * kPointerSize;
112 static const int kFunctionOffset = StandardFrameConstants::kMarkerOffset;
113
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000114 // CallerSP-relative (aka PP-relative)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000115 static const int kParam0Offset = -2 * kPointerSize;
116 static const int kReceiverOffset = -1 * kPointerSize;
117};
118
119
120class ArgumentsAdaptorFrameConstants : public AllStatic {
121 public:
122 static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset;
123};
124
125
126class InternalFrameConstants : public AllStatic {
127 public:
128 static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset;
129};
130
131
132inline Object* JavaScriptFrame::function() const {
133 const int offset = JavaScriptFrameConstants::kFunctionOffset;
134 Object* result = Memory::Object_at(fp() + offset);
135 ASSERT(result->IsJSFunction());
136 return result;
137}
138
139
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000140// ----------------------------------------------------
141
142
143
144
145 // C Entry frames:
146
147 // lower | Stack |
148 // addresses | ^ |
149 // | | |
150 // | |
151 // +-------------+
152 // | entry_pc |
153 // +-------------+ <--+ entry_sp
154 // . |
155 // . |
156 // . |
157 // +-------------+ |
158 // -3 | entry_sp --+----+
159 // e +-------------+
160 // n -2 | C function |
161 // t +-------------+
162 // r -1 | caller_pp |
163 // y +-------------+ <--- fp (frame pointer, ebp)
164 // 0 | caller_fp |
165 // f +-------------+
166 // r 1 | caller_pc |
167 // a +-------------+ <--- caller_sp (stack pointer, esp)
168 // m 2 | |
169 // e | arguments |
170 // | |
171 // +- - - - - - -+
172 // | argument0 |
173 // +=============+
174 // | |
175 // | caller |
176 // higher | expressions |
177 // addresses | |
178
179
180 // Proper JS frames:
181
182 // lower | Stack |
183 // addresses | ^ |
184 // | | |
185 // | |
186 // ----------- +=============+ <--- sp (stack pointer, esp)
187 // | function |
188 // +-------------+
189 // | |
190 // | expressions |
191 // | |
192 // +-------------+
193 // a | |
194 // c | locals |
195 // t | |
196 // i +- - - - - - -+ <---
197 // v -4 | local0 | ^
198 // a +-------------+ |
199 // t -3 | code | |
200 // i +-------------+ |
201 // o -2 | context | | kLocal0Offset
202 // n +-------------+ |
203 // -1 | caller_pp | v
204 // f +-------------+ <--- fp (frame pointer, ebp)
205 // r 0 | caller_fp |
206 // a +-------------+
207 // m 1 | caller_pc |
208 // e +-------------+ <--- caller_sp (incl. parameters)
209 // 2 | |
210 // | parameters |
211 // | |
212 // +- - - - - - -+ <---
213 // -2 | parameter0 | ^
214 // +-------------+ | kParam0Offset
215 // -1 | receiver | v
216 // ----------- +=============+ <--- pp (parameter pointer, edi)
217 // 0 | function |
218 // +-------------+
219 // | |
220 // | caller |
221 // higher | expressions |
222 // addresses | |
223
224
225 // JS entry frames: When calling from C to JS, we construct two extra
226 // frames: An entry frame (C) and a trampoline frame (JS). The
227 // following pictures shows the two frames:
228
229 // lower | Stack |
230 // addresses | ^ |
231 // | | |
232 // | |
233 // ----------- +=============+ <--- sp (stack pointer, esp)
234 // | |
235 // | parameters |
236 // t | |
237 // r +- - - - - - -+
238 // a | parameter0 |
239 // m +-------------+
240 // p | receiver |
241 // o +-------------+ <---
242 // l | function | ^
243 // i +-------------+ |
244 // n -3 | code | | kLocal0Offset
245 // e +-------------+
246 // -2 | NULL | context is always NULL
247 // +-------------+
248 // f -1 | NULL | caller pp is always NULL for entry frames
249 // r +-------------+ <--- fp (frame pointer, ebp)
250 // a 0 | caller fp |
251 // m +-------------+
252 // e 1 | caller pc |
253 // +-------------+ <--- caller_sp (incl. parameters)
254 // | 0 |
255 // ----------- +=============+ <--- pp (parameter pointer, edi)
256 // | 0 |
257 // +-------------+ <---
258 // . ^
259 // . | try-handler (HandlerOffsets::kSize)
260 // . v
261 // +-------------+ <---
262 // -5 | next top pp |
263 // +-------------+
264 // e -4 | next top fp |
265 // n +-------------+ <---
266 // t -3 | ebx | ^
267 // r +-------------+ |
268 // y -2 | esi | | callee-saved registers
269 // +-------------+ |
270 // -1 | edi | v
271 // f +-------------+ <--- fp
272 // r 0 | caller fp |
273 // a +-------------+ pp == NULL (parameter pointer)
274 // m 1 | caller pc |
275 // e +-------------+ <--- caller sp
276 // 2 | code entry | ^
277 // +-------------+ |
278 // 3 | function | |
279 // +-------------+ | arguments passed from C code
280 // 4 | receiver | |
281 // +-------------+ |
282 // 5 | argc | |
283 // +-------------+ |
284 // 6 | argv | v
285 // +-------------+ <---
286 // | |
287 // higher | |
288 // addresses | |
289
290
291} } // namespace v8::internal
292
293#endif // V8_FRAMES_IA32_H_