intermezzOS / book

The main docs for intermezzOS
http://intermezzos.github.io/book
367 stars 79 forks source link

Magic numbers not clear in pagging #103

Closed Razican closed 6 years ago

Razican commented 8 years ago

So, when enabling PAE:

    ; enable PAE
    mov eax, cr4
    or eax, 1 << 5
    mov cr4, eax

Why do we put the fifth bit to 1? What do other bits mean? It would be great to have some more info. The same happens when setting the long mode bit:

    ; set the long mode bit
    mov ecx, 0xC0000080
    rdmsr
    or eax, 1 << 8
    wrmsr

It says

This is just what you have to do to set this up. Again, we won’t get into too much detail, as it’s not very interesting.

But, well, it would at least be interesting to say what that 0xC0000080 means, or why is it there, and why is the 8th bit being set to 1.

And finally, when enabling paging:

    ; enable paging
    mov eax, cr0
    or eax, 1 << 31
    or eax, 1 << 16
    mov cr0, eax

It would be great to explain what those 31st and 16th bits do, and what other bits are there.

LaylBongers commented 8 years ago

I'm not sure what you're asking, with the exception of the last snipped it seems reasonably clear to me. When we enable PAE we set bit 5 because bit 5 is the bit that enables PAE. The other bits are irrelevant in this situation as they're various other settings. If you want to read up on what the others are you could go to the spec or the wiki page for the register.

https://en.wikipedia.org/wiki/Control_register#CR4

It would indeed be useful to know why enabling paging requires two bits and what they're specifically are though. Looking on the wiki page, 31 is just paging itself while 16 is for enabling write-protection on read-only pages.

steveklabnik commented 8 years ago

@Razican I think you're right, even though these details don't matter, it seems contrary to everything else to not explain them in depth. We can do better.

Razican commented 8 years ago

Maybe there should be an appendix explaining a bit about registers and how do they work etc. Maybe a bit of assembly code explanation. That would be awesome. That way, the ones who don't want to, don't need to look at it, but the ones that want to deepen into it could go to the appendix and read about it.

LaylBongers commented 8 years ago

Perhaps a brief explanation on bit flags when it first comes up?

Razican commented 8 years ago

That makes sense, but I think that in the future, for a great book, having some appendixes about x86/x86_64 architechtures (or even others) would make a difference.

steveklabnik commented 6 years ago

I'm not working on the first edition anymore, so I'm going to give this a close. This stuff isn't in the second edition yet, and it's not likely to make it exactly. If someone wants to send in a PR to fix up the first edition, please feel free!