
x86 Paging Tutorial - signa11
http://www.cirosantilli.com/x86-paging/
======
kruhft
Relevant: "Ask HN: Would you design a modern CPU with virtual memory support?"

[https://news.ycombinator.com/item?id=13775321](https://news.ycombinator.com/item?id=13775321)

------
bogomipz
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.

~~~
DSMan195276
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).

------
Drisc0
This would have been useful when I was still in school

------
fsaintjacques
Ciro, your work is amazing.

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

------
TempleOS
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.

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

