TSOS/src/bootloader/util/disk.s

49 lines
1.2 KiB
ArmAsm

; Utilities to read data from the disk. Used to load the kernel
; into main memory
load_disk:
; Loads 'dh' sectors from drive 'dl' (this
; register is set by the BIOS before calling
; the bootloader) into es:bx
pusha
push dx
mov ah, 0x2 ; Perform a read operation
mov al, dh ; Number of sectors
mov cl, 0x2 ; 0x1 is us, so 0x2 is the first sector we want
mov ch, 0x0 ; Cylinder 0
mov dh, 0x0 ; Head position is 0 too
int 0x13 ; Once this returns, the data will be in es:bx
jc disk_error ; If an error occurs, the carry bit is set
pop dx
; The BIOS tells us how many sectors have been
; actually read. If the desired and actual value
; don't match, an error occurred
cmp al, dh
jne sectors_error
popa
ret
disk_error:
mov si, disk_read_error_msg
call bios_print
mov dh, ah ; Error code is in ah
call bios_printh
call bios_newline
jmp disk_loop
sectors_error:
mov si, disk_sectors_error_msg
call bios_println
disk_loop:
jmp $
disk_read_info: db "Booting from disk type ", 0
disk_read_error_msg: db "Read error: ", 0
disk_sectors_error_msg: db "Read error (wrong number of sectors)", 0