From 632566f6c3115826f81fe3b013787d8b3a2fe5f1 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 31 Jul 2021 23:16:52 +0200 Subject: [PATCH] Disk read error refactor --- src/bios/disk.asm | 15 +++++++++++++-- src/bootloader.asm | 18 ++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/bios/disk.asm b/src/bios/disk.asm index e717981..0f1b171 100644 --- a/src/bios/disk.asm +++ b/src/bios/disk.asm @@ -1,4 +1,5 @@ disk_read: + pusha push dx ; store dx on stack so that we can compare later mov ah, BIOS_DISK_READ ; specify function @@ -16,7 +17,8 @@ disk_read: pop dx cmp dh, al ; if dh != al then error jne sector_error - + + popa ret sector_error: @@ -24,13 +26,22 @@ sector_error: call println read_error: + ; Inform the user mov bx, read_error_string call println + ; Print the error + mov bx, error_code_string + call print + mov dh, ah call print_hex + mov bx, [ASCII_END] + call println + jmp $ -read_error_string: db "Disk read error!", ASCII_END +read_error_string: db ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK, "ERROR! Disk read failed.", ASCII_END +error_code_string: db "Error code: ", ASCII_END sector_error_string: db "Invalid number of sectors read!", ASCII_END diff --git a/src/bootloader.asm b/src/bootloader.asm index c7d97b8..a1cab27 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -1,11 +1,25 @@ [org 0x7c00] ; bootsector + ; Save the boot drive index + mov [BOOT_DRIVE], dl + + ; Move the stack pointer somewhere safe + mov bp, 0x8000 ; move it to 0x8000 + mov sp, bp ; Print the welcome string mov bx, welcome_string call println - ; Read second sector + ; Read second sector (outside bootsector) + mov bx, 0x9000 ; LOAD LOCATION + mov dh, 3 ; SECTOR-COUNT + mov dl, [BOOT_DRIVE] ; DISK-INDEX + call disk_read + + ; Print out whatever bloated data that was read + mov dx, [0x9000] + call print_hex jmp $ ; inf loop @@ -14,7 +28,7 @@ ; Data welcome_string: db "e Operating-System (eOS)", ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK, "Version 2021 0.0", ASCII_END -read_test_string: db "Read bytes: ", ASCII_END +BOOT_DRIVE: db 0 ; Bootsector times 510-($-$$) db 0