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

Got Insutrction Fetch Exception on new QEMU version #35

Open
timlee0212 opened this issue Aug 4, 2023 · 0 comments
Open

Got Insutrction Fetch Exception on new QEMU version #35

timlee0212 opened this issue Aug 4, 2023 · 0 comments

Comments

@timlee0212
Copy link

The code starting from Chapter 3 does not work on newer versions of QEMU (it seems for any version >= 6.0). You will get an exception as soon as entering the supervisor mode with mcause=1 . This indicates an instruction access fault as per the manual.
image

After some investigation, I think this might be caused by the newer version of QEMU implementing Physical Memory Protection (PMP). As mentioned in the manual, if the registers are not configured, all memory access in supervisor mode will fail.
image

A simple (but dirty) solution is to bypass the PMP by adding one configuration in the kinit function.

        asm!("csrw pmpaddr0, {}", in(reg) 0);
        asm!("csrw pmpcfg0, {}", in(reg) (7 | (1 << 3))); // RWX, A_TOR

This allows read, write, and execution for all physical addresses starting from 0.

Reference: https://five-embeddev.com/riscv-isa-manual/latest/machine.html#sec:pmp

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

No branches or pull requests

1 participant