From 201436d4bd12167ccd723dc737618ceaf3d1cd79 Mon Sep 17 00:00:00 2001 From: "jochen@chromium.org" Date: Wed, 26 Feb 2014 14:50:58 +0000 Subject: [PATCH] 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 --- src/a64/decoder-a64.h | 3 ++- src/a64/simulator-a64.cc | 46 +++++++++++++++++++++++++++++++++------------- src/a64/simulator-a64.h | 17 +++++++++++++++-- src/flag-definitions.h | 1 + 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/a64/decoder-a64.h b/src/a64/decoder-a64.h index 8ad6b44..22a7e35 100644 --- a/src/a64/decoder-a64.h +++ b/src/a64/decoder-a64.h @@ -146,10 +146,11 @@ template class Decoder : public V { public: Decoder() {} + virtual ~Decoder() {} // Top-level instruction decoder function. Decodes an instruction and calls // the visitor functions registered with the Decoder class. - void Decode(Instruction *instr); + virtual void Decode(Instruction *instr); private: // Decode the PC relative addressing instruction, and call the corresponding diff --git a/src/a64/simulator-a64.cc b/src/a64/simulator-a64.cc index f337690..1ae0bf0 100644 --- a/src/a64/simulator-a64.cc +++ b/src/a64/simulator-a64.cc @@ -105,8 +105,12 @@ Simulator* Simulator::current(Isolate* isolate) { Simulator* sim = isolate_data->simulator(); if (sim == NULL) { - // TODO(146): delete the simulator object when a thread/isolate goes away. - sim = new Simulator(new Decoder(), isolate); + if (FLAG_trace_sim || FLAG_log_instruction_stats || FLAG_debug_sim) { + sim = new Simulator(new Decoder(), isolate); + } else { + sim = new Decoder(); + sim->isolate_ = isolate; + } isolate_data->set_simulator(sim); } return sim; @@ -343,6 +347,32 @@ Simulator::Simulator(Decoder* decoder, // Setup the decoder. 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(); // Allocate and setup the simulator stack. @@ -356,21 +386,10 @@ Simulator::Simulator(Decoder* decoder, stream_ = 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 // instruction, so we create a dedicated decoder. disassembler_decoder_ = new Decoder(); 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() { delete disassembler_decoder_; delete print_disasm_; DeleteArray(last_debugger_input_); + delete decoder_; } diff --git a/src/a64/simulator-a64.h b/src/a64/simulator-a64.h index 73d7a85..c4f1472 100644 --- a/src/a64/simulator-a64.h +++ b/src/a64/simulator-a64.h @@ -195,6 +195,7 @@ class Simulator : public DecoderVisitor { explicit Simulator(Decoder* decoder, Isolate* isolate = NULL, FILE* stream = stderr); + Simulator(); ~Simulator(); // System functions. @@ -334,10 +335,14 @@ class Simulator : public DecoderVisitor { pc_modified_ = false; } + virtual void Decode(Instruction* instr) { + decoder_->Decode(instr); + } + void ExecuteInstruction() { ASSERT(IsAligned(reinterpret_cast(pc_), kInstructionSize)); CheckBreakNext(); - decoder_->Decode(pc_); + Decode(pc_); LogProcessorState(); increment_pc(); CheckBreakpoints(); @@ -582,12 +587,18 @@ class Simulator : public DecoderVisitor { int log_parameters() { return log_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) { decoder_->InsertVisitorBefore(print_disasm_, this); } else { decoder_->RemoveVisitor(print_disasm_); } - log_parameters_ = new_parameters; } static inline const char* WRegNameForCode(unsigned code, @@ -819,6 +830,8 @@ class Simulator : public DecoderVisitor { char* last_debugger_input_; private: + void Init(FILE* stream); + int log_parameters_; Isolate* isolate_; }; diff --git a/src/flag-definitions.h b/src/flag-definitions.h index e7da42e..bd8cbe3 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -585,6 +585,7 @@ DEFINE_bool(trace_parse, false, "trace parsing and preparsing") // simulator-arm.cc, simulator-a64.cc and simulator-mips.cc DEFINE_bool(trace_sim, false, "Trace simulator execution") +DEFINE_bool(debug_sim, false, "Enable debugging the simulator") DEFINE_bool(check_icache, false, "Check icache flushes in ARM and MIPS simulator") DEFINE_int(stop_sim_at, 0, "Simulator stop after x number of instructions") -- 2.7.4