リビジョン | 79f26b3b951dd8eeec23d437c41f0944167ce44d (tree) |
---|---|
日時 | 2022-01-21 14:52:57 |
作者 | LIU Zhiwei <zhiwei_liu@c-sk...> |
コミッター | Alistair Francis |
target/riscv: Adjust pmpcfg access with mxl
Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-id: 20220120122050.41546-2-zhiwei_liu@c-sky.com
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
@@ -1497,9 +1497,23 @@ static RISCVException write_mseccfg(CPURISCVState *env, int csrno, | ||
1497 | 1497 | return RISCV_EXCP_NONE; |
1498 | 1498 | } |
1499 | 1499 | |
1500 | +static bool check_pmp_reg_index(CPURISCVState *env, uint32_t reg_index) | |
1501 | +{ | |
1502 | + /* TODO: RV128 restriction check */ | |
1503 | + if ((reg_index & 1) && (riscv_cpu_mxl(env) == MXL_RV64)) { | |
1504 | + return false; | |
1505 | + } | |
1506 | + return true; | |
1507 | +} | |
1508 | + | |
1500 | 1509 | static RISCVException read_pmpcfg(CPURISCVState *env, int csrno, |
1501 | 1510 | target_ulong *val) |
1502 | 1511 | { |
1512 | + uint32_t reg_index = csrno - CSR_PMPCFG0; | |
1513 | + | |
1514 | + if (!check_pmp_reg_index(env, reg_index)) { | |
1515 | + return RISCV_EXCP_ILLEGAL_INST; | |
1516 | + } | |
1503 | 1517 | *val = pmpcfg_csr_read(env, csrno - CSR_PMPCFG0); |
1504 | 1518 | return RISCV_EXCP_NONE; |
1505 | 1519 | } |
@@ -1507,6 +1521,11 @@ static RISCVException read_pmpcfg(CPURISCVState *env, int csrno, | ||
1507 | 1521 | static RISCVException write_pmpcfg(CPURISCVState *env, int csrno, |
1508 | 1522 | target_ulong val) |
1509 | 1523 | { |
1524 | + uint32_t reg_index = csrno - CSR_PMPCFG0; | |
1525 | + | |
1526 | + if (!check_pmp_reg_index(env, reg_index)) { | |
1527 | + return RISCV_EXCP_ILLEGAL_INST; | |
1528 | + } | |
1510 | 1529 | pmpcfg_csr_write(env, csrno - CSR_PMPCFG0, val); |
1511 | 1530 | return RISCV_EXCP_NONE; |
1512 | 1531 | } |
@@ -463,16 +463,11 @@ void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index, | ||
463 | 463 | { |
464 | 464 | int i; |
465 | 465 | uint8_t cfg_val; |
466 | + int pmpcfg_nums = 2 << riscv_cpu_mxl(env); | |
466 | 467 | |
467 | 468 | trace_pmpcfg_csr_write(env->mhartid, reg_index, val); |
468 | 469 | |
469 | - if ((reg_index & 1) && (sizeof(target_ulong) == 8)) { | |
470 | - qemu_log_mask(LOG_GUEST_ERROR, | |
471 | - "ignoring pmpcfg write - incorrect address\n"); | |
472 | - return; | |
473 | - } | |
474 | - | |
475 | - for (i = 0; i < sizeof(target_ulong); i++) { | |
470 | + for (i = 0; i < pmpcfg_nums; i++) { | |
476 | 471 | cfg_val = (val >> 8 * i) & 0xff; |
477 | 472 | pmp_write_cfg(env, (reg_index * 4) + i, cfg_val); |
478 | 473 | } |
@@ -490,8 +485,9 @@ target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index) | ||
490 | 485 | int i; |
491 | 486 | target_ulong cfg_val = 0; |
492 | 487 | target_ulong val = 0; |
488 | + int pmpcfg_nums = 2 << riscv_cpu_mxl(env); | |
493 | 489 | |
494 | - for (i = 0; i < sizeof(target_ulong); i++) { | |
490 | + for (i = 0; i < pmpcfg_nums; i++) { | |
495 | 491 | val = pmp_read_cfg(env, (reg_index * 4) + i); |
496 | 492 | cfg_val |= (val << (i * 8)); |
497 | 493 | } |