diff --git a/boot.asm b/boot.asm index beb1127..126351c 100644 --- a/boot.asm +++ b/boot.asm @@ -1,8 +1,45 @@ [org 0x7c00] +section BOOTSECTOR start=7C00h +OS_SEGMENT equ 0x100 + +; https://github.com/cfenollosa/os-tutorial boot: - mov bx, HELLO_WORLD2 - call println + ; Load from disk + mov ah, 0x02 ; read + mov al, 0x01 ; No of sectors (1) + mov cl, 0x02 ; Sector start (1 = boot sector, 2 = OS) + mov ch, 0x00 ; Cylinder 0 + mov dh, 0x00 ; Head 0 + + mov bx, OS_SEGMENT ; Set target segment + mov es, bx + mov bx, 0x0 ; Target offset in segment + + int 0x13 ; Send read interrupt + jc disk_error + + ; Now that the OS is loaded in 0x1000, let's call main! + jmp 0x100:0x0 + +disk_error: + mov si, DISK_ERR_MSG + call bs_print + jmp $ + +; https://stackoverflow.com/a/53403853 +bs_print: + mov ah, 0x0e ; BIOS TTY function + + .L0: + lodsb + or al, al + jnz .J0 + ret + .J0: + + int 0x10 + jmp .L0 jmp $ ; Halt @@ -10,7 +47,8 @@ jmp $ ; Halt ; Boot sector data - +DISK_ERR_MSG: + db 'DISK ERROR: Failed to load kernel!', 0 ; Boot sector padding and magic number times 510-($-$$) db 0 diff --git a/main.asm b/main.asm index 188af92..bbbfc03 100644 --- a/main.asm +++ b/main.asm @@ -1,6 +1,9 @@ ; Bootloader %include "boot.asm" + +section KERNEL follows=BOOTSECTOR vstart=1000h + main: mov bx, HELLO_WORLD call println diff --git a/main.bin b/main.bin index 7ca3f4e..fe4ae11 100644 Binary files a/main.bin and b/main.bin differ