12 #ifndef V8_MIPS_SIMULATOR_MIPS_H_ 13 #define V8_MIPS_SIMULATOR_MIPS_H_ 15 #include "src/allocation.h" 16 #include "src/mips/constants-mips.h" 18 #if defined(USE_SIMULATOR) 21 #include "src/assembler.h" 22 #include "src/base/hashmap.h" 23 #include "src/simulator-base.h" 33 static const int LINE_VALID = 0;
34 static const int LINE_INVALID = 1;
36 static const int kPageShift = 12;
37 static const int kPageSize = 1 << kPageShift;
38 static const int kPageMask = kPageSize - 1;
39 static const int kLineShift = 2;
40 static const int kLineLength = 1 << kLineShift;
41 static const int kLineMask = kLineLength - 1;
44 memset(&validity_map_, LINE_INVALID,
sizeof(validity_map_));
47 char* ValidityByte(
int offset) {
48 return &validity_map_[offset >> kLineShift];
51 char* CachedData(
int offset) {
52 return &data_[offset];
56 char data_[kPageSize];
57 static const int kValidityMapSize = kPageSize >> kLineShift;
58 char validity_map_[kValidityMapSize];
61 class SimInstructionBase :
public InstructionBase {
63 Type InstructionType()
const {
return type_; }
64 inline Instruction* instr()
const {
return instr_; }
65 inline int32_t operand()
const {
return operand_; }
68 SimInstructionBase() : operand_(-1), instr_(nullptr), type_(kUnsupported) {}
69 explicit SimInstructionBase(Instruction* instr) {}
76 DISALLOW_ASSIGN(SimInstructionBase);
79 class SimInstruction :
public InstructionGetters<SimInstructionBase> {
83 explicit SimInstruction(Instruction* instr) { *
this = instr; }
85 SimInstruction& operator=(Instruction* instr) {
86 operand_ = *
reinterpret_cast<const int32_t*
>(instr);
88 type_ = InstructionBase::InstructionType();
89 DCHECK(reinterpret_cast<void*>(&operand_) ==
this);
94 class Simulator :
public SimulatorBase {
96 friend class MipsDebugger;
105 t0, t1, t2, t3, t4, t5, t6, t7,
106 s0, s1, s2, s3, s4, s5, s6, s7,
125 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11,
127 f16, f17, f18, f19, f20, f21, f22, f23, f24, f25,
128 f26, f27, f28, f29, f30, f31,
169 explicit Simulator(Isolate* isolate);
179 void set_register(
int reg, int32_t value);
180 void set_dw_register(
int dreg,
const int* dbl);
181 int32_t get_register(
int reg)
const;
182 double get_double_from_register_pair(
int reg);
184 void set_fpu_register(
int fpureg,
int64_t value);
185 void set_fpu_register_word(
int fpureg, int32_t value);
186 void set_fpu_register_hi_word(
int fpureg, int32_t value);
187 void set_fpu_register_float(
int fpureg,
float value);
188 void set_fpu_register_double(
int fpureg,
double value);
189 void set_fpu_register_invalid_result64(
float original,
float rounded);
190 void set_fpu_register_invalid_result(
float original,
float rounded);
191 void set_fpu_register_word_invalid_result(
float original,
float rounded);
192 void set_fpu_register_invalid_result64(
double original,
double rounded);
193 void set_fpu_register_invalid_result(
double original,
double rounded);
194 void set_fpu_register_word_invalid_result(
double original,
double rounded);
195 int64_t get_fpu_register(
int fpureg)
const;
196 int32_t get_fpu_register_word(
int fpureg)
const;
197 int32_t get_fpu_register_signed_word(
int fpureg)
const;
198 int32_t get_fpu_register_hi_word(
int fpureg)
const;
199 float get_fpu_register_float(
int fpureg)
const;
200 double get_fpu_register_double(
int fpureg)
const;
201 template <
typename T>
202 void get_msa_register(
int wreg, T* value);
203 template <
typename T>
204 void set_msa_register(
int wreg,
const T* value);
205 void set_fcsr_bit(
uint32_t cc,
bool value);
207 void set_fcsr_rounding_mode(FPURoundingMode mode);
208 void set_msacsr_rounding_mode(FPURoundingMode mode);
209 unsigned int get_fcsr_rounding_mode();
210 unsigned int get_msacsr_rounding_mode();
211 bool set_fcsr_round_error(
double original,
double rounded);
212 bool set_fcsr_round_error(
float original,
float rounded);
213 bool set_fcsr_round64_error(
double original,
double rounded);
214 bool set_fcsr_round64_error(
float original,
float rounded);
215 void round_according_to_fcsr(
double toRound,
double& rounded,
216 int32_t& rounded_int,
double fs);
217 void round_according_to_fcsr(
float toRound,
float& rounded,
218 int32_t& rounded_int,
float fs);
219 template <
typename Tfp,
typename T
int>
220 void round_according_to_msacsr(Tfp toRound, Tfp& rounded, Tint& rounded_int);
221 void round64_according_to_fcsr(
double toRound,
double& rounded,
222 int64_t& rounded_int,
double fs);
223 void round64_according_to_fcsr(
float toRound,
float& rounded,
224 int64_t& rounded_int,
float fs);
226 void set_pc(int32_t value);
227 int32_t get_pc()
const;
229 Address get_sp()
const {
return static_cast<Address
>(get_register(sp)); }
237 template <
typename Return,
typename... Args>
238 Return Call(Address entry, Args... args) {
239 return VariadicCall<Return>(
this, &Simulator::CallImpl, entry, args...);
243 double CallFP(Address entry,
double d0,
double d1);
252 void set_last_debugger_input(
char* input);
253 char* last_debugger_input() {
return last_debugger_input_; }
256 static void SetRedirectInstruction(Instruction* instruction);
259 static bool ICacheMatch(
void* one,
void* two);
260 static void FlushICache(base::CustomMatcherHashMap* i_cache,
void* start,
265 bool has_bad_pc()
const;
268 enum special_values {
278 Unpredictable = 0xbadbeaf
281 V8_EXPORT_PRIVATE intptr_t CallImpl(Address entry,
int argument_count,
282 const intptr_t* arguments);
285 void Format(Instruction* instr,
const char* format);
288 enum TraceType { BYTE, HALF, WORD, DWORD, FLOAT, DOUBLE, FLOAT_DOUBLE };
291 enum MSADataFormat { MSA_VECT = 0, MSA_BYTE, MSA_HALF, MSA_WORD, MSA_DWORD };
293 int8_t b[kMSALanesByte];
294 uint8_t ub[kMSALanesByte];
295 int16_t h[kMSALanesHalf];
296 uint16_t uh[kMSALanesHalf];
297 int32_t w[kMSALanesWord];
300 uint64_t ud[kMSALanesDword];
304 inline uint32_t ReadBU(int32_t addr);
305 inline int32_t ReadB(int32_t addr);
306 inline void WriteB(int32_t addr, uint8_t value);
307 inline void WriteB(int32_t addr, int8_t value);
309 inline uint16_t ReadHU(int32_t addr, Instruction* instr);
310 inline int16_t ReadH(int32_t addr, Instruction* instr);
312 inline void WriteH(int32_t addr, uint16_t value, Instruction* instr);
313 inline void WriteH(int32_t addr, int16_t value, Instruction* instr);
315 inline int ReadW(int32_t addr, Instruction* instr, TraceType t = WORD);
316 inline void WriteW(int32_t addr,
int value, Instruction* instr);
318 inline double ReadD(int32_t addr, Instruction* instr);
319 inline void WriteD(int32_t addr,
double value, Instruction* instr);
321 template <
typename T>
322 T ReadMem(int32_t addr, Instruction* instr);
324 template <
typename T>
325 void WriteMem(int32_t addr, T value, Instruction* instr);
327 void TraceRegWr(int32_t value, TraceType t = WORD);
328 void TraceRegWr(
int64_t value, TraceType t = DWORD);
329 template <
typename T>
330 void TraceMSARegWr(T* value, TraceType t);
331 template <
typename T>
332 void TraceMSARegWr(T* value);
333 void TraceMemWr(int32_t addr, int32_t value, TraceType t = WORD);
334 void TraceMemRd(int32_t addr, int32_t value, TraceType t = WORD);
335 void TraceMemWr(int32_t addr,
int64_t value, TraceType t = DWORD);
336 void TraceMemRd(int32_t addr,
int64_t value, TraceType t = DWORD);
337 template <
typename T>
338 void TraceMemRd(int32_t addr, T value);
339 template <
typename T>
340 void TraceMemWr(int32_t addr, T value);
341 EmbeddedVector<char, 128> trace_buf_;
345 inline int32_t GetDoubleHIW(
double* addr);
346 inline int32_t GetDoubleLOW(
double* addr);
348 inline int32_t SetDoubleHIW(
double* addr);
349 inline int32_t SetDoubleLOW(
double* addr);
351 SimInstruction instr_;
354 void DecodeTypeRegister();
357 void DecodeTypeRegisterCOP1();
359 void DecodeTypeRegisterCOP1X();
361 void DecodeTypeRegisterSPECIAL();
363 void DecodeTypeRegisterSPECIAL2();
365 void DecodeTypeRegisterSPECIAL3();
368 void DecodeTypeRegisterSRsType();
370 void DecodeTypeRegisterDRsType();
372 void DecodeTypeRegisterWRsType();
374 void DecodeTypeRegisterLRsType();
376 int DecodeMsaDataFormat();
377 void DecodeTypeMsaI8();
378 void DecodeTypeMsaI5();
379 void DecodeTypeMsaI10();
380 void DecodeTypeMsaELM();
381 void DecodeTypeMsaBIT();
382 void DecodeTypeMsaMI10();
383 void DecodeTypeMsa3R();
384 void DecodeTypeMsa3RF();
385 void DecodeTypeMsaVec();
386 void DecodeTypeMsa2R();
387 void DecodeTypeMsa2RF();
388 template <
typename T>
389 T MsaI5InstrHelper(
uint32_t opcode, T ws, int32_t i5);
390 template <
typename T>
391 T MsaBitInstrHelper(
uint32_t opcode, T wd, T ws, int32_t m);
392 template <
typename T>
393 T Msa3RInstrHelper(
uint32_t opcode, T wd, T ws, T wt);
395 inline int32_t rs_reg()
const {
return instr_.RsValue(); }
396 inline int32_t rs()
const {
return get_register(rs_reg()); }
398 return static_cast<uint32_t>(get_register(rs_reg()));
400 inline int32_t rt_reg()
const {
return instr_.RtValue(); }
401 inline int32_t rt()
const {
return get_register(rt_reg()); }
403 return static_cast<uint32_t>(get_register(rt_reg()));
405 inline int32_t rd_reg()
const {
return instr_.RdValue(); }
406 inline int32_t fr_reg()
const {
return instr_.FrValue(); }
407 inline int32_t fs_reg()
const {
return instr_.FsValue(); }
408 inline int32_t ft_reg()
const {
return instr_.FtValue(); }
409 inline int32_t fd_reg()
const {
return instr_.FdValue(); }
410 inline int32_t sa()
const {
return instr_.SaValue(); }
411 inline int32_t lsa_sa()
const {
return instr_.LsaSaValue(); }
412 inline int32_t ws_reg()
const {
return instr_.WsValue(); }
413 inline int32_t wt_reg()
const {
return instr_.WtValue(); }
414 inline int32_t wd_reg()
const {
return instr_.WdValue(); }
416 inline void SetResult(int32_t rd_reg, int32_t alu_out) {
417 set_register(rd_reg, alu_out);
421 inline void SetFPUWordResult(int32_t fd_reg, int32_t alu_out) {
422 set_fpu_register_word(fd_reg, alu_out);
423 TraceRegWr(get_fpu_register_word(fd_reg));
426 inline void SetFPUResult(int32_t fd_reg,
int64_t alu_out) {
427 set_fpu_register(fd_reg, alu_out);
428 TraceRegWr(get_fpu_register(fd_reg));
431 inline void SetFPUFloatResult(int32_t fd_reg,
float alu_out) {
432 set_fpu_register_float(fd_reg, alu_out);
433 TraceRegWr(get_fpu_register_word(fd_reg), FLOAT);
436 inline void SetFPUDoubleResult(int32_t fd_reg,
double alu_out) {
437 set_fpu_register_double(fd_reg, alu_out);
438 TraceRegWr(get_fpu_register(fd_reg), DOUBLE);
441 void DecodeTypeImmediate();
442 void DecodeTypeJump();
445 void SoftwareInterrupt();
448 void CheckForbiddenSlot(int32_t current_pc) {
449 Instruction* instr_after_compact_branch =
450 reinterpret_cast<Instruction*
>(current_pc + kInstrSize);
451 if (instr_after_compact_branch->IsForbiddenAfterBranch()) {
453 "Error: Unexpected instruction 0x%08x immediately after a " 454 "compact branch instruction.",
455 *reinterpret_cast<uint32_t*>(instr_after_compact_branch));
461 void PrintWatchpoint(
uint32_t code);
462 void HandleStop(
uint32_t code, Instruction* instr);
463 bool IsStopInstruction(Instruction* instr);
467 void IncreaseStopCounter(
uint32_t code);
472 void InstructionDecode(Instruction* instr);
474 void BranchDelayInstructionDecode(Instruction* instr) {
475 if (instr->InstructionBits() == nopInstr) {
481 if (instr->IsForbiddenInBranchDelay()) {
482 FATAL(
"Eror:Unexpected %i opcode in a branch delay slot.",
483 instr->OpcodeValue());
485 InstructionDecode(instr);
486 SNPrintF(trace_buf_,
" ");
490 static void CheckICache(base::CustomMatcherHashMap* i_cache,
492 static void FlushOnePage(base::CustomMatcherHashMap* i_cache, intptr_t start,
494 static CachePage* GetCachePage(base::CustomMatcherHashMap* i_cache,
506 void SignalException(Exception e);
509 void GetFpArgs(
double* x,
double* y, int32_t* z);
510 void SetFpResult(
const double& result);
512 void CallInternal(Address entry);
516 int32_t registers_[kNumSimuRegisters];
522 int64_t FPUregisters_[kNumFPURegisters * 2];
530 static const size_t stack_size_ = 1 * 1024*1024;
537 char* last_debugger_input_;
542 Instruction* break_pc_;
546 static const uint32_t kStopDisabledBit = 1 << 31;
552 struct StopCountAndDesc {
556 StopCountAndDesc watched_stops_[kMaxStopCode + 1];
562 #endif // defined(USE_SIMULATOR) 563 #endif // V8_MIPS_SIMULATOR_MIPS_H_