2

I’m developing a custom OS and facing a chicken-and-egg problem with my page frame allocator. I need to map a specific page, but if the corresponding PML4 entry is NULL, I must allocate a PDPT. Allocating a PDPT, however, requires allocating another page—which itself requires mapping. This creates a recursive dependency.

Has anyone encountered this issue? I’ve heard that using a self-referential entry in the PML4 might be a solution, but I’m not sure how it resolves the problem.

4
  • 1
    I recommend you read this article: os.phil-opp.com/paging-implementation . Although the author uses Rust, the ways to achieve what you are doing are well laid out and can be applied to any language: Commented Mar 2 at 4:25
  • @MichaelPetch I read the article but they don’t seem to cover this particular problem. It seems that my approach is completely different, but I don’t know why. Commented Mar 2 at 11:28
  • Every method mentioned there is a solution to this chicken and egg problem that every OS designer comes up against when dealing with paging. Since you are on x86_64 the easiest thing for you to do is map the entire 39 bits of physical address space into the higher half of the 48-bit virtual memory space (I recommend using 2MiB pages for that). A convenient place is to map it all starting at address 0xffff800000000000. The advantage is you can gain access to every physical address through a corresponding virtual memory offset by just adding 0xffff800000000000 to the physical address. Commented Mar 2 at 13:28
  • @MichaelPetch so if im understanding this correctly I need to allocate and fill (whichever are needed to cover the physical address range I want to access) every table (PML4, PDPT, PD, PT). Am I understanding it correctly? Commented Mar 2 at 13:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.