paging.S 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* https://github.com/cirosantilli/x86-bare-metal-examples#paging */
  2. #include "common.h"
  3. BEGIN
  4. CLEAR
  5. STAGE2
  6. PROTECTED_MODE
  7. SETUP_PAGING_4M
  8. /* Setup a test canary value. */
  9. movl $0x1234, 0x1000
  10. /* Print the canary to make sure it is really there. */
  11. VGA_PRINT_HEX_4 0x1000
  12. /* Make page 0 point to page frame 1(i.e. virtual address 0 points to physical address 4KB)
  13. * by setting bit 12 of the Page Table Entry structure.
  14. *
  15. * At SETUP_PAGING_4M, page_table has been setup to
  16. * point page frame 0(i.e. page 0 point to page frame 0).
  17. * Bit 12 is the lowest bit of the "Address of 4KB page frame" field,
  18. * By setting it, can relocate page 0 point to page frame 1.
  19. */
  20. orw $0x1000, page_table
  21. PAGING_ON
  22. /* THIS is what we've been working for!!!
  23. * Even though we mov to 0, the paging circuit reads that as physical address 0x1000,
  24. * so the canary value 0x1234 should be modified to 0x5678.
  25. **/
  26. movl $0x5678, 0
  27. /* Turn paging back off to prevent it from messing with us.
  28. * Remember that VGA does memory accesses, so if paging is still on,
  29. * we must identity map up to it, which we have, so this is not mandatory.
  30. * */
  31. PAGING_OFF
  32. /* Print the (hopefully) modified value 0x5678. */
  33. VGA_PRINT_HEX_4 0x1000
  34. jmp .