From 1bffedd1c0a205fc4790e3269ac1d92cf234c57d Mon Sep 17 00:00:00 2001 From: Saurabh Singh Date: Sat, 24 Feb 2024 14:40:33 -0500 Subject: [PATCH] Add support for historyfile in atomsim debug mode - read historyfile when entering interactive mode (create if necessary), write to history file after each command. - print cycles when exiting atomsim --- .gitignore | 2 +- sim/atomsim.cpp | 2 +- sim/interactive.cpp | 27 +++++++++++++++++++++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index fd3b82ca..793aba91 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,6 @@ docs/_build/ *.out *.vcd python/ - +.atomsim_history simport userport \ No newline at end of file diff --git a/sim/atomsim.cpp b/sim/atomsim.cpp index aa6a1e5a..0aa114ae 100755 --- a/sim/atomsim.cpp +++ b/sim/atomsim.cpp @@ -82,7 +82,7 @@ int Atomsim::run() // check ebreak if(simstate_.state_.ins_e == RV_INSTR_EBREAK) { - printf("EBreak hit at %s0x%08x%s\n", ansicode(FG_BLUE), simstate_.state_.pc_e, ansicode(FG_RESET)); + printf("EBreak hit at %ld ticks, PC=%s0x%08x%s\n", simstate_.state_.tickcount_total, ansicode(FG_BLUE), simstate_.state_.pc_e, ansicode(FG_RESET)); if(sim_config_.dump_on_ebreak_flag) // For SCAR simstate_.dump_simstate(sim_config_.dump_file); diff --git a/sim/interactive.cpp b/sim/interactive.cpp index 41503588..03bb7e54 100755 --- a/sim/interactive.cpp +++ b/sim/interactive.cpp @@ -17,6 +17,7 @@ #define DEFAULT_DUMPMEM_PATH "memdump.txt" #define DEFAULT_TRACEFILE_PATH "trace.vcd" #define ATOMSIM_PROMPT "atomsim> " +#define ATOMSIM_HISTORY_FILE ".atomsim_history" void Atomsim::display_dbg_screen() @@ -187,6 +188,18 @@ Rcode Atomsim::run_interactive_mode() static std::string prev_cmd; static std::vector prev_args; + // create history file if it doen't exist + FILE *history_file = fopen(ATOMSIM_HISTORY_FILE, "a"); + if (history_file != NULL) { + fclose(history_file); + } else { + std::cerr << "Error creating history file.\n"; + return RC_EXIT; + } + + // read history file + read_history(ATOMSIM_HISTORY_FILE); + while(!backend_.done()) { // get input @@ -214,16 +227,18 @@ Rcode Atomsim::run_interactive_mode() cmd = prev_cmd; args = prev_args; } - - // prev <= current - prev_cmd = cmd; - prev_args = args; - // Add to history - if(input!=""){ + // Add input to history if it's != previous input + if(cmd != prev_cmd){ add_history(input.c_str()); + // save to history file + write_history(ATOMSIM_HISTORY_FILE); } + // prev <= current + prev_cmd = cmd; + prev_args = args; + // execute if (funcs.count(cmd)) // check if command exists {