@@ -155,6 +155,13 @@ bool riscv_virt2phys_mode_is_sw(const struct target *target)
155155 return r -> virt2phys_mode == RISCV_VIRT2PHYS_MODE_SW ;
156156}
157157
158+ bool riscv_virt2phys_mode_is_off (const struct target * target )
159+ {
160+ assert (target );
161+ RISCV_INFO (r );
162+ return r -> virt2phys_mode == RISCV_VIRT2PHYS_MODE_OFF ;
163+ }
164+
158165const char * riscv_virt2phys_mode_to_str (riscv_virt2phys_mode_t mode )
159166{
160167 assert (mode == RISCV_VIRT2PHYS_MODE_OFF
@@ -3149,7 +3156,7 @@ static int riscv_address_translate(struct target *target,
31493156 .increment = 4 ,
31503157 .count = (1 << info -> pte_shift ) / 4 ,
31513158 };
3152- int retval = r -> access_memory (target , args );
3159+ int retval = r -> access_memory (target , args , /* is_virtual */ false );
31533160 if (retval != ERROR_OK )
31543161 return ERROR_FAIL ;
31553162
@@ -3382,6 +3389,14 @@ static int check_virt_memory_access(struct target *target, target_addr_t address
33823389 return ERROR_OK ;
33833390}
33843391
3392+ static int riscv_access_phys_memory (struct target * target ,
3393+ const riscv_mem_access_args_t args )
3394+ {
3395+ RISCV_INFO (r );
3396+ return r -> access_memory (target , args , /* is_virtual */ false);
3397+ }
3398+
3399+
33853400static int riscv_read_phys_memory (struct target * target , target_addr_t phys_address ,
33863401 uint32_t size , uint32_t count , uint8_t * buffer )
33873402{
@@ -3392,8 +3407,7 @@ static int riscv_read_phys_memory(struct target *target, target_addr_t phys_addr
33923407 .count = count ,
33933408 .increment = size ,
33943409 };
3395- RISCV_INFO (r );
3396- return r -> access_memory (target , args );
3410+ return riscv_access_phys_memory (target , args );
33973411}
33983412
33993413static int riscv_write_phys_memory (struct target * target , target_addr_t phys_address ,
@@ -3406,12 +3420,11 @@ static int riscv_write_phys_memory(struct target *target, target_addr_t phys_add
34063420 .count = count ,
34073421 .increment = size ,
34083422 };
3409-
3410- RISCV_INFO (r );
3411- return r -> access_memory (target , args );
3423+ return riscv_access_phys_memory (target , args );
34123424}
34133425
3414- static int riscv_rw_memory (struct target * target , const riscv_mem_access_args_t args )
3426+ static int riscv_access_virt_memory (struct target * target ,
3427+ const riscv_mem_access_args_t args )
34153428{
34163429 assert (riscv_mem_access_is_valid (args ));
34173430
@@ -3423,8 +3436,11 @@ static int riscv_rw_memory(struct target *target, const riscv_mem_access_args_t
34233436 }
34243437
34253438 RISCV_INFO (r );
3439+ if (riscv_virt2phys_mode_is_off (target ))
3440+ return r -> access_memory (target , args , /* is_virtual */ false);
3441+
34263442 if (riscv_virt2phys_mode_is_hw (target ))
3427- return r -> access_memory (target , args );
3443+ return r -> access_memory (target , args , /* is_virtual */ true );
34283444
34293445 int result = check_virt_memory_access (target , args .address ,
34303446 args .size , args .count , is_write );
@@ -3456,7 +3472,8 @@ static int riscv_rw_memory(struct target *target, const riscv_mem_access_args_t
34563472 else
34573473 current_access .read_buffer += current_count * args .size ;
34583474
3459- result = r -> access_memory (target , current_access );
3475+ result = r -> access_memory (target ,
3476+ current_access , /* is_virtual */ false);
34603477 if (result != ERROR_OK )
34613478 return result ;
34623479
@@ -3477,7 +3494,7 @@ static int riscv_read_memory(struct target *target, target_addr_t address,
34773494 .increment = size ,
34783495 };
34793496
3480- return riscv_rw_memory (target , args );
3497+ return riscv_access_virt_memory (target , args );
34813498}
34823499
34833500static int riscv_write_memory (struct target * target , target_addr_t address ,
@@ -3491,7 +3508,7 @@ static int riscv_write_memory(struct target *target, target_addr_t address,
34913508 .increment = size ,
34923509 };
34933510
3494- return riscv_rw_memory (target , args );
3511+ return riscv_access_virt_memory (target , args );
34953512}
34963513
34973514static const char * riscv_get_gdb_arch (const struct target * target )
@@ -5224,7 +5241,9 @@ COMMAND_HANDLER(handle_repeat_read)
52245241 .count = count ,
52255242 .increment = 0 ,
52265243 };
5227- int result = r -> access_memory (target , args );
5244+ /* TODO: Add a command parameter that enables
5245+ * choosing between virtual and physical access */
5246+ int result = r -> access_memory (target , args , /* is_virtual */ false);
52285247 if (result == ERROR_OK ) {
52295248 target_handle_md_output (cmd , target , address , size , count , buffer ,
52305249 false);
@@ -5607,7 +5626,7 @@ static const struct command_registration riscv_exec_command_handlers[] = {
56075626 .handler = handle_repeat_read ,
56085627 .mode = COMMAND_ANY ,
56095628 .usage = "count address [size=4]" ,
5610- .help = "Repeatedly read the value at address."
5629+ .help = "Repeatedly read the value at physical address."
56115630 },
56125631 {
56135632 .name = "set_command_timeout_sec" ,
0 commit comments