Hacker News new | past | comments | ask | show | jobs | submit login
x86 Paging Tutorial (cirosantilli.com)
142 points by signa11 on March 2, 2017 | hide | past | favorite | 11 comments

Relevant: "Ask HN: Would you design a modern CPU with virtual memory support?"


The author mentions:

> "In any case, the OS needs to know which address generated the Page Fault to be able to deal with the problem. This is why the nice IA32 developers set the value of cr2 to that address whenever a Page Fault occurs. The exception handler can then just look into cr2 to get the address."

The CR3 register holds address of the page table for the currently executing process and CR3 gets updated on every context switch.

Did they mean CR3? If not what is CR2? I am not familiar with the CR2 register and its significance in demand paging systems.

CR2 holds the address that the access was attempted on that faulted. So for example, if you attempt to access 0x23456789 and that faults because there is no page, CR2 contains that 0x23456789. But that might not be an "invalid" address - the OS may simply not have mapped the page in yet (Which is what happens with dynamic paging). So the OS checks the CR2, and if it is valid address the OS maps the correct page in and then returns back to the code that the program attempted to execute (Which now works).

I read it as cr2 holds the logical address that you were looking up when the page fault occurred.

According to "Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 3A:", http://www.intel.com/Assets/en_US/PDF/manual/253668.pdf

CR2 — Contains the page-fault linear address (the linear address that caused a page fault)

This would have been useful when I was still in school

Ciro, your work is amazing.

Thanks :-) Or maybe, thank my unemployment at the time :-)

TempleOS has two main features. Ring-0-only and no paging. (It's identity mapped because long mode requires it.)

Linux and Windows have ring 3 and paging.

That's great, but I think it's mainly because TempleOS has different target use cases to other modern OSs.

> It's identity mapped because long mode requires it

How can long mode require identity mapping? Do you mean for ring 0 code?

For some reason I always thought templeOS was real mode.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact