@@ -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,12 +3435,18 @@ 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 )
3428
3448
return result ;
3429
3449
3430
- RISCV_INFO (r );
3431
3450
uint32_t current_count = 0 ;
3432
3451
target_addr_t current_address = args .address ;
3433
3452
while (current_count < args .count ) {
@@ -3453,7 +3472,8 @@ static int riscv_rw_memory(struct target *target, const riscv_mem_access_args_t
3453
3472
else
3454
3473
current_access .read_buffer += current_count * args .size ;
3455
3474
3456
- result = r -> access_memory (target , current_access );
3475
+ result = r -> access_memory (target ,
3476
+ current_access , /* is_virtual */ false);
3457
3477
if (result != ERROR_OK )
3458
3478
return result ;
3459
3479
@@ -3474,7 +3494,7 @@ static int riscv_read_memory(struct target *target, target_addr_t address,
3474
3494
.increment = size ,
3475
3495
};
3476
3496
3477
- return riscv_rw_memory (target , args );
3497
+ return riscv_access_virt_memory (target , args );
3478
3498
}
3479
3499
3480
3500
static 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,
3488
3508
.increment = size ,
3489
3509
};
3490
3510
3491
- return riscv_rw_memory (target , args );
3511
+ return riscv_access_virt_memory (target , args );
3492
3512
}
3493
3513
3494
3514
static const char * riscv_get_gdb_arch (const struct target * target )
@@ -5221,7 +5241,9 @@ COMMAND_HANDLER(handle_repeat_read)
5221
5241
.count = count ,
5222
5242
.increment = 0 ,
5223
5243
};
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);
5225
5247
if (result == ERROR_OK ) {
5226
5248
target_handle_md_output (cmd , target , address , size , count , buffer ,
5227
5249
false);
@@ -5604,7 +5626,7 @@ static const struct command_registration riscv_exec_command_handlers[] = {
5604
5626
.handler = handle_repeat_read ,
5605
5627
.mode = COMMAND_ANY ,
5606
5628
.usage = "count address [size=4]" ,
5607
- .help = "Repeatedly read the value at address."
5629
+ .help = "Repeatedly read the value at physical address."
5608
5630
},
5609
5631
{
5610
5632
.name = "set_command_timeout_sec" ,
0 commit comments