Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enable hardware translation when progbufsize too small #1188

Open
lz-bro opened this issue Dec 23, 2024 · 2 comments · May be fixed by #1190
Open

How to enable hardware translation when progbufsize too small #1188

lz-bro opened this issue Dec 23, 2024 · 2 comments · May be fixed by #1190

Comments

@lz-bro
Copy link
Contributor

lz-bro commented Dec 23, 2024

Hardware translation requires a program buffer size of at least 4. Can we use a register_write_direct function instead of two instructions csrrsi zero, dcsr, dcsr_mprven and csrrci zero, dcsr, dcsr_mprven ?

if (info->progbufsize < 4 && riscv_virt2phys_mode_is_hw(target)) {
LOG_TARGET_ERROR(target, "software address translation "
"is not available on this target. It requires a "
"program buffer size of at least 4. (progbufsize=%d) "
"Use `riscv set_enable_virtual off` to continue.", info->progbufsize);
}

* modify_privilege function used only for program buffer memory access.
* Privilege modification requires progbuf size to be at least 5 */
if (!has_sufficient_progbuf(target, 5)) {
LOG_TARGET_WARNING(target, "Can't modify privilege to provide "
"hardware translation: program buffer too small.");
return ERROR_OK;
}

static int riscv_program_load_mprv(struct riscv_program *p, enum gdb_regno d,
enum gdb_regno b, int offset, unsigned int size, bool mprven)
{
if (mprven && riscv_program_csrrsi(p, GDB_REGNO_ZERO, CSR_DCSR_MPRVEN,
GDB_REGNO_DCSR) != ERROR_OK)
return ERROR_FAIL;
if (riscv_program_load(p, d, b, offset, size) != ERROR_OK)
return ERROR_FAIL;
if (mprven && riscv_program_csrrci(p, GDB_REGNO_ZERO, CSR_DCSR_MPRVEN,
GDB_REGNO_DCSR) != ERROR_OK)
return ERROR_FAIL;
return ERROR_OK;
}

@en-sc
Copy link
Collaborator

en-sc commented Dec 23, 2024

@lz-bro, AFAIK dcsr modification can be moved out of program buffer and into modify_privilege().
However, I'd like to ask you to avoid using register_read/write_direct() functions. I believe it's safer to use the standard riscv_reg_get/riscv_reg_set functions -- there is no need to bypass the register cache.

@lz-bro
Copy link
Contributor Author

lz-bro commented Dec 24, 2024

@lz-bro, AFAIK dcsr modification can be moved out of program buffer and into modify_privilege(). However, I'd like to ask you to avoid using register_read/write_direct() functions. I believe it's safer to use the standard riscv_reg_get/riscv_reg_set functions -- there is no need to bypass the register cache.

I found that the register_read/write_direct() was used by modify_privilege(), and even the riscv-013. c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants