frames-arm.h revision b0fe1620dcb4135ac3ab2d66ff93072373911299
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
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_ARM_FRAMES_ARM_H_
29#define V8_ARM_FRAMES_ARM_H_
30
31namespace v8 {
32namespace internal {
33
34
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:
38static const int kR9Available = 1;  // 1 if available to us, 0 if reserved
39
40
41// Register list in load/store instructions
42// Note that the bit values must match those used in actual instruction encoding
43static const int kNumRegs = 16;
44
45
46// Caller-saved/arguments registers
47static const RegList kJSCallerSaved =
48  1 << 0 |  // r0 a1
49  1 << 1 |  // r1 a2
50  1 << 2 |  // r2 a3
51  1 << 3;   // r3 a4
52
53static const int kNumJSCallerSaved = 4;
54
55typedef Object* JSCallerSavedBuffer[kNumJSCallerSaved];
56
57// Return the code of the n-th caller-saved register available to JavaScript
58// e.g. JSCallerSavedReg(0) returns r0.code() == 0
59int JSCallerSavedCode(int n);
60
61
62// Callee-saved registers preserved when switching from C to JavaScript
63static const RegList kCalleeSaved =
64  1 <<  4 |  //  r4 v1
65  1 <<  5 |  //  r5 v2
66  1 <<  6 |  //  r6 v3
67  1 <<  7 |  //  r7 v4
68  1 <<  8 |  //  r8 v5 (cp in JavaScript code)
69  kR9Available
70    <<  9 |  //  r9 v6
71  1 << 10 |  // r10 v7
72  1 << 11;   // r11 v8 (fp in JavaScript code)
73
74static const int kNumCalleeSaved = 7 + kR9Available;
75
76
77// Number of registers for which space is reserved in safepoints. Must be a
78// multiple of 8.
79// TODO(regis): Only 8 registers may actually be sufficient. Revisit.
80static const int kNumSafepointRegisters = 16;
81
82// Define the list of registers actually saved at safepoints.
83// Note that the number of saved registers may be smaller than the reserved
84// space, i.e. kNumSafepointSavedRegisters <= kNumSafepointRegisters.
85static const RegList kSafepointSavedRegisters = kJSCallerSaved | kCalleeSaved;
86static const int kNumSafepointSavedRegisters =
87    kNumJSCallerSaved + kNumCalleeSaved;
88
89// ----------------------------------------------------
90
91
92class StackHandlerConstants : public AllStatic {
93 public:
94  static const int kNextOffset  = 0 * kPointerSize;
95  static const int kStateOffset = 1 * kPointerSize;
96  static const int kFPOffset    = 2 * kPointerSize;
97  static const int kPCOffset    = 3 * kPointerSize;
98
99  static const int kSize = kPCOffset + kPointerSize;
100};
101
102
103class EntryFrameConstants : public AllStatic {
104 public:
105  static const int kCallerFPOffset      = -3 * kPointerSize;
106};
107
108
109class ExitFrameConstants : public AllStatic {
110 public:
111  static const int kCodeOffset = -1 * kPointerSize;
112  static const int kSPOffset = -1 * kPointerSize;
113
114  // TODO(regis): Use a patched sp value on the stack instead.
115  // A marker of 0 indicates that double registers are saved.
116  static const int kMarkerOffset = -2 * kPointerSize;
117
118  // The caller fields are below the frame pointer on the stack.
119  static const int kCallerFPOffset = +0 * kPointerSize;
120  // The calling JS function is between FP and PC.
121  static const int kCallerPCOffset = +2 * kPointerSize;
122
123  // FP-relative displacement of the caller's SP.  It points just
124  // below the saved PC.
125  static const int kCallerSPDisplacement = +3 * kPointerSize;
126};
127
128
129class StandardFrameConstants : public AllStatic {
130 public:
131  static const int kExpressionsOffset = -3 * kPointerSize;
132  static const int kMarkerOffset      = -2 * kPointerSize;
133  static const int kContextOffset     = -1 * kPointerSize;
134  static const int kCallerFPOffset    =  0 * kPointerSize;
135  static const int kCallerPCOffset    = +1 * kPointerSize;
136  static const int kCallerSPOffset    = +2 * kPointerSize;
137};
138
139
140class JavaScriptFrameConstants : public AllStatic {
141 public:
142  // FP-relative.
143  static const int kLocal0Offset = StandardFrameConstants::kExpressionsOffset;
144  static const int kSavedRegistersOffset = +2 * kPointerSize;
145  static const int kFunctionOffset = StandardFrameConstants::kMarkerOffset;
146
147  // Caller SP-relative.
148  static const int kParam0Offset   = -2 * kPointerSize;
149  static const int kReceiverOffset = -1 * kPointerSize;
150};
151
152
153class ArgumentsAdaptorFrameConstants : public AllStatic {
154 public:
155  static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset;
156};
157
158
159class InternalFrameConstants : public AllStatic {
160 public:
161  static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset;
162};
163
164
165inline Object* JavaScriptFrame::function_slot_object() const {
166  const int offset = JavaScriptFrameConstants::kFunctionOffset;
167  return Memory::Object_at(fp() + offset);
168}
169
170
171} }  // namespace v8::internal
172
173#endif  // V8_ARM_FRAMES_ARM_H_
174