Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/mips/macro-assembler-mips.h

Issue 549079: Support for MIPS in architecture independent files.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #ifndef V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
2 #define V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
3
4 #include "assembler.h"
5 #include "mips/assembler-mips.h"
6
7 namespace v8 {
8 namespace internal {
9
10 // Forward declaration.
11 class JumpTarget;
12
13
14 // Registers aliases
15 const Register cp = s7; // JavaScript context pointer
16 const Register fp = s8_fp; // Alias fp
17
18 // Register at is used for insruction generation. So it is not safe to use it
19 // unless we know exactly what we do.
20 const Register ip = t8; // Alias ip. equivalent to arm ip scratch register
21
22 enum InvokeJSFlags {
23 CALL_JS,
24 JUMP_JS
25 };
26
27 // MacroAssembler implements a collection of frequently used macros.
28 class MacroAssembler: public Assembler {
29 public:
30 MacroAssembler(void* buffer, int size);
31
32 // ---------------------------------------------------------------------------
33 // Low-level helpers for compiler
34
35 // Jump, Call, and Ret pseudo instructions implementing inter-working
36 private:
37 void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = cc_always,
38 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
39 void Call(intptr_t target, RelocInfo::Mode rmode, Condition cond = cc_always,
40 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
41 // With arguments slots setup.
42 void Jump_was(intptr_t target, RelocInfo::Mode rmode, Condition cond = cc_alwa ys,
43 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
44 void Call_was(intptr_t target, RelocInfo::Mode rmode, Condition cond = cc_alwa ys,
45 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
46 public:
47 void Jump(Register target, Condition cond = cc_always,
48 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
49 void Jump(byte* target, RelocInfo::Mode rmode, Condition cond = cc_always,
50 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
51 void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = cc_always ,
52 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
53 void Call(Register target, Condition cond = cc_always,
54 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
55 void Call(byte* target, RelocInfo::Mode rmode, Condition cond = cc_always,
56 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
57 void Call(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = cc_always ,
58 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
59 // With arguments slots setup.
60 void Jump_was(Register target, Condition cond = cc_always,
61 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
62 void Jump_was(byte* target, RelocInfo::Mode rmode, Condition cond = cc_always,
63 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
64 void Jump_was(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = cc_al ways,
65 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
66 void Call_was(Register target, Condition cond = cc_always,
67 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
68 void Call_was(byte* target, RelocInfo::Mode rmode, Condition cond = cc_always,
69 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
70 void Call_was(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = cc_al ways,
71 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
72 void Ret(Condition cond = cc_always, Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
73 // Jumps to the label at the index given by the Smi in "index".
74 void SmiJumpTable(Register index, Vector<Label*> targets);
75 // Load an object from the root table.
76 void LoadRoot(Register destination,
77 Heap::RootListIndex index);
78 void LoadRoot(Register destination,
79 Heap::RootListIndex index,
80 Condition cond, Register src1, const Operand& sr c2);
81
82 // Sets the remembered set bit for [address+offset], where address is the
83 // address of the heap object 'object'. The address must be in the first 8K
84 // of an allocated page. The 'scratch' register is used in the
85 // implementation and all 3 registers are clobbered by the operation, as
86 // well as the ip register.
87 void RecordWrite(Register object, Register offset, Register scratch);
88
89 // ---------------------------------------------------------------------------
90 // Activation frames
91
92 void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); }
93 void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); }
94
95 void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); }
96 void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); }
97
98 // Enter specific kind of exit frame; either EXIT or
99 // EXIT_DEBUG. Expects the number of arguments in register r0 and
100 // the builtin function to call in register r1. Exits with argc in
101 // r4, argv in r6, and and the builtin function to call in r5.
102 void EnterExitFrame(ExitFrame::Mode mode);
103
104 // Leave the current exit frame. Expects the return value in r0.
105 void LeaveExitFrame(ExitFrame::Mode mode);
106
107 // Align the stack by optionally pushing a Smi zero.
108 void AlignStack(int offset);
109
110 // Setup call with sp aligned to 8 bytes. The scratch register is clobbered.
111 // When using this function we suppose that the size of objects pushed on the
112 // stack (other than arguments) is a multiple of 8 bytes. (Usually the
113 // function name and receiver are pushed before the arguments.)
114 void SetupAlignedCall(Register scratch, int arg_count = 0);
115 // Restore sp and s3 (used to save sp).
116 void ReturnFromAlignedCall();
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 bool withArgsSlots = false);
128
129 void InvokeCode(Handle<Code> code,
130 const ParameterCount& expected,
131 const ParameterCount& actual,
132 RelocInfo::Mode rmode,
133 InvokeFlag flag,
134 bool withArgsSlots = false);
135
136 // Invoke the JavaScript function in the given register. Changes the
137 // current context to the context in the function before invoking.
138 void InvokeFunction(Register function,
139 const ParameterCount& actual,
140 InvokeFlag flag,
141 bool withArgsSlots = false);
142
143
144 #ifdef ENABLE_DEBUGGER_SUPPORT
145 // ---------------------------------------------------------------------------
146 // Debugger Support
147
148 void SaveRegistersToMemory(RegList regs);
149 void RestoreRegistersFromMemory(RegList regs);
150 void CopyRegistersFromMemoryToStack(Register base, RegList regs);
151 void CopyRegistersFromStackToMemory(Register base,
152 Register scratch,
153 RegList regs);
154 #endif
155
156 // ---------------------------------------------------------------------------
157 // Exception handling
158
159 // Push a new try handler and link into try handler chain.
160 // The return address must be passed in register lr.
161 // On exit, r0 contains TOS (code slot).
162 void PushTryHandler(CodeLocation try_location, HandlerType type);
163
164
165 // ---------------------------------------------------------------------------
166 // Inline caching support
167
168 // Generates code that verifies that the maps of objects in the
169 // prototype chain of object hasn't changed since the code was
170 // generated and branches to the miss label if any map has. If
171 // necessary the function also generates code for security check
172 // in case of global object holders. The scratch and holder
173 // registers are always clobbered, but the object register is only
174 // clobbered if it the same as the holder register. The function
175 // returns a register containing the holder - either object_reg or
176 // holder_reg.
177 Register CheckMaps(JSObject* object, Register object_reg,
178 JSObject* holder, Register holder_reg,
179 Register scratch, Label* miss);
180
181 // Generate code for checking access rights - used for security checks
182 // on access to global objects across environments. The holder register
183 // is left untouched, whereas both scratch registers are clobbered.
184 void CheckAccessGlobalProxy(Register holder_reg,
185 Register scratch,
186 Label* miss);
187
188
189 // ---------------------------------------------------------------------------
190 // Allocation support
191
192 // Allocate an object in new space. The object_size is specified in words (not
193 // bytes). If the new space is exhausted control continues at the gc_required
194 // label. The allocated object is returned in result. If the flag
195 // tag_allocated_object is true the result is tagged as as a heap object.
196 void AllocateInNewSpace(int object_size,
197 Register result,
198 Register scratch1,
199 Register scratch2,
200 Label* gc_required,
201 AllocationFlags flags);
202 void AllocateInNewSpace(Register object_size,
203 Register result,
204 Register scratch1,
205 Register scratch2,
206 Label* gc_required,
207 AllocationFlags flags);
208
209 // Undo allocation in new space. The object passed and objects allocated after
210 // it will no longer be allocated. The caller must make sure that no pointers
211 // are left to the object(s) no longer allocated as they would be invalid when
212 // allocation is undone.
213 void UndoAllocationInNewSpace(Register object, Register scratch);
214
215 // ---------------------------------------------------------------------------
216 // Support functions.
217
218 // Try to get function prototype of a function and puts the value in
219 // the result register. Checks that the function really is a
220 // function and jumps to the miss label if the fast checks fail. The
221 // function register will be untouched; the other registers may be
222 // clobbered.
223 void TryGetFunctionPrototype(Register function,
224 Register result,
225 Register scratch,
226 Label* miss);
227
228 // Compare object type for heap object. heap_object contains a non-Smi
229 // whose object type should be compared with the given type. This both
230 // sets the flags and leaves the object type in the type_reg register.
231 // It leaves the map in the map register (unless the type_reg and map register
232 // are the same register). It leaves the heap object in the heap_object
233 // register unless the heap_object register is the same register as one of the
234 // other registers.
235 // REMOVED : code architecture does not fit MIPS
236 // void CompareObjectType(Register heap_object,
237 // Register map,
238 // Register type_reg,
239 // InstanceType type);
240
241 // Compare instance type in a map. map contains a valid map object whose
242 // object type should be compared with the given type. This both
243 // sets the flags and leaves the object type in the type_reg register. It
244 // leaves the heap object in the heap_object register unless the heap_object
245 // register is the same register as type_reg.
246 // REMOVED : code architecture does not fit MIPS
247 // void CompareInstanceType(Register map,
248 // Register type_reg,
249 // InstanceType type);
250
251 // Replaces CompareObjectType and CompareInstanceType functions.
252 void GetObjectType(Register function,
253 Register map,
254 Register type_reg);
255
256 inline void BranchOnSmi(Register value, Label* smi_label, Register scratch = a t) {
257 andi(scratch, value, Operand(kSmiTagMask));
258 bcond(eq, smi_label, scratch, Operand(zero_reg));
259 }
260
261 inline void BranchOnNotSmi(Register value, Label* not_smi_label) {
262 // tst(value, Operand(kSmiTagMask));
263 // b(ne, not_smi_label);
264 }
265
266 // Generates code for reporting that an illegal operation has
267 // occurred.
268 void IllegalOperation(int num_arguments);
269
270
271 // ---------------------------------------------------------------------------
272 // Runtime calls
273
274 // Call a code stub.
275 void CallStub(CodeStub* stub, Condition cond = cc_always,
276 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
277 void CallJSExitStub(CodeStub* stub);
278
279 // Return from a code stub after popping its arguments.
280 void StubReturn(int argc);
281
282 // Call a runtime routine.
283 // Eventually this should be used for all C calls.
284 void CallRuntime(Runtime::Function* f, int num_arguments);
285
286 // Convenience function: Same as above, but takes the fid instead.
287 void CallRuntime(Runtime::FunctionId fid, int num_arguments);
288
289 // Tail call of a runtime routine (jump).
290 // Like JumpToRuntime, but also takes care of passing the number
291 // of parameters.
292 void TailCallRuntime(const ExternalReference& ext,
293 int num_arguments,
294 int result_size);
295
296 // Jump to the builtin routine.
297 void JumpToRuntime(const ExternalReference& builtin);
298
299 // Invoke specified builtin JavaScript function. Adds an entry to
300 // the unresolved list if the name does not resolve.
301 void InvokeBuiltin(Builtins::JavaScript id, InvokeJSFlags flags);
302
303 // Store the code object for the given builtin in the target register and
304 // setup the function in r1.
305 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
306
307 struct Unresolved {
308 int pc;
309 uint32_t flags; // see Bootstrapper::FixupFlags decoders/encoders.
310 const char* name;
311 };
312 List<Unresolved>* unresolved() { return &unresolved_; }
313
314 Handle<Object> CodeObject() { return code_object_; }
315
316
317 // ---------------------------------------------------------------------------
318 // StatsCounter support
319
320 void SetCounter(StatsCounter* counter, int value,
321 Register scratch1, Register scratch2);
322 void IncrementCounter(StatsCounter* counter, int value,
323 Register scratch1, Register scratch2);
324 void DecrementCounter(StatsCounter* counter, int value,
325 Register scratch1, Register scratch2);
326
327
328 // ---------------------------------------------------------------------------
329 // Debugging
330
331 // Calls Abort(msg) if the condition cc is not satisfied.
332 // Use --debug_code to enable.
333 void Assert(Condition cc, const char* msg, Register rs, Operand rt);
334
335 // Like Assert(), but always enabled.
336 void Check(Condition cc, const char* msg, Register rs, Operand rt);
337
338 // Print a message to stdout and abort execution.
339 void Abort(const char* msg);
340
341 // Verify restrictions about code generated in stubs.
342 void set_generating_stub(bool value) { generating_stub_ = value; }
343 bool generating_stub() { return generating_stub_; }
344 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
345 bool allow_stub_calls() { return allow_stub_calls_; }
346
347 private:
348 List<Unresolved> unresolved_;
349 bool generating_stub_;
350 bool allow_stub_calls_;
351 Handle<Object> code_object_; // This handle will be patched with the code
352 // object on installation.
353
354 // Helper functions for generating invokes.
355 void InvokePrologue(const ParameterCount& expected,
356 const ParameterCount& actual,
357 Handle<Code> code_constant,
358 Register code_reg,
359 Label* done,
360 InvokeFlag flag,
361 bool withArgsSlots);
362
363 // Get the code for the given builtin. Returns if able to resolve
364 // the function in the 'resolved' flag.
365 Handle<Code> ResolveBuiltin(Builtins::JavaScript id, bool* resolved);
366
367 // Activation support.
368 // EnterFrame clobbers t0 and t1.
369 void EnterFrame(StackFrame::Type type);
370 void LeaveFrame(StackFrame::Type type);
371 };
372
373
374 #ifdef ENABLE_DEBUGGER_SUPPORT
375 // The code patcher is used to patch (typically) small parts of code e.g. for
376 // debugging and other types of instrumentation. When using the code patcher
377 // the exact number of bytes specified must be emitted. It is not legal to emit
378 // relocation information. If any of these constraints are violated it causes
379 // an assertion to fail.
380 class CodePatcher {
381 public:
382 CodePatcher(byte* address, int instructions);
383 virtual ~CodePatcher();
384
385 // Macro assembler to emit code.
386 MacroAssembler* masm() { return &masm_; }
387
388 // Emit an instruction directly.
389 void Emit(Instr x);
390
391 // Emit an address directly.
392 void Emit(Address addr);
393
394 private:
395 byte* address_; // The address of the code being patched.
396 int instructions_; // Number of instructions of the expected patch size.
397 int size_; // Number of bytes of the expected patch size.
398 MacroAssembler masm_; // Macro assembler used to generate the code.
399 };
400 #endif // ENABLE_DEBUGGER_SUPPORT
401
402
403 // -----------------------------------------------------------------------------
404 // Static helper functions.
405
406 // Generate a MemOperand for loading a field from an object.
407 static inline MemOperand FieldMemOperand(Register object, int offset) {
408 return MemOperand(object, offset - kHeapObjectTag);
409 }
410
411
412
413 #ifdef GENERATED_CODE_COVERAGE
414 #define CODE_COVERAGE_STRINGIFY(x) #x
415 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
416 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
417 #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
418 #else
419 #define ACCESS_MASM(masm) masm->
420 #endif
421
422
423 } } // namespace v8::internal
424
425 #endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698