@@ -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,6 +3435,13 @@ 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 )
@@ -3453,7 +3473,8 @@ static int riscv_rw_memory(struct target *target, const riscv_mem_access_args_t
34533473 else
34543474 current_access .read_buffer += current_count * args .size ;
34553475
3456- result = r -> access_memory (target , current_access );
3476+ result = r -> access_memory (target ,
3477+ current_access , /* is_virtual */ false);
34573478 if (result != ERROR_OK )
34583479 return result ;
34593480
@@ -3474,7 +3495,7 @@ static int riscv_read_memory(struct target *target, target_addr_t address,
34743495 .increment = size ,
34753496 };
34763497
3477- return riscv_rw_memory (target , args );
3498+ return riscv_access_virt_memory (target , args );
34783499}
34793500
34803501static int riscv_write_memory (struct target * target , target_addr_t address ,
@@ -3488,7 +3509,7 @@ static int riscv_write_memory(struct target *target, target_addr_t address,
34883509 .increment = size ,
34893510 };
34903511
3491- return riscv_rw_memory (target , args );
3512+ return riscv_access_virt_memory (target , args );
34923513}
34933514
34943515static const char * riscv_get_gdb_arch (const struct target * target )
@@ -5221,7 +5242,9 @@ COMMAND_HANDLER(handle_repeat_read)
52215242 .count = count ,
52225243 .increment = 0 ,
52235244 };
5224- int result = r -> access_memory (target , args );
5245+ /* TODO: Add a command parameter that enables
5246+ * choosing between virtual and physical access */
5247+ int result = r -> access_memory (target , args , /* is_virtual */ false);
52255248 if (result == ERROR_OK ) {
52265249 target_handle_md_output (cmd , target , address , size , count , buffer ,
52275250 false);
@@ -5604,7 +5627,7 @@ static const struct command_registration riscv_exec_command_handlers[] = {
56045627 .handler = handle_repeat_read ,
56055628 .mode = COMMAND_ANY ,
56065629 .usage = "count address [size=4]" ,
5607- .help = "Repeatedly read the value at address."
5630+ .help = "Repeatedly read the value at physical address."
56085631 },
56095632 {
56105633 .name = "set_command_timeout_sec" ,
0 commit comments