{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreiabbjieexikexij7lror5sq4tuci3aegnsqdtpzglbrvbbxtjyuei",
"uri": "at://did:plc:ndtvnkebzmsduapq2rqlsru4/app.bsky.feed.post/3mbqtzjrvurq2"
},
"path": "/syndications/kl-os-2026-01-02/",
"publishedAt": "2026-01-02T00:00:00.000Z",
"site": "https://scientiac.space",
"tags": [
"https://scientiac.space/syndications/kl-os-2026-01-02/POSSE",
"Day 12"
],
"textContent": "Day 12 was about user mode.\n\nThe application that we had made had to be run on the user mode. And since, the execution image is a raw binary, it needs to be prepared with a fixed binary.\n\n\n #define USER_BASE 0x1000000\n\nAfter defining the symbols to use in the embedded raw binary, the create process function is updated to start the application from the `user_entry`.\n\nThe `create_process` is modified to take the pointer to the execution image and image size as arguments. It copies the execution image page by page for the specified size and maps it to the process page table.\n\nFinally, the `create_process` function is modified to create a user process.\n\nAfter checking if the execution image is mapped as expected, to run applications we must transition the CPU to the user mode. Or, in RISC-V, the U-Mode.\n\nThis switch from `S-Mode` to `U-mode` is done with the `sret` instruction. It does two writes to CSRs while switching:\n\n * `PC` is set for when transitioning in U-Mode in the `sepc` register where `sret` jumps to.\n * Then, setting `SPIE` bit in the `sstatus` register enables hardware interrupts and the handler set in the `stvec` register will be called while entering the `U-Mode`.\n\n",
"title": "KL-OS: User Mode",
"updatedAt": "2026-04-22T08:40:49.867Z"
}