This is the second article covering the memory management of xv6, continuing from the previous article which covered the memory management at the early stages of xv6’s kernel initialization before getting into its main function. In this article, the memory management mechanism in both kernel mode and user mode is covered. Specifically xv6 uses 2-level memory paging supported by MMU (memory management unit). This is essentially the same mechanism that Linux kernel manages its memory though the number of levels is different.
Memory management is one of the key concepts to understand OS and architecture. Naturally it was necessary for me to understand it for the development of an x86 simulator, dax86 and it was indeed tricky to connect all the xv6’s source code with the understanding of MMU. This article talks about the initial part of memory addressing in xv6 as well as how it organizes the instruction addresses of kernel.
One of the difficulties I faced in the development of an x86 simulator, dax86 was the end-to-end understanding of the OS image structure. This article talks about the creation of the booting block and how it is formed into the OS image as well as how hardware loads and executes it. Makefile Makefile is where we start obviously. It has all the setup for creating different binaries and linked objects required to compose the OS image.
I wrote an x86 simulator that runs a small OS, xv6 for study purpose without translating binaries or memory. Everything is implemented C codes. Repository Link: https://github.com/ykskb/dax86 Here’s some key points about it (excerpt from README): Why: I wanted to learn how an OS runs on CPUs at architecture / instruction level. What: Runs vanilla xv6 (memfs) image from boot. Each instruction is manually implemented and executed sequentially without binary translation, pipeline or OoOE.