@@ -862,12 +862,9 @@ static block_t *block_find_or_translate(riscv_t *rv)
862862 block_translate (rv , next_blk );
863863
864864 optimize_constant (rv , next_blk );
865- #if RV32_HAS (GDBSTUB )
866- if (likely (!rv -> debug_mode ))
867- #endif
868865#if RV32_HAS (MOP_FUSION )
869- /* macro operation fusion */
870- match_pattern (rv , next_blk );
866+ /* macro operation fusion */
867+ match_pattern (rv , next_blk );
871868#endif
872869
873870#if !RV32_HAS (JIT )
@@ -958,7 +955,83 @@ static bool rv_has_plic_trap(riscv_t *rv)
958955 return ((rv -> csr_sstatus & SSTATUS_SIE || !rv -> priv_mode ) &&
959956 (rv -> csr_sip & rv -> csr_sie ));
960957}
958+
959+ static void rv_check_interrupt (riscv_t * rv )
960+ {
961+ vm_attr_t * attr = PRIV (rv );
962+ /* check for any interrupt after every block/instruction emulation */
963+ if (peripheral_update_ctr -- == 0 ) {
964+ peripheral_update_ctr = 64 ;
965+
966+ u8250_check_ready (PRIV (rv )-> uart );
967+ if (PRIV (rv )-> uart -> in_ready )
968+ emu_update_uart_interrupts (rv );
969+ }
970+
971+ if (ctr > attr -> timer )
972+ rv -> csr_sip |= RV_INT_STI ;
973+ else
974+ rv -> csr_sip &= ~RV_INT_STI ;
975+
976+ if (rv_has_plic_trap (rv )) {
977+ uint32_t intr_applicable = rv -> csr_sip & rv -> csr_sie ;
978+ uint8_t intr_idx = ilog2 (intr_applicable );
979+ switch (intr_idx ) {
980+ case (SUPERVISOR_SW_INTR & 0xf ):
981+ SET_CAUSE_AND_TVAL_THEN_TRAP (rv , SUPERVISOR_SW_INTR , 0 );
982+ break ;
983+ case (SUPERVISOR_TIMER_INTR & 0xf ):
984+ SET_CAUSE_AND_TVAL_THEN_TRAP (rv , SUPERVISOR_TIMER_INTR , 0 );
985+ break ;
986+ case (SUPERVISOR_EXTERNAL_INTR & 0xf ):
987+ SET_CAUSE_AND_TVAL_THEN_TRAP (rv , SUPERVISOR_EXTERNAL_INTR , 0 );
988+ break ;
989+ default :
990+ break ;
991+ }
992+ }
993+ }
994+ #else
995+ static void rv_check_interrupt (UNUSED riscv_t * rv )
996+ {
997+ return ;
998+ }
999+ #endif
1000+
1001+ void rv_step_debug (void * arg )
1002+ {
1003+ assert (arg );
1004+ riscv_t * rv = arg ;
1005+
1006+ rv_check_interrupt (rv );
1007+
1008+ retranslate :
1009+ /* fetch the next instruction */
1010+ rv_insn_t ir ;
1011+ memset (& ir , 0 , sizeof (rv_insn_t ));
1012+
1013+ uint32_t insn = rv -> io .mem_ifetch (rv , rv -> PC );
1014+ #if RV32_HAS (SYSTEM )
1015+ if (!insn && need_retranslate ) {
1016+ need_retranslate = false;
1017+ goto retranslate ;
1018+ }
9611019#endif
1020+ assert (insn );
1021+
1022+ /* decode the instruction */
1023+ if (!rv_decode (& ir , insn )) {
1024+ rv -> compressed = is_compressed (insn );
1025+ SET_CAUSE_AND_TVAL_THEN_TRAP (rv , ILLEGAL_INSN , insn );
1026+ return ;
1027+ }
1028+
1029+ ir .impl = dispatch_table [ir .opcode ];
1030+ ir .pc = rv -> PC ;
1031+ ir .next = NULL ;
1032+ ir .impl (rv , & ir , rv -> csr_cycle , rv -> PC );
1033+ return ;
1034+ }
9621035
9631036void rv_step (void * arg )
9641037{
@@ -973,40 +1046,7 @@ void rv_step(void *arg)
9731046
9741047 /* loop until hitting the cycle target */
9751048 while (rv -> csr_cycle < cycles_target && !rv -> halt ) {
976- #if RV32_HAS (SYSTEM ) && !RV32_HAS (ELF_LOADER )
977- /* check for any interrupt after every block emulation */
978-
979- if (peripheral_update_ctr -- == 0 ) {
980- peripheral_update_ctr = 64 ;
981-
982- u8250_check_ready (PRIV (rv )-> uart );
983- if (PRIV (rv )-> uart -> in_ready )
984- emu_update_uart_interrupts (rv );
985- }
986-
987- if (ctr > attr -> timer )
988- rv -> csr_sip |= RV_INT_STI ;
989- else
990- rv -> csr_sip &= ~RV_INT_STI ;
991-
992- if (rv_has_plic_trap (rv )) {
993- uint32_t intr_applicable = rv -> csr_sip & rv -> csr_sie ;
994- uint8_t intr_idx = ilog2 (intr_applicable );
995- switch (intr_idx ) {
996- case (SUPERVISOR_SW_INTR & 0xf ):
997- SET_CAUSE_AND_TVAL_THEN_TRAP (rv , SUPERVISOR_SW_INTR , 0 );
998- break ;
999- case (SUPERVISOR_TIMER_INTR & 0xf ):
1000- SET_CAUSE_AND_TVAL_THEN_TRAP (rv , SUPERVISOR_TIMER_INTR , 0 );
1001- break ;
1002- case (SUPERVISOR_EXTERNAL_INTR & 0xf ):
1003- SET_CAUSE_AND_TVAL_THEN_TRAP (rv , SUPERVISOR_EXTERNAL_INTR , 0 );
1004- break ;
1005- default :
1006- break ;
1007- }
1008- }
1009- #endif /* RV32_HAS(SYSTEM) && !RV32_HAS(ELF_LOADER) */
1049+ rv_check_interrupt (rv );
10101050
10111051 if (prev && prev -> pc_start != last_pc ) {
10121052 /* update previous block */
0 commit comments