diff --git a/src/bootloader.asm b/src/bootloader.asm index 101bd51..eadcf6d 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -1,19 +1,21 @@ [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) - 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 hexToASCII - 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" -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 +read_test_string: db "Disk read: ", ASCII_END times 510-($-$$) db 0 db 0x55, 0xaa ; magic BIOS numbers diff --git a/src/bootloader_bios_disk.asm b/src/bootloader_bios_disk.asm deleted file mode 100644 index 21e3204..0000000 --- a/src/bootloader_bios_disk.asm +++ /dev/null @@ -1,5 +0,0 @@ -disk_read: - pusha - - mov ah, BIOS_DISK_READ - mov al, dh ; number of sectors to read diff --git a/src/elib/bios_disk.asm b/src/elib/bios_disk.asm new file mode 100644 index 0000000..9a563a8 --- /dev/null +++ b/src/elib/bios_disk.asm @@ -0,0 +1,38 @@ +disk_read: + pusha + + push dx + mov ah, BIOS_DISK_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 read_error ; if flag is set then jump to 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 + + mov dh, ah + call print_hex + +disk_loop: + jmp $ + +read_error_string: db "Disk read error", ASCII_END +sector_error_string: db "Invalid number of sectors read", ASCII_END 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: 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