Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2006-2010 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_MIPS_MACRO_ASSEMBLER_MIPS_H_ | |
| 29 #define V8_MIPS_MACRO_ASSEMBLER_MIPS_H_ | |
| 30 | |
| 31 #include "assembler.h" | |
| 32 #include "mips/assembler-mips.h" | |
| 33 | |
| 34 namespace v8 { | |
| 35 namespace internal { | |
| 36 | |
| 37 // Forward declaration. | |
| 38 class JumpTarget; | |
| 39 | |
| 40 // Register at is used for instruction generation. So it is not safe to use it | |
| 41 // unless we know exactly what we do. | |
| 42 | |
| 43 // Registers aliases | |
| 44 const Register cp = s7; // JavaScript context pointer | |
| 45 const Register fp = s8_fp; // Alias fp | |
| 46 | |
| 47 enum InvokeJSFlags { | |
| 48 CALL_JS, | |
| 49 JUMP_JS | |
| 50 }; | |
| 51 | |
| 52 // MacroAssembler implements a collection of frequently used macros. | |
| 53 class MacroAssembler: public Assembler { | |
| 54 public: | |
| 55 MacroAssembler(void* buffer, int size); | |
| 56 | |
| 57 // --------------------------------------------------------------------------- | |
| 58 // Low-level helpers for compiler | |
| 59 | |
| 60 // Jump, Call, and Ret pseudo instructions implementing inter-working | |
| 61 private: | |
| 62 void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = cc_always, | |
| 63 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg)); | |
| 64 void Call(intptr_t target, RelocInfo::Mode rmode, Condition cond = cc_always, | |
| 65 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg)); | |
| 66 public: | |
| 67 void Jump(const Operand& target, | |
| 68 Condition cond = cc_always, | |
| 69 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg)); | |
| 70 void Call(const Operand& target, | |
| 71 Condition cond = cc_always, | |
| 72 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg)); | |
| 73 void Jump(Register target, | |
| 74 Condition cond = cc_always, | |
| 75 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg)); | |
| 76 void Jump(byte* target, RelocInfo::Mode rmode, | |
| 77 Condition cond = cc_always, | |
| 78 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg)); | |
| 79 void Jump(Handle<Code> code, RelocInfo::Mode rmode, | |
| 80 Condition cond = cc_always, | |
| 81 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg)); | |
| 82 void Call(Register target, | |
| 83 Condition cond = cc_always, | |
| 84 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg)); | |
| 85 void Call(byte* target, RelocInfo::Mode rmode, | |
| 86 Condition cond = cc_always, | |
| 87 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg)); | |
| 88 void Call(Handle<Code> code, RelocInfo::Mode rmode, | |
| 89 Condition cond = cc_always, | |
| 90 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg)); | |
| 91 void Ret(Condition cond = cc_always, | |
| 92 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg)); | |
| 93 void Branch(Condition cond, int16_t offset, Register rs = zero_reg, | |
| 94 const Operand& rt = Operand(zero_reg), Register scratch = at); | |
| 95 void Branch(Condition cond, Label* L, Register rs = zero_reg, | |
| 96 const Operand& rt = Operand(zero_reg), Register scratch = at); | |
| 97 // conditionnal branch and link | |
| 98 void BranchAndLink(Condition cond, int16_t offset, Register rs = zero_reg, | |
| 99 const Operand& rt = Operand(zero_reg), | |
| 100 Register scratch = at); | |
| 101 void BranchAndLink(Condition cond, Label* L, Register rs = zero_reg, | |
| 102 const Operand& rt = Operand(zero_reg), | |
| 103 Register scratch = at); | |
| 104 | |
| 105 // Emit code to discard a non-negative number of pointer-sized elements | |
| 106 // from the stack, clobbering only the sp register. | |
| 107 void Drop(int count, Condition cond = cc_always); | |
| 108 | |
| 109 void Call(Label* target); | |
| 110 | |
| 111 // Jump unconditionally to given label. | |
| 112 // We NEED a nop in the branch delay slot, as it used by v8, for example in | |
| 113 // CodeGenerator::ProcessDeferred(). | |
| 114 // Use rather b(Label) for code generation. | |
| 115 void jmp(Label* L) { | |
| 116 Branch(cc_always, L); | |
| 117 nop(); | |
| 118 } | |
| 119 | |
| 120 // Load an object from the root table. | |
| 121 void LoadRoot(Register destination, | |
| 122 Heap::RootListIndex index); | |
| 123 void LoadRoot(Register destination, | |
| 124 Heap::RootListIndex index, | |
| 125 Condition cond, Register src1, const Operand& src2); | |
| 126 | |
| 127 // Sets the remembered set bit for [address+offset], where address is the | |
|
Alexandre
2010/02/04 02:30:39
Removed this comment.
| |
| 128 // address of the heap object 'object'. The address must be in the first 8K | |
| 129 // of an allocated page. The 'scratch' register is used in the | |
| 130 // implementation and all 3 registers are clobbered by the operation, as | |
| 131 // well as the ip register. | |
| 132 void RecordWrite(Register object, Register offset, Register scratch); | |
| 133 | |
| 134 | |
| 135 // --------------------------------------------------------------------------- | |
| 136 // Instruction macros | |
| 137 | |
| 138 #define DEFINE_INSTRUCTION(instr) \ | |
| 139 void instr(Register rd, Register rs, const Operand& rt); \ | |
| 140 void instr(Register rd, Register rs, Register rt) { \ | |
| 141 instr(rd, rs, Operand(rt)); \ | |
| 142 } \ | |
| 143 void instr(Register rs, Register rt, int32_t j) { \ | |
| 144 instr(rs, rt, Operand(j)); \ | |
| 145 } | |
| 146 | |
| 147 #define DEFINE_INSTRUCTION2(instr) \ | |
| 148 void instr(Register rs, const Operand& rt); \ | |
| 149 void instr(Register rs, Register rt) { \ | |
| 150 instr(rs, Operand(rt)); \ | |
| 151 } \ | |
| 152 void instr(Register rs, int32_t j) { \ | |
| 153 instr(rs, Operand(j)); \ | |
| 154 } | |
| 155 | |
| 156 DEFINE_INSTRUCTION(Add); | |
| 157 DEFINE_INSTRUCTION(Addu); | |
| 158 DEFINE_INSTRUCTION(Mul); | |
| 159 DEFINE_INSTRUCTION2(Mult); | |
| 160 DEFINE_INSTRUCTION2(Multu); | |
| 161 DEFINE_INSTRUCTION2(Div); | |
| 162 DEFINE_INSTRUCTION2(Divu); | |
| 163 | |
| 164 DEFINE_INSTRUCTION(And); | |
| 165 DEFINE_INSTRUCTION(Or); | |
| 166 DEFINE_INSTRUCTION(Xor); | |
| 167 DEFINE_INSTRUCTION(Nor); | |
| 168 | |
| 169 DEFINE_INSTRUCTION(Slt); | |
| 170 DEFINE_INSTRUCTION(Sltu); | |
| 171 | |
| 172 #undef DEFINE_INSTRUCTION | |
| 173 #undef DEFINE_INSTRUCTION2 | |
| 174 | |
| 175 | |
| 176 //------------Pseudo-instructions------------- | |
| 177 | |
| 178 void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); } | |
| 179 // Move the logical ones complement of source to dest. | |
| 180 void movn(Register rd, Register rt); | |
| 181 | |
| 182 | |
| 183 // load int32 in the rd register | |
| 184 void li(Register rd, Operand j, bool gen2instr = false); | |
| 185 inline void li(Register rd, int32_t j, bool gen2instr = false) { | |
| 186 li(rd, Operand(j), gen2instr); | |
| 187 } | |
| 188 | |
| 189 // Exception-generating instructions and debugging support | |
| 190 void stop(const char* msg); | |
| 191 | |
| 192 | |
| 193 // Push multiple registers on the stack. | |
| 194 // With MultiPush, lower registers are pushed first on the stack. | |
| 195 // For example if you push t0, t1, s0, and ra you get: | |
| 196 // | | | |
| 197 // |-----------------------| | |
| 198 // | t0 | + | |
| 199 // |-----------------------| | | |
| 200 // | t1 | | | |
| 201 // |-----------------------| | | |
| 202 // | s0 | v | |
| 203 // |-----------------------| - | |
| 204 // | ra | | |
| 205 // |-----------------------| | |
| 206 // | | | |
| 207 void MultiPush(RegList regs); | |
| 208 void MultiPushReversed(RegList regs); | |
| 209 void Push(Register src) { | |
| 210 Addu(sp, sp, Operand(-kPointerSize)); | |
| 211 sw(src, MemOperand(sp, 0)); | |
| 212 } | |
| 213 inline void push(Register src) { Push(src); } | |
| 214 | |
| 215 void Push(Register src, Condition cond, Register tst1, Register tst2) { | |
| 216 // Since we don't have conditionnal execution we use a Branch. | |
| 217 Branch(cond, 3, tst1, Operand(tst2)); | |
| 218 nop(); | |
| 219 Addu(sp, sp, Operand(-kPointerSize)); | |
| 220 sw(src, MemOperand(sp, 0)); | |
| 221 } | |
| 222 | |
| 223 // Pops multiple values from the stack and load them in the | |
| 224 // registers specified in regs. Pop order is the opposite as in MultiPush. | |
| 225 void MultiPop(RegList regs); | |
| 226 void MultiPopReversed(RegList regs); | |
| 227 void Pop(Register dst) { | |
| 228 lw(dst, MemOperand(sp, 0)); | |
| 229 Addu(sp, sp, Operand(kPointerSize)); | |
| 230 } | |
| 231 void Pop() { | |
| 232 Add(sp, sp, Operand(kPointerSize)); | |
| 233 } | |
| 234 | |
| 235 | |
| 236 // --------------------------------------------------------------------------- | |
| 237 // Exception handling | |
| 238 | |
| 239 // Push a new try handler and link into try handler chain. | |
| 240 // The return address must be passed in register lr. | |
| 241 // On exit, r0 contains TOS (code slot). | |
| 242 void PushTryHandler(CodeLocation try_location, HandlerType type); | |
| 243 | |
| 244 // Unlink the stack handler on top of the stack from the try handler chain. | |
| 245 // Must preserve the result register. | |
| 246 void PopTryHandler(); | |
| 247 | |
| 248 | |
| 249 // --------------------------------------------------------------------------- | |
| 250 // Support functions. | |
| 251 | |
| 252 inline void BranchOnSmi(Register value, Label* smi_label, | |
| 253 Register scratch = at) { | |
| 254 ASSERT_EQ(0, kSmiTag); | |
| 255 andi(scratch, value, kSmiTagMask); | |
| 256 Branch(eq, smi_label, scratch, Operand(zero_reg)); | |
| 257 } | |
| 258 | |
| 259 | |
| 260 inline void BranchOnNotSmi(Register value, Label* not_smi_label, | |
| 261 Register scratch = at) { | |
| 262 ASSERT_EQ(0, kSmiTag); | |
| 263 andi(scratch, value, kSmiTagMask); | |
| 264 Branch(ne, not_smi_label, scratch, Operand(zero_reg)); | |
| 265 } | |
| 266 | |
| 267 | |
| 268 // --------------------------------------------------------------------------- | |
| 269 // Runtime calls | |
| 270 | |
| 271 // Call a code stub. | |
| 272 void CallStub(CodeStub* stub, Condition cond = cc_always, | |
| 273 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg)); | |
| 274 void CallJSExitStub(CodeStub* stub); | |
| 275 | |
| 276 // Return from a code stub after popping its arguments. | |
| 277 void StubReturn(int argc); | |
| 278 | |
| 279 // Call a runtime routine. | |
| 280 // Eventually this should be used for all C calls. | |
| 281 void CallRuntime(Runtime::Function* f, int num_arguments); | |
| 282 | |
| 283 // Convenience function: Same as above, but takes the fid instead. | |
| 284 void CallRuntime(Runtime::FunctionId fid, int num_arguments); | |
| 285 | |
| 286 // Tail call of a runtime routine (jump). | |
| 287 // Like JumpToRuntime, but also takes care of passing the number | |
| 288 // of parameters. | |
| 289 void TailCallRuntime(const ExternalReference& ext, | |
| 290 int num_arguments, | |
| 291 int result_size); | |
| 292 | |
| 293 // Jump to the builtin routine. | |
| 294 void JumpToRuntime(const ExternalReference& builtin); | |
| 295 | |
| 296 // Invoke specified builtin JavaScript function. Adds an entry to | |
| 297 // the unresolved list if the name does not resolve. | |
| 298 void InvokeBuiltin(Builtins::JavaScript id, InvokeJSFlags flags); | |
| 299 | |
| 300 // Store the code object for the given builtin in the target register and | |
| 301 // setup the function in r1. | |
| 302 void GetBuiltinEntry(Register target, Builtins::JavaScript id); | |
| 303 | |
| 304 struct Unresolved { | |
| 305 int pc; | |
| 306 uint32_t flags; // see Bootstrapper::FixupFlags decoders/encoders. | |
| 307 const char* name; | |
| 308 }; | |
| 309 List<Unresolved>* unresolved() { return &unresolved_; } | |
| 310 | |
| 311 Handle<Object> CodeObject() { return code_object_; } | |
| 312 | |
| 313 | |
| 314 // --------------------------------------------------------------------------- | |
| 315 // Stack limit support | |
| 316 | |
| 317 void StackLimitCheck(Label* on_stack_limit_hit); | |
| 318 | |
| 319 | |
| 320 // --------------------------------------------------------------------------- | |
| 321 // StatsCounter support | |
| 322 | |
| 323 void SetCounter(StatsCounter* counter, int value, | |
| 324 Register scratch1, Register scratch2); | |
| 325 void IncrementCounter(StatsCounter* counter, int value, | |
| 326 Register scratch1, Register scratch2); | |
| 327 void DecrementCounter(StatsCounter* counter, int value, | |
| 328 Register scratch1, Register scratch2); | |
| 329 | |
| 330 | |
| 331 // --------------------------------------------------------------------------- | |
| 332 // Debugging | |
| 333 | |
| 334 // Calls Abort(msg) if the condition cc is not satisfied. | |
| 335 // Use --debug_code to enable. | |
| 336 void Assert(Condition cc, const char* msg, Register rs, Operand rt); | |
| 337 | |
| 338 // Like Assert(), but always enabled. | |
| 339 void Check(Condition cc, const char* msg, Register rs, Operand rt); | |
| 340 | |
| 341 // Print a message to stdout and abort execution. | |
| 342 void Abort(const char* msg); | |
| 343 | |
| 344 // Verify restrictions about code generated in stubs. | |
| 345 void set_generating_stub(bool value) { generating_stub_ = value; } | |
| 346 bool generating_stub() { return generating_stub_; } | |
| 347 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; } | |
| 348 bool allow_stub_calls() { return allow_stub_calls_; } | |
| 349 | |
| 350 private: | |
| 351 List<Unresolved> unresolved_; | |
| 352 bool generating_stub_; | |
| 353 bool allow_stub_calls_; | |
| 354 Handle<Object> code_object_; // This handle will be patched with the code | |
| 355 // object on installation. | |
| 356 | |
| 357 // Get the code for the given builtin. Returns if able to resolve | |
| 358 // the function in the 'resolved' flag. | |
| 359 Handle<Code> ResolveBuiltin(Builtins::JavaScript id, bool* resolved); | |
| 360 }; | |
| 361 | |
| 362 | |
| 363 // ----------------------------------------------------------------------------- | |
| 364 // Static helper functions. | |
| 365 | |
| 366 // Generate a MemOperand for loading a field from an object. | |
| 367 static inline MemOperand FieldMemOperand(Register object, int offset) { | |
| 368 return MemOperand(object, offset - kHeapObjectTag); | |
| 369 } | |
| 370 | |
| 371 | |
| 372 | |
| 373 #ifdef GENERATED_CODE_COVERAGE | |
| 374 #define CODE_COVERAGE_STRINGIFY(x) #x | |
| 375 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) | |
| 376 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) | |
| 377 #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm-> | |
| 378 #else | |
| 379 #define ACCESS_MASM(masm) masm-> | |
| 380 #endif | |
| 381 | |
| 382 } } // namespace v8::internal | |
| 383 | |
| 384 #endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_ | |
| 385 | |
| OLD | NEW |