Skip to content

Page Table

Celve edited this page Jan 21, 2024 · 2 revisions

Page Table

The page table used in this kernel is SV39. To enable MMU in the supervisor mode, we only need to setup the satp to the physical page number of the root page of the page table with a mode field to indicate the type of page table it used.

Create Page Table for Kernel

The function corresponds to the stuff is located at kernel/src/mm/page_table.rs.

For kernel, we should mark the begins and the ends for each sections linker script, which could be found in kernel/build.rs. With this information, we are able to map these sections inside the page table. Besides, the identical mapping of trampoline is necessary to make sure that the switching of page table when restoring and trapping could access the same piece of code.

Create Page Table for User

The function that does this work is located at kernel/src/mm/page_table.rs.

A external crate is used to parse the ELF file. According to the result of the parser, we map sections in the page table of the user program. Lastly, we also need to map trampoline.

With Frame Allocator

All pages would be fetched from the frame allocator in Allocator. When the page table is destroy, all frames inside it would be deallocated by the frame allocator, with the help of RAII.

Clone this wiki locally