KL-OS: Exceptions

2025-12-27Genre: POSSE

Day 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.


Webmentions

Have you written a response to this? Let me know the URL, Or, you can send your response via mail:iac@scientiac.space