
The Complete Guide to Writing a RISC-V Kernel
Write a 64-bit RISC-V kernel in C and assembly for QEMU virt: boot through OpenSBI, traps, timer, paging with Sv39, a page allocator, tasks and user mode.
Tag
362 posts

Write a 64-bit RISC-V kernel in C and assembly for QEMU virt: boot through OpenSBI, traps, timer, paging with Sv39, a page allocator, tasks and user mode.

Keep the OpenGL viewport and projection correct when a GLFW 3.4 window resizes, using the framebuffer size callback and the window size versus pixel size rules.

Replace strcpy, strcat and sprintf in C with snprintf, memcpy with a checked length, and strlcpy, and detect truncation instead of overflowing a buffer.

Learn why computers use layers of memory from registers to storage, how a cache line works, and how to read your own machine's cache sizes with a C program.

Build a single-threaded C echo server that serves many clients with select, fd_set, FD_SET and FD_ISSET, and learn why you rebuild the set on every loop.

Add two float arrays of any length with SSE intrinsics in C: a four-wide main loop, a scalar tail, unaligned loads and the assembly you should see.

Negative Zephyr thread priorities are cooperative and never preempted, while zero and above are preemptible. Learn the ranges, the rules and when to use each.

Check every system call result in C: the -1 convention, short reads and writes, EINTR retries and close errors, with working helpers for Linux and glibc 2.41.

Follow a Cortex-M core from power-on to main: the two vector table words it fetches, the reset handler, and the C runtime setup that runs before your code.

Create an OpenGL 3.3 core window and context with SDL 3.2 in C, load functions with glad, handle the quit event, and clear the screen each frame.

One byte too few for the terminating NUL is enough to corrupt memory. See the common off-by-one patterns in C strings and how to write them correctly.

Learn what registers, the ALU and the control unit do inside a CPU, with a small C model of an 8-bit ALU and its status flags that you can read line by line.