paging.S 950 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* https://github.com/cirosantilli/x86-bare-metal-examples# */
  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 4KiB. */
  13. orb $0x10, page_table + 1
  14. PAGING_ON
  15. /* THIS is what we've been working for!!!
  16. * Even though we mov to 0, the paging circuit reads that as physical address 0x1000,
  17. * so the canary value 0x1234 should be modified to 0x5678.
  18. **/
  19. movl $0x5678, 0
  20. /* Turn paging back off to prevent it from messing with us.
  21. * Remember that VGA does memory accesses, so if paging is still on,
  22. * we must identity map up to it, which we have, so this is not mandatory.
  23. * */
  24. PAGING_OFF
  25. /* Print the (hopefully) modified value 0x5678. */
  26. VGA_PRINT_HEX_4 0x1000
  27. jmp .