@@ -459,6 +459,36 @@ static void test_riscv64_ecall(void)
459459 OK (uc_close (uc ));
460460}
461461
462+ static void test_riscv32_architectural_exception_entry (void )
463+ {
464+ uc_engine * uc ;
465+ char code [] = "\x73\x00\x00\x00" ; // ecall
466+ uint32_t mtvec = 0x1800 ;
467+ uint32_t pc , mepc , mcause , priv ;
468+ int enabled = 0 ;
469+ uc_hook h ;
470+
471+ uc_common_setup (& uc , UC_ARCH_RISCV , UC_MODE_RISCV32 , code ,
472+ sizeof (code ) - 1 );
473+ OK (uc_reg_write (uc , UC_RISCV_REG_MTVEC , & mtvec ));
474+ OK (uc_ctl_set_architectural_exceptions (uc , 1 ));
475+ OK (uc_ctl_get_architectural_exceptions (uc , & enabled ));
476+ TEST_CHECK (enabled == 1 );
477+ OK (uc_hook_add (uc , & h , UC_HOOK_INTR , test_riscv64_ecall_cb , NULL , 1 , 0 ));
478+ OK (uc_emu_start (uc , code_start , code_start + sizeof (code ) - 1 , 0 , 0 ));
479+
480+ OK (uc_reg_read (uc , UC_RISCV_REG_PC , & pc ));
481+ OK (uc_reg_read (uc , UC_RISCV_REG_MEPC , & mepc ));
482+ OK (uc_reg_read (uc , UC_RISCV_REG_MCAUSE , & mcause ));
483+ OK (uc_reg_read (uc , UC_RISCV_REG_PRIV , & priv ));
484+ TEST_CHECK (pc == mtvec );
485+ TEST_CHECK (mepc == code_start );
486+ TEST_CHECK (mcause == 11 ); // machine-mode ecall
487+ TEST_CHECK (priv == 3 ); // machine mode
488+
489+ OK (uc_close (uc ));
490+ }
491+
462492static uint64_t test_riscv32_mmio_map_read_cb (uc_engine * uc , uint64_t offset ,
463493 unsigned size , void * data )
464494{
@@ -810,6 +840,8 @@ TEST_LIST = {
810840 test_riscv64_fp_move_from_int_reg_write },
811841 {"test_riscv64_fp_move_to_int" , test_riscv64_fp_move_to_int },
812842 {"test_riscv64_ecall" , test_riscv64_ecall },
843+ {"test_riscv32_architectural_exception_entry" ,
844+ test_riscv32_architectural_exception_entry },
813845 {"test_riscv32_mmio_map" , test_riscv32_mmio_map },
814846 {"test_riscv64_mmio_map" , test_riscv64_mmio_map },
815847 {"test_riscv32_map" , test_riscv32_map },
0 commit comments