From da54b3b6d3db776eb57ca502822558577e6c4c4e Mon Sep 17 00:00:00 2001 From: uvok Date: Mon, 19 Jan 2026 20:16:34 +0100 Subject: Add halt state and flag --- eater_cpu/cpp/Veater_computer__main.cpp | 7 +++++-- eater_cpu/cpp/simpc_term.cpp | 4 ++-- eater_cpu/eater_computer.sv | 3 +++ eater_cpu/eater_decoder.sv | 7 +++++++ eater_cpu/eater_types.sv | 10 ++++++++-- eater_cpu/readme.txt | 4 ++-- 6 files changed, 27 insertions(+), 8 deletions(-) (limited to 'eater_cpu') diff --git a/eater_cpu/cpp/Veater_computer__main.cpp b/eater_cpu/cpp/Veater_computer__main.cpp index 315d52a..7afa4d0 100644 --- a/eater_cpu/cpp/Veater_computer__main.cpp +++ b/eater_cpu/cpp/Veater_computer__main.cpp @@ -20,6 +20,8 @@ void load_program(const std::unique_ptr &topp) { topp->eater_computer->RAM->r_datastore[1] = 0x1f; // OUT topp->eater_computer->RAM->r_datastore[2] = 0xe0; + // HALT + topp->eater_computer->RAM->r_datastore[3] = 0xf0; // Data @ 14 topp->eater_computer->RAM->r_datastore[14] = 14; // Data @ 15 @@ -53,7 +55,8 @@ int main(int argc, char **argv, char **) { // Simulate until $finish while (VL_LIKELY(!contextp->gotFinish()) && - VL_LIKELY(contextp->time() < 100)) { + VL_LIKELY(contextp->time() < 100) && + VL_LIKELY(!(topp->eater_computer->flags.__PVT__halt))) { // Evaluate model topp->eval(); @@ -65,7 +68,7 @@ int main(int argc, char **argv, char **) { topp->clk_in = !topp->clk_in; - if (topp->eater_computer->PC_out == 4 && + if (topp->eater_computer->PC_out == 6 && topp->eater_computer->decoder__DOT__internal_state == 0x01) break; } diff --git a/eater_cpu/cpp/simpc_term.cpp b/eater_cpu/cpp/simpc_term.cpp index 540cc98..a2144b2 100644 --- a/eater_cpu/cpp/simpc_term.cpp +++ b/eater_cpu/cpp/simpc_term.cpp @@ -42,7 +42,7 @@ void simpc_ui_write(const std::unique_ptr &topp, uint64_t i) { // uint16_t opcode = topp->eater_computer->; uint8_t opcode = topp->eater_computer->INS->r_datastore; // topp->halt - uint8_t halt = 0; + uint8_t halt = topp->eater_computer->flags.__PVT__halt; PRINT_ME_W(status_top, 0, 0, "Step: %10lu", i); PRINT_ME_W(status_top, 1, 0, "%-20s", paused ? "Paused" : "Running"); @@ -100,7 +100,7 @@ void simpc_ui_finish_message(const std::unique_ptr &contextp, PRINT_ME_W(status_top, 0, xpos, "Simulation finished."); const char *msg; // topp->halt - bool halt = false; + bool halt = topp->eater_computer->flags.__PVT__halt; if (halt) { msg = "Halt encountered."; } else if (!contextp->gotFinish()) { diff --git a/eater_cpu/eater_computer.sv b/eater_cpu/eater_computer.sv index 18b6833..6569831 100644 --- a/eater_cpu/eater_computer.sv +++ b/eater_cpu/eater_computer.sv @@ -9,6 +9,8 @@ module eater_computer( input wire clk_in, // Whether to automatically run (vs manual control) input wire auto_run_in, + + output wire halt, // current content of the bus output wire [7:0] debug_bus ); @@ -47,6 +49,7 @@ wire CpuControlFlags automatic_flags; wire CpuControlFlags flags; assign flags = auto_run_in ? automatic_flags : manual_flags; +assign halt = flags.halt; /* verilator public_off */ diff --git a/eater_cpu/eater_decoder.sv b/eater_cpu/eater_decoder.sv index 78d4e6c..53cc39c 100644 --- a/eater_cpu/eater_decoder.sv +++ b/eater_cpu/eater_decoder.sv @@ -28,6 +28,7 @@ function CpuState insdep_state; LDA: insdep_state = LDA_INS_to_MAR; ADD: insdep_state = ADD_INS_to_MAR; OUT: insdep_state = OUT_A_to_OUT; + HALT_op: insdep_state = HALT_st; default: insdep_state = INIT; endcase @@ -54,6 +55,8 @@ always @(posedge clk_i) begin OUT_A_to_OUT: next_state = PC_to_MAR; + HALT_st: next_state = HALT_st; + default: begin next_state = INIT; end @@ -115,6 +118,10 @@ always_comb begin internal_flags.OUT_in = 1; end + HALT_st: begin + internal_flags.halt = 1; + end + default: begin end diff --git a/eater_cpu/eater_types.sv b/eater_cpu/eater_types.sv index 6061a03..57a7adc 100644 --- a/eater_cpu/eater_types.sv +++ b/eater_cpu/eater_types.sv @@ -25,13 +25,17 @@ typedef enum logic[7:0] { ADD_ALU_to_A, // OUT: A -> OUT - OUT_A_to_OUT + OUT_A_to_OUT, + + // HALT: set halt flag + HALT_st } CpuState; typedef enum logic[3:0] { LDA = 'b0000, ADD = 'b0001, - OUT = 'b1110 + OUT = 'b1110, + HALT_op = 'b1111 } eater_instruction; // CPU control flags @@ -45,6 +49,7 @@ typedef struct packed { logic ALU_out; logic PC_out, PC_in, PC_count; logic OUT_in; + logic halt; } CpuControlFlags; `else typedef struct { @@ -56,6 +61,7 @@ typedef struct { logic ALU_out, ALU_subtract_nadd; logic PC_out, PC_in, PC_count; logic OUT_in; + logic halt; } CpuControlFlags; `endif diff --git a/eater_cpu/readme.txt b/eater_cpu/readme.txt index 9ff0090..aa72328 100644 --- a/eater_cpu/readme.txt +++ b/eater_cpu/readme.txt @@ -30,8 +30,8 @@ instruction set LDA 0b_0000_ Load memory > A ADD 0b_0001_ "Add memory" + A -> A -OUT 0b_1110_xxxx Output A -> OUT - +OUT ____________ 0b_1110_xxxx Output A -> OUT +HLT ____________ 0b_1111_xxxx Sets halt flag --- operation -- cgit v1.2.3