Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Tracking: Support RISC-V #1135
This RISC-V architecture continues to gain momentum, and having Tock support risc-v boards seems quite feasible. With the embedded version still in development, it seems like Tock could be a leading embedded OS for risc-v platforms. Also, supporting multiple architectures would demonstrate the Tock architecture flexibility.
The development for this is happening in the https://github.com/tock/tock/tree/riscv branch.
I'm having trouble figuring out how to implement the context switch for Tock. Now the HiFive E310 chip only has M-mode, which means we won't have the application isolation we want, but it will serve as a proof of concept.
I think there are three primary operations to make context switching happen:
Switching to userland the first time
After the kernel is setup and the processes are loaded, the kernel must switch to the first process. I believe this can be done by setting the
// Set mepc to the starting PC of the app. // Here it is assuming the app entry point is at address 0x20c00000. lui a0, %hi(0x20c00000) addi a0, a0, %lo(0x20c00000) csrw 0x341, a0 // Now go to what is in mepc. mret
Returning from the app to the kernel.
To call a syscall the app has to return control to the kernel. I believe the app can do this with the
Handling the syscall and returning to the app
When the app calls the
So based on this, we would have to set mepc to mepc + 4 and then mret which will then return to the userland app, if that is what is required. Setting mepc to the next instruction address is necessary.