From f7729c3cbf44f7b09c7253a517fd6b7ccd2ad4fb Mon Sep 17 00:00:00 2001 From: rgimad <33692565+rgimad@users.noreply.github.com> Date: Sun, 26 Jan 2025 01:01:31 +0300 Subject: [PATCH] don't use proc & fastcall when not necessary i.e with my own simple internal functions. But we keep using it i.e when invoking uefi functions cause then follow calling convention --- kernel/boot/bootx64.asm | 44 ++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/kernel/boot/bootx64.asm b/kernel/boot/bootx64.asm index 702919c..15b6187 100644 --- a/kernel/boot/bootx64.asm +++ b/kernel/boot/bootx64.asm @@ -19,46 +19,35 @@ include '../const.inc' purge DQ ; because of some struct DQ in const.inc include 'uefi64.inc' -; hmm proc64.inc uses TCHAR. to define string literals (?) -struc TCHAR [val] { - common match any, val \{ . du val \} - match , val \{ . du ? \} -} -sizeof.TCHAR = 2 - ; rcx - color = fore | back -proc efi_set_text_color +efi_set_text_color: mov rax, [efi_table] mov rax, [rax+EFI_SYSTEM_TABLE.ConOut] mov rdx, rcx ; arg2 - color mov rcx, rax ; arg1 - this fstcall [rax+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute] ret -endp ; rcx - null-terminated string -proc efi_puts +efi_puts: mov rax, [efi_table] mov rax, [rax+EFI_SYSTEM_TABLE.ConOut] mov rdx, rcx ; arg2 - string mov rcx, rax ; arg1 - this fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString] ret -endp ; rcx - char -proc efi_putc -locals - cstr dq 0 -endl +efi_putc: mov rax, [efi_table] mov rax, [rax+EFI_SYSTEM_TABLE.ConOut] - mov byte [cstr], cl - lea rdx, [cstr] + push qword 0 + mov byte [rsp], cl + mov rdx, rsp mov rcx, rax fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString] + add rsp, 8 ret -endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -73,15 +62,20 @@ proc main _efi_handle, _efi_table test eax, eax jnz $ ; loop if fail to init text - fstcall efi_set_text_color, EFI_BLUE or EFI_BACKGROUND_GREEN - fstcall efi_puts, msg_hello_k64_loader - fstcall efi_puts, <'hi there', 13, 10> ;; didnt work unless declared TCHAR + mov rcx, EFI_BLUE or EFI_BACKGROUND_GREEN + call efi_set_text_color + mov rcx, msg_hello_k64_loader + call efi_puts - fstcall efi_set_text_color, EFI_LIGHTRED - fstcall efi_puts, msg_2 + mov rcx, EFI_LIGHTRED + call efi_set_text_color + mov rcx, msg_2 + call efi_puts - fstcall efi_set_text_color, EFI_CYAN - fstcall efi_putc, 0+'a' ;; 0+ is to cast it to number to put in register it itself, not the address of string literal 'a' but function expects char in rcx + mov rcx, EFI_CYAN + call efi_set_text_color + mov rcx, 'a' + call efi_putc ;; TODO: print some dec, hex. => impl simple printf. fdo.inc