From e661ed65adb071a0c685305019fa079d42fd57d2 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 31 Jul 2021 01:16:31 +0200 Subject: [PATCH 1/8] Minor tweak to string --- src/bootloader.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index e8bf21e..6223862 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -39,7 +39,7 @@ welcome_string: db "e Operating-System (eOS)", ASCII_END info_string: db "Version 2021 0.0", ASCII_END -read_test_string: db "Disk read: ", ASCII_END +read_test_string: db "Read bytes: ", ASCII_END byte_sep_string: db "; ", ASCII_END empty_string: db ASCII_END From 7e2743af968ba78f79c9f67affbe046a1cbb3ea2 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 31 Jul 2021 22:38:02 +0200 Subject: [PATCH 2/8] Refactor --- src/bios/disk.asm | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/bios/disk.asm b/src/bios/disk.asm index 22c6e46..c72dfe1 100644 --- a/src/bios/disk.asm +++ b/src/bios/disk.asm @@ -1,6 +1,4 @@ disk_read: - pusha - push dx mov ah, BIOS_DISK_READ mov al, dh ; sector count @@ -17,7 +15,6 @@ disk_read: cmp al, dh jne sector_error - popa ret sector_error: From 219164c7bbbfa98fd996bfff6e5479ac1e8d525c Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 31 Jul 2021 22:49:19 +0200 Subject: [PATCH 3/8] Disk read refactor --- src/bios/disk.asm | 49 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/src/bios/disk.asm b/src/bios/disk.asm index c72dfe1..6a3acbe 100644 --- a/src/bios/disk.asm +++ b/src/bios/disk.asm @@ -1,21 +1,42 @@ +;disk_read: +; push dx +; mov ah, BIOS_DISK_READ +; mov al, dh ; sector count +; mov cl, 0x02 ; second sector (after bootsection) +; +; mov ch, 0x00 ; read from first cylinder +; mov dh, 0x00 ; head +; +; ; data pointer: es:bx (standard) +; int BIOS_DISK_INT ; do the interrupt +; jc read_error ; if flag is set then jump to error +; +; pop dx +; cmp al, dh +; jne sector_error +; +; ret + disk_read: - push dx - mov ah, BIOS_DISK_READ - mov al, dh ; sector count - mov cl, 0x02 + push dx ; store dx on stack so that we can compare later + + mov ah, BIOS_DISK_READ ; specify function - mov ch, 0x00 ; read from first cylinder - mov dh, 0x00 ; head + mov al, dh ; read dh amount of sectors + mov ch, 0x00 ; CYLINDER + mov dh, 0x00 ; HEAD + mov cl, 0x02 ; SECTOR - ; data pointer: es:bx (standard) - int BIOS_DISK_INT ; do the interrupt - jc read_error ; if flag is set then jump to error + int BIOS_DISK_INT ; interrupt + + ; Error checks + jc read_error ; carry flag set -> error pop dx - cmp al, dh + cmp dh, al ; if dh != al then error jne sector_error - - ret + + ret sector_error: mov bx, sector_error_string @@ -31,5 +52,5 @@ read_error: disk_loop: jmp $ -read_error_string: db "Disk read error", ASCII_END -sector_error_string: db "Invalid number of sectors read", ASCII_END +read_error_string: db "Disk read error!", ASCII_END +sector_error_string: db "Invalid number of sectors read!", ASCII_END From 7fd4fcd3308a2d396c8db928174fb632cf4f84fd Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 31 Jul 2021 22:49:50 +0200 Subject: [PATCH 4/8] Removed commented code --- src/bios/disk.asm | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/bios/disk.asm b/src/bios/disk.asm index 6a3acbe..b985ffd 100644 --- a/src/bios/disk.asm +++ b/src/bios/disk.asm @@ -1,22 +1,3 @@ -;disk_read: -; push dx -; mov ah, BIOS_DISK_READ -; mov al, dh ; sector count -; mov cl, 0x02 ; second sector (after bootsection) -; -; mov ch, 0x00 ; read from first cylinder -; mov dh, 0x00 ; head -; -; ; data pointer: es:bx (standard) -; int BIOS_DISK_INT ; do the interrupt -; jc read_error ; if flag is set then jump to error -; -; pop dx -; cmp al, dh -; jne sector_error -; -; ret - disk_read: push dx ; store dx on stack so that we can compare later From f79009d15792db5f76c2713acf448fd3aa041a19 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 31 Jul 2021 22:52:23 +0200 Subject: [PATCH 5/8] Refactor --- src/bios/disk.asm | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bios/disk.asm b/src/bios/disk.asm index b985ffd..e717981 100644 --- a/src/bios/disk.asm +++ b/src/bios/disk.asm @@ -30,7 +30,6 @@ read_error: mov dh, ah call print_hex -disk_loop: jmp $ read_error_string: db "Disk read error!", ASCII_END From 9260b7c6c66536741fc901cca0a81ba6474b251f Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 31 Jul 2021 22:58:19 +0200 Subject: [PATCH 6/8] More refactoring --- src/bootloader.asm | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index 6223862..c7d97b8 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -1,51 +1,25 @@ [org 0x7c00] ; bootsector - mov bx, welcome_string ; Print the welcome string + ; Print the welcome string + mov bx, welcome_string call println - mov bx, info_string ; Print version info - call println - - ; Read from disk - mov bp, 0x8000 - mov sp, bp ; move the stack away so that it does not get overwritten - - mov bx, 0x9000 - mov dh, 2 ; read 2 sectors - call disk_read ; read - - mov bx, read_test_string - call print - - mov dx, [0x9000] - call print_hex + ; Read second sector - mov bx, byte_sep_string - call print - - mov dx, [0x9000 + 512] - call print_hex - - mov bx, empty_string - call println jmp $ ; inf loop -; Constants %include "equ/ASCII.asm" - -; SRs etc %include "bios.asm" -welcome_string: db "e Operating-System (eOS)", ASCII_END -info_string: db "Version 2021 0.0", ASCII_END +; 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 -byte_sep_string: db "; ", ASCII_END -empty_string: db ASCII_END +; Bootsector times 510-($-$$) db 0 -db 0x55, 0xaa ; magic BIOS numbers +dw 0xaa55 ; magic BIOS numbers -; Bloat bytes to test reading +; After bootsector times 256 dw 0xEEEE times 256 dw 0xAAAA From 632566f6c3115826f81fe3b013787d8b3a2fe5f1 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 31 Jul 2021 23:16:52 +0200 Subject: [PATCH 7/8] 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 From 05b70d86053ac376620409c58b446b46e4eb974c Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 31 Jul 2021 23:19:15 +0200 Subject: [PATCH 8/8] Refactor --- src/bootloader.asm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index a1cab27..036c78b 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -12,7 +12,7 @@ ; Read second sector (outside bootsector) mov bx, 0x9000 ; LOAD LOCATION - mov dh, 3 ; SECTOR-COUNT + mov dh, 2 ; SECTOR-COUNT mov dl, [BOOT_DRIVE] ; DISK-INDEX call disk_read @@ -21,6 +21,12 @@ mov dx, [0x9000] call print_hex + mov bx, [ASCII_END] + call println + + mov dx, [0x9000 + 512] ; read from second sector too + call print_hex + jmp $ ; inf loop %include "equ/ASCII.asm"