00001 // Copyright 2006-2008 the V8 project authors. All rights reserved. 00002 // Redistribution and use in source and binary forms, with or without 00003 // modification, are permitted provided that the following conditions are 00004 // met: 00005 // 00006 // * Redistributions of source code must retain the above copyright 00007 // notice, this list of conditions and the following disclaimer. 00008 // * Redistributions in binary form must reproduce the above 00009 // copyright notice, this list of conditions and the following 00010 // disclaimer in the documentation and/or other materials provided 00011 // with the distribution. 00012 // * Neither the name of Google Inc. nor the names of its 00013 // contributors may be used to endorse or promote products derived 00014 // from this software without specific prior written permission. 00015 // 00016 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00017 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00018 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00019 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00020 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00021 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00026 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 00028 #ifndef V8_FRAMES_ARM_H_ 00029 #define V8_FRAMES_ARM_H_ 00030 00031 namespace v8 { namespace internal { 00032 00033 00034 // The ARM ABI does not specify the usage of register r9, which may be reserved 00035 // as the static base or thread register on some platforms, in which case we 00036 // leave it alone. Adjust the value of kR9Available accordingly: 00037 static const int kR9Available = 1; // 1 if available to us, 0 if reserved 00038 00039 00040 // Register list in load/store instructions 00041 // Note that the bit values must match those used in actual instruction encoding 00042 static const int kNumRegs = 16; 00043 00044 00045 // Caller-saved/arguments registers 00046 static const RegList kJSCallerSaved = 00047 1 << 0 | // r0 a1 00048 1 << 1 | // r1 a2 00049 1 << 2 | // r2 a3 00050 1 << 3; // r3 a4 00051 00052 static const int kNumJSCallerSaved = 4; 00053 00054 typedef Object* JSCallerSavedBuffer[kNumJSCallerSaved]; 00055 00056 // Return the code of the n-th caller-saved register available to JavaScript 00057 // e.g. JSCallerSavedReg(0) returns r0.code() == 0 00058 int JSCallerSavedCode(int n); 00059 00060 00061 // Callee-saved registers preserved when switching from C to JavaScript 00062 static const RegList kCalleeSaved = 00063 1 << 4 | // r4 v1 00064 1 << 5 | // r5 v2 00065 1 << 6 | // r6 v3 00066 1 << 7 | // r7 v4 00067 1 << 8 | // r8 v5 (cp in JavaScript code) 00068 kR9Available 00069 << 9 | // r9 v6 00070 1 << 10 | // r10 v7 (pp in JavaScript code) 00071 1 << 11; // r11 v8 (fp in JavaScript code) 00072 00073 static const int kNumCalleeSaved = 7 + kR9Available; 00074 00075 00076 // ---------------------------------------------------- 00077 00078 00079 class StackHandlerConstants : public AllStatic { 00080 public: 00081 // TODO(1233780): Get rid of the code slot in stack handlers. 00082 static const int kCodeOffset = 0 * kPointerSize; 00083 static const int kNextOffset = 1 * kPointerSize; 00084 static const int kStateOffset = 2 * kPointerSize; 00085 static const int kPPOffset = 3 * kPointerSize; 00086 static const int kFPOffset = 4 * kPointerSize; 00087 static const int kPCOffset = 5 * kPointerSize; 00088 00089 static const int kAddressDisplacement = -1 * kPointerSize; 00090 static const int kSize = kPCOffset + kPointerSize; 00091 }; 00092 00093 00094 class EntryFrameConstants : public AllStatic { 00095 public: 00096 static const int kCallerFPOffset = -3 * kPointerSize; 00097 }; 00098 00099 00100 class ExitFrameConstants : public AllStatic { 00101 public: 00102 // Exit frames have a debug marker on the stack. 00103 static const int kSPDisplacement = -1 * kPointerSize; 00104 00105 // The debug marker is just above the frame pointer. 00106 static const int kDebugMarkOffset = -1 * kPointerSize; 00107 00108 static const int kSavedRegistersOffset = 0 * kPointerSize; 00109 00110 // Let the parameters pointer for exit frames point just below the 00111 // frame structure on the stack. 00112 static const int kPPDisplacement = 3 * kPointerSize; 00113 00114 // The caller fields are below the frame pointer on the stack. 00115 static const int kCallerFPOffset = +0 * kPointerSize; 00116 static const int kCallerPPOffset = +1 * kPointerSize; 00117 static const int kCallerPCOffset = +2 * kPointerSize; 00118 }; 00119 00120 00121 class StandardFrameConstants : public AllStatic { 00122 public: 00123 static const int kExpressionsOffset = -3 * kPointerSize; 00124 static const int kMarkerOffset = -2 * kPointerSize; 00125 static const int kContextOffset = -1 * kPointerSize; 00126 static const int kCallerFPOffset = 0 * kPointerSize; 00127 static const int kCallerPCOffset = +1 * kPointerSize; 00128 static const int kCallerSPOffset = +2 * kPointerSize; 00129 }; 00130 00131 00132 class JavaScriptFrameConstants : public AllStatic { 00133 public: 00134 // FP-relative. 00135 static const int kLocal0Offset = StandardFrameConstants::kExpressionsOffset; 00136 static const int kSavedRegistersOffset = +2 * kPointerSize; 00137 static const int kFunctionOffset = StandardFrameConstants::kMarkerOffset; 00138 00139 // PP-relative. 00140 static const int kParam0Offset = -2 * kPointerSize; 00141 static const int kReceiverOffset = -1 * kPointerSize; 00142 }; 00143 00144 00145 class ArgumentsAdaptorFrameConstants : public AllStatic { 00146 public: 00147 static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset; 00148 }; 00149 00150 00151 class InternalFrameConstants : public AllStatic { 00152 public: 00153 static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset; 00154 }; 00155 00156 00157 inline Object* JavaScriptFrame::function() const { 00158 const int offset = JavaScriptFrameConstants::kFunctionOffset; 00159 Object* result = Memory::Object_at(fp() + offset); 00160 ASSERT(result->IsJSFunction()); 00161 return result; 00162 } 00163 00164 00165 // ---------------------------------------------------- 00166 00167 00168 00169 00170 // lower | Stack | 00171 // addresses | ^ | 00172 // | | | 00173 // | | 00174 // | JS frame | 00175 // | | 00176 // | | 00177 // ----------- +=============+ <--- sp (stack pointer) 00178 // | function | 00179 // +-------------+ 00180 // +-------------+ 00181 // | | 00182 // | expressions | 00183 // | | 00184 // +-------------+ 00185 // | | 00186 // a | locals | 00187 // c | | 00188 // t +- - - - - - -+ <--- 00189 // i -4 | local0 | ^ 00190 // v +-------------+ | 00191 // a -3 | code | | 00192 // t +-------------+ | kLocal0Offset 00193 // i -2 | context | | 00194 // o +-------------+ | 00195 // n -1 | args_length | v 00196 // +-------------+ <--- fp (frame pointer) 00197 // 0 | caller_pp | 00198 // f +-------------+ 00199 // r 1 | caller_fp | 00200 // a +-------------+ 00201 // m 2 | sp_on_exit | (pp if return, caller_sp if no return) 00202 // e +-------------+ 00203 // 3 | caller_pc | 00204 // +-------------+ <--- caller_sp (incl. parameters) 00205 // | | 00206 // | parameters | 00207 // | | 00208 // +- - - - - - -+ <--- 00209 // -2 | parameter0 | ^ 00210 // +-------------+ | kParam0Offset 00211 // -1 | receiver | v 00212 // ----------- +=============+ <--- pp (parameter pointer, r10) 00213 // 0 | function | 00214 // +-------------+ 00215 // | | 00216 // |caller-saved | (must be valid JS values, traversed during GC) 00217 // | regs | 00218 // | | 00219 // +-------------+ 00220 // | | 00221 // | caller | 00222 // higher | expressions | 00223 // addresses | | 00224 // | | 00225 // | JS frame | 00226 00227 00228 00229 // Handler frames (part of expressions of JS frames): 00230 00231 // lower | Stack | 00232 // addresses | ^ | 00233 // | | | 00234 // | | 00235 // h | expressions | 00236 // a | | 00237 // n +-------------+ 00238 // d -1 | code | 00239 // l +-------------+ <--- handler sp 00240 // e 0 | next_sp | link to next handler (next handler's sp) 00241 // r +-------------+ 00242 // 1 | state | 00243 // f +-------------+ 00244 // r 2 | pp | 00245 // a +-------------+ 00246 // m 3 | fp | 00247 // e +-------------+ 00248 // 4 | pc | 00249 // +-------------+ 00250 // | | 00251 // higher | expressions | 00252 // addresses | | 00253 00254 00255 00256 // JS entry frames: When calling from C to JS, we construct two extra 00257 // frames: An entry frame (C) and a trampoline frame (JS). The 00258 // following pictures shows the two frames: 00259 00260 // lower | Stack | 00261 // addresses | ^ | 00262 // | | | 00263 // | | 00264 // | JS frame | 00265 // | | 00266 // | | 00267 // ----------- +=============+ <--- sp (stack pointer) 00268 // | | 00269 // | parameters | 00270 // t | | 00271 // r +- - - - - - -+ 00272 // a | parameter0 | 00273 // m +-------------+ 00274 // p | receiver | 00275 // o +-------------+ 00276 // l | function | 00277 // i +-------------+ 00278 // n -3 | code | 00279 // e +-------------+ 00280 // -2 | NULL | context is always NULL 00281 // +-------------+ 00282 // f -1 | 0 | args_length is always zero 00283 // r +-------------+ <--- fp (frame pointer) 00284 // a 0 | NULL | caller pp is always NULL for entries 00285 // m +-------------+ 00286 // e 1 | caller_fp | 00287 // +-------------+ 00288 // 2 | sp_on_exit | (caller_sp) 00289 // +-------------+ 00290 // 3 | caller_pc | 00291 // ----------- +=============+ <--- caller_sp == pp 00292 // . ^ 00293 // . | try-handler, fake, not GC'ed 00294 // . v 00295 // +-------------+ <--- 00296 // -2 | next top pp | 00297 // +-------------+ 00298 // -1 | next top fp | 00299 // +-------------+ <--- fp 00300 // | r4 | r4-r9 holding non-JS values must be preserved 00301 // +-------------+ 00302 // J | r5 | before being initialized not to confuse GC 00303 // S +-------------+ 00304 // | r6 | 00305 // +-------------+ 00306 // e | r7 | 00307 // n +-------------+ 00308 // t | r8 | 00309 // r +-------------+ 00310 // y [ | r9 | ] only if r9 available 00311 // +-------------+ 00312 // | r10 | 00313 // f +-------------+ 00314 // r | r11 | 00315 // a +-------------+ 00316 // m | caller_sp | 00317 // e +-------------+ 00318 // | caller_pc | 00319 // +-------------+ <--- caller_sp 00320 // | argv | passed on stack from C code 00321 // +-------------+ 00322 // | | 00323 // higher | | 00324 // addresses | C frame | 00325 00326 00327 // The first 4 args are passed from C in r0-r3 and are not spilled on entry: 00328 // r0: code entry 00329 // r1: function 00330 // r2: receiver 00331 // r3: argc 00332 // [sp+0]: argv 00333 00334 00335 // C entry frames: When calling from JS to C, we construct one extra 00336 // frame: 00337 00338 // lower | Stack | 00339 // addresses | ^ | 00340 // | | | 00341 // | | 00342 // | C frame | 00343 // | | 00344 // | | 00345 // ----------- +=============+ <--- sp (stack pointer) 00346 // | | 00347 // | parameters | (first 4 args are passed in r0-r3) 00348 // | | 00349 // +-------------+ <--- fp (frame pointer) 00350 // f 4/5 | caller_fp | 00351 // r +-------------+ 00352 // a 5/6 | sp_on_exit | (pp) 00353 // m +-------------+ 00354 // e 6/7 | caller_pc | 00355 // +-------------+ <--- caller_sp (incl. parameters) 00356 // 7/8 | | 00357 // | parameters | 00358 // | | 00359 // +- - - - - - -+ <--- 00360 // -2 | parameter0 | ^ 00361 // +-------------+ | kParam0Offset 00362 // -1 | receiver | v 00363 // ----------- +=============+ <--- pp (parameter pointer, r10) 00364 // 0 | function | 00365 // +-------------+ 00366 // | | 00367 // |caller-saved | 00368 // | regs | 00369 // | | 00370 // +-------------+ 00371 // | | 00372 // | caller | 00373 // | expressions | 00374 // | | 00375 // higher | | 00376 // addresses | JS frame | 00377 00378 00379 } } // namespace v8::internal 00380 00381 #endif // V8_FRAMES_ARM_H_