protected_mode.S 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. # Protected mode
  3. Major changes from real moe:
  4. - BIOS cannot be used anymore
  5. - GDT and segmentation take effect immediately so we *have*
  6. to deal with it now.
  7. - we have to encode instructions differently, thus a `.code32` is needed.
  8. Note that in 16-bit, 32-bit instructions were encodable, but with a prefix.
  9. ## Linux kernel
  10. arch/x86/include/asm/segment.h contains a lot of action:
  11. - the user privilege level
  12. - the segment steup (kernel an user code and data segments)
  13. ## Bibliography
  14. - http://stackoverflow.com/questions/28645439/how-do-i-enter-32-bit-protected-mode-in-nasm-assembly Initially adapted from this.
  15. - http://wiki.osdev.org/Journey_To_The_Protected_Land
  16. - http://wiki.osdev.org/Protected_Mode
  17. - https://github.com/chrisdew/xv6/blob/master/bootasm.S
  18. - https://thiscouldbebetter.wordpress.com/2011/03/17/entering-protected-mode-from-assembly/ FASM based. Did not word on first try, but looks real clean.
  19. - http://skelix.net/skelixos/tutorial02_en.html
  20. */
  21. #include "common.h"
  22. BEGIN
  23. CLEAR
  24. PROTECTED_MODE
  25. VGA_PRINT_STRING $message
  26. jmp .
  27. message:
  28. .asciz "hello world"