Boot sector complete

This commit is contained in:
maelstrom 2024-07-24 20:16:51 +03:00
parent e4c3f4af3a
commit 18591b2770
3 changed files with 44 additions and 3 deletions

View file

@ -1,8 +1,45 @@
[org 0x7c00] [org 0x7c00]
section BOOTSECTOR start=7C00h
OS_SEGMENT equ 0x100
; https://github.com/cfenollosa/os-tutorial
boot: boot:
mov bx, HELLO_WORLD2 ; Load from disk
call println 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 jmp $ ; Halt
@ -10,7 +47,8 @@ jmp $ ; Halt
; Boot sector data ; Boot sector data
DISK_ERR_MSG:
db 'DISK ERROR: Failed to load kernel!', 0
; Boot sector padding and magic number ; Boot sector padding and magic number
times 510-($-$$) db 0 times 510-($-$$) db 0

View file

@ -1,6 +1,9 @@
; Bootloader ; Bootloader
%include "boot.asm" %include "boot.asm"
section KERNEL follows=BOOTSECTOR vstart=1000h
main: main:
mov bx, HELLO_WORLD mov bx, HELLO_WORLD
call println call println

BIN
main.bin

Binary file not shown.