Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 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 | |
| 29 | |
| 30 | #ifndef V8_MIPS_FRAMES_MIPS_H_ |
| 31 | #define V8_MIPS_FRAMES_MIPS_H_ |
| 32 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 33 | namespace v8 { |
| 34 | namespace internal { |
| 35 | |
| 36 | // Register lists. |
| 37 | // Note that the bit values must match those used in actual instruction |
| 38 | // encoding. |
| 39 | static const int kNumRegs = 32; |
| 40 | |
| 41 | static const RegList kJSCallerSaved = |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame^] | 42 | 1 << 2 | // v0 |
| 43 | 1 << 3 | // v1 |
| 44 | 1 << 4 | // a0 |
| 45 | 1 << 5 | // a1 |
| 46 | 1 << 6 | // a2 |
| 47 | 1 << 7 | // a3 |
| 48 | 1 << 8 | // t0 |
| 49 | 1 << 9 | // t1 |
| 50 | 1 << 10 | // t2 |
| 51 | 1 << 11 | // t3 |
| 52 | 1 << 12 | // t4 |
| 53 | 1 << 13 | // t5 |
| 54 | 1 << 14 | // t6 |
| 55 | 1 << 15; // t7 |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 56 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame^] | 57 | static const int kNumJSCallerSaved = 14; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 58 | |
| 59 | |
| 60 | // Return the code of the n-th caller-saved register available to JavaScript |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 61 | // e.g. JSCallerSavedReg(0) returns a0.code() == 4. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 62 | int JSCallerSavedCode(int n); |
| 63 | |
| 64 | |
| 65 | // Callee-saved registers preserved when switching from C to JavaScript. |
| 66 | static const RegList kCalleeSaved = |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame^] | 67 | 1 << 16 | // s0 |
| 68 | 1 << 17 | // s1 |
| 69 | 1 << 18 | // s2 |
| 70 | 1 << 19 | // s3 |
| 71 | 1 << 20 | // s4 |
| 72 | 1 << 21 | // s5 |
| 73 | 1 << 22 | // s6 (roots in Javascript code) |
| 74 | 1 << 23 | // s7 (cp in Javascript code) |
| 75 | 1 << 30; // fp/s8 |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 76 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 77 | static const int kNumCalleeSaved = 9; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 78 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame^] | 79 | static const RegList kCalleeSavedFPU = |
| 80 | 1 << 20 | // f20 |
| 81 | 1 << 22 | // f22 |
| 82 | 1 << 24 | // f24 |
| 83 | 1 << 26 | // f26 |
| 84 | 1 << 28 | // f28 |
| 85 | 1 << 30; // f30 |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 86 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame^] | 87 | static const int kNumCalleeSavedFPU = 6; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 88 | // Number of registers for which space is reserved in safepoints. Must be a |
| 89 | // multiple of 8. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame^] | 90 | static const int kNumSafepointRegisters = 24; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 91 | |
| 92 | // Define the list of registers actually saved at safepoints. |
| 93 | // Note that the number of saved registers may be smaller than the reserved |
| 94 | // space, i.e. kNumSafepointSavedRegisters <= kNumSafepointRegisters. |
| 95 | static const RegList kSafepointSavedRegisters = kJSCallerSaved | kCalleeSaved; |
| 96 | static const int kNumSafepointSavedRegisters = |
| 97 | kNumJSCallerSaved + kNumCalleeSaved; |
| 98 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 99 | typedef Object* JSCallerSavedBuffer[kNumJSCallerSaved]; |
| 100 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 101 | static const int kUndefIndex = -1; |
| 102 | // Map with indexes on stack that corresponds to codes of saved registers. |
| 103 | static const int kSafepointRegisterStackIndexMap[kNumRegs] = { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame^] | 104 | kUndefIndex, // zero_reg |
| 105 | kUndefIndex, // at |
| 106 | 0, // v0 |
| 107 | 1, // v1 |
| 108 | 2, // a0 |
| 109 | 3, // a1 |
| 110 | 4, // a2 |
| 111 | 5, // a3 |
| 112 | 6, // t0 |
| 113 | 7, // t1 |
| 114 | 8, // t2 |
| 115 | 9, // t3 |
| 116 | 10, // t4 |
| 117 | 11, // t5 |
| 118 | 12, // t6 |
| 119 | 13, // t7 |
| 120 | 14, // s0 |
| 121 | 15, // s1 |
| 122 | 16, // s2 |
| 123 | 17, // s3 |
| 124 | 18, // s4 |
| 125 | 19, // s5 |
| 126 | 20, // s6 |
| 127 | 21, // s7 |
| 128 | kUndefIndex, // t8 |
| 129 | kUndefIndex, // t9 |
| 130 | kUndefIndex, // k0 |
| 131 | kUndefIndex, // k1 |
| 132 | kUndefIndex, // gp |
| 133 | kUndefIndex, // sp |
| 134 | 22, // fp |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 135 | kUndefIndex |
| 136 | }; |
| 137 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 138 | |
| 139 | // ---------------------------------------------------- |
| 140 | |
| 141 | class StackHandlerConstants : public AllStatic { |
| 142 | public: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 143 | static const int kNextOffset = 0 * kPointerSize; |
| 144 | static const int kStateOffset = 1 * kPointerSize; |
| 145 | static const int kContextOffset = 2 * kPointerSize; |
| 146 | static const int kFPOffset = 3 * kPointerSize; |
| 147 | static const int kPCOffset = 4 * kPointerSize; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 148 | |
| 149 | static const int kSize = kPCOffset + kPointerSize; |
| 150 | }; |
| 151 | |
| 152 | |
| 153 | class EntryFrameConstants : public AllStatic { |
| 154 | public: |
| 155 | static const int kCallerFPOffset = -3 * kPointerSize; |
| 156 | }; |
| 157 | |
| 158 | |
| 159 | class ExitFrameConstants : public AllStatic { |
| 160 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 161 | // See some explanation in MacroAssembler::EnterExitFrame. |
| 162 | // This marks the top of the extra allocated stack space. |
| 163 | static const int kStackSpaceOffset = -3 * kPointerSize; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 164 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 165 | static const int kCodeOffset = -2 * kPointerSize; |
| 166 | |
| 167 | static const int kSPOffset = -1 * kPointerSize; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 168 | |
| 169 | // The caller fields are below the frame pointer on the stack. |
| 170 | static const int kCallerFPOffset = +0 * kPointerSize; |
| 171 | // The calling JS function is between FP and PC. |
| 172 | static const int kCallerPCOffset = +1 * kPointerSize; |
| 173 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 174 | // MIPS-specific: a pointer to the old sp to avoid unnecessary calculations. |
| 175 | static const int kCallerSPOffset = +2 * kPointerSize; |
| 176 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 177 | // FP-relative displacement of the caller's SP. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 178 | static const int kCallerSPDisplacement = +2 * kPointerSize; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | |
| 182 | class StandardFrameConstants : public AllStatic { |
| 183 | public: |
| 184 | static const int kExpressionsOffset = -3 * kPointerSize; |
| 185 | static const int kMarkerOffset = -2 * kPointerSize; |
| 186 | static const int kContextOffset = -1 * kPointerSize; |
| 187 | static const int kCallerFPOffset = 0 * kPointerSize; |
| 188 | static const int kCallerPCOffset = +1 * kPointerSize; |
| 189 | static const int kCallerSPOffset = +2 * kPointerSize; |
| 190 | |
| 191 | // Size of the MIPS 4 32-bit argument slots. |
| 192 | // This is just an alias with a shorter name. Use it from now on. |
| 193 | static const int kRArgsSlotsSize = 4 * kPointerSize; |
| 194 | static const int kRegularArgsSlotsSize = kRArgsSlotsSize; |
| 195 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 196 | // JS argument slots size. |
| 197 | static const int kJSArgsSlotsSize = 0 * kPointerSize; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 198 | // Assembly builtins argument slots size. |
| 199 | static const int kBArgsSlotsSize = 0 * kPointerSize; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | |
| 203 | class JavaScriptFrameConstants : public AllStatic { |
| 204 | public: |
| 205 | // FP-relative. |
| 206 | static const int kLocal0Offset = StandardFrameConstants::kExpressionsOffset; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 207 | static const int kLastParameterOffset = +2 * kPointerSize; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 208 | static const int kFunctionOffset = StandardFrameConstants::kMarkerOffset; |
| 209 | |
| 210 | // Caller SP-relative. |
| 211 | static const int kParam0Offset = -2 * kPointerSize; |
| 212 | static const int kReceiverOffset = -1 * kPointerSize; |
| 213 | }; |
| 214 | |
| 215 | |
| 216 | class ArgumentsAdaptorFrameConstants : public AllStatic { |
| 217 | public: |
| 218 | static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset; |
| 219 | }; |
| 220 | |
| 221 | |
| 222 | class InternalFrameConstants : public AllStatic { |
| 223 | public: |
| 224 | static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset; |
| 225 | }; |
| 226 | |
| 227 | |
| 228 | inline Object* JavaScriptFrame::function_slot_object() const { |
| 229 | const int offset = JavaScriptFrameConstants::kFunctionOffset; |
| 230 | return Memory::Object_at(fp() + offset); |
| 231 | } |
| 232 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 233 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 234 | } } // namespace v8::internal |
| 235 | |
| 236 | #endif |