ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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 | #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. |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 42 | enum InvokeFlag { |
| 43 | CALL_FUNCTION, |
| 44 | JUMP_FUNCTION |
| 45 | }; |
| 46 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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: |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 80 | void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al); |
| 81 | void Call(intptr_t target, RelocInfo::Mode rmode, Condition cond = al); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 82 | public: |
| 83 | void Jump(Register target, Condition cond = al); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 84 | void Jump(byte* target, RelocInfo::Mode rmode, Condition cond = al); |
| 85 | void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 86 | void Call(Register target, Condition cond = al); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 87 | void Call(byte* target, RelocInfo::Mode rmode, Condition cond = al); |
| 88 | void Call(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 89 | void Ret(); |
| 90 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 91 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 92 | // Sets the remembered set bit for [address+offset], where address is the |
| 93 | // address of the heap object 'object'. The address must be in the first 8K |
| 94 | // of an allocated page. The 'scratch' register is used in the |
| 95 | // implementation and all 3 registers are clobbered by the operation, as |
| 96 | // well as the ip register. |
| 97 | void RecordWrite(Register object, Register offset, Register scratch); |
| 98 | |
| 99 | // --------------------------------------------------------------------------- |
| 100 | // Activation frames |
| 101 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 102 | void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); } |
| 103 | void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); } |
| 104 | |
| 105 | void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); } |
| 106 | void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 107 | |
| 108 | // Enter specific kind of exit frame; either EXIT or |
| 109 | // EXIT_DEBUG. Expects the number of arguments in register r0 and |
| 110 | // the builtin function to call in register r1. Exits with argc in |
| 111 | // r4, argv in r6, and and the builtin function to call in r5. |
| 112 | void EnterExitFrame(StackFrame::Type type); |
| 113 | |
| 114 | // Leave the current exit frame. Expects the return value in r0. |
| 115 | void LeaveExitFrame(StackFrame::Type type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 116 | |
| 117 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 118 | // --------------------------------------------------------------------------- |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 119 | // JavaScript invokes |
| 120 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 121 | // Invoke the JavaScript function code by either calling or jumping. |
| 122 | void InvokeCode(Register code, |
| 123 | const ParameterCount& expected, |
| 124 | const ParameterCount& actual, |
| 125 | InvokeFlag flag); |
| 126 | |
| 127 | void InvokeCode(Handle<Code> code, |
| 128 | const ParameterCount& expected, |
| 129 | const ParameterCount& actual, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 130 | RelocInfo::Mode rmode, |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 131 | InvokeFlag flag); |
| 132 | |
| 133 | // Invoke the JavaScript function in the given register. Changes the |
| 134 | // current context to the context in the function before invoking. |
| 135 | void InvokeFunction(Register function, |
| 136 | const ParameterCount& actual, |
| 137 | InvokeFlag flag); |
| 138 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 139 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 140 | // --------------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 141 | // Debugger Support |
| 142 | |
| 143 | void SaveRegistersToMemory(RegList regs); |
| 144 | void RestoreRegistersFromMemory(RegList regs); |
| 145 | void CopyRegistersFromMemoryToStack(Register base, RegList regs); |
| 146 | void CopyRegistersFromStackToMemory(Register base, |
| 147 | Register scratch, |
| 148 | RegList regs); |
| 149 | |
| 150 | |
| 151 | // --------------------------------------------------------------------------- |
| 152 | // Exception handling |
| 153 | |
| 154 | // Push a new try handler and link into try handler chain. |
| 155 | // The return address must be passed in register lr. |
| 156 | // On exit, r0 contains TOS (code slot). |
| 157 | void PushTryHandler(CodeLocation try_location, HandlerType type); |
| 158 | |
| 159 | |
| 160 | // --------------------------------------------------------------------------- |
| 161 | // Inline caching support |
| 162 | |
| 163 | // Generates code that verifies that the maps of objects in the |
| 164 | // prototype chain of object hasn't changed since the code was |
| 165 | // generated and branches to the miss label if any map has. If |
| 166 | // necessary the function also generates code for security check |
| 167 | // in case of global object holders. The scratch and holder |
| 168 | // registers are always clobbered, but the object register is only |
| 169 | // clobbered if it the same as the holder register. The function |
| 170 | // returns a register containing the holder - either object_reg or |
| 171 | // holder_reg. |
| 172 | Register CheckMaps(JSObject* object, Register object_reg, |
| 173 | JSObject* holder, Register holder_reg, |
| 174 | Register scratch, Label* miss); |
| 175 | |
| 176 | // Generate code for checking access rights - used for security checks |
| 177 | // on access to global objects across environments. The holder register |
| 178 | // is left untouched, whereas both scratch registers are clobbered. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 179 | void CheckAccessGlobalProxy(Register holder_reg, |
| 180 | Register scratch, |
| 181 | Label* miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 182 | |
| 183 | |
| 184 | // --------------------------------------------------------------------------- |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 185 | // Support functions. |
| 186 | |
| 187 | // Generates code for reporting that an illegal operation has |
| 188 | // occurred. |
| 189 | void IllegalOperation(int num_arguments); |
| 190 | |
| 191 | |
| 192 | // --------------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 193 | // Runtime calls |
| 194 | |
| 195 | // Call a code stub. |
| 196 | void CallStub(CodeStub* stub); |
| 197 | void CallJSExitStub(CodeStub* stub); |
| 198 | |
| 199 | // Return from a code stub after popping its arguments. |
| 200 | void StubReturn(int argc); |
| 201 | |
| 202 | // Call a runtime routine. |
| 203 | // Eventually this should be used for all C calls. |
| 204 | void CallRuntime(Runtime::Function* f, int num_arguments); |
| 205 | |
| 206 | // Convenience function: Same as above, but takes the fid instead. |
| 207 | void CallRuntime(Runtime::FunctionId fid, int num_arguments); |
| 208 | |
| 209 | // Tail call of a runtime routine (jump). |
| 210 | // Like JumpToBuiltin, but also takes care of passing the number |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 211 | // of parameters. |
| 212 | void TailCallRuntime(const ExternalReference& ext, int num_arguments); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 213 | |
| 214 | // Jump to the builtin routine. |
| 215 | void JumpToBuiltin(const ExternalReference& builtin); |
| 216 | |
| 217 | // Invoke specified builtin JavaScript function. Adds an entry to |
| 218 | // the unresolved list if the name does not resolve. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 219 | void InvokeBuiltin(Builtins::JavaScript id, InvokeJSFlags flags); |
| 220 | |
| 221 | // Store the code object for the given builtin in the target register and |
| 222 | // setup the function in r1. |
| 223 | void GetBuiltinEntry(Register target, Builtins::JavaScript id); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 224 | |
| 225 | struct Unresolved { |
| 226 | int pc; |
| 227 | uint32_t flags; // see Bootstrapper::FixupFlags decoders/encoders. |
| 228 | const char* name; |
| 229 | }; |
| 230 | List<Unresolved>* unresolved() { return &unresolved_; } |
| 231 | |
| 232 | |
| 233 | // --------------------------------------------------------------------------- |
| 234 | // Debugging |
| 235 | |
| 236 | // Calls Abort(msg) if the condition cc is not satisfied. |
| 237 | // Use --debug_code to enable. |
| 238 | void Assert(Condition cc, const char* msg); |
| 239 | |
| 240 | // Like Assert(), but always enabled. |
| 241 | void Check(Condition cc, const char* msg); |
| 242 | |
| 243 | // Print a message to stdout and abort execution. |
| 244 | void Abort(const char* msg); |
| 245 | |
| 246 | // Verify restrictions about code generated in stubs. |
| 247 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 248 | bool generating_stub() { return generating_stub_; } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 249 | void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; } |
| 250 | bool allow_stub_calls() { return allow_stub_calls_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 251 | |
| 252 | private: |
| 253 | List<Unresolved> unresolved_; |
| 254 | bool generating_stub_; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 255 | bool allow_stub_calls_; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 256 | |
| 257 | // Helper functions for generating invokes. |
| 258 | void InvokePrologue(const ParameterCount& expected, |
| 259 | const ParameterCount& actual, |
| 260 | Handle<Code> code_constant, |
| 261 | Register code_reg, |
| 262 | Label* done, |
| 263 | InvokeFlag flag); |
| 264 | |
| 265 | // Get the code for the given builtin. Returns if able to resolve |
| 266 | // the function in the 'resolved' flag. |
| 267 | Handle<Code> ResolveBuiltin(Builtins::JavaScript id, bool* resolved); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 268 | |
| 269 | // Activation support. |
| 270 | void EnterFrame(StackFrame::Type type); |
| 271 | void LeaveFrame(StackFrame::Type type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | |
| 275 | // ----------------------------------------------------------------------------- |
| 276 | // Static helper functions. |
| 277 | |
| 278 | // Generate a MemOperand for loading a field from an object. |
| 279 | static inline MemOperand FieldMemOperand(Register object, int offset) { |
| 280 | return MemOperand(object, offset - kHeapObjectTag); |
| 281 | } |
| 282 | |
| 283 | |
| 284 | |
| 285 | } } // namespace v8::internal |
| 286 | |
| 287 | #endif // V8_MACRO_ASSEMBLER_ARM_H_ |