bootsect.asm 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. [org 0x7c00]
  2. KERNEL_OFFSET equ 0x1000 ; The same one we used when linking the kernel
  3. mov [BOOT_DRIVE], dl ; Remember that the BIOS sets us the boot drive in 'dl' on boot
  4. mov bp, 0x9000
  5. mov sp, bp
  6. mov bx, MSG_REAL_MODE
  7. call print
  8. call print_nl
  9. call load_kernel ; read the kernel from disk
  10. call switch_to_pm ; disable interrupts, load GDT, etc. Finally jumps to 'BEGIN_PM'
  11. jmp $ ; Never executed
  12. %include "../05-bootsector-functions-strings/boot_sect_print.asm"
  13. %include "../05-bootsector-functions-strings/boot_sect_print_hex.asm"
  14. %include "../07-bootsector-disk/boot_sect_disk.asm"
  15. %include "../09-32bit-gdt/32bit-gdt.asm"
  16. %include "../08-32bit-print/32bit-print.asm"
  17. %include "../10-32bit-enter/32bit-switch.asm"
  18. [bits 16]
  19. load_kernel:
  20. mov bx, MSG_LOAD_KERNEL
  21. call print
  22. call print_nl
  23. mov bx, KERNEL_OFFSET ; Read from disk and store in 0x1000
  24. mov dh, 2
  25. mov dl, [BOOT_DRIVE]
  26. call disk_load
  27. ret
  28. [bits 32]
  29. BEGIN_PM:
  30. mov ebx, MSG_PROT_MODE
  31. call print_string_pm
  32. call KERNEL_OFFSET ; Give control to the kernel
  33. jmp $ ; Stay here when the kernel returns control to us (if ever)
  34. BOOT_DRIVE db 0 ; It is a good idea to store it in memory because 'dl' may get overwritten
  35. MSG_REAL_MODE db "Started in 16-bit Real Mode", 0
  36. MSG_PROT_MODE db "Landed in 32-bit Protected Mode", 0
  37. MSG_LOAD_KERNEL db "Loading kernel into memory", 0
  38. ; padding
  39. times 510 - ($-$$) db 0
  40. dw 0xaa55