Skip to content

Commit 7d8f471

Browse files
committed
degu tracing update, but still sensitive to timing
1 parent 42120d2 commit 7d8f471

File tree

6 files changed

+104
-106
lines changed

6 files changed

+104
-106
lines changed

hdl/tbn/riscof/r5p_degu_riscof_tb.sv

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,10 @@ module r5p_degu_riscof_tb
268268
) trace_hdldb (
269269
// GPR register file array
270270
// hierarchical path to GPR inside RTL
271-
.gpr_wen (dut.gpr.e_rd),
272-
.gpr_wid (dut.gpr.a_rd),
273-
.gpr_wdt (dut.gpr.d_rd),
271+
.gpr_den (dut.gpr.e_rd),
272+
.gpr_did (dut.gpr.a_rd),
273+
.gpr_ddt (dut.gpr.d_rd),
274+
.gpr_sid (dut.gpr.a_rs1),
274275
// TCB IFU/LSU system busses
275276
.tcb_ifu (tcb_ifu),
276277
.tcb_lsu (tcb_lsu)

hdl/tbn/riscof/r5p_mouse_riscof_tb.sv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ import riscv_asm_pkg::*;
242242

243243
// trace with Spike format
244244
r5p_mouse_trace #(
245-
.XLEN (XLEN),
246245
.FORMAT (format)
247246
) trace_hdldb (
248247
// instruction execution phase

hdl/tbn/riscof/trace_spike_pkg.sv

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,42 @@ package trace_spike_pkg;
5858
function void trace (
5959
int unsigned core, // core (hart) index
6060
// IFU
61-
logic [XLEN-1:0] ifu_adr, // PC (IFU address)
62-
logic [XLEN-1:0] ifu_ins, // instruction
61+
logic [XLEN-1:0] ifu_adr, // PC (IFU address)
62+
logic ifu_siz, // instruction size (0-16bit, 1-32bit)
63+
logic [XLEN-1:0] ifu_ins, // instruction
64+
logic ifu_ill, // instruction is illegal
6365
// WBU (write back to destination register)
64-
logic wbu_ena, // enable
65-
logic [ 5-1:0] wbu_idx, // index of destination register
66-
logic [XLEN-1:0] wbu_dat, // data
67-
// LSU
68-
logic lsu_ena, // enable
69-
logic lsu_wen, // write enable
70-
logic lsu_ren, // read enable
71-
logic [XLEN-1:0] lsu_adr, // PC (IFU address)
72-
logic [XLEN-1:0] lsu_siz, // load/store size
73-
logic [XLEN-1:0] lsu_wdt // write data (store)
66+
logic wbu_ena, // enable
67+
logic [ 5-1:0] wbu_idx, // index of destination register
68+
logic [XLEN-1:0] wbu_dat, // data
69+
// LSU (load/store unit)
70+
logic lsu_ena, // enable
71+
logic lsu_wen, // write enable
72+
logic lsu_ren, // read enable
73+
logic [ 5-1:0] lsu_wid, // index of data source GPR
74+
logic [ 5-1:0] lsu_rid, // index of data destination GPR
75+
logic [XLEN-1:0] lsu_adr, // PC (IFU address)
76+
logic [ 2-1:0] lsu_siz, // load/store logarithmic size
77+
logic [XLEN-1:0] lsu_wdt, // write data (store)
78+
logic [XLEN-1:0] lsu_rdt // read data (load)
7479
);
7580
string str_if; // instruction fetch
7681
string str_wb; // write-back
7782
string str_ls; // load/store
7883

79-
// prepare fetch
80-
// TODO: add handling of compressed instructions
84+
// fetch address
8185
case (XLEN)
82-
32: str_if = $sformatf(" 0x%8h (0x%8h)" , ifu_adr, ifu_ins);
83-
64: str_if = $sformatf(" 0x%16h (0x%8h)", ifu_adr, ifu_ins);
86+
32: str_if = $sformatf(" 0x%8h" , ifu_adr);
87+
64: str_if = $sformatf(" 0x%16h", ifu_adr);
88+
endcase
89+
// fetch instruction
90+
case (ifu_siz)
91+
0: str_if = {str_if, $sformatf(" (0x%4h)", ifu_ins[16-1:0])}; // 16bit
92+
1: str_if = {str_if, $sformatf(" (0x%8h)", ifu_ins[32-1:0])}; // 32bit
8493
endcase
8594

86-
// prepare write-back
87-
if (wbu_ena) begin
95+
// write-back (x0 access is not logged)
96+
if (wbu_ena && (wbu_idx != 0)) begin
8897
case (XLEN)
8998
32: str_wb = $sformatf(" %s 0x%8h" , format_gpr(wbu_idx), wbu_dat);
9099
64: str_wb = $sformatf(" %s 0x%16h", format_gpr(wbu_idx), wbu_dat);
@@ -93,12 +102,16 @@ package trace_spike_pkg;
93102
str_wb = "";
94103
end
95104

96-
// prepare load/store
105+
// load/store
97106
if (lsu_ena) begin
98-
case (XLEN)
99-
32: str_ls = $sformatf(" mem 0x%8h" , lsu_adr);
100-
64: str_ls = $sformatf(" mem 0x%16h", lsu_adr);
101-
endcase
107+
// load/store address
108+
if (lsu_wen | lsu_wen) begin
109+
case (XLEN)
110+
32: str_ls = $sformatf(" mem 0x%8h" , lsu_adr);
111+
64: str_ls = $sformatf(" mem 0x%16h", lsu_adr);
112+
endcase
113+
end
114+
// store data
102115
if (lsu_wen) begin
103116
case (lsu_siz)
104117
2'd0: str_ls = {str_ls, $sformatf(" 0x%2h" , lsu_wdt[ 8-1:0])};

hdl/tbn/soc/r5p_degu_trace.sv

Lines changed: 50 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
module r5p_degu_trace
2020
import tcb_pkg::*;
2121
import trace_spike_pkg::*;
22+
import riscv_isa_pkg::*;
23+
import riscv_isa_i_pkg::*;
24+
// import riscv_asm_pkg::*;
2225
#(
2326
// constants used across the design in signal range sizing instead of literals
24-
localparam int unsigned XLEN = 32,
27+
parameter int unsigned XLEN = 32,
2528
localparam int unsigned XLOG = $clog2(XLEN),
2629
// trace format class type (HDLDB, Spike, ...)
2730
parameter type FORMAT = trace_spike_pkg::spike,
@@ -32,25 +35,23 @@ module r5p_degu_trace
3235
localparam int unsigned GLOG = $clog2(GNUM)
3336
)(
3437
// GPR array
35-
input logic gpr_wen,
36-
input logic [GLOG-1:0] gpr_wid,
37-
input logic [XLEN-1:0] gpr_wdt,
38+
input logic gpr_den, // destination enable
39+
input logic [GLOG-1:0] gpr_did, // destination index
40+
input logic [XLEN-1:0] gpr_ddt, // destination data
41+
input logic [GLOG-1:0] gpr_sid, // source index
3842
// TCB IFU/LSU system busses
3943
tcb_if.mon tcb_ifu,
4044
tcb_if.mon tcb_lsu
4145
);
4246

