1
0

32bit-switch.asm 611 B

12345678910111213141516171819202122
  1. [bits 16]
  2. switch_to_pm:
  3. cli ; 1. disable interrupts
  4. lgdt [gdt_descriptor] ; 2. load the GDT descriptor
  5. mov eax, cr0
  6. or eax, 0x1 ; 3. set 32-bit mode bit in cr0
  7. mov cr0, eax
  8. jmp CODE_SEG:init_pm ; 4. far jump by using a different segment
  9. [bits 32]
  10. init_pm: ; we are now using 32-bit instructions
  11. mov ax, DATA_SEG ; 5. update the segment registers
  12. mov ds, ax
  13. mov ss, ax
  14. mov es, ax
  15. mov fs, ax
  16. mov gs, ax
  17. mov ebp, 0x90000 ; 6. update the stack right at the top of the free space
  18. mov esp, ebp
  19. call BEGIN_PM ; 7. Call a well-known label with useful code