; 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' starting ; from sector 'cl' pusha push dx mov ah, 0x2 ; Perform a read operation mov al, dh ; Number of sectors 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 mov si, parenthesis call bios_print call bios_newline jmp disk_loop sectors_error: mov si, disk_sectors_error_msg call bios_println disk_loop: jmp $ parenthesis: db ')', 0 disk_read_error_msg: db "TSOS - ERROR: Disk read failed (error code ", 0 disk_sectors_error_msg: db "TSOS - ERROR: Disk read failed (sector number mismatch)", 0