From 18591b2770da1b2f3ed738fe4932e6319a5e9bbf Mon Sep 17 00:00:00 2001 From: maelstrom Date: Wed, 24 Jul 2024 20:16:51 +0300 Subject: [PATCH] Boot sector complete --- boot.asm | 44 +++++++++++++++++++++++++++++++++++++++++--- main.asm | 3 +++ main.bin | Bin 531 -> 683 bytes 3 files changed, 44 insertions(+), 3 deletions(-) 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 7ca3f4e48733e6920afbdbc759f4176fa2fa196f..fe4ae114ded8add81650b9ce28f78f5193a857a9 100644 GIT binary patch delta 104 zcmV-u0GI!h1giy8v;wdJu>!RKwg9^T0gl7F007Msas}!D0005LF?{F(0PFs=4y*{k zbpgZ85bO5q{zOSrOCUv3QcqGkAVy(nY-MC1bZ;PRZ((F0Yh`k7Wo#j_u}uMyz+MGa Ks=JyHkprk72`GC2 delta 38 ucmZ3@I+=xe_pF-9%uFjbCIvH!hOT=3&m%P_CtpXQJijO>MNz@Zg#iE_zzydB