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

Side by Side Diff: src/mips/simulator-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 // Declares a Simulator for MIPS instructions if we are not generating a native
2 // MIPS binary. This Simulator allows us to run and debug MIPS code generation o n
3 // regular desktop machines.
4 // V8 calls into generated code by "calling" the CALL_GENERATED_CODE macro,
5 // which will start execution in the Simulator or forwards to the real entry
6 // on a MIPS HW platform.
7
8 #ifndef V8_MIPS_SIMULATOR_MIPS_H_
9 #define V8_MIPS_SIMULATOR_MIPS_H_
10
11 #include "allocation.h"
12
13 #if defined(__mips)
14
15 // When running without a simulator we call the entry directly.
16 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \
17 entry(p0, p1, p2, p3, p4);
18
19 // TODO TOCHECK: Is this the same on MIPS ?
20 // The stack limit beyond which we will throw stack overflow errors in
21 // generated code. Because generated code on arm uses the C stack, we
22 // just use the C stack limit.
23 class SimulatorStack : public v8::internal::AllStatic {
24 public:
25 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) {
26 return c_limit;
27 }
28 };
29
30 // Calculated the stack limit beyond which we will throw stack overflow errors.
31 // This macro must be called from a C++ method. It relies on being able to take
32 // the address of "this" to get a value on the current execution stack and then
33 // calculates the stack limit based on that value.
34 // NOTE: The check for overflow is not safe as there is no guarantee that the
35 // running thread has its stack in all memory up to address 0x00000000.
36 #define GENERATED_CODE_STACK_LIMIT(limit) \
37 (reinterpret_cast<uintptr_t>(this) >= limit ? \
38 reinterpret_cast<uintptr_t>(this) - limit : 0)
39
40 // Call the generated regexp code directly. The entry function pointer should
41 // expect seven int/pointer sized arguments and return an int.
42 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \
43 entry(p0, p1, p2, p3, p4, p5, p6)
44
45
46 #else // #if defined(__mips)
47
48 // printf("Giving control to MIPS simulator.\n");
49 // asm("break");
50 // When running with the simulator transition into simulated execution at this
51 // point.
52 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \
53 reinterpret_cast<Object*>( \
54 assembler::mips::Simulator::current()->Call(FUNCTION_ADDR(entry), 5, \
55 p0, p1, p2, p3, p4))
56
57 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \
58 assembler::mips::Simulator::current()->Call( \
59 FUNCTION_ADDR(entry), 7, p0, p1, p2, p3, p4, p5, p6)
60
61
62 namespace assembler {
63 namespace mips {
64
65 class Simulator {
66 public:
67 friend class Debugger;
68
69 // Registers are declared in order. See SMRL chapter 2.
70 enum Register {
71 no_reg = -1,
72 zero_reg = 0,
73 at,
74 v0, v1,
75 a0, a1, a2, a3,
76 t0, t1, t2, t3, t4, t5, t6, t7,
77 s0, s1, s2, s3, s4, s5, s6, s7,
78 t8, t9,
79 k0, k1,
80 gp,
81 sp,
82 s8,
83 ra,
84 // HI, LO, and pc
85 HI,
86 LO,
87 pc,
88 num_registers,
89 // aliases
90 fp = s8
91 };
92
93 // Coprocessor registers.
94 // Generated code will always use doubles. So we will only use even registers.
95 enum CRegister {
96 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11,
97 f12, f13, f14, f15, // f12 and f14 are arguments CRegisters
98 f16, f17, f18, f19, f20, f21, f22, f23, f24, f25,
99 f26, f27, f28, f29, f30, f31,
100 num_Cregisters
101 };
102
103 Simulator();
104 ~Simulator();
105
106 // The currently executing Simulator instance. Potentially there can be one
107 // for each native thread.
108 static Simulator* current();
109
110 // Accessors for register state. Reading the pc value adheres to the ARM
111 // architecture specification and is off by a 8 from the currently executing
112 // instruction.
113 void set_register(int reg, int32_t value);
114 int32_t get_register(int reg) const;
115 // Same for CRegisters
116 void set_Cregister(int creg, double value);
117 double get_Cregister(int creg) const;
118 // Get 16 high or low bits of the Cregister
119 int32_t get_CregisterHI(int creg) const;
120 int32_t get_CregisterLO(int creg) const;
121
122 // Special case of set_register and get_register to access the raw PC value.
123 void set_pc(int32_t value);
124 int32_t get_pc() const;
125
126 // Accessor to the internal simulator stack area.
127 uintptr_t StackLimit() const;
128
129 // Executes MIPS instructions until the PC reaches end_sim_pc.
130 void Execute();
131
132 // Call on program start.
133 static void Initialize();
134
135 // V8 generally calls into generated JS code with 5 parameters and into
136 // generated RegExp code with 7 parameters. This is a convenience function,
137 // which sets up the simulator state and grabs the result on return.
138 int32_t Call(byte* entry, int argument_count, ...);
139
140 private:
141 enum special_values {
142 // Known bad pc value to ensure that the simulator does not execute
143 // without being properly setup.
144 bad_ra = -1,
145 // A pc value used to signal the simulator to stop execution. Generally
146 // the ra is set to this value on transition from native C code to
147 // simulated execution, so that the simulator can "return" to the native
148 // C code.
149 end_sim_pc = -2
150 };
151
152 // Unsupported instructions use Format to print an error and stop execution.
153 void Format(Instruction* instr, const char* format);
154
155 // Read and write memory.
156 inline uint32_t ReadBU(int32_t addr);
157 inline int32_t ReadB(int32_t addr);
158 inline void WriteB(int32_t addr, uint8_t value);
159 inline void WriteB(int32_t addr, int8_t value);
160
161 inline uint16_t ReadHU(int32_t addr, Instruction* instr);
162 inline int16_t ReadH(int32_t addr, Instruction* instr);
163 // Note: Overloaded on the sign of the value.
164 inline void WriteH(int32_t addr, uint16_t value, Instruction* instr);
165 inline void WriteH(int32_t addr, int16_t value, Instruction* instr);
166
167 inline int ReadW(int32_t addr, Instruction* instr);
168 inline void WriteW(int32_t addr, int value, Instruction* instr);
169
170 // Executing is handled based on the instruction type.
171 void DecodeType1(Instruction* instr);
172 void DecodeType3(Instruction* instr);
173 void DecodeType2(Instruction* instr);
174
175 // Executes one instruction.
176 void InstructionDecode(Instruction* instr);
177 // Execute one instruction placed in a branch delay slot.
178 void BranchDelayInstructionDecode(Instruction* instr) {
179 if(instr->isForbiddenInBranchDelay()) {
180 V8_Fatal(__FILE__, __LINE__,
181 "Eror:Unexpected %i opcode in a branch delay slot.",
182 instr->OpcodeField());
183 }
184 InstructionDecode(instr);
185 }
186
187 enum Exception {
188 none,
189 integer_overflow,
190 integer_underflow,
191 num_exceptions
192 };
193 int16_t exceptions[num_exceptions];
194
195 // Exceptions
196 void SignalExceptions();
197
198 // Runtime call support.
199 static void* RedirectExternalReference(void* external_function,
200 bool fp_return);
201
202 // architecture state
203 // Registers
204 int32_t registers_[num_registers];
205 // Coprocessor Registers
206 double Cregisters_[num_Cregisters];
207
208 // simulator support
209 char* stack_;
210 bool pc_modified_;
211 int icount_;
212 static bool initialized_;
213
214 // registered breakpoints
215 Instruction* break_pc_;
216 Instr break_instr_;
217 };
218
219 } } // namespace assembler::mips
220
221
222 // The simulator has its own stack. Thus it has a different stack limit from
223 // the C-based native code. Setting the c_limit to indicate a very small
224 // stack cause stack overflow errors, since the simulator ignores the input.
225 // This is unlikely to be an issue in practice, though it might cause testing
226 // trouble down the line.
227 class SimulatorStack : public v8::internal::AllStatic {
228 public:
229 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) {
230 return assembler::mips::Simulator::current()->StackLimit();
231 }
232 };
233
234 #endif // defined(__mips)
235
236 #endif // V8_MIPS_SIMULATOR_MIPS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698