From b5d9cf5c89cb89dc49a2ff0af7ad9b334b4d8953 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 23 Feb 2021 11:35:43 +0100 Subject: [PATCH 1/5] Disk read stuff --- src/bootloader_bios_disk.asm | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/bootloader_bios_disk.asm b/src/bootloader_bios_disk.asm index 21e3204..211051f 100644 --- a/src/bootloader_bios_disk.asm +++ b/src/bootloader_bios_disk.asm @@ -1,5 +1,24 @@ disk_read: pusha + push dx mov ah, BIOS_DISK_READ - mov al, dh ; number of sectors to read + mov al, dh ; sector count + mov cl, 0x02 + + mov ch, 0x00 ; read from first cylinder + mov dh, 0x00 ; head + + ; data pointer: es:bx (standard) + int BIOS_DISK_INT ; do the interrupt + jc disk_error ; if flag is set then jump to error + +disk_error: + mov bx, DISK_ERROR + call println + + mov dh, ah + + +DISK_ERROR: db "Disk read error", ASCII_END +SECTORS_ERROR: db "Invalid number of sectors read", ASCII_END From cccdb7db83d35899052847faf46c9a690afce5b6 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 23 Feb 2021 11:37:51 +0100 Subject: [PATCH 2/5] Refactor --- src/bootloader.asm | 14 +++++++------- src/elib/convert.asm | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index 101bd51..b20de8a 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -1,17 +1,17 @@ [org 0x7c00] ; bootsector - mov bx, welcomeString ; Print the welcome string + mov bx, welcome_string ; Print the welcome string call println - mov bx, infoString ; Print version info + mov bx, info_string ; Print version info call println - mov bx, hexTestPrefixString ; Hex print test (not needed but fun) + mov bx, hex_test_string ; Hex print test (not needed but fun) call print pusha mov dx, 0x002e ; test the conversion - call hexToASCII + call hex_to_ascii call println popa @@ -25,9 +25,9 @@ %include "elib/io.asm" %include "elib/convert.asm" -welcomeString: db "Welcome to: e Operating-System (eOS)", ASCII_END -infoString: db "Version 2021 0.0", ASCII_END -hexTestPrefixString: db "Hex printing test: ", ASCII_END +welcome_string: db "e Operating-System (eOS)", ASCII_END +info_string: db "Version 2021 0.0", ASCII_END +hex_test_string: db "Hex printing test: ", ASCII_END times 510-($-$$) db 0 db 0x55, 0xaa ; magic BIOS numbers diff --git a/src/elib/convert.asm b/src/elib/convert.asm index 72489d8..50643d0 100644 --- a/src/elib/convert.asm +++ b/src/elib/convert.asm @@ -5,7 +5,7 @@ HEX_OUT: db "0x0000", ASCII_END ; since it fills the register with the desired ; pointer toward the string. -hexToASCII: +hex_to_ascii: mov cx, 0 ; incrementor hexloop: From d06848a17393c08b571673dffc7de679eaa32085 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 23 Feb 2021 11:45:09 +0100 Subject: [PATCH 3/5] Stuff --- src/bootloader_bios_disk.asm | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/bootloader_bios_disk.asm b/src/bootloader_bios_disk.asm index 211051f..601f22d 100644 --- a/src/bootloader_bios_disk.asm +++ b/src/bootloader_bios_disk.asm @@ -11,14 +11,31 @@ disk_read: ; data pointer: es:bx (standard) int BIOS_DISK_INT ; do the interrupt - jc disk_error ; if flag is set then jump to error + jc read_error ; if flag is set then jump to error -disk_error: - mov bx, DISK_ERROR + pop dx + cmp al, dh + jne sector_error + + popa + ret + +sector_error: + mov bx, sector_error_string + call println + +read_error: + mov bx, read_error_string call println + pusha mov dh, ah + call hex_to_ascii + call println + popa +disk_loop: + jmp $ -DISK_ERROR: db "Disk read error", ASCII_END -SECTORS_ERROR: 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 1758888b27bdc84a6db3c4707dc94ff873f85ad2 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 23 Feb 2021 11:46:20 +0100 Subject: [PATCH 4/5] Moved bios disk to elib --- src/{bootloader_bios_disk.asm => elib/bios_disk.asm} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{bootloader_bios_disk.asm => elib/bios_disk.asm} (100%) diff --git a/src/bootloader_bios_disk.asm b/src/elib/bios_disk.asm similarity index 100% rename from src/bootloader_bios_disk.asm rename to src/elib/bios_disk.asm From e779668334c816ffe81c27a7ca02104421b96cfe Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 23 Feb 2021 11:56:09 +0100 Subject: [PATCH 5/5] Added print_hex SR & refactor --- src/bootloader.asm | 22 +++++++++++++--------- src/elib/bios_disk.asm | 5 +---- src/elib/io.asm | 10 ++++++++++ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index b20de8a..eadcf6d 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -6,14 +6,16 @@ mov bx, info_string ; Print version info call println - mov bx, hex_test_string ; Hex print test (not needed but fun) - call print + ; Read from disk + mov bp, 0x8000 + mov sp, bp ; move the stack away so that it does not get overwritten - pusha - mov dx, 0x002e ; test the conversion - call hex_to_ascii - call println - popa + mov bx, 0x9000 + mov dh, 2 ; read 2 sectors + call disk_read ; read + + mov dx, [0x9000] + call print_hex jmp $ ; inf loop @@ -22,12 +24,14 @@ %include "equ/ASCII.asm" ; SRs -%include "elib/io.asm" %include "elib/convert.asm" +%include "elib/io.asm" + +%include "elib/bios_disk.asm" welcome_string: db "e Operating-System (eOS)", ASCII_END info_string: db "Version 2021 0.0", ASCII_END -hex_test_string: db "Hex printing test: ", ASCII_END +read_test_string: db "Disk read: ", ASCII_END times 510-($-$$) db 0 db 0x55, 0xaa ; magic BIOS numbers diff --git a/src/elib/bios_disk.asm b/src/elib/bios_disk.asm index 601f22d..9a563a8 100644 --- a/src/elib/bios_disk.asm +++ b/src/elib/bios_disk.asm @@ -28,11 +28,8 @@ read_error: mov bx, read_error_string call println - pusha mov dh, ah - call hex_to_ascii - call println - popa + call print_hex disk_loop: jmp $ diff --git a/src/elib/io.asm b/src/elib/io.asm index 34c62e2..4624849 100644 --- a/src/elib/io.asm +++ b/src/elib/io.asm @@ -40,3 +40,13 @@ println: popa ret + + +; Subroutine to print a hex value +print_hex: + pusha + call hex_to_ascii + call print + popa + + ret