| OLD | NEW |
| (Empty) |
| 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_MACRO_ASSEMBLER_ARM_H_ | |
| 29 #define V8_MACRO_ASSEMBLER_ARM_H_ | |
| 30 | |
| 31 #include "assembler.h" | |
| 32 | |
| 33 namespace v8 { namespace internal { | |
| 34 | |
| 35 | |
| 36 // Give alias names to registers | |
| 37 extern Register cp; // JavaScript context pointer | |
| 38 extern Register pp; // parameter pointer | |
| 39 | |
| 40 | |
| 41 // Helper types to make boolean flag easier to read at call-site. | |
| 42 enum InvokeFlag { | |
| 43 CALL_FUNCTION, | |
| 44 JUMP_FUNCTION | |
| 45 }; | |
| 46 | |
| 47 enum InvokeJSFlags { | |
| 48 CALL_JS, | |
| 49 JUMP_JS | |
| 50 }; | |
| 51 | |
| 52 enum ExitJSFlag { | |
| 53 RETURN, | |
| 54 DO_NOT_RETURN | |
| 55 }; | |
| 56 | |
| 57 enum CodeLocation { | |
| 58 IN_JAVASCRIPT, | |
| 59 IN_JS_ENTRY, | |
| 60 IN_C_ENTRY | |
| 61 }; | |
| 62 | |
| 63 enum HandlerType { | |
| 64 TRY_CATCH_HANDLER, | |
| 65 TRY_FINALLY_HANDLER, | |
| 66 JS_ENTRY_HANDLER | |
| 67 }; | |
| 68 | |
| 69 | |
| 70 // MacroAssembler implements a collection of frequently used macros. | |
| 71 class MacroAssembler: public Assembler { | |
| 72 public: | |
| 73 MacroAssembler(void* buffer, int size); | |
| 74 | |
| 75 // --------------------------------------------------------------------------- | |
| 76 // Low-level helpers for compiler | |
| 77 | |
| 78 // Jump, Call, and Ret pseudo instructions implementing inter-working | |
| 79 private: | |
| 80 void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al); | |
| 81 void Call(intptr_t target, RelocInfo::Mode rmode, Condition cond = al); | |
| 82 public: | |
| 83 void Jump(Register target, Condition cond = al); | |
| 84 void Jump(byte* target, RelocInfo::Mode rmode, Condition cond = al); | |
| 85 void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al); | |
| 86 void Call(Register target, Condition cond = al); | |
| 87 void Call(byte* target, RelocInfo::Mode rmode, Condition cond = al); | |
| 88 void Call(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al); | |
| 89 void Ret(Condition cond = al); | |
| 90 // Jumps to the label at the index given by the Smi in "index". | |
| 91 void SmiJumpTable(Register index, Vector<Label*> targets); | |
| 92 | |
| 93 // Sets the remembered set bit for [address+offset], where address is the | |
| 94 // address of the heap object 'object'. The address must be in the first 8K | |
| 95 // of an allocated page. The 'scratch' register is used in the | |
| 96 // implementation and all 3 registers are clobbered by the operation, as | |
| 97 // well as the ip register. | |
| 98 void RecordWrite(Register object, Register offset, Register scratch); | |
| 99 | |
| 100 // --------------------------------------------------------------------------- | |
| 101 // Activation frames | |
| 102 | |
| 103 void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); } | |
| 104 void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); } | |
| 105 | |
| 106 void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); } | |
| 107 void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); } | |
| 108 | |
| 109 // Enter specific kind of exit frame; either EXIT or | |
| 110 // EXIT_DEBUG. Expects the number of arguments in register r0 and | |
| 111 // the builtin function to call in register r1. Exits with argc in | |
| 112 // r4, argv in r6, and and the builtin function to call in r5. | |
| 113 void EnterExitFrame(StackFrame::Type type); | |
| 114 | |
| 115 // Leave the current exit frame. Expects the return value in r0. | |
| 116 void LeaveExitFrame(StackFrame::Type type); | |
| 117 | |
| 118 | |
| 119 // --------------------------------------------------------------------------- | |
| 120 // JavaScript invokes | |
| 121 | |
| 122 // Invoke the JavaScript function code by either calling or jumping. | |
| 123 void InvokeCode(Register code, | |
| 124 const ParameterCount& expected, | |
| 125 const ParameterCount& actual, | |
| 126 InvokeFlag flag); | |
| 127 | |
| 128 void InvokeCode(Handle<Code> code, | |
| 129 const ParameterCount& expected, | |
| 130 const ParameterCount& actual, | |
| 131 RelocInfo::Mode rmode, | |
| 132 InvokeFlag flag); | |
| 133 | |
| 134 // Invoke the JavaScript function in the given register. Changes the | |
| 135 // current context to the context in the function before invoking. | |
| 136 void InvokeFunction(Register function, | |
| 137 const ParameterCount& actual, | |
| 138 InvokeFlag flag); | |
| 139 | |
| 140 | |
| 141 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 142 // --------------------------------------------------------------------------- | |
| 143 // Debugger Support | |
| 144 | |
| 145 void SaveRegistersToMemory(RegList regs); | |
| 146 void RestoreRegistersFromMemory(RegList regs); | |
| 147 void CopyRegistersFromMemoryToStack(Register base, RegList regs); | |
| 148 void CopyRegistersFromStackToMemory(Register base, | |
| 149 Register scratch, | |
| 150 RegList regs); | |
| 151 #endif | |
| 152 | |
| 153 // --------------------------------------------------------------------------- | |
| 154 // Exception handling | |
| 155 | |
| 156 // Push a new try handler and link into try handler chain. | |
| 157 // The return address must be passed in register lr. | |
| 158 // On exit, r0 contains TOS (code slot). | |
| 159 void PushTryHandler(CodeLocation try_location, HandlerType type); | |
| 160 | |
| 161 | |
| 162 // --------------------------------------------------------------------------- | |
| 163 // Inline caching support | |
| 164 | |
| 165 // Generates code that verifies that the maps of objects in the | |
| 166 // prototype chain of object hasn't changed since the code was | |
| 167 // generated and branches to the miss label if any map has. If | |
| 168 // necessary the function also generates code for security check | |
| 169 // in case of global object holders. The scratch and holder | |
| 170 // registers are always clobbered, but the object register is only | |
| 171 // clobbered if it the same as the holder register. The function | |
| 172 // returns a register containing the holder - either object_reg or | |
| 173 // holder_reg. | |
| 174 Register CheckMaps(JSObject* object, Register object_reg, | |
| 175 JSObject* holder, Register holder_reg, | |
| 176 Register scratch, Label* miss); | |
| 177 | |
| 178 // Generate code for checking access rights - used for security checks | |
| 179 // on access to global objects across environments. The holder register | |
| 180 // is left untouched, whereas both scratch registers are clobbered. | |
| 181 void CheckAccessGlobalProxy(Register holder_reg, | |
| 182 Register scratch, | |
| 183 Label* miss); | |
| 184 | |
| 185 | |
| 186 // --------------------------------------------------------------------------- | |
| 187 // Support functions. | |
| 188 | |
| 189 // Generates code for reporting that an illegal operation has | |
| 190 // occurred. | |
| 191 void IllegalOperation(int num_arguments); | |
| 192 | |
| 193 | |
| 194 // --------------------------------------------------------------------------- | |
| 195 // Runtime calls | |
| 196 | |
| 197 // Call a code stub. | |
| 198 void CallStub(CodeStub* stub); | |
| 199 void CallJSExitStub(CodeStub* stub); | |
| 200 | |
| 201 // Return from a code stub after popping its arguments. | |
| 202 void StubReturn(int argc); | |
| 203 | |
| 204 // Call a runtime routine. | |
| 205 // Eventually this should be used for all C calls. | |
| 206 void CallRuntime(Runtime::Function* f, int num_arguments); | |
| 207 | |
| 208 // Convenience function: Same as above, but takes the fid instead. | |
| 209 void CallRuntime(Runtime::FunctionId fid, int num_arguments); | |
| 210 | |
| 211 // Tail call of a runtime routine (jump). | |
| 212 // Like JumpToBuiltin, but also takes care of passing the number | |
| 213 // of parameters. | |
| 214 void TailCallRuntime(const ExternalReference& ext, int num_arguments); | |
| 215 | |
| 216 // Jump to the builtin routine. | |
| 217 void JumpToBuiltin(const ExternalReference& builtin); | |
| 218 | |
| 219 // Invoke specified builtin JavaScript function. Adds an entry to | |
| 220 // the unresolved list if the name does not resolve. | |
| 221 void InvokeBuiltin(Builtins::JavaScript id, InvokeJSFlags flags); | |
| 222 | |
| 223 // Store the code object for the given builtin in the target register and | |
| 224 // setup the function in r1. | |
| 225 void GetBuiltinEntry(Register target, Builtins::JavaScript id); | |
| 226 | |
| 227 struct Unresolved { | |
| 228 int pc; | |
| 229 uint32_t flags; // see Bootstrapper::FixupFlags decoders/encoders. | |
| 230 const char* name; | |
| 231 }; | |
| 232 List<Unresolved>* unresolved() { return &unresolved_; } | |
| 233 | |
| 234 Handle<Object> CodeObject() { return code_object_; } | |
| 235 | |
| 236 | |
| 237 // --------------------------------------------------------------------------- | |
| 238 // StatsCounter support | |
| 239 | |
| 240 void SetCounter(StatsCounter* counter, int value, | |
| 241 Register scratch1, Register scratch2); | |
| 242 void IncrementCounter(StatsCounter* counter, int value, | |
| 243 Register scratch1, Register scratch2); | |
| 244 void DecrementCounter(StatsCounter* counter, int value, | |
| 245 Register scratch1, Register scratch2); | |
| 246 | |
| 247 | |
| 248 // --------------------------------------------------------------------------- | |
| 249 // Debugging | |
| 250 | |
| 251 // Calls Abort(msg) if the condition cc is not satisfied. | |
| 252 // Use --debug_code to enable. | |
| 253 void Assert(Condition cc, const char* msg); | |
| 254 | |
| 255 // Like Assert(), but always enabled. | |
| 256 void Check(Condition cc, const char* msg); | |
| 257 | |
| 258 // Print a message to stdout and abort execution. | |
| 259 void Abort(const char* msg); | |
| 260 | |
| 261 // Verify restrictions about code generated in stubs. | |
| 262 void set_generating_stub(bool value) { generating_stub_ = value; } | |
| 263 bool generating_stub() { return generating_stub_; } | |
| 264 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; } | |
| 265 bool allow_stub_calls() { return allow_stub_calls_; } | |
| 266 | |
| 267 private: | |
| 268 List<Unresolved> unresolved_; | |
| 269 bool generating_stub_; | |
| 270 bool allow_stub_calls_; | |
| 271 Handle<Object> code_object_; // This handle will be patched with the code | |
| 272 // object on installation. | |
| 273 | |
| 274 // Helper functions for generating invokes. | |
| 275 void InvokePrologue(const ParameterCount& expected, | |
| 276 const ParameterCount& actual, | |
| 277 Handle<Code> code_constant, | |
| 278 Register code_reg, | |
| 279 Label* done, | |
| 280 InvokeFlag flag); | |
| 281 | |
| 282 // Get the code for the given builtin. Returns if able to resolve | |
| 283 // the function in the 'resolved' flag. | |
| 284 Handle<Code> ResolveBuiltin(Builtins::JavaScript id, bool* resolved); | |
| 285 | |
| 286 // Activation support. | |
| 287 void EnterFrame(StackFrame::Type type); | |
| 288 void LeaveFrame(StackFrame::Type type); | |
| 289 }; | |
| 290 | |
| 291 | |
| 292 // ----------------------------------------------------------------------------- | |
| 293 // Static helper functions. | |
| 294 | |
| 295 // Generate a MemOperand for loading a field from an object. | |
| 296 static inline MemOperand FieldMemOperand(Register object, int offset) { | |
| 297 return MemOperand(object, offset - kHeapObjectTag); | |
| 298 } | |
| 299 | |
| 300 | |
| 301 #ifdef GENERATED_CODE_COVERAGE | |
| 302 #define CODE_COVERAGE_STRINGIFY(x) #x | |
| 303 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) | |
| 304 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) | |
| 305 #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm-> | |
| 306 #else | |
| 307 #define ACCESS_MASM(masm) masm-> | |
| 308 #endif | |
| 309 | |
| 310 | |
| 311 } } // namespace v8::internal | |
| 312 | |
| 313 #endif // V8_MACRO_ASSEMBLER_ARM_H_ | |
| OLD | NEW |