Skip to content

Commit

Permalink
Add support for historyfile in atomsim debug mode
Browse files Browse the repository at this point in the history
- read historyfile when entering interactive mode
  (create if necessary), write to history file
  after each command.
- print cycles when exiting atomsim
  • Loading branch information
saursin committed Feb 24, 2024
1 parent 3455ab8 commit 1bffedd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ docs/_build/
*.out
*.vcd
python/

.atomsim_history
simport
userport
2 changes: 1 addition & 1 deletion sim/atomsim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 21 additions & 6 deletions sim/interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -187,6 +188,18 @@ Rcode Atomsim::run_interactive_mode()
static std::string prev_cmd;
static std::vector<std::string> 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
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 1bffedd

Please sign in to comment.