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

Side by Side Diff: src/mips/simulator-mips.h

Issue 6709022: Re-establish mips basic infrastructure. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 9 years, 9 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
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 19 matching lines...) Expand all
30 // MIPS binary. This Simulator allows us to run and debug MIPS code generation 30 // MIPS binary. This Simulator allows us to run and debug MIPS code generation
31 // on regular desktop machines. 31 // on regular desktop machines.
32 // V8 calls into generated code by "calling" the CALL_GENERATED_CODE macro, 32 // V8 calls into generated code by "calling" the CALL_GENERATED_CODE macro,
33 // which will start execution in the Simulator or forwards to the real entry 33 // which will start execution in the Simulator or forwards to the real entry
34 // on a MIPS HW platform. 34 // on a MIPS HW platform.
35 35
36 #ifndef V8_MIPS_SIMULATOR_MIPS_H_ 36 #ifndef V8_MIPS_SIMULATOR_MIPS_H_
37 #define V8_MIPS_SIMULATOR_MIPS_H_ 37 #define V8_MIPS_SIMULATOR_MIPS_H_
38 38
39 #include "allocation.h" 39 #include "allocation.h"
40 #include "constants-mips.h"
40 41
41 #if defined(__mips) && !defined(USE_SIMULATOR) 42 #if !defined(USE_SIMULATOR)
43 // Running without a simulator on a native mips platform.
44
45 namespace v8 {
46 namespace internal {
42 47
43 // When running without a simulator we call the entry directly. 48 // When running without a simulator we call the entry directly.
44 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \ 49 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \
45 entry(p0, p1, p2, p3, p4); 50 entry(p0, p1, p2, p3, p4)
51
52 typedef int (*mips_regexp_matcher)(String*, int, const byte*, const byte*,
53 void*, int*, Address, int);
54
55 // Call the generated regexp code directly. The code at the entry address
56 // should act as a function matching the type arm_regexp_matcher.
57 // The fifth argument is a dummy that reserves the space used for
58 // the return address added by the ExitFrame in native calls.
59 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \
60 (FUNCTION_CAST<mips_regexp_matcher>(entry)(p0, p1, p2, p3, NULL, p4, p5, p6))
61
62 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \
63 (reinterpret_cast<TryCatch*>(try_catch_address))
46 64
47 // The stack limit beyond which we will throw stack overflow errors in 65 // The stack limit beyond which we will throw stack overflow errors in
48 // generated code. Because generated code on mips uses the C stack, we 66 // generated code. Because generated code on mips uses the C stack, we
49 // just use the C stack limit. 67 // just use the C stack limit.
50 class SimulatorStack : public v8::internal::AllStatic { 68 class SimulatorStack : public v8::internal::AllStatic {
51 public: 69 public:
52 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) { 70 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) {
53 return c_limit; 71 return c_limit;
54 } 72 }
55 73
56 static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) { 74 static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) {
57 return try_catch_address; 75 return try_catch_address;
58 } 76 }
59 77
60 static inline void UnregisterCTryCatch() { } 78 static inline void UnregisterCTryCatch() { }
61 }; 79 };
62 80
81 } } // namespace v8::internal
82
63 // Calculated the stack limit beyond which we will throw stack overflow errors. 83 // Calculated the stack limit beyond which we will throw stack overflow errors.
64 // This macro must be called from a C++ method. It relies on being able to take 84 // This macro must be called from a C++ method. It relies on being able to take
65 // the address of "this" to get a value on the current execution stack and then 85 // the address of "this" to get a value on the current execution stack and then
66 // calculates the stack limit based on that value. 86 // calculates the stack limit based on that value.
67 // NOTE: The check for overflow is not safe as there is no guarantee that the 87 // NOTE: The check for overflow is not safe as there is no guarantee that the
68 // running thread has its stack in all memory up to address 0x00000000. 88 // running thread has its stack in all memory up to address 0x00000000.
69 #define GENERATED_CODE_STACK_LIMIT(limit) \ 89 #define GENERATED_CODE_STACK_LIMIT(limit) \
70 (reinterpret_cast<uintptr_t>(this) >= limit ? \ 90 (reinterpret_cast<uintptr_t>(this) >= limit ? \
71 reinterpret_cast<uintptr_t>(this) - limit : 0) 91 reinterpret_cast<uintptr_t>(this) - limit : 0)
72 92
73 // Call the generated regexp code directly. The entry function pointer should 93 #else // !defined(USE_SIMULATOR)
74 // expect seven int/pointer sized arguments and return an int. 94 // Running with a simulator.
75 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \
76 entry(p0, p1, p2, p3, p4, p5, p6)
77 95
78 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \ 96 #include "hashmap.h"
79 reinterpret_cast<TryCatch*>(try_catch_address)
80 97
98 namespace v8 {
99 namespace internal {
81 100
82 #else // #if !defined(__mips) || defined(USE_SIMULATOR) 101 // -----------------------------------------------------------------------------
102 // Utility functions
83 103
84 // When running with the simulator transition into simulated execution at this 104 class CachePage {
85 // point. 105 public:
86 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \ 106 static const int LINE_VALID = 0;
87 reinterpret_cast<Object*>(\ 107 static const int LINE_INVALID = 1;
88 assembler::mips::Simulator::current()->Call(FUNCTION_ADDR(entry), 5, \
89 p0, p1, p2, p3, p4))
90 108
91 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \ 109 static const int kPageShift = 12;
92 assembler::mips::Simulator::current()->Call(\ 110 static const int kPageSize = 1 << kPageShift;
93 FUNCTION_ADDR(entry), 7, p0, p1, p2, p3, p4, p5, p6) 111 static const int kPageMask = kPageSize - 1;
112 static const int kLineShift = 2; // The cache line is only 4 bytes right now.
113 static const int kLineLength = 1 << kLineShift;
114 static const int kLineMask = kLineLength - 1;
94 115
95 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \ 116 CachePage() {
96 try_catch_address == NULL ? \ 117 memset(&validity_map_, LINE_INVALID, sizeof(validity_map_));
97 NULL : *(reinterpret_cast<TryCatch**>(try_catch_address)) 118 }
98 119
120 char* ValidityByte(int offset) {
121 return &validity_map_[offset >> kLineShift];
122 }
99 123
100 namespace assembler { 124 char* CachedData(int offset) {
101 namespace mips { 125 return &data_[offset];
126 }
127
128 private:
129 char data_[kPageSize]; // The cached data.
130 static const int kValidityMapSize = kPageSize >> kLineShift;
131 char validity_map_[kValidityMapSize]; // One byte per line.
132 };
102 133
103 class Simulator { 134 class Simulator {
104 public: 135 public:
105 friend class Debugger; 136 friend class Debugger;
106 137
107 // Registers are declared in order. See SMRL chapter 2. 138 // Registers are declared in order. See SMRL chapter 2.
108 enum Register { 139 enum Register {
109 no_reg = -1, 140 no_reg = -1,
110 zero_reg = 0, 141 zero_reg = 0,
111 at, 142 at,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // for each native thread. 176 // for each native thread.
146 static Simulator* current(); 177 static Simulator* current();
147 178
148 // Accessors for register state. Reading the pc value adheres to the MIPS 179 // Accessors for register state. Reading the pc value adheres to the MIPS
149 // architecture specification and is off by a 8 from the currently executing 180 // architecture specification and is off by a 8 from the currently executing
150 // instruction. 181 // instruction.
151 void set_register(int reg, int32_t value); 182 void set_register(int reg, int32_t value);
152 int32_t get_register(int reg) const; 183 int32_t get_register(int reg) const;
153 // Same for FPURegisters 184 // Same for FPURegisters
154 void set_fpu_register(int fpureg, int32_t value); 185 void set_fpu_register(int fpureg, int32_t value);
186 void set_fpu_register_float(int fpureg, float value);
155 void set_fpu_register_double(int fpureg, double value); 187 void set_fpu_register_double(int fpureg, double value);
156 int32_t get_fpu_register(int fpureg) const; 188 int32_t get_fpu_register(int fpureg) const;
189 int64_t get_fpu_register_long(int fpureg) const;
190 float get_fpu_register_float(int fpureg) const;
157 double get_fpu_register_double(int fpureg) const; 191 double get_fpu_register_double(int fpureg) const;
192 void set_fcsr_bit(uint32_t cc, bool value);
193 bool test_fcsr_bit(uint32_t cc);
194 bool set_fcsr_round_error(double original, double rounded);
158 195
159 // Special case of set_register and get_register to access the raw PC value. 196 // Special case of set_register and get_register to access the raw PC value.
160 void set_pc(int32_t value); 197 void set_pc(int32_t value);
161 int32_t get_pc() const; 198 int32_t get_pc() const;
162 199
163 // Accessor to the internal simulator stack area. 200 // Accessor to the internal simulator stack area.
164 uintptr_t StackLimit() const; 201 uintptr_t StackLimit() const;
165 202
166 // Executes MIPS instructions until the PC reaches end_sim_pc. 203 // Executes MIPS instructions until the PC reaches end_sim_pc.
167 void Execute(); 204 void Execute();
168 205
169 // Call on program start. 206 // Call on program start.
170 static void Initialize(); 207 static void Initialize();
171 208
172 // V8 generally calls into generated JS code with 5 parameters and into 209 // V8 generally calls into generated JS code with 5 parameters and into
173 // generated RegExp code with 7 parameters. This is a convenience function, 210 // generated RegExp code with 7 parameters. This is a convenience function,
174 // which sets up the simulator state and grabs the result on return. 211 // which sets up the simulator state and grabs the result on return.
175 int32_t Call(byte_* entry, int argument_count, ...); 212 int32_t Call(byte* entry, int argument_count, ...);
176 213
177 // Push an address onto the JS stack. 214 // Push an address onto the JS stack.
178 uintptr_t PushAddress(uintptr_t address); 215 uintptr_t PushAddress(uintptr_t address);
179 216
180 // Pop an address from the JS stack. 217 // Pop an address from the JS stack.
181 uintptr_t PopAddress(); 218 uintptr_t PopAddress();
182 219
220 // ICache checking.
221 static void FlushICache(void* start, size_t size);
222
223 // Returns true if pc register contains one of the 'special_values' defined
224 // below (bad_ra, end_sim_pc).
225 bool has_bad_pc() const;
226
183 private: 227 private:
184 enum special_values { 228 enum special_values {
185 // Known bad pc value to ensure that the simulator does not execute 229 // Known bad pc value to ensure that the simulator does not execute
186 // without being properly setup. 230 // without being properly setup.
187 bad_ra = -1, 231 bad_ra = -1,
188 // A pc value used to signal the simulator to stop execution. Generally 232 // A pc value used to signal the simulator to stop execution. Generally
189 // the ra is set to this value on transition from native C code to 233 // the ra is set to this value on transition from native C code to
190 // simulated execution, so that the simulator can "return" to the native 234 // simulated execution, so that the simulator can "return" to the native
191 // C code. 235 // C code.
192 end_sim_pc = -2, 236 end_sim_pc = -2,
(...skipping 26 matching lines...) Expand all
219 // Get Double Higher / Lower word. 263 // Get Double Higher / Lower word.
220 inline int32_t GetDoubleHIW(double* addr); 264 inline int32_t GetDoubleHIW(double* addr);
221 inline int32_t GetDoubleLOW(double* addr); 265 inline int32_t GetDoubleLOW(double* addr);
222 // Set Double Higher / Lower word. 266 // Set Double Higher / Lower word.
223 inline int32_t SetDoubleHIW(double* addr); 267 inline int32_t SetDoubleHIW(double* addr);
224 inline int32_t SetDoubleLOW(double* addr); 268 inline int32_t SetDoubleLOW(double* addr);
225 269
226 270
227 // Executing is handled based on the instruction type. 271 // Executing is handled based on the instruction type.
228 void DecodeTypeRegister(Instruction* instr); 272 void DecodeTypeRegister(Instruction* instr);
273
274 // Helper function for DecodeTypeRegister.
275 void ConfigureTypeRegister(Instruction* instr,
276 int32_t& alu_out,
277 int64_t& i64hilo,
278 uint64_t& u64hilo,
279 int32_t& next_pc,
280 bool& do_interrupt);
281
229 void DecodeTypeImmediate(Instruction* instr); 282 void DecodeTypeImmediate(Instruction* instr);
230 void DecodeTypeJump(Instruction* instr); 283 void DecodeTypeJump(Instruction* instr);
231 284
232 // Used for breakpoints and traps. 285 // Used for breakpoints and traps.
233 void SoftwareInterrupt(Instruction* instr); 286 void SoftwareInterrupt(Instruction* instr);
234 287
235 // Executes one instruction. 288 // Executes one instruction.
236 void InstructionDecode(Instruction* instr); 289 void InstructionDecode(Instruction* instr);
237 // Execute one instruction placed in a branch delay slot. 290 // Execute one instruction placed in a branch delay slot.
238 void BranchDelayInstructionDecode(Instruction* instr) { 291 void BranchDelayInstructionDecode(Instruction* instr) {
239 if (instr->IsForbiddenInBranchDelay()) { 292 if (instr->IsForbiddenInBranchDelay()) {
240 V8_Fatal(__FILE__, __LINE__, 293 V8_Fatal(__FILE__, __LINE__,
241 "Eror:Unexpected %i opcode in a branch delay slot.", 294 "Eror:Unexpected %i opcode in a branch delay slot.",
242 instr->OpcodeField()); 295 instr->OpcodeValue());
243 } 296 }
244 InstructionDecode(instr); 297 InstructionDecode(instr);
245 } 298 }
246 299
300 // ICache.
301 static void CheckICache(Instruction* instr);
302 static void FlushOnePage(intptr_t start, int size);
303 static CachePage* GetCachePage(void* page);
304
305
247 enum Exception { 306 enum Exception {
248 none, 307 none,
249 kIntegerOverflow, 308 kIntegerOverflow,
250 kIntegerUnderflow, 309 kIntegerUnderflow,
251 kDivideByZero, 310 kDivideByZero,
252 kNumExceptions 311 kNumExceptions
253 }; 312 };
254 int16_t exceptions[kNumExceptions]; 313 int16_t exceptions[kNumExceptions];
255 314
256 // Exceptions. 315 // Exceptions.
257 void SignalExceptions(); 316 void SignalExceptions();
258 317
259 // Runtime call support. 318 // Runtime call support.
260 static void* RedirectExternalReference(void* external_function, 319 static void* RedirectExternalReference(void* external_function,
261 bool fp_return); 320 ExternalReference::Type type);
262 321
263 // Used for real time calls that takes two double values as arguments and 322 // Used for real time calls that takes two double values as arguments and
264 // returns a double. 323 // returns a double.
265 void SetFpResult(double result); 324 void SetFpResult(double result);
266 325
267 // Architecture state. 326 // Architecture state.
268 // Registers. 327 // Registers.
269 int32_t registers_[kNumSimuRegisters]; 328 int32_t registers_[kNumSimuRegisters];
270 // Coprocessor Registers. 329 // Coprocessor Registers.
271 int32_t FPUregisters_[kNumFPURegisters]; 330 int32_t FPUregisters_[kNumFPURegisters];
331 // FPU control register.
332 uint32_t FCSR_;
272 333
273 // Simulator support. 334 // Simulator support.
335 // Allocate 1MB for stack.
336 static const size_t stack_size_ = 1 * 1024*1024;
274 char* stack_; 337 char* stack_;
275 bool pc_modified_; 338 bool pc_modified_;
276 int icount_; 339 int icount_;
277 static bool initialized_; 340 static bool initialized_;
341 int break_count_;
342
343 // Icache simulation
344 static v8::internal::HashMap* i_cache_;
278 345
279 // Registered breakpoints. 346 // Registered breakpoints.
280 Instruction* break_pc_; 347 Instruction* break_pc_;
281 Instr break_instr_; 348 Instr break_instr_;
282 }; 349 };
283 350
284 } } // namespace assembler::mips 351
352 // When running with the simulator transition into simulated execution at this
353 // point.
354 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \
355 reinterpret_cast<Object*>(Simulator::current()->Call( \
356 FUNCTION_ADDR(entry), 5, p0, p1, p2, p3, p4))
357
358 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \
359 Simulator::current()->Call(entry, 8, p0, p1, p2, p3, NULL, p4, p5, p6)
360
361 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \
362 try_catch_address == \
363 NULL ? NULL : *(reinterpret_cast<TryCatch**>(try_catch_address))
285 364
286 365
287 // The simulator has its own stack. Thus it has a different stack limit from 366 // The simulator has its own stack. Thus it has a different stack limit from
288 // the C-based native code. Setting the c_limit to indicate a very small 367 // the C-based native code. Setting the c_limit to indicate a very small
289 // stack cause stack overflow errors, since the simulator ignores the input. 368 // stack cause stack overflow errors, since the simulator ignores the input.
290 // This is unlikely to be an issue in practice, though it might cause testing 369 // This is unlikely to be an issue in practice, though it might cause testing
291 // trouble down the line. 370 // trouble down the line.
292 class SimulatorStack : public v8::internal::AllStatic { 371 class SimulatorStack : public v8::internal::AllStatic {
293 public: 372 public:
294 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) { 373 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) {
295 return assembler::mips::Simulator::current()->StackLimit(); 374 return Simulator::current()->StackLimit();
296 } 375 }
297 376
298 static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) { 377 static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) {
299 assembler::mips::Simulator* sim = assembler::mips::Simulator::current(); 378 Simulator* sim = Simulator::current();
300 return sim->PushAddress(try_catch_address); 379 return sim->PushAddress(try_catch_address);
301 } 380 }
302 381
303 static inline void UnregisterCTryCatch() { 382 static inline void UnregisterCTryCatch() {
304 assembler::mips::Simulator::current()->PopAddress(); 383 Simulator::current()->PopAddress();
305 } 384 }
306 }; 385 };
307 386
308 #endif // !defined(__mips) || defined(USE_SIMULATOR) 387 } } // namespace v8::internal
309 388
389 #endif // !defined(USE_SIMULATOR)
310 #endif // V8_MIPS_SIMULATOR_MIPS_H_ 390 #endif // V8_MIPS_SIMULATOR_MIPS_H_
311 391
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698