Home | History | Annotate | Download | only in mips
      1 // Copyright 2011 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 
     29 
     30 #ifndef V8_MIPS_FRAMES_MIPS_H_
     31 #define V8_MIPS_FRAMES_MIPS_H_
     32 
     33 
     34 namespace v8 {
     35 namespace internal {
     36 
     37 // Register lists.
     38 // Note that the bit values must match those used in actual instruction
     39 // encoding.
     40 static const int kNumRegs = 32;
     41 
     42 static const RegList kJSCallerSaved =
     43   1 << 2 |  // v0
     44   1 << 4 |  // a0
     45   1 << 5 |  // a1
     46   1 << 6 |  // a2
     47   1 << 7;   // a3
     48 
     49 static const int kNumJSCallerSaved = 5;
     50 
     51 
     52 // Return the code of the n-th caller-saved register available to JavaScript
     53 // e.g. JSCallerSavedReg(0) returns a0.code() == 4.
     54 int JSCallerSavedCode(int n);
     55 
     56 
     57 // Callee-saved registers preserved when switching from C to JavaScript.
     58 static const RegList kCalleeSaved =
     59   // Saved temporaries.
     60   1 << 16 | 1 << 17 | 1 << 18 | 1 << 19 |
     61   1 << 20 | 1 << 21 | 1 << 22 | 1 << 23 |
     62   // gp, sp, fp
     63   1 << 28 | 1 << 29 | 1 << 30;
     64 
     65 static const int kNumCalleeSaved = 11;
     66 
     67 
     68 // Number of registers for which space is reserved in safepoints. Must be a
     69 // multiple of 8.
     70 // TODO(mips): Only 8 registers may actually be sufficient. Revisit.
     71 static const int kNumSafepointRegisters = 16;
     72 
     73 // Define the list of registers actually saved at safepoints.
     74 // Note that the number of saved registers may be smaller than the reserved
     75 // space, i.e. kNumSafepointSavedRegisters <= kNumSafepointRegisters.
     76 static const RegList kSafepointSavedRegisters = kJSCallerSaved | kCalleeSaved;
     77 static const int kNumSafepointSavedRegisters =
     78     kNumJSCallerSaved + kNumCalleeSaved;
     79 
     80 typedef Object* JSCallerSavedBuffer[kNumJSCallerSaved];
     81 
     82 
     83 // ----------------------------------------------------
     84 
     85 class StackHandlerConstants : public AllStatic {
     86  public:
     87   static const int kNextOffset  = 0 * kPointerSize;
     88   static const int kStateOffset = 1 * kPointerSize;
     89   static const int kFPOffset    = 2 * kPointerSize;
     90   static const int kPCOffset    = 3 * kPointerSize;
     91 
     92   static const int kSize = kPCOffset + kPointerSize;
     93 };
     94 
     95 
     96 class EntryFrameConstants : public AllStatic {
     97  public:
     98   static const int kCallerFPOffset      = -3 * kPointerSize;
     99 };
    100 
    101 
    102 class ExitFrameConstants : public AllStatic {
    103  public:
    104   static const int kDebugMarkOffset = -1 * kPointerSize;
    105   // Must be the same as kDebugMarkOffset. Alias introduced when upgrading.
    106   static const int kCodeOffset = -1 * kPointerSize;
    107   static const int kSPOffset = -1 * kPointerSize;
    108 
    109   // TODO(mips): Use a patched sp value on the stack instead.
    110   // A marker of 0 indicates that double registers are saved.
    111   static const int kMarkerOffset = -2 * kPointerSize;
    112 
    113   // The caller fields are below the frame pointer on the stack.
    114   static const int kCallerFPOffset = +0 * kPointerSize;
    115   // The calling JS function is between FP and PC.
    116   static const int kCallerPCOffset = +1 * kPointerSize;
    117 
    118   // FP-relative displacement of the caller's SP.
    119   static const int kCallerSPDisplacement = +3 * kPointerSize;
    120 };
    121 
    122 
    123 class StandardFrameConstants : public AllStatic {
    124  public:
    125   static const int kExpressionsOffset = -3 * kPointerSize;
    126   static const int kMarkerOffset      = -2 * kPointerSize;
    127   static const int kContextOffset     = -1 * kPointerSize;
    128   static const int kCallerFPOffset    =  0 * kPointerSize;
    129   static const int kCallerPCOffset    = +1 * kPointerSize;
    130   static const int kCallerSPOffset    = +2 * kPointerSize;
    131 
    132   // Size of the MIPS 4 32-bit argument slots.
    133   // This is just an alias with a shorter name. Use it from now on.
    134   static const int kRArgsSlotsSize = 4 * kPointerSize;
    135   static const int kRegularArgsSlotsSize = kRArgsSlotsSize;
    136 
    137   // C/C++ argument slots size.
    138   static const int kCArgsSlotsSize = 4 * kPointerSize;
    139   // JS argument slots size.
    140   static const int kJSArgsSlotsSize = 0 * kPointerSize;
    141   // Assembly builtins argument slots size.
    142   static const int kBArgsSlotsSize = 0 * kPointerSize;
    143 };
    144 
    145 
    146 class JavaScriptFrameConstants : public AllStatic {
    147  public:
    148   // FP-relative.
    149   static const int kLocal0Offset = StandardFrameConstants::kExpressionsOffset;
    150   static const int kLastParameterOffset = +2 * kPointerSize;
    151   static const int kFunctionOffset = StandardFrameConstants::kMarkerOffset;
    152 
    153   // Caller SP-relative.
    154   static const int kParam0Offset   = -2 * kPointerSize;
    155   static const int kReceiverOffset = -1 * kPointerSize;
    156 };
    157 
    158 
    159 class ArgumentsAdaptorFrameConstants : public AllStatic {
    160  public:
    161   static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset;
    162 };
    163 
    164 
    165 class InternalFrameConstants : public AllStatic {
    166  public:
    167   static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset;
    168 };
    169 
    170 
    171 inline Object* JavaScriptFrame::function_slot_object() const {
    172   const int offset = JavaScriptFrameConstants::kFunctionOffset;
    173   return Memory::Object_at(fp() + offset);
    174 }
    175 
    176 
    177 } }  // namespace v8::internal
    178 
    179 #endif
    180