@@ -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
@@ -3422,12 +3435,18 @@ static int riscv_rw_memory(struct target *target, const riscv_mem_access_args_t
34223435 return ERROR_OK ;
34233436 }
34243437
3438+ RISCV_INFO (r );
3439+ if (riscv_virt2phys_mode_is_off (target ))
3440+ return r -> access_memory (target , args , /* is_virtual */ false);
3441+
3442+ if (riscv_virt2phys_mode_is_hw (target ))
3443+ return r -> access_memory (target , args , /* is_virtual */ true);
3444+
34253445 int result = check_virt_memory_access (target , args .address ,
34263446 args .size , args .count , is_write );
34273447 if (result != ERROR_OK )
34283448 return result ;
34293449
3430- RISCV_INFO (r );
34313450 uint32_t current_count = 0 ;
34323451 target_addr_t current_address = args .address ;
34333452 while (current_count < args .count ) {
@@ -3453,7 +3472,8 @@ static int riscv_rw_memory(struct target *target, const riscv_mem_access_args_t
34533472 else
34543473 current_access .read_buffer += current_count * args .size ;
34553474
3456- result = r -> access_memory (target , current_access );
3475+ result = r -> access_memory (target ,
3476+ current_access , /* is_virtual */ false);
34573477 if (result != ERROR_OK )
34583478 return result ;
34593479
@@ -3474,7 +3494,7 @@ static int riscv_read_memory(struct target *target, target_addr_t address,
34743494 .increment = size ,
34753495 };
34763496
3477- return riscv_rw_memory (target , args );
3497+ return riscv_access_virt_memory (target , args );
34783498}
34793499
34803500static int riscv_write_memory (struct target * target , target_addr_t address ,
@@ -3488,7 +3508,7 @@ static int riscv_write_memory(struct target *target, target_addr_t address,
34883508 .increment = size ,
34893509 };
34903510
3491- return riscv_rw_memory (target , args );
3511+ return riscv_access_virt_memory (target , args );
34923512}
34933513
34943514static const char * riscv_get_gdb_arch (const struct target * target )
@@ -5221,7 +5241,9 @@ COMMAND_HANDLER(handle_repeat_read)
52215241 .count = count ,
52225242 .increment = 0 ,
52235243 };
5224- 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);
52255247 if (result == ERROR_OK ) {
52265248 target_handle_md_output (cmd , target , address , size , count , buffer ,
52275249 false);
@@ -5604,7 +5626,7 @@ static const struct command_registration riscv_exec_command_handlers[] = {
56045626 .handler = handle_repeat_read ,
56055627 .mode = COMMAND_ANY ,
56065628 .usage = "count address [size=4]" ,
5607- .help = "Repeatedly read the value at address."
5629+ .help = "Repeatedly read the value at physical address."
56085630 },
56095631 {
56105632 .name = "set_command_timeout_sec" ,
0 commit comments