From 512f348d748fb7148f36c4957987abd924b648ef Mon Sep 17 00:00:00 2001 From: Mattia Giambirtone Date: Sat, 19 Nov 2022 11:02:51 +0100 Subject: [PATCH] Got rid of vga_print in assembly --- src/boot/mbr.s | 6 --- src/boot/util/disk.s | 4 +- src/boot/util/enablea20.s | 9 ----- src/boot/util/io.s | 80 --------------------------------------- 4 files changed, 2 insertions(+), 97 deletions(-) diff --git a/src/boot/mbr.s b/src/boot/mbr.s index 5cce3cc..46d04b0 100644 --- a/src/boot/mbr.s +++ b/src/boot/mbr.s @@ -90,11 +90,7 @@ load_kernel: [bits 32] BEGIN_32BIT: ; After the switch we will get here - mov esi, protected_mode_msg - call vga_print call enableA20 - mov esi, calling_kernel_msg - call vga_print call kernel_offset cli hlt @@ -109,9 +105,7 @@ BEGIN_32BIT: ; After the switch we will get here ; Here we define our variables used in the second stage -protected_mode_msg: db "TSBL - INFO: Successfully switched to protected mode, enabling A20 line", 0 kernel_loaded_msg: db "TSBL - INFO: Kernel loaded, switching to protected mode", 0 -calling_kernel_msg: db "TSBL - INFO: Calling kernel entrypoint", 0 stage2_loaded_msg: db "TSBL - INFO: Stage 2 loaded, loading kernel", 0 diff --git a/src/boot/util/disk.s b/src/boot/util/disk.s index 6bed450..7e0f3f8 100644 --- a/src/boot/util/disk.s +++ b/src/boot/util/disk.s @@ -58,5 +58,5 @@ disk_loop: parenthesis: db ')', 0 -disk_read_error_msg: db "TSOS - ERROR: Disk read failed (error code ", 0 -disk_sectors_error_msg: db "TSOS - ERROR: Disk read failed (sector number mismatch)", 0 +disk_read_error_msg: db "TSBL - ERROR: Disk read failed (error code ", 0 +disk_sectors_error_msg: db "TSBL - ERROR: Disk read failed (sector number mismatch)", 0 diff --git a/src/boot/util/enablea20.s b/src/boot/util/enablea20.s index 709a6cb..50166f5 100644 --- a/src/boot/util/enablea20.s +++ b/src/boot/util/enablea20.s @@ -182,11 +182,7 @@ enableA20: ;; Here you may or may not want to print a warning message about ;; the fact that we had to use the nonstandard alternate enabling ;; method - mov esi, a20_warning_msg - call vga_print .success: - mov esi, a20_enabled_msg - call vga_print ;sti ; Note: When this is uncommented, shit breaks. I have a few theories as to why, ; but none of them make sense, so ¯\_(ツ)_/¯ @@ -199,8 +195,3 @@ enableA20: popa mov eax, -1 ret - - -a20_enabled_msg: db "TSBL - INFO: A20 line enabled successfully", 0 -a20_warning_msg: db "TSBL - WARN: A20 line was enabled with nonstandard method", 0 -a20_failed_msg: db "TSBL - ERROR: Failed to enable A20 line" \ No newline at end of file diff --git a/src/boot/util/io.s b/src/boot/util/io.s index becbf52..6d04af6 100644 --- a/src/boot/util/io.s +++ b/src/boot/util/io.s @@ -121,83 +121,3 @@ bios_cls: HEX_OUT: db '0x0000', 0 ; reserve memory for our new string - -[bits 32] - -; I/O routines that work with the VGA controller and video memory -; to print to the screen - - -VMEM_START: equ 0xb8000 ; Video memory always starts at this address -; A character on the screen in VGA text mode is composed of 2 bytes: -; the first byte is the ASCII codepoint to be printed, while the next -; octet represents additional formatting information (color, blink, -; underline, etc.). More info: https://en.wikipedia.org/wiki/VGA_text_mode -TEXT_COLOR: equ 0x07 - - -vga_print: - ; Prints a null-terminated string located - ; on the esi register. - pusha - mov ebx, VMEM_START - vga_print_loop: - mov al, [esi] - cmp al, 0 - je vga_print_done - mov ah, TEXT_COLOR - mov [ebx], ax ; Write the 2-byte character to video memory - inc esi ; Go to the next character in the string - add ebx, 2 - jmp vga_print_loop - vga_print_done: - popa - ret - - -vga_printh: - ; Prints the value of edx in hexadecimal format - pusha - xor ecx, ecx ; This serves as our index and loop counter - vga_printh_loop: - cmp ecx, 8 ; loop 8 times - je vga_printh_end - ; Here we extract the last digit from edx using - ; a bitmask, with eax as our working register, - ; and convert it to ASCII by adding 30 to it if - ; it's less than 9 (meaning it's a digit) or 37 - ; if if it's a letter (that's because letters and - ; numbers are 7 digits apart in the ASCII table) - mov eax, edx - and eax, 0xf - add ax, 0x30 - cmp ax, 0x39 - jle vga_printh_step2 - add ax, 7 - - vga_printh_step2: - ; Now we start filling our string variable (starting from the - ; back, since we are extracting digits from the end of the - ; number) and then rotate the number by 4 bits to access the - ; next digit. This works and is the same as the more common - ; modulo division because each hexadecimal digits represents - ; exactly 4 bits and we can take advantage of the CPU's much - ; faster bitwise operations rather than burden ourselves with - ; a costly modulo 10 division (which would take hundreds of - ; clock cycles, as opposed to it only taking one for a rotate - ; operation) - mov esi, HEX_OUT_LONG + 9 ; We skip the '0x' part and jump to the last digit - sub esi, ecx ; We subtract esi by ecx so we land on the right digit - mov [esi], ax ; We copy the character in ax to the character pointed to by esi - ror edx, 4 ; With an example input: 0x1234 -> 0x4123 -> 0x3412 -> 0x2341 -> 0x1234 - inc ecx - jmp vga_printh_loop - - vga_printh_end: - mov esi, HEX_OUT_LONG - call vga_print - popa - ret - - -HEX_OUT_LONG: db '0x00000000', 0 \ No newline at end of file