@@ -171,9 +171,9 @@ module csr_regfile
171
171
// RVFI
172
172
output rvfi_probes_csr_t rvfi_csr_o,
173
173
// jvt output
174
- output jvt_t jvt_o
174
+ output jvt_t jvt_o,
175
175
// action 0 request from trigger module
176
- // output breakpoint_from_tigger_module_o
176
+ output logic breakpoint_from_tigger_module_o
177
177
);
178
178
179
179
localparam logic [63 : 0 ] SMODE_STATUS_READ_MASK = ariane_pkg :: smode_status_read_mask (CVA6Cfg);
@@ -286,16 +286,16 @@ module csr_regfile
286
286
logic [N_Triggers- 1 : 0 ] tselect_q, tselect_d;
287
287
logic [3 : 0 ] trigger_type_q[N_Triggers], trigger_type_d[N_Triggers];
288
288
logic [CVA6Cfg.XLEN - 1 : 0 ] scontext_d, scontext_q;
289
- // logic trigger_breakpoint_fire;
290
- // logic breakpoint_from_tigger_module,
291
- // logic priv_match;
289
+ logic priv_match;
292
290
// icount trigger
293
291
icount32_tdata1_t icount32_tdata1_q[N_Triggers], icount32_tdata1_d[N_Triggers];
294
292
textra32_tdata3_t textra32_tdata3_q[N_Triggers], textra32_tdata3_d[N_Triggers];
295
293
textra64_tdata3_t textra64_tdata3_q[N_Triggers], textra64_tdata3_d[N_Triggers];
296
294
logic [CVA6Cfg.XLEN - 1 : 0 ] tdata2_q[N_Triggers], tdata2_d[N_Triggers];
295
+ logic breakpoint_from_tigger_module;
296
+ logic in_trap_handler;
297
+ logic prev_csr_write;
297
298
// icount64_tdata1_t icount64_tdata1;
298
- // logic [13:0] icount_q[N_Triggers], icount_d[N_Triggers]; // because tdata1.count is 14 bits
299
299
300
300
301
301
localparam logic [CVA6Cfg.XLEN - 1 : 0 ] IsaCode = (CVA6Cfg.XLEN ' (CVA6Cfg.RVA ) << 0 ) // A - Atomic Instructions extension
@@ -1148,7 +1148,6 @@ module csr_regfile
1148
1148
if (CVA6Cfg.SDTRIG ) begin
1149
1149
if (csr_wdata[31 : 28 ] == 4'd3 && CVA6Cfg.XLEN == 32 ) begin
1150
1150
trigger_type_d[tselect_q] = csr_wdata[31 : 28 ];
1151
- // icount_d[tselect_q] = csr_wdata[23:10];
1152
1151
icount32_tdata1_d[tselect_q].t_type = (csr_wdata[31 : 28 ] == 4'd3 || csr_wdata[31 : 28 ] == 4'd4 || csr_wdata[31 : 28 ] == 4'd5 || csr_wdata[31 : 28 ] == 4'd6 || csr_wdata[31 : 28 ] == 4'd15 ) ? csr_wdata[31 : 28 ] : trigger_type_q[tselect_q];
1153
1152
icount32_tdata1_d[tselect_q].dmode = csr_wdata[27 ];
1154
1153
icount32_tdata1_d[tselect_q].vs = 0 ;
@@ -1160,7 +1159,7 @@ module csr_regfile
1160
1159
icount32_tdata1_d[tselect_q].s = csr_wdata[7 ];
1161
1160
icount32_tdata1_d[tselect_q].u = csr_wdata[6 ];
1162
1161
icount32_tdata1_d[tselect_q].action = csr_wdata[5 : 0 ];
1163
- // flush_o = 1'b1;
1162
+ flush_o = 1'b1 ;
1164
1163
end
1165
1164
end else begin
1166
1165
update_access_exception = 1'b1 ;
@@ -2286,27 +2285,35 @@ module csr_regfile
2286
2285
end
2287
2286
end
2288
2287
2289
- // if (CVA6Cfg.SDTRIG) begin
2290
- // if (trigger_type_d[tselect_q] == 4'd3) begin
2291
- // // case(priv_lvl_o) // trigger will only fire if current priv lvl is same as the trigger wants to fire in
2292
- // // riscv::PRIV_LVL_M : if (icount32_tdata1_d[tselect_q].m) priv_match = 1'b1;
2293
- // // riscv::PRIV_LVL_S : if (icount32_tdata1_d[tselect_q].s) priv_match = 1'b1;
2294
- // // riscv::PRIV_LVL_U : if (icount32_tdata1_d[tselect_q].u) priv_match = 1'b1;
2295
- // // endcase
2296
- // // if (commit_ack_i) begin
2297
- // // icount_d--;
2298
- // // end
2299
- // // if ((icache_d == 0) && priv_match) begin
2300
- // //icount32_tdata1_q[tselect_q].pending = 1'b1;
2301
- // //icount32_tdata1_q[tselect_q].hit = 1'b1;
2302
- // // case (icount32_tdata1_d[tselect_q].action)
2303
- // //breakpoint_from_tigger_module_o = 1'b1;
2304
- // //6'd1 : debug_from_trigger_module = 1'b1 //into debug mode;
2305
- // // default: ;
2306
- // // endcase
2307
- // // end
2308
- // end
2309
- // end
2288
+ // Triggers Match Logic
2289
+ if (CVA6Cfg.SDTRIG ) begin
2290
+ if (trigger_type_d[tselect_q] == 4'd3 ) begin // icount match logic
2291
+ case (priv_lvl_o) // trigger will only fire if current priv lvl is same as the trigger wants to fire in
2292
+ riscv :: PRIV_LVL_M : if (icount32_tdata1_d[tselect_q].m) priv_match = 1'b1 ;
2293
+ riscv :: PRIV_LVL_S : if (icount32_tdata1_d[tselect_q].s) priv_match = 1'b1 ;
2294
+ riscv :: PRIV_LVL_U : if (icount32_tdata1_d[tselect_q].u) priv_match = 1'b1 ;
2295
+ default : priv_match = 1'b0 ;
2296
+ endcase
2297
+ if (ex_i.valid) begin
2298
+ in_trap_handler = 1'b1 ;
2299
+ icount32_tdata1_d[tselect_q].count = icount32_tdata1_d[tselect_q].count - 1 ;
2300
+ end
2301
+ if (commit_ack_i && mret) in_trap_handler = 1'b0 ;
2302
+ if (| commit_ack_i && ! in_trap_handler && icount32_tdata1_q[tselect_q].count != 0 ) begin
2303
+ icount32_tdata1_d[tselect_q].count = icount32_tdata1_d[tselect_q].count - 1 ;
2304
+ end
2305
+ if ((icount32_tdata1_d[tselect_q].count == 0 ) && priv_match) begin
2306
+ icount32_tdata1_d[tselect_q].pending = 1'b1 ;
2307
+ // icount32_tdata1_d[tselect_q].hit = 1'b1;
2308
+ case (icount32_tdata1_d[tselect_q].action)
2309
+ 6'd0 : breakpoint_from_tigger_module = 1'b1 ;
2310
+ 6'd1 : breakpoint_from_tigger_module = 1'b1 ; // into debug mode;
2311
+ default : ;
2312
+ endcase
2313
+ end
2314
+ end
2315
+ end
2316
+
2310
2317
end
2311
2318
2312
2319
// ---------------------------
@@ -2740,17 +2747,17 @@ module csr_regfile
2740
2747
if (CVA6Cfg.SDTRIG ) begin
2741
2748
scontext_q <= '0 ;
2742
2749
tselect_q <= '0 ;
2750
+ prev_csr_write <= 1'b0 ;
2743
2751
for (int i = 0 ; i < N_Triggers; ++ i) begin
2744
2752
trigger_type_q[i] <= '0 ;
2745
- // icount_q[i] <= 0;
2746
2753
icount32_tdata1_q[i] <= '0 ;
2747
2754
icount32_tdata1_q[i].count <= 1 ;
2748
2755
textra32_tdata3_q[i] <= '0 ;
2749
2756
textra64_tdata3_q[i] <= '0 ;
2750
2757
tdata2_q[i] <= '0 ;
2751
2758
end
2752
- // trigger_breakpoint_fire <= 0;
2753
- // priv_match <= 0;
2759
+ priv_match <= 0 ;
2760
+ in_trap_handler <= 0 ;
2754
2761
end
2755
2762
// timer and counters
2756
2763
cycle_q <= 64'b0 ;
@@ -2837,13 +2844,13 @@ module csr_regfile
2837
2844
end
2838
2845
if (CVA6Cfg.SDTRIG ) begin
2839
2846
trigger_type_q <= trigger_type_d;
2840
- // icount_q <= icount_d;
2841
2847
tselect_q <= tselect_d;
2842
2848
tdata2_q <= tdata2_d;
2843
2849
icount32_tdata1_q <= icount32_tdata1_d;
2844
2850
textra32_tdata3_q <= textra32_tdata3_d;
2845
2851
textra64_tdata3_q <= textra64_tdata3_d;
2846
2852
scontext_q <= scontext_d;
2853
+ prev_csr_write <= breakpoint_from_tigger_module;
2847
2854
end
2848
2855
// timer and counters
2849
2856
cycle_q <= cycle_d;
@@ -2858,6 +2865,8 @@ module csr_regfile
2858
2865
end
2859
2866
end
2860
2867
2868
+ assign breakpoint_from_tigger_module_o = breakpoint_from_tigger_module & ~ prev_csr_write;
2869
+
2861
2870
// write logic pmp
2862
2871
always_comb begin : write
2863
2872
for (int i = 0 ; i < 64 ; i++ ) begin
0 commit comments