ibis-os/boot.asm

56 lines
1 KiB
NASM
Raw Normal View History

2024-07-24 17:02:54 +00:00
[org 0x7c00]
2024-07-24 17:16:51 +00:00
section BOOTSECTOR start=7C00h
2024-07-24 17:02:54 +00:00
2024-07-24 17:16:51 +00:00
OS_SEGMENT equ 0x100
; https://github.com/cfenollosa/os-tutorial
2024-07-24 17:02:54 +00:00
boot:
2024-07-24 17:16:51 +00:00
; Load from disk
mov ah, 0x02 ; read
2024-07-26 09:15:20 +00:00
mov al, 0x02 ; No of sectors (2)
2024-07-24 17:16:51 +00:00
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
2024-07-24 17:16:51 +00:00
; 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
2024-07-24 17:02:54 +00:00
jmp $ ; Halt
; Boot sector libs
; Boot sector data
2024-07-24 17:16:51 +00:00
DISK_ERR_MSG:
db 'DISK ERROR: Failed to load kernel!', 0
2024-07-24 17:02:54 +00:00
; Boot sector padding and magic number
times 510-($-$$) db 0
dw 0xaa55