2025-12-27Genre: POSSEDay 6 was about Exceptions and handling those Exceptions in the kernel.
In RISC-V the CPU first checks medeleg register to determine which operation mode should handle the exception. In our case U-mode/S-mode is already handled by OpenSBI. Then, the CPU saves states into various CSRs. stvec register is set to pc then the exception is handled using the handler. Then sret is called to resume execution from the point where exception occurred.
The handle_trap function reads why the exception occurred and triggers the kernel panic. Which was implemented yesterday.
A Computer Engineering student who loves FOSS and is learning about privacy, the Internet and languages writing about the things he does.