TSOS/src/boot/util/disk.s

62 lines
1.7 KiB
ArmAsm

; Copyright 2022 Mattia Giambirtone & Contributors
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
; 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_error_msg: db "Read error: ", 0
disk_sectors_error_msg: db "Sector read count error", 0