switch_prot.asm 975 B

123456789101112131415161718192021222324252627282930
  1. [bits 16]
  2. switch_to_pm:
  3. cli ; turn off all interrupts until we have properly
  4. ; properly set them up
  5. lgdt [gdt_descriptor] ; load the global descriptor table defining
  6. ; protected mode segments
  7. mov eax, cr0 ; set flag in register to switch to protected mode
  8. or eax, 0x1
  9. mov cr0, eax
  10. jmp GDT_CODE_SEG:init_pm ; make a far jump to the 32-bit code forcing a flush
  11. ; of the pipelining
  12. [bits 32]
  13. ; initialize registers and the stack once in protected mode
  14. init_pm:
  15. mov ax, GDT_DATA_SEG ; point our new segment registers to the data
  16. mov ds, ax ; selector defined in the GDT, since we cannot
  17. mov ss, ax ; use the old 16-bit code
  18. mov es, ax
  19. mov fs, ax
  20. mov gs, ax
  21. mov ebp, 0x90000 ; Update the stack position so it's at the top
  22. mov esp, ebp ; of the free space
  23. call BEGIN_PM