Commit 201436d4 authored by jochen@chromium.org's avatar jochen@chromium.org

A64: Hardwire the decoder and the simulator

If one of --trace-sim --debug-sim or --log-instruction-stats flags is
given, we use the decoder dispatcher instead.

BUG=none
R=rodolph.perfetta@arm.com, ulan@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/177533023

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19564 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 597a4b4d
...@@ -146,10 +146,11 @@ template<typename V> ...@@ -146,10 +146,11 @@ template<typename V>
class Decoder : public V { class Decoder : public V {
public: public:
Decoder() {} Decoder() {}
virtual ~Decoder() {}
// Top-level instruction decoder function. Decodes an instruction and calls // Top-level instruction decoder function. Decodes an instruction and calls
// the visitor functions registered with the Decoder class. // the visitor functions registered with the Decoder class.
void Decode(Instruction *instr); virtual void Decode(Instruction *instr);
private: private:
// Decode the PC relative addressing instruction, and call the corresponding // Decode the PC relative addressing instruction, and call the corresponding
......
...@@ -105,8 +105,12 @@ Simulator* Simulator::current(Isolate* isolate) { ...@@ -105,8 +105,12 @@ Simulator* Simulator::current(Isolate* isolate) {
Simulator* sim = isolate_data->simulator(); Simulator* sim = isolate_data->simulator();
if (sim == NULL) { if (sim == NULL) {
// TODO(146): delete the simulator object when a thread/isolate goes away. if (FLAG_trace_sim || FLAG_log_instruction_stats || FLAG_debug_sim) {
sim = new Simulator(new Decoder<DispatchingDecoderVisitor>(), isolate); sim = new Simulator(new Decoder<DispatchingDecoderVisitor>(), isolate);
} else {
sim = new Decoder<Simulator>();
sim->isolate_ = isolate;
}
isolate_data->set_simulator(sim); isolate_data->set_simulator(sim);
} }
return sim; return sim;
...@@ -343,6 +347,32 @@ Simulator::Simulator(Decoder<DispatchingDecoderVisitor>* decoder, ...@@ -343,6 +347,32 @@ Simulator::Simulator(Decoder<DispatchingDecoderVisitor>* decoder,
// Setup the decoder. // Setup the decoder.
decoder_->AppendVisitor(this); decoder_->AppendVisitor(this);
Init(stream);
if (FLAG_trace_sim) {
decoder_->InsertVisitorBefore(print_disasm_, this);
log_parameters_ = LOG_ALL;
}
if (FLAG_log_instruction_stats) {
instrument_ = new Instrument(FLAG_log_instruction_file,
FLAG_log_instruction_period);
decoder_->AppendVisitor(instrument_);
}
}
Simulator::Simulator()
: decoder_(NULL),
last_debugger_input_(NULL),
log_parameters_(NO_PARAM),
isolate_(NULL) {
Init(NULL);
CHECK(!FLAG_trace_sim && !FLAG_log_instruction_stats);
}
void Simulator::Init(FILE* stream) {
ResetState(); ResetState();
// Allocate and setup the simulator stack. // Allocate and setup the simulator stack.
...@@ -356,21 +386,10 @@ Simulator::Simulator(Decoder<DispatchingDecoderVisitor>* decoder, ...@@ -356,21 +386,10 @@ Simulator::Simulator(Decoder<DispatchingDecoderVisitor>* decoder,
stream_ = stream; stream_ = stream;
print_disasm_ = new PrintDisassembler(stream_); print_disasm_ = new PrintDisassembler(stream_);
if (FLAG_trace_sim) {
decoder_->InsertVisitorBefore(print_disasm_, this);
log_parameters_ = LOG_ALL;
}
// The debugger needs to disassemble code without the simulator executing an // The debugger needs to disassemble code without the simulator executing an
// instruction, so we create a dedicated decoder. // instruction, so we create a dedicated decoder.
disassembler_decoder_ = new Decoder<DispatchingDecoderVisitor>(); disassembler_decoder_ = new Decoder<DispatchingDecoderVisitor>();
disassembler_decoder_->AppendVisitor(print_disasm_); disassembler_decoder_->AppendVisitor(print_disasm_);
if (FLAG_log_instruction_stats) {
instrument_ = new Instrument(FLAG_log_instruction_file,
FLAG_log_instruction_period);
decoder_->AppendVisitor(instrument_);
}
} }
...@@ -405,6 +424,7 @@ Simulator::~Simulator() { ...@@ -405,6 +424,7 @@ Simulator::~Simulator() {
delete disassembler_decoder_; delete disassembler_decoder_;
delete print_disasm_; delete print_disasm_;
DeleteArray(last_debugger_input_); DeleteArray(last_debugger_input_);
delete decoder_;
} }
......
...@@ -195,6 +195,7 @@ class Simulator : public DecoderVisitor { ...@@ -195,6 +195,7 @@ class Simulator : public DecoderVisitor {
explicit Simulator(Decoder<DispatchingDecoderVisitor>* decoder, explicit Simulator(Decoder<DispatchingDecoderVisitor>* decoder,
Isolate* isolate = NULL, Isolate* isolate = NULL,
FILE* stream = stderr); FILE* stream = stderr);
Simulator();
~Simulator(); ~Simulator();
// System functions. // System functions.
...@@ -334,10 +335,14 @@ class Simulator : public DecoderVisitor { ...@@ -334,10 +335,14 @@ class Simulator : public DecoderVisitor {
pc_modified_ = false; pc_modified_ = false;
} }
virtual void Decode(Instruction* instr) {
decoder_->Decode(instr);
}
void ExecuteInstruction() { void ExecuteInstruction() {
ASSERT(IsAligned(reinterpret_cast<uintptr_t>(pc_), kInstructionSize)); ASSERT(IsAligned(reinterpret_cast<uintptr_t>(pc_), kInstructionSize));
CheckBreakNext(); CheckBreakNext();
decoder_->Decode(pc_); Decode(pc_);
LogProcessorState(); LogProcessorState();
increment_pc(); increment_pc();
CheckBreakpoints(); CheckBreakpoints();
...@@ -582,12 +587,18 @@ class Simulator : public DecoderVisitor { ...@@ -582,12 +587,18 @@ class Simulator : public DecoderVisitor {
int log_parameters() { return log_parameters_; } int log_parameters() { return log_parameters_; }
void set_log_parameters(int new_parameters) { void set_log_parameters(int new_parameters) {
log_parameters_ = new_parameters;
if (!decoder_) {
if (new_parameters & LOG_DISASM) {
PrintF("Run --debug-sim to dynamically turn on disassembler\n");
}
return;
}
if (new_parameters & LOG_DISASM) { if (new_parameters & LOG_DISASM) {
decoder_->InsertVisitorBefore(print_disasm_, this); decoder_->InsertVisitorBefore(print_disasm_, this);
} else { } else {
decoder_->RemoveVisitor(print_disasm_); decoder_->RemoveVisitor(print_disasm_);
} }
log_parameters_ = new_parameters;
} }
static inline const char* WRegNameForCode(unsigned code, static inline const char* WRegNameForCode(unsigned code,
...@@ -819,6 +830,8 @@ class Simulator : public DecoderVisitor { ...@@ -819,6 +830,8 @@ class Simulator : public DecoderVisitor {
char* last_debugger_input_; char* last_debugger_input_;
private: private:
void Init(FILE* stream);
int log_parameters_; int log_parameters_;
Isolate* isolate_; Isolate* isolate_;
}; };
......
...@@ -585,6 +585,7 @@ DEFINE_bool(trace_parse, false, "trace parsing and preparsing") ...@@ -585,6 +585,7 @@ DEFINE_bool(trace_parse, false, "trace parsing and preparsing")
// simulator-arm.cc, simulator-a64.cc and simulator-mips.cc // simulator-arm.cc, simulator-a64.cc and simulator-mips.cc
DEFINE_bool(trace_sim, false, "Trace simulator execution") DEFINE_bool(trace_sim, false, "Trace simulator execution")
DEFINE_bool(debug_sim, false, "Enable debugging the simulator")
DEFINE_bool(check_icache, false, DEFINE_bool(check_icache, false,
"Check icache flushes in ARM and MIPS simulator") "Check icache flushes in ARM and MIPS simulator")
DEFINE_int(stop_sim_at, 0, "Simulator stop after x number of instructions") DEFINE_int(stop_sim_at, 0, "Simulator stop after x number of instructions")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment