Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_PPC_FRAMES_PPC_H_ |
| 6 | #define V8_PPC_FRAMES_PPC_H_ |
| 7 | |
| 8 | namespace v8 { |
| 9 | namespace internal { |
| 10 | |
| 11 | |
| 12 | // Register list in load/store instructions |
| 13 | // Note that the bit values must match those used in actual instruction encoding |
| 14 | const int kNumRegs = 32; |
| 15 | |
| 16 | |
| 17 | // Caller-saved/arguments registers |
| 18 | const RegList kJSCallerSaved = 1 << 3 | // r3 a1 |
| 19 | 1 << 4 | // r4 a2 |
| 20 | 1 << 5 | // r5 a3 |
| 21 | 1 << 6 | // r6 a4 |
| 22 | 1 << 7 | // r7 a5 |
| 23 | 1 << 8 | // r8 a6 |
| 24 | 1 << 9 | // r9 a7 |
| 25 | 1 << 10 | // r10 a8 |
| 26 | 1 << 11; |
| 27 | |
| 28 | const int kNumJSCallerSaved = 9; |
| 29 | |
| 30 | // Return the code of the n-th caller-saved register available to JavaScript |
| 31 | // e.g. JSCallerSavedReg(0) returns r0.code() == 0 |
| 32 | int JSCallerSavedCode(int n); |
| 33 | |
| 34 | |
| 35 | // Callee-saved registers preserved when switching from C to JavaScript |
| 36 | const RegList kCalleeSaved = 1 << 14 | // r14 |
| 37 | 1 << 15 | // r15 |
| 38 | 1 << 16 | // r16 |
| 39 | 1 << 17 | // r17 |
| 40 | 1 << 18 | // r18 |
| 41 | 1 << 19 | // r19 |
| 42 | 1 << 20 | // r20 |
| 43 | 1 << 21 | // r21 |
| 44 | 1 << 22 | // r22 |
| 45 | 1 << 23 | // r23 |
| 46 | 1 << 24 | // r24 |
| 47 | 1 << 25 | // r25 |
| 48 | 1 << 26 | // r26 |
| 49 | 1 << 27 | // r27 |
| 50 | 1 << 28 | // r28 |
| 51 | 1 << 29 | // r29 |
| 52 | 1 << 30 | // r20 |
| 53 | 1 << 31; // r31 |
| 54 | |
| 55 | |
| 56 | const int kNumCalleeSaved = 18; |
| 57 | |
| 58 | // Number of registers for which space is reserved in safepoints. Must be a |
| 59 | // multiple of 8. |
| 60 | // TODO(regis): Only 8 registers may actually be sufficient. Revisit. |
| 61 | const int kNumSafepointRegisters = 32; |
| 62 | |
| 63 | // Define the list of registers actually saved at safepoints. |
| 64 | // Note that the number of saved registers may be smaller than the reserved |
| 65 | // space, i.e. kNumSafepointSavedRegisters <= kNumSafepointRegisters. |
| 66 | const RegList kSafepointSavedRegisters = kJSCallerSaved | kCalleeSaved; |
| 67 | const int kNumSafepointSavedRegisters = kNumJSCallerSaved + kNumCalleeSaved; |
| 68 | |
| 69 | // The following constants describe the stack frame linkage area as |
| 70 | // defined by the ABI. Note that kNumRequiredStackFrameSlots must |
| 71 | // satisfy alignment requirements (rounding up if required). |
| 72 | #if V8_TARGET_ARCH_PPC64 && V8_TARGET_LITTLE_ENDIAN |
| 73 | // [0] back chain |
| 74 | // [1] condition register save area |
| 75 | // [2] link register save area |
| 76 | // [3] TOC save area |
| 77 | // [4] Parameter1 save area |
| 78 | // ... |
| 79 | // [11] Parameter8 save area |
| 80 | // [12] Parameter9 slot (if necessary) |
| 81 | // ... |
| 82 | const int kNumRequiredStackFrameSlots = 12; |
| 83 | const int kStackFrameLRSlot = 2; |
| 84 | const int kStackFrameExtraParamSlot = 12; |
| 85 | #elif V8_OS_AIX || V8_TARGET_ARCH_PPC64 |
| 86 | // [0] back chain |
| 87 | // [1] condition register save area |
| 88 | // [2] link register save area |
| 89 | // [3] reserved for compiler |
| 90 | // [4] reserved by binder |
| 91 | // [5] TOC save area |
| 92 | // [6] Parameter1 save area |
| 93 | // ... |
| 94 | // [13] Parameter8 save area |
| 95 | // [14] Parameter9 slot (if necessary) |
| 96 | // ... |
| 97 | #if V8_TARGET_ARCH_PPC64 |
| 98 | const int kNumRequiredStackFrameSlots = 14; |
| 99 | #else |
| 100 | const int kNumRequiredStackFrameSlots = 16; |
| 101 | #endif |
| 102 | const int kStackFrameLRSlot = 2; |
| 103 | const int kStackFrameExtraParamSlot = 14; |
| 104 | #else |
| 105 | // [0] back chain |
| 106 | // [1] link register save area |
| 107 | // [2] Parameter9 slot (if necessary) |
| 108 | // ... |
| 109 | const int kNumRequiredStackFrameSlots = 4; |
| 110 | const int kStackFrameLRSlot = 1; |
| 111 | const int kStackFrameExtraParamSlot = 2; |
| 112 | #endif |
| 113 | |
| 114 | // ---------------------------------------------------- |
| 115 | |
| 116 | |
| 117 | class EntryFrameConstants : public AllStatic { |
| 118 | public: |
| 119 | static const int kCallerFPOffset = |
| 120 | -(StandardFrameConstants::kFixedFrameSizeFromFp + kPointerSize); |
| 121 | }; |
| 122 | |
| 123 | |
| 124 | class ExitFrameConstants : public AllStatic { |
| 125 | public: |
| 126 | #if V8_OOL_CONSTANT_POOL |
| 127 | static const int kFrameSize = 3 * kPointerSize; |
| 128 | static const int kConstantPoolOffset = -3 * kPointerSize; |
| 129 | #else |
| 130 | static const int kFrameSize = 2 * kPointerSize; |
| 131 | static const int kConstantPoolOffset = 0; // Not used. |
| 132 | #endif |
| 133 | static const int kCodeOffset = -2 * kPointerSize; |
| 134 | static const int kSPOffset = -1 * kPointerSize; |
| 135 | |
| 136 | // The caller fields are below the frame pointer on the stack. |
| 137 | static const int kCallerFPOffset = 0 * kPointerSize; |
| 138 | // The calling JS function is below FP. |
| 139 | static const int kCallerPCOffset = 1 * kPointerSize; |
| 140 | |
| 141 | // FP-relative displacement of the caller's SP. It points just |
| 142 | // below the saved PC. |
| 143 | static const int kCallerSPDisplacement = 2 * kPointerSize; |
| 144 | }; |
| 145 | |
| 146 | |
| 147 | class JavaScriptFrameConstants : public AllStatic { |
| 148 | public: |
| 149 | // FP-relative. |
| 150 | static const int kLocal0Offset = StandardFrameConstants::kExpressionsOffset; |
| 151 | static const int kLastParameterOffset = +2 * kPointerSize; |
| 152 | static const int kFunctionOffset = StandardFrameConstants::kMarkerOffset; |
| 153 | |
| 154 | // Caller SP-relative. |
| 155 | static const int kParam0Offset = -2 * kPointerSize; |
| 156 | static const int kReceiverOffset = -1 * kPointerSize; |
| 157 | }; |
| 158 | |
| 159 | |
| 160 | class ArgumentsAdaptorFrameConstants : public AllStatic { |
| 161 | public: |
| 162 | // FP-relative. |
| 163 | static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset; |
| 164 | |
| 165 | static const int kFrameSize = |
| 166 | StandardFrameConstants::kFixedFrameSize + kPointerSize; |
| 167 | }; |
| 168 | |
| 169 | |
| 170 | class ConstructFrameConstants : public AllStatic { |
| 171 | public: |
| 172 | // FP-relative. |
| 173 | static const int kImplicitReceiverOffset = -6 * kPointerSize; |
| 174 | static const int kConstructorOffset = -5 * kPointerSize; |
| 175 | static const int kLengthOffset = -4 * kPointerSize; |
| 176 | static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset; |
| 177 | |
| 178 | static const int kFrameSize = |
| 179 | StandardFrameConstants::kFixedFrameSize + 4 * kPointerSize; |
| 180 | }; |
| 181 | |
| 182 | |
| 183 | class InternalFrameConstants : public AllStatic { |
| 184 | public: |
| 185 | // FP-relative. |
| 186 | static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset; |
| 187 | }; |
| 188 | |
| 189 | |
| 190 | inline Object* JavaScriptFrame::function_slot_object() const { |
| 191 | const int offset = JavaScriptFrameConstants::kFunctionOffset; |
| 192 | return Memory::Object_at(fp() + offset); |
| 193 | } |
| 194 | |
| 195 | |
| 196 | inline void StackHandler::SetFp(Address slot, Address fp) { |
| 197 | Memory::Address_at(slot) = fp; |
| 198 | } |
| 199 | } |
| 200 | } // namespace v8::internal |
| 201 | |
| 202 | #endif // V8_PPC_FRAMES_PPC_H_ |