bootsect.asm 1.4 KB

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