frames-arm.h revision 7d3e7fc4b65010eabe860313ee0c64f50843f6e3
1a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Copyright 2006-2008 the V8 project authors. All rights reserved.
2a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Redistribution and use in source and binary forms, with or without
3a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// modification, are permitted provided that the following conditions are
4a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// met:
5a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
6a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions of source code must retain the above copyright
7a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       notice, this list of conditions and the following disclaimer.
8a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions in binary form must reproduce the above
9a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       copyright notice, this list of conditions and the following
10a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       disclaimer in the documentation and/or other materials provided
11a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       with the distribution.
12a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Neither the name of Google Inc. nor the names of its
13a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       contributors may be used to endorse or promote products derived
14a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       from this software without specific prior written permission.
15a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
16a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
28a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifndef V8_ARM_FRAMES_ARM_H_
29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8_ARM_FRAMES_ARM_H_
30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
31a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace v8 {
32a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal {
33a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
34a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
35a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The ARM ABI does not specify the usage of register r9, which may be reserved
36a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// as the static base or thread register on some platforms, in which case we
37a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// leave it alone. Adjust the value of kR9Available accordingly:
38a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockstatic const int kR9Available = 1;  // 1 if available to us, 0 if reserved
39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
40a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
41a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Register list in load/store instructions
42a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Note that the bit values must match those used in actual instruction encoding
43a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockstatic const int kNumRegs = 16;
44a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
45a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
46a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Caller-saved/arguments registers
47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockstatic const RegList kJSCallerSaved =
48a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  1 << 0 |  // r0 a1
49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  1 << 1 |  // r1 a2
50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  1 << 2 |  // r2 a3
51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  1 << 3;   // r3 a4
52a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockstatic const int kNumJSCallerSaved = 4;
54a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
55a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Object* JSCallerSavedBuffer[kNumJSCallerSaved];
56a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
57a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Return the code of the n-th caller-saved register available to JavaScript
58a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// e.g. JSCallerSavedReg(0) returns r0.code() == 0
59a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockint JSCallerSavedCode(int n);
60a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
61a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
62a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Callee-saved registers preserved when switching from C to JavaScript
63a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockstatic const RegList kCalleeSaved =
64a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  1 <<  4 |  //  r4 v1
65a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  1 <<  5 |  //  r5 v2
66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  1 <<  6 |  //  r6 v3
67a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  1 <<  7 |  //  r7 v4
68a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  1 <<  8 |  //  r8 v5 (cp in JavaScript code)
691e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  kR9Available <<  9 |  //  r9 v6
70a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  1 << 10 |  // r10 v7
71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  1 << 11;   // r11 v8 (fp in JavaScript code)
72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockstatic const int kNumCalleeSaved = 7 + kR9Available;
74a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
757d3e7fc4b65010eabe860313ee0c64f50843f6e3Ben Murdoch// Double registers d8 to d15 are callee-saved.
767d3e7fc4b65010eabe860313ee0c64f50843f6e3Ben Murdochstatic const int kNumDoubleCalleeSaved = 8;
777d3e7fc4b65010eabe860313ee0c64f50843f6e3Ben Murdoch
78a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
79b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// Number of registers for which space is reserved in safepoints. Must be a
80b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// multiple of 8.
81b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// TODO(regis): Only 8 registers may actually be sufficient. Revisit.
82b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochstatic const int kNumSafepointRegisters = 16;
83b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
84b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// Define the list of registers actually saved at safepoints.
85b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// Note that the number of saved registers may be smaller than the reserved
86b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// space, i.e. kNumSafepointSavedRegisters <= kNumSafepointRegisters.
87b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochstatic const RegList kSafepointSavedRegisters = kJSCallerSaved | kCalleeSaved;
88b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochstatic const int kNumSafepointSavedRegisters =
89b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    kNumJSCallerSaved + kNumCalleeSaved;
90b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// ----------------------------------------------------
92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass StackHandlerConstants : public AllStatic {
95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kNextOffset  = 0 * kPointerSize;
97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kStateOffset = 1 * kPointerSize;
98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFPOffset    = 2 * kPointerSize;
99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPCOffset    = 3 * kPointerSize;
100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kPCOffset + kPointerSize;
102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass EntryFrameConstants : public AllStatic {
106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kCallerFPOffset      = -3 * kPointerSize;
108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ExitFrameConstants : public AllStatic {
112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1131e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kCodeOffset = -2 * kPointerSize;
11480d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen  static const int kSPOffset = -1 * kPointerSize;
115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The caller fields are below the frame pointer on the stack.
1171e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kCallerFPOffset = 0 * kPointerSize;
1181e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // The calling JS function is below FP.
1191e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kCallerPCOffset = 1 * kPointerSize;
120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // FP-relative displacement of the caller's SP.  It points just
122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // below the saved PC.
1231e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kCallerSPDisplacement = 2 * kPointerSize;
124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass StandardFrameConstants : public AllStatic {
128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kExpressionsOffset = -3 * kPointerSize;
130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMarkerOffset      = -2 * kPointerSize;
131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kContextOffset     = -1 * kPointerSize;
132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kCallerFPOffset    =  0 * kPointerSize;
1331e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kCallerPCOffset    =  1 * kPointerSize;
1341e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kCallerSPOffset    =  2 * kPointerSize;
135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass JavaScriptFrameConstants : public AllStatic {
139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // FP-relative.
141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kLocal0Offset = StandardFrameConstants::kExpressionsOffset;
1428b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  static const int kLastParameterOffset = +2 * kPointerSize;
143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFunctionOffset = StandardFrameConstants::kMarkerOffset;
144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Caller SP-relative.
146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kParam0Offset   = -2 * kPointerSize;
147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kReceiverOffset = -1 * kPointerSize;
148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ArgumentsAdaptorFrameConstants : public AllStatic {
152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset;
154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass InternalFrameConstants : public AllStatic {
158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset;
160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockinline Object* JavaScriptFrame::function_slot_object() const {
164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const int offset = JavaScriptFrameConstants::kFunctionOffset;
165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Memory::Object_at(fp() + offset);
166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} }  // namespace v8::internal
170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // V8_ARM_FRAMES_ARM_H_
172