diff options
| author | Alejandro Soto <alejandro@34project.org> | 2022-12-06 15:27:42 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2022-12-06 15:27:42 -0600 |
| commit | b1761b8eac5777c09723bbc8cd31cc05d8ec35ae (patch) | |
| tree | a7a50591a1b5f9d7e26a7f6797a97d9ac213879a | |
| parent | 064b72ae4eb22336438288a9664a37c0dd07f4bc (diff) | |
Implement breakpoints
Diffstat (limited to '')
| -rw-r--r-- | rtl/core/arm810.sv | 4 | ||||
| -rw-r--r-- | rtl/core/control/control.sv | 1 | ||||
| -rw-r--r-- | rtl/core/control/issue.sv | 2 | ||||
| -rw-r--r-- | rtl/core/control/stall.sv | 2 | ||||
| -rw-r--r-- | rtl/core/decode/decode.sv | 5 | ||||
| -rw-r--r-- | rtl/core/decode/isa.sv | 4 | ||||
| -rw-r--r-- | rtl/core/decode/mux.sv | 11 | ||||
| -rw-r--r-- | rtl/core/uarch.sv | 3 | ||||
| -rw-r--r-- | rtl/top/conspiracion.sv | 1 | ||||
| -rw-r--r-- | sim/gdbstub.py | 11 | ||||
| -rw-r--r-- | tb/top/conspiracion.cpp | 7 |
11 files changed, 39 insertions, 12 deletions
diff --git a/rtl/core/arm810.sv b/rtl/core/arm810.sv index 89a2a68..05bce76 100644 --- a/rtl/core/arm810.sv +++ b/rtl/core/arm810.sv @@ -14,7 +14,9 @@ module arm810 input word bus_data_rd, output word bus_data_wr, output logic[3:0] bus_data_be, - output logic halted + + output logic halted, + breakpoint ); ptr fetch_insn_pc, fetch_head, insn_addr; diff --git a/rtl/core/control/control.sv b/rtl/core/control/control.sv index 9f398dc..92e27d6 100644 --- a/rtl/core/control/control.sv +++ b/rtl/core/control/control.sv @@ -32,6 +32,7 @@ module core_control stall, branch, writeback, + breakpoint, update_flags, c_in, output reg_num rd, diff --git a/rtl/core/control/issue.sv b/rtl/core/control/issue.sv index ffdf250..b8cf3ff 100644 --- a/rtl/core/control/issue.sv +++ b/rtl/core/control/issue.sv @@ -18,6 +18,7 @@ module core_control_issue output logic issue, undefined, + breakpoint, output ptr pc, pc_visible, next_pc_visible @@ -27,6 +28,7 @@ module core_control_issue assign valid = !next_bubble && !halt; assign issue = next_cycle.issue && dec.ctrl.execute && valid; + assign breakpoint = issue && dec.ctrl.bkpt; assign next_pc_visible = insn_pc + 2; always_ff @(posedge clk or negedge rst_n) diff --git a/rtl/core/control/stall.sv b/rtl/core/control/stall.sv index 085f11e..f42dcf0 100644 --- a/rtl/core/control/stall.sv +++ b/rtl/core/control/stall.sv @@ -24,7 +24,7 @@ module core_control_stall logic pc_rd_hazard, pc_wr_hazard, rn_pc_hazard, snd_pc_hazard, psr_hazard, flags_hazard; assign stall = !next_cycle.issue || next_bubble || halt; - assign halted = halt && !next_bubble; + assign halted = halt && !next_bubble && next_cycle.issue; assign next_bubble = pc_rd_hazard || pc_wr_hazard || flags_hazard || psr_hazard; //FIXME: pc_rd_hazard no deberÃa definirse sin final_writeback? diff --git a/rtl/core/decode/decode.sv b/rtl/core/decode/decode.sv index f16db9a..6534897 100644 --- a/rtl/core/decode/decode.sv +++ b/rtl/core/decode/decode.sv @@ -29,6 +29,7 @@ module core_decode assign dec_ctrl.mul = mul; assign dec_ctrl.psr = psr; assign dec_ctrl.ldst = ldst; + assign dec_ctrl.bkpt = bkpt; assign dec_ctrl.branch = branch; assign dec_ctrl.coproc = coproc; assign dec_ctrl.execute = execute; @@ -44,8 +45,8 @@ module core_decode assign dec_psr.restore_spsr = restore_spsr; logic execute, undefined, conditional, writeback, update_flags, - restore_spsr, branch, ldst, mul, psr, coproc, psr_saved, - psr_write, psr_wr_flags, psr_wr_control; + restore_spsr, branch, ldst, mul, psr, coproc, bkpt, + psr_saved, psr_write, psr_wr_flags, psr_wr_control; core_decode_mux mux ( diff --git a/rtl/core/decode/isa.sv b/rtl/core/decode/isa.sv index 7c27f49..4c9f316 100644 --- a/rtl/core/decode/isa.sv +++ b/rtl/core/decode/isa.sv @@ -209,4 +209,8 @@ `define FIELD_SWI_IMM [23:0] +// GDB swbreak (a magic 'und') + +`define INSN_GDB_SWBREAK 28'h7ffdefe + `endif diff --git a/rtl/core/decode/mux.sv b/rtl/core/decode/mux.sv index 3f613a4..f05b711 100644 --- a/rtl/core/decode/mux.sv +++ b/rtl/core/decode/mux.sv @@ -57,6 +57,7 @@ module core_decode_mux mul, psr, coproc, + bkpt, psr_saved, psr_write, psr_wr_flags, @@ -71,6 +72,7 @@ module core_decode_mux always_comb begin mul = 0; ldst = 0; + bkpt = 0; branch = 0; coproc = 0; execute = 1; @@ -230,6 +232,14 @@ module core_decode_mux writeback = 1; end +`ifdef VERILATOR + // No es parte de ARM del todo, es un hack para soportar gdb + `INSN_GDB_SWBREAK: begin + bkpt = 1; + dec_data.uses_rn = 0; + end +`endif + default: undefined = 1; endcase @@ -252,6 +262,7 @@ module core_decode_mux mul = 1'bx; psr = 1'bx; + bkpt = 1'bx; ldst = 1'bx; branch = 1'bx; coproc = 1'bx; diff --git a/rtl/core/uarch.sv b/rtl/core/uarch.sv index c1e5abb..ac3b567 100644 --- a/rtl/core/uarch.sv +++ b/rtl/core/uarch.sv @@ -87,7 +87,8 @@ typedef struct packed coproc, ldst, mul, - psr; + psr, + bkpt; } ctrl_decode; typedef struct packed diff --git a/rtl/top/conspiracion.sv b/rtl/top/conspiracion.sv index 84b875e..507a74c 100644 --- a/rtl/top/conspiracion.sv +++ b/rtl/top/conspiracion.sv @@ -4,6 +4,7 @@ module conspiracion input wire rst_n, input wire halt, output wire cpu_halted, + output wire breakpoint, output wire [12:0] memory_mem_a, output wire [2:0] memory_mem_ba, output wire memory_mem_ck, diff --git a/sim/gdbstub.py b/sim/gdbstub.py index b262971..e214a73 100644 --- a/sim/gdbstub.py +++ b/sim/gdbstub.py @@ -50,14 +50,14 @@ def halt(): client.send(b'+') - if data[0] == b'?'[0]: + if data == b'?': out = b'S05' elif data[0] == b'c'[0]: assert not data[1:] #TODO break - elif data[0] == b'D'[0]: + elif data == b'D': out = b'OK' - elif data[0] == b'g'[0]: + elif data == b'g': out = hexout(read_reg(gdb_reg(r)) for r in range(16)) elif data[0] == b'm'[0]: addr, length = (int(x, 16) for x in data[1:].split(b',')) @@ -128,7 +128,6 @@ def hexout(data, size=4): elif type(data) is bytes: return data.hex().encode('ascii') elif type(data) is int: - data = [data] - - return b''.join(hex(d)[2:].zfill(2 * size)[:2 * size].encode('ascii') for d in data) + return data.to_bytes(size, 'little').hex().encode('ascii') + return b''.join(hexout(d) for d in data) diff --git a/tb/top/conspiracion.cpp b/tb/top/conspiracion.cpp index 15da2ea..96fd57f 100644 --- a/tb/top/conspiracion.cpp +++ b/tb/top/conspiracion.cpp @@ -379,6 +379,11 @@ int main(int argc, char **argv) { tick(); tick(); + + if(top.breakpoint) + { + top.halt = 1; + } }; if(!no_tty) @@ -481,7 +486,7 @@ int main(int argc, char **argv) const char *cmd = std::strtok(line, " "); if(!std::strcmp(cmd, "continue")) { - top.halt = false; + top.halt = 0; break; } else if(!std::strcmp(cmd, "dump-mem")) { |
