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

Trap return address question #9

Open
Paulo-D2000 opened this issue Sep 12, 2024 · 1 comment
Open

Trap return address question #9

Paulo-D2000 opened this issue Sep 12, 2024 · 1 comment

Comments

@Paulo-D2000
Copy link

At

let exception_pc = cpu.pc.wrapping_sub(4);
shouldn't the sepc / mepc get loaded with the NEXT instruction PC ? so PC, instead of PC-4 ? After the sret / mret the program would loop back on itself doing the same ecall....

Eg:
0x80000000: ecall, pc is 0x80000004, stvec / mtvec = pc-4 = 0x80000000
... jump to supervisor / machine trap handler
sret / mret from the trap handler
PC = sepc / mepc = 0x80000000 = ecall (again
0x80000000: ecall, pc is 0x80000004, stvec / mtvec = pc-4 = 0x80000000
.... infinite loop...

@Paulo-D2000
Copy link
Author

Confirmed this might be a bug since rvemu does use PC not PC-4... https://github.com/d0iasm/rvemu/blob/main/src/interrupt.rs#L45

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