1919module 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
163146endmodule : r5p_degu_trace
0 commit comments