From 66289aa8ecfa07b20bad424eb9860b196641ef52 Mon Sep 17 00:00:00 2001 From: Brett Weiland Date: Fri, 19 Mar 2021 10:54:25 -0500 Subject: first commit --- src/bootloader/bios_functions/bios_disk.asm | 38 +++++++++++++++++++ src/bootloader/bios_functions/print.asm | 59 +++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/bootloader/bios_functions/bios_disk.asm create mode 100644 src/bootloader/bios_functions/print.asm (limited to 'src/bootloader/bios_functions') diff --git a/src/bootloader/bios_functions/bios_disk.asm b/src/bootloader/bios_functions/bios_disk.asm new file mode 100644 index 0000000..28fc74d --- /dev/null +++ b/src/bootloader/bios_functions/bios_disk.asm @@ -0,0 +1,38 @@ +bios_disk: +.load_sectors: +pusha +mov es, dx + +mov ah, 0x02 ; read disc sectors +mov ch, 0x00 ; track 0 +mov dh, 0x00 ; head 0 +mov dl, [stage0.boot_device] + +int 0x13 + +jc .failed + +mov ah, 0 +popa +ret + +.failed: + +mov bx, .loadsectors_error +mov cx, 0 +call bios_print + +push 0 +mov al, ah +mov ah, 0 ; you need to clean up the bios print function! +push ax +mov cx, 1 +mov bx, sp +call bios_print + + +mov ah, 1 +popa +ret + +.loadsectors_error: db "Error loading sectors: ", 0 diff --git a/src/bootloader/bios_functions/print.asm b/src/bootloader/bios_functions/print.asm new file mode 100644 index 0000000..d071cd9 --- /dev/null +++ b/src/bootloader/bios_functions/print.asm @@ -0,0 +1,59 @@ +;TODO fix null problem, allow direct passes +bios_print: +;push ax ; we need to use ax, so let's push it in case whoever called needs it +pusha +mov ah, 0x0e ; tells bios we're in tty mode + +.print_loop: +mov al, [bx] ; al is the char MEANT TO BE CX +cmp al, 0 ; compare the char we're about to print with null +je .fini ; if it is null, we gonna scoot the fuck outta here + +test cx, cx ; if cx is zero, ascii, otherwise hex string +jne .print_hex +int 0x10 ; bios call, actually prints the char +.print_hex_ret: +inc bx ; adds to the pointer +jmp .print_loop ; goes back to loop start + +.fini: +mov al, 0xd ; \r +int 0x10 +mov al, 0xa ; \n +int 0x10 +popa +ret + + +.print_hex: +mov al, '0' +int 0x10 + +mov al, 'x' +int 0x10 + +mov al, [bx] ; shift bits to get first nibble +shr al, 4 +call .bios_print_nibble + +mov al, [bx] +and al, 0x0f +call .bios_print_nibble + +mov al, ' ' +int 0x10 + +jmp .print_hex_ret + + +.bios_print_nibble: +cmp al, 9 ; see if letter worthy +ja .print_hex_letter +add al, 0x30 ;'1' +int 0x10 +ret + +.print_hex_letter: +add al, 0x57 ;'a' +int 0x10 +ret -- cgit v1.2.3