@@ -229,9 +229,9 @@ begin
229229 trap.ecall <= '0' ;
230230 trap.ebreak <= '0' ;
231231 ctrl_nxt <= ctrl_bus_zero_c; -- all zero/off by default (ALU operation = ZERO, ALU.adder_out = ADD)
232- ctrl_nxt.csr_addr <= ctrl.csr_addr; -- keep previous CSR address
233- ctrl_nxt.lsu_rd <= ctrl.lsu_rd; -- keep memory access read/write type
234- ctrl_nxt.lsu_wr <= ctrl.lsu_wr;
232+ ctrl_nxt.csr_addr <= ctrl.csr_addr; -- keep previous CSR address
233+ ctrl_nxt.lsu_rd <= ctrl.lsu_rd; -- keep memory read access type
234+ ctrl_nxt.lsu_wr <= ctrl.lsu_wr; -- keep memory write access type
235235
236236 -- immediate --
237237 case opcode_v is
@@ -794,6 +794,35 @@ begin
794794 (trap.ebreak and (not csr.prv_level) and (not csr.dcsr_ebreaku) and (not debug_ctrl.run)); -- M-mode trap on U-ebreak
795795
796796
797+ -- Trap Triggers --------------------------------------------------------------------------
798+ -- -------------------------------------------------------------------------------------------
799+ trap_pending: process (rstn_i, clk_i)
800+ begin
801+ if (rstn_i = '0' ) then
802+ trap.env_pend <= '0' ;
803+ elsif rising_edge (clk_i) then
804+ if (trap.env_enter = '1' ) then -- start of trap environment acknowledged by execute engine
805+ trap.env_pend <= '0' ;
806+ elsif (trap.exc_fire = '1' ) or (or_reduce_f(trap.irq_fire) = '1' ) then -- trap trigger
807+ trap.env_pend <= '1' ;
808+ end if ;
809+ end if ;
810+ end process trap_pending;
811+
812+ -- any sync. exception? --
813+ trap.exc_fire <= or_reduce_f(trap.exc_buf); -- cannot be masked
814+
815+ -- any system interrupt? --
816+ trap.irq_fire(0 ) <= '1' when
817+ ((exec.state = S_EXECUTE) or (exec.state = S_SLEEP)) and -- trigger system IRQ only in S_EXECUTE state or in sleep mode
818+ (or_reduce_f(trap.irq_buf(irq_firq_15_c downto irq_msi_irq_c)) = '1' ) and -- pending system IRQ
819+ ((csr.mstatus_mie = '1' ) or (csr.prv_level = priv_mode_u_c)) and -- IRQ only when in M-mode and MIE=1 OR when in U-mode
820+ (debug_ctrl.run = '0' ) and (csr.dcsr_step = '0' ) else '0' ; -- no system IRQs when in debug-mode / during single-stepping
821+
822+ -- debug-entry halt interrupt? allow halt also after "reset" (#879) --
823+ trap.irq_fire(1 ) <= trap.irq_buf(irq_db_halt_c) when (exec.state = S_RESTART) or (exec.state = S_EXECUTE) or (exec.state = S_SLEEP) else '0' ;
824+
825+
797826 -- Trap Priority Encoder ------------------------------------------------------------------
798827 -- -------------------------------------------------------------------------------------------
799828 trap.cause <=
@@ -807,7 +836,7 @@ begin
807836 trap_lma_c when (trap.exc_buf(exc_lalign_c) = '1' ) else -- load address misaligned
808837 trap_saf_c when (trap.exc_buf(exc_saccess_c) = '1' ) else -- store access fault
809838 trap_laf_c when (trap.exc_buf(exc_laccess_c) = '1' ) else -- load access fault
810- -- standard RISC-V debug mode traps --
839+ -- standard RISC-V debug- mode traps --
811840 trap_db_halt_c when (trap.irq_buf(irq_db_halt_c) = '1' ) else -- external halt request
812841 trap_db_trig_c when (trap.exc_buf(exc_db_trig_c) = '1' ) else -- hardware trigger
813842 trap_db_brkp_c when (trap.exc_buf(exc_db_brkp_c) = '1' ) else -- breakpoint
@@ -841,35 +870,6 @@ begin
841870 trap.pc <= exec.pc2 when (trap.cause(trap.cause'left ) = '1' ) else exec.pc;
842871
843872
844- -- Trap Triggers --------------------------------------------------------------------------
845- -- -------------------------------------------------------------------------------------------
846- trap_pending: process (rstn_i, clk_i)
847- begin
848- if (rstn_i = '0' ) then
849- trap.env_pend <= '0' ;
850- elsif rising_edge (clk_i) then
851- if (trap.env_enter = '1' ) then -- start of trap environment acknowledged by execute engine
852- trap.env_pend <= '0' ;
853- elsif (trap.exc_fire = '1' ) or (or_reduce_f(trap.irq_fire) = '1' ) then -- trap trigger
854- trap.env_pend <= '1' ;
855- end if ;
856- end if ;
857- end process trap_pending;
858-
859- -- any sync. exception? --
860- trap.exc_fire <= or_reduce_f(trap.exc_buf); -- cannot be masked
861-
862- -- any system interrupt? --
863- trap.irq_fire(0 ) <= '1' when
864- ((exec.state = S_EXECUTE) or (exec.state = S_SLEEP)) and -- trigger system IRQ only in S_EXECUTE state or in sleep mode
865- (or_reduce_f(trap.irq_buf(irq_firq_15_c downto irq_msi_irq_c)) = '1' ) and -- pending system IRQ
866- ((csr.mstatus_mie = '1' ) or (csr.prv_level = priv_mode_u_c)) and -- IRQ only when in M-mode and MIE=1 OR when in U-mode
867- (debug_ctrl.run = '0' ) and (csr.dcsr_step = '0' ) else '0' ; -- no system IRQs when in debug-mode / during single-stepping
868-
869- -- debug-entry halt interrupt? allow halt also after "reset" (#879) --
870- trap.irq_fire(1 ) <= trap.irq_buf(irq_db_halt_c) when (exec.state = S_RESTART) or (exec.state = S_EXECUTE) or (exec.state = S_SLEEP) else '0' ;
871-
872-
873873 -- Debug-Mode Control ---------------------------------------------------------------------
874874 -- -------------------------------------------------------------------------------------------
875875 debug_mode_enabled:
0 commit comments