43-
// import riscv_isa_pkg::*;
44-
// import riscv_isa_i_pkg::*;
45-
// import riscv_asm_pkg::*;
46-
4747
////////////////////////////////////////////////////////////////////////////////
4848
// local signals
4949
////////////////////////////////////////////////////////////////////////////////
5050

5151
// IFU (instruction fetch unit)
5252
logic ifu_ena = 1'b0; // enable
5353
logic [XLEN-1:0] ifu_adr; // PC (IFU address)
54+
logic ifu_siz; // instruction size (0-16bit, 1-32bit)
5455
logic [XLEN-1:0] ifu_ins; // instruction
5556
logic ifu_ill; // instruction is illegal
5657
// WBU (write back to destination register)
@@ -64,10 +65,16 @@ module r5p_degu_trace
6465
logic [ 5-1:0] lsu_wid; // index of data source GPR
6566
logic [ 5-1:0] lsu_rid; // index of data destination GPR
6667
logic [XLEN-1:0] lsu_adr; // PC (IFU address)
67-
logic [XLEN-1:0] lsu_siz; // load/store size
68+
logic [ 2-1:0] lsu_siz; // load/store logarithmic size
6869
logic [XLEN-1:0] lsu_wdt; // write data (store)
6970
logic [XLEN-1:0] lsu_rdt; // read data (load)
7071

72+
// instruction pipeline
73+
logic [XLEN-1:0] ifp_adr; // PC (IFU address)
74+
logic ifp_siz; // instruction size (0-16bit, 1-32bit)
75+
logic [XLEN-1:0] ifp_ins; // instruction
76+
logic ifp_ill; // instruction is illegal
77+
7178
////////////////////////////////////////////////////////////////////////////////
7279
// tracing
7380
////////////////////////////////////////////////////////////////////////////////
@@ -86,78 +93,54 @@ module r5p_degu_trace
8693
else if (FILE) begin
8794
filename = FILE;
8895
end
89-
if (filename) begin
90-
tracer = new(filename);
91-
$display("TRACING: opened trace file: '%s'.", filename);
92-
end else begin
93-
$display("TRACING: no trace file name was provided.");
94-
end
96+
// initialize tracing object
97+
tracer = new(filename);
9598
end
9699

97100
final
98101
begin
99102
tracer.close();
100103
end
101104

102-
// initialize dummy data into the queue to enforce order
103-
initial
104-
begin
105-
str_gpr = '{};
106-
str_lsu = '{};
107-
str_ifu = '{""};
108-
end
109-
110-
// instruction fetch
105+
// instruction pipeline
111106
always_ff @(posedge tcb_ifu.clk)
112-
begin
113-
if ($past(tcb_ifu.trn)) begin
114-
if (opsiz(tcb_ifu.rsp.rdt) == 4) begin
115-
str_ifu.push_front($sformatf(" 0x%8h (0x%8h)", $past(tcb_ifu.req.adr), tcb_ifu.rsp.rdt));
116-
end else begin
117-
str_ifu.push_front($sformatf(" 0x%8h (0x%4h)", $past(tcb_ifu.req.adr), tcb_ifu.rsp.rdt[16-1:0]));
118-
end
119-
end
107+
if ($past(tcb_ifu.trn, 1)) begin
108+
ifu_ena <= 1'b0; // enable
109+
ifp_adr <= $past(tcb_ifu.req.adr);
110+
ifp_siz <= opsiz(tcb_ifu.rsp.rdt) == 4;
111+
ifp_ins <= tcb_ifu.rsp.rdt ;
112+
ifp_ill <= 1'b0; // TODO
120113
end
121114

122-
// GPR write-back (rs1/rs2 reads are not logged)
115+
// instruction fetch
123116
always_ff @(posedge tcb_ifu.clk)
124117
begin
125-
if ($past(tcb_ifu.trn)) begin
126-
if (gpr_wen) begin
127-
// ignore GPR x0
128-
if (gpr_wid != 0) begin
129-
str_gpr.push_front($sformatf(" %s 0x%8h", format_gpr(gpr_wid), gpr_wdt));
130-
end
131-
end else begin
132-
str_gpr.push_front("");
133-
end
134-
end
135-
end
136-
137-
// memory load/store
138-
always_ff @(posedge tcb_lsu.clk)
139-
begin
140-
if ($past(tcb_lsu.trn)) begin
141-
if ($past(tcb_lsu.req.wen)) begin
142-
// memory store
143-
str_lsu.push_front($sformatf(" mem 0x%8h 0x%8h", $past(tcb_lsu.req.adr), $past(tcb_lsu.req.wdt)));
144-
end else begin
145-
// memory load
146-
str_lsu.push_front($sformatf(" 0x%8h (0x%8h)", $past(tcb_lsu.req.adr), tcb_lsu.rsp.rdt));
147-
end
148-
end
149-
end
118+
if ($past(tcb_ifu.trn, 2)) begin
119+
// $display("DEBUG: fetch");
120+
tracer.trace(
121+
.core (0),
122+
// IFU
123+
.ifu_adr (ifp_adr),
124+
.ifu_siz (ifp_siz),
125+
.ifu_ins (ifp_ins),
126+
.ifu_ill (ifp_ill),
127+
// WBU (write back to destination register)
128+
.wbu_ena (gpr_den),
129+
.wbu_idx (gpr_did),
130+
.wbu_dat (gpr_ddt),
131+
// LSU
132+
.lsu_ena ($past(tcb_lsu.trn )),
133+
.lsu_wen ($past(tcb_lsu.req.wen)),
134+
.lsu_ren ($past(tcb_lsu.req.ren)),
135+
.lsu_wid ($past(gpr_sid)),
136+
.lsu_rid ( gpr_did),
137+
.lsu_adr ($past(tcb_lsu.req.adr)),
138+
.lsu_siz ($past(tcb_lsu.req.siz)),
139+
.lsu_wdt ($past(tcb_lsu.req.wdt)),
140+
.lsu_rdt ( tcb_lsu.rsp.rdt )
141+
);
150142

151-
// prepare string for committed instruction
152-
always_ff @(posedge tcb_ifu.clk)
153-
begin
154-
// only log if a log file was opened
155-
if (fd) begin
156-
// at instruction fetch combine strings from previous instructions
157-
if ($past(tcb_ifu.trn)) begin
158-
$fwrite(fd, "core 0: 3%s%s%s\n", str_ifu.pop_back(), str_gpr.pop_back(), str_lsu.pop_back());
159143
end
160-
end
161144
end
162145

163146
endmodule: r5p_degu_trace

hdl/tbn/soc/r5p_mouse_trace.sv

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module r5p_mouse_trace
5757
// IFU (instruction fetch unit)
5858
logic ifu_ena = 1'b0; // enable
5959
logic [XLEN-1:0] ifu_adr; // PC (IFU address)
60+
logic ifu_siz; // instruction size (0-16bit, 1-32bit)
6061
logic [XLEN-1:0] ifu_ins; // instruction
6162
logic ifu_ill; // instruction is illegal
6263
// WBU (write back to destination register)
@@ -70,7 +71,7 @@ module r5p_mouse_trace
7071
logic [ 5-1:0] lsu_wid; // index of data source GPR
7172
logic [ 5-1:0] lsu_rid; // index of data destination GPR
7273
logic [XLEN-1:0] lsu_adr; // PC (IFU address)
73-
logic [XLEN-1:0] lsu_siz; // load/store size
74+
logic [ 2-1:0] lsu_siz; // load/store logarithmic size
7475
logic [XLEN-1:0] lsu_wdt; // write data (store)
7576
logic [XLEN-1:0] lsu_rdt; // read data (load)
7677

@@ -92,12 +93,8 @@ module r5p_mouse_trace
9293
else if (FILE) begin
9394
filename = FILE;
9495
end
95-
if (filename) begin
96-
tracer = new(filename);
97-
$display("TRACING: opened trace file: '%s'.", filename);
98-
end else begin
99-
$display("TRACING: no trace file name was provided.");
100-
end
96+
// initialize tracing object
97+
tracer = new(filename);
10198
end
10299

103100
final
@@ -118,7 +115,9 @@ module r5p_mouse_trace
118115
.core (0),
119116
// IFU
120117
.ifu_adr (ifu_adr),
118+
.ifu_siz ( 1),
121119
.ifu_ins (ifu_ins),
120+
.ifu_ill (ifu_ill),
122121
// WBU (write back to destination register)
123122
.wbu_ena (wbu_ena),
124123
.wbu_idx (wbu_idx),
@@ -127,9 +126,12 @@ module r5p_mouse_trace
127126
.lsu_ena (lsu_ena),
128127
.lsu_wen (lsu_wen),
129128
.lsu_ren (lsu_ren),
129+
.lsu_wid ('x),
130+
.lsu_rid ('x),
130131
.lsu_adr (lsu_adr),
131132
.lsu_siz (lsu_siz),
132-
.lsu_wdt (lsu_wdt)
133+
.lsu_wdt (lsu_wdt),
134+
.lsu_rdt (lsu_rdt)
133135
);
134136
end
135137
// instruction fetch

sim/sources-degu.mk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ TSV+=${PATH_TCB}/tbn/vip/tcb_vip_protocol_checker.sv
3030
PATH_GDB=../../submodules/hdldb/hdl
3131

3232
# SystemVerilog bench (Test SV)
33-
TSV+=${PATH_GDB}/hdldb_trace_pkg.sv
33+
#TSV+=${PATH_GDB}/hdldb_trace_pkg.sv
3434

3535
# R5P files
3636
PATH_R5P=../../hdl
@@ -64,11 +64,11 @@ RTL+=${PATH_R5P}/rtl/soc/r5p_degu_soc_top.sv
6464

6565
# SystemVerilog bench (Test SV)
6666
TSV+=${PATH_R5P}/tbn/riscv/riscv_asm_pkg.sv
67+
TSV+=${PATH_R5P}/tbn/soc/r5p_degu_trace.sv
68+
TSV+=${PATH_R5P}/tbn/soc/r5p_degu_soc_top_tb.sv
6769
TSV+=${PATH_R5P}/tbn/htif/r5p_htif.sv
68-
TSV+=${PATH_R5P}/tbn/riscof/r5p_degu_trace_spike.sv
70+
TSV+=${PATH_R5P}/tbn/riscof/trace_spike_pkg.sv
6971
TSV+=${PATH_R5P}/tbn/riscof/r5p_degu_riscof_tb.sv
70-
TSV+=${PATH_R5P}/tbn/soc/r5p_degu_trace_hdldb.sv
71-
TSV+=${PATH_R5P}/tbn/soc/r5p_degu_soc_top_tb.sv
7272

7373
# combined HDL sources
7474
HDL =${RTL}

0 commit comments

Comments
 (0)