@@ -155,6 +155,13 @@ bool riscv_virt2phys_mode_is_sw(const struct target *target)
155
155
return r -> virt2phys_mode == RISCV_VIRT2PHYS_MODE_SW ;
156
156
}
157
157
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
+
158
165
const char * riscv_virt2phys_mode_to_str (riscv_virt2phys_mode_t mode )
159
166
{
160
167
assert (mode == RISCV_VIRT2PHYS_MODE_OFF
@@ -3149,7 +3156,7 @@ static int riscv_address_translate(struct target *target,
3149
3156
.increment = 4 ,
3150
3157
.count = (1 << info -> pte_shift ) / 4 ,
3151
3158
};
3152
- int retval = r -> access_memory (target , args );
3159
+ int retval = r -> access_memory (target , args , /* is_virtual */ false );
3153
3160
if (retval != ERROR_OK )
3154
3161
return ERROR_FAIL ;
3155
3162
@@ -3382,6 +3389,14 @@ static int check_virt_memory_access(struct target *target, target_addr_t address
3382
3389
return ERROR_OK ;
3383
3390
}
3384
3391
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
+
3385
3400
static int riscv_read_phys_memory (struct target * target , target_addr_t phys_address ,
3386
3401
uint32_t size , uint32_t count , uint8_t * buffer )
3387
3402
{
@@ -3392,8 +3407,7 @@ static int riscv_read_phys_memory(struct target *target, target_addr_t phys_addr
3392
3407
.count = count ,
3393
3408
.increment = size ,
3394
3409
};
3395
- RISCV_INFO (r );
3396
- return r -> access_memory (target , args );
3410
+ return riscv_access_phys_memory (target , args );
3397
3411
}
3398
3412
3399
3413
static 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
3406
3420
.count = count ,
3407
3421
.increment = size ,
3408
3422
};
3409
-
3410
- RISCV_INFO (r );
3411
- return r -> access_memory (target , args );
3423
+ return riscv_access_phys_memory (target , args );
3412
3424
}
3413
3425
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 )
3415
3428
{
3416
3429
assert (riscv_mem_access_is_valid (args ));
3417
3430
@@ -3422,6 +3435,13 @@ static int riscv_rw_memory(struct target *target, const riscv_mem_access_args_t
3422
3435
return ERROR_OK ;
3423
3436
}
3424
3437
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
+
3425
3445
int result = check_virt_memory_access (target , args .address ,
3426
3446
args .size , args .count , is_write );
3427
3447
if (result != ERROR_OK )
@@ -3453,7 +3473,8 @@ static int riscv_rw_memory(struct target *target, const riscv_mem_access_args_t
3453
3473
else
3454
3474
current_access .read_buffer += current_count * args .size ;
3455
3475
3456
- result = r -> access_memory (target , current_access );
3476
+ result = r -> access_memory (target ,
3477
+ current_access , /* is_virtual */ false);
3457
3478
if (result != ERROR_OK )
3458
3479
return result ;
3459
3480
@@ -3474,7 +3495,7 @@ static int riscv_read_memory(struct target *target, target_addr_t address,
3474
3495
.increment = size ,
3475
3496
};
3476
3497
3477
- return riscv_rw_memory (target , args );
3498
+ return riscv_access_virt_memory (target , args );
3478
3499
}
3479
3500
3480
3501
static 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,
3488
3509
.increment = size ,
3489
3510
};
3490
3511
3491
- return riscv_rw_memory (target , args );
3512
+ return riscv_access_virt_memory (target , args );
3492
3513
}
3493
3514
3494
3515
static const char * riscv_get_gdb_arch (const struct target * target )
@@ -5221,7 +5242,9 @@ COMMAND_HANDLER(handle_repeat_read)
5221
5242
.count = count ,
5222
5243
.increment = 0 ,
5223
5244
};
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);
5225
5248
if (result == ERROR_OK ) {
5226
5249
target_handle_md_output (cmd , target , address , size , count , buffer ,
5227
5250
false);
@@ -5604,7 +5627,7 @@ static const struct command_registration riscv_exec_command_handlers[] = {
5604
5627
.handler = handle_repeat_read ,
5605
5628
.mode = COMMAND_ANY ,
5606
5629
.usage = "count address [size=4]" ,
5607
- .help = "Repeatedly read the value at address."
5630
+ .help = "Repeatedly read the value at physical address."
5608
5631
},
5609
5632
{
5610
5633
.name = "set_command_timeout_sec" ,
0 commit comments