📄 or1200_except.v
字号:
sig_trap & du_dsr[`OR1200_DU_DSR_TE] & ~ex_freeze, sig_syscall & du_dsr[`OR1200_DU_DSR_SCE] & ~ex_freeze };//// PC and Exception flags pipelines//always @(posedge clk or posedge rst) begin if (rst) begin id_pc <= #1 32'd0; id_exceptflags <= #1 3'b000; end else if (flushpipe) begin id_pc <= #1 32'h0000_0000; id_exceptflags <= #1 3'b000; end else if (!id_freeze) begin id_pc <= #1 if_pc; id_exceptflags <= #1 { sig_ibuserr, sig_itlbmiss, sig_immufault }; endend//// delayed_iee//// SR[IEE] should not enable interrupts right away// when it is restored with l.rfe. Instead delayed_iee// together with SR[IEE] enables interrupts once// pipeline is again ready.//always @(posedge rst or posedge clk) if (rst) delayed_iee <= #1 3'b000; else if (!sr[`OR1200_SR_IEE]) delayed_iee <= #1 3'b000; else delayed_iee <= #1 {delayed_iee[1:0], 1'b1};//// delayed_tee//// SR[TEE] should not enable tick exceptions right away// when it is restored with l.rfe. Instead delayed_tee// together with SR[TEE] enables tick exceptions once// pipeline is again ready.//always @(posedge rst or posedge clk) if (rst) delayed_tee <= #1 3'b000; else if (!sr[`OR1200_SR_TEE]) delayed_tee <= #1 3'b000; else delayed_tee <= #1 {delayed_tee[1:0], 1'b1};//// PC and Exception flags pipelines//always @(posedge clk or posedge rst) begin if (rst) begin ex_dslot <= #1 1'b0; ex_pc <= #1 32'd0; ex_exceptflags <= #1 3'b000; delayed1_ex_dslot <= #1 1'b0; delayed2_ex_dslot <= #1 1'b0; end else if (flushpipe) begin ex_dslot <= #1 1'b0; ex_pc <= #1 32'h0000_0000; ex_exceptflags <= #1 3'b000; delayed1_ex_dslot <= #1 1'b0; delayed2_ex_dslot <= #1 1'b0; end else if (!ex_freeze & id_freeze) begin ex_dslot <= #1 1'b0; ex_pc <= #1 id_pc; ex_exceptflags <= #1 3'b000; delayed1_ex_dslot <= #1 ex_dslot; delayed2_ex_dslot <= #1 delayed1_ex_dslot; end else if (!ex_freeze) begin ex_dslot <= #1 branch_taken; ex_pc <= #1 id_pc; ex_exceptflags <= #1 id_exceptflags; delayed1_ex_dslot <= #1 ex_dslot; delayed2_ex_dslot <= #1 delayed1_ex_dslot; endend//// PC and Exception flags pipelines//always @(posedge clk or posedge rst) begin if (rst) begin wb_pc <= #1 32'd0; end else if (!wb_freeze) begin wb_pc <= #1 ex_pc; endend//// Flush pipeline//assign flushpipe = except_flushpipe | pc_we | extend_flush;//// We have started execution of exception handler:// 1. Asserted for 3 clock cycles// 2. Don't execute any instruction that is still in pipeline and is not part of exception handler//assign except_flushpipe = |except_trig & ~|state;//// Exception FSM that sequences execution of exception handler//// except_type signals which exception handler we start fetching in:// 1. Asserted in next clock cycle after exception is recognized//always @(posedge clk or posedge rst) begin if (rst) begin state <= #1 `OR1200_EXCEPTFSM_IDLE; except_type <= #1 `OR1200_EXCEPT_NONE; extend_flush <= #1 1'b0; epcr <= #1 32'b0; eear <= #1 32'b0; esr <= #1 {1'b1, {`OR1200_SR_WIDTH-2{1'b0}}, 1'b1}; extend_flush_last <= #1 1'b0; end else begin`ifdef OR1200_CASE_DEFAULT case (state) // synopsys parallel_case`else case (state) // synopsys full_case parallel_case`endif `OR1200_EXCEPTFSM_IDLE: if (except_flushpipe) begin state <= #1 `OR1200_EXCEPTFSM_FLU1; extend_flush <= #1 1'b1; esr <= #1 sr_we ? to_sr : sr; casex (except_trig)`ifdef OR1200_EXCEPT_TICK 13'b1_xxxx_xxxx_xxxx: begin except_type <= #1 `OR1200_EXCEPT_TICK; epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc; end`endif`ifdef OR1200_EXCEPT_INT 13'b0_1xxx_xxxx_xxxx: begin except_type <= #1 `OR1200_EXCEPT_INT; epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc; end`endif`ifdef OR1200_EXCEPT_ITLBMISS 13'b0_01xx_xxxx_xxxx: begin except_type <= #1 `OR1200_EXCEPT_ITLBMISS;//// itlb miss exception and active ex_dslot caused wb_pc to put into eear instead of +4 address of ex_pc (or id_pc since it was equal to ex_pc?)// eear <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;// mmu-icdc-O2 ex_pc only OK when no ex_dslot eear <= #1 ex_dslot ? ex_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;// mmu-icdc-O2 ex_pc only OK when no ex_dslot epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc; eear <= #1 ex_dslot ? ex_pc : ex_pc; epcr <= #1 ex_dslot ? wb_pc : ex_pc;// eear <= #1 ex_dslot ? ex_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc;// epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc; end`endif`ifdef OR1200_EXCEPT_IPF 13'b0_001x_xxxx_xxxx: begin except_type <= #1 `OR1200_EXCEPT_IPF;//// ipf exception and active ex_dslot caused wb_pc to put into eear instead of +4 address of ex_pc (or id_pc since it was equal to ex_pc?)// eear <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc; eear <= #1 ex_dslot ? ex_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc; epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc; end`endif`ifdef OR1200_EXCEPT_BUSERR 13'b0_0001_xxxx_xxxx: begin except_type <= #1 `OR1200_EXCEPT_BUSERR; eear <= #1 ex_dslot ? wb_pc : ex_pc; epcr <= #1 ex_dslot ? wb_pc : ex_pc; end`endif`ifdef OR1200_EXCEPT_ILLEGAL 13'b0_0000_1xxx_xxxx: begin except_type <= #1 `OR1200_EXCEPT_ILLEGAL; eear <= #1 ex_pc; epcr <= #1 ex_dslot ? wb_pc : ex_pc; end`endif`ifdef OR1200_EXCEPT_ALIGN 13'b0_0000_01xx_xxxx: begin except_type <= #1 `OR1200_EXCEPT_ALIGN; eear <= #1 lsu_addr; epcr <= #1 ex_dslot ? wb_pc : ex_pc; end`endif`ifdef OR1200_EXCEPT_DTLBMISS 13'b0_0000_001x_xxxx: begin except_type <= #1 `OR1200_EXCEPT_DTLBMISS; eear <= #1 lsu_addr; epcr <= #1 ex_dslot ? wb_pc : ex_pc; end`endif`ifdef OR1200_EXCEPT_DPF 13'b0_0000_0001_xxxx: begin except_type <= #1 `OR1200_EXCEPT_DPF; eear <= #1 lsu_addr; epcr <= #1 ex_dslot ? wb_pc : ex_pc; end`endif`ifdef OR1200_EXCEPT_BUSERR 13'b0_0000_0000_1xxx: begin // Data Bus Error except_type <= #1 `OR1200_EXCEPT_BUSERR; eear <= #1 lsu_addr; epcr <= #1 ex_dslot ? wb_pc : ex_pc; end`endif`ifdef OR1200_EXCEPT_RANGE 13'b0_0000_0000_01xx: begin except_type <= #1 `OR1200_EXCEPT_RANGE; epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc; end`endif`ifdef OR1200_EXCEPT_TRAP 13'b0_0000_0000_001x: begin except_type <= #1 `OR1200_EXCEPT_TRAP; epcr <= #1 ex_dslot ? wb_pc : ex_pc; end`endif`ifdef OR1200_EXCEPT_SYSCALL 13'b0_0000_0000_0001: begin except_type <= #1 `OR1200_EXCEPT_SYSCALL; epcr <= #1 ex_dslot ? wb_pc : delayed1_ex_dslot ? id_pc : delayed2_ex_dslot ? id_pc : id_pc; end`endif default: except_type <= #1 `OR1200_EXCEPT_NONE; endcase end else if (pc_we) begin state <= #1 `OR1200_EXCEPTFSM_FLU1; extend_flush <= #1 1'b1; end else begin if (epcr_we) epcr <= #1 datain; if (eear_we) eear <= #1 datain; if (esr_we) esr <= #1 {1'b1, datain[`OR1200_SR_WIDTH-2:0]}; end `OR1200_EXCEPTFSM_FLU1: if (icpu_ack_i | icpu_err_i | genpc_freeze) state <= #1 `OR1200_EXCEPTFSM_FLU2; `OR1200_EXCEPTFSM_FLU2:`ifdef OR1200_EXCEPT_TRAP if (except_type == `OR1200_EXCEPT_TRAP) begin state <= #1 `OR1200_EXCEPTFSM_IDLE; extend_flush <= #1 1'b0; extend_flush_last <= #1 1'b0; except_type <= #1 `OR1200_EXCEPT_NONE; end else`endif state <= #1 `OR1200_EXCEPTFSM_FLU3; `OR1200_EXCEPTFSM_FLU3: begin state <= #1 `OR1200_EXCEPTFSM_FLU4; end `OR1200_EXCEPTFSM_FLU4: begin state <= #1 `OR1200_EXCEPTFSM_FLU5; extend_flush <= #1 1'b0; extend_flush_last <= #1 1'b0; // damjan end`ifdef OR1200_CASE_DEFAULT default: begin`else `OR1200_EXCEPTFSM_FLU5: begin`endif if (!if_stall && !id_freeze) begin state <= #1 `OR1200_EXCEPTFSM_IDLE; except_type <= #1 `OR1200_EXCEPT_NONE; extend_flush_last <= #1 1'b0; end end endcase endendendmodule
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -