@@ -3035,31 +3035,16 @@ static int riscv_mmu(struct target *target, int *enabled)
30353035 unsigned int xlen = riscv_xlen (target );
30363036
30373037 if (v_mode ) {
3038- /* vsatp and hgatp registers are considered active for the
3039- * purposes of the address-translation algorithm unless the
3040- * effective privilege mode is U and hstatus.HU=0. */
3041- if (effective_mode == PRV_U ) {
3042- riscv_reg_t hstatus ;
3043- if (riscv_reg_get (target , & hstatus , GDB_REGNO_HSTATUS ) != ERROR_OK ) {
3044- LOG_TARGET_ERROR (target , "Failed to read hstatus register." );
3045- return ERROR_FAIL ;
3046- }
3047-
3048- if (get_field (hstatus , HSTATUS_HU ) == 0 )
3049- /* In hypervisor mode regular satp translation
3050- * doesn't happen. */
3051- return ERROR_OK ;
3052-
3053- }
3054-
3038+ /* In VU or VS mode, MMU is considered enabled when
3039+ * either hgatp or vsatp mode is not OFF */
30553040 riscv_reg_t vsatp ;
30563041 if (riscv_reg_get (target , & vsatp , GDB_REGNO_VSATP ) != ERROR_OK ) {
30573042 LOG_TARGET_ERROR (target , "Failed to read vsatp register; priv=0x%" PRIx64 ,
30583043 priv );
30593044 return ERROR_FAIL ;
30603045 }
30613046 /* vsatp is identical to satp, so we can use the satp macros. */
3062- if (RISCV_SATP_MODE (xlen ) != SATP_MODE_OFF ) {
3047+ if (get_field ( vsatp , RISCV_SATP_MODE (xlen ) ) != SATP_MODE_OFF ) {
30633048 LOG_TARGET_DEBUG (target , "VS-stage translation is enabled." );
30643049 * enabled = 1 ;
30653050 return ERROR_OK ;
@@ -3071,7 +3056,7 @@ static int riscv_mmu(struct target *target, int *enabled)
30713056 priv );
30723057 return ERROR_FAIL ;
30733058 }
3074- if (RISCV_HGATP_MODE (xlen ) != HGATP_MODE_OFF ) {
3059+ if (get_field ( hgatp , RISCV_HGATP_MODE (xlen ) ) != HGATP_MODE_OFF ) {
30753060 LOG_TARGET_DEBUG (target , "G-stage address translation is enabled." );
30763061 * enabled = 1 ;
30773062 } else {
0 commit comments