From bcba0c88f4eaddac8e0d8c0fa68264b2e81ee272 Mon Sep 17 00:00:00 2001 From: Jonas Hvid Date: Sun, 4 Oct 2020 01:40:36 +0200 Subject: [PATCH] Rename UEFI procedures to generic naming scheme --- main.asm | 27 +++++++++++++++++++++++---- os/uefi.asm | 23 +++++++---------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/main.asm b/main.asm index 0190d18..5985b99 100644 --- a/main.asm +++ b/main.asm @@ -1,5 +1,24 @@ ;; vim: syntax=fasm +;; At compile-time we load the module given by the environment variable +;; OS_INCLUDE. This module should define the following macros: +;; +;; Each of these functions should preserve the value of RSI and RSP. They may +;; use other registers as they like. +;; +;; os_initialize +;; Called at initialization. +;; +;; os_print_string +;; Takes a string buffer in RCX and the length in RDX, and prints the string +;; to the console. +;; +;; os_read_char +;; Wait for the user to type a key, and then put the corresponding ASCII byte +;; into the buffer pointed to by RCX. +;; +;; os_terminate +;; Shut down the system. include '%OS_INCLUDE%' ;; Print a string of a given length. @@ -14,7 +33,7 @@ macro sys_print_string { push r9 push r10 - call uefi_print_string + call os_print_string pop r10 pop r9 @@ -38,7 +57,7 @@ macro sys_read_char { push r15 mov rcx, rsi - call uefi_read_char + call os_read_char pop r15 pop r10 @@ -49,7 +68,7 @@ macro sys_read_char { macro sys_terminate code { mov rax, code - call uefi_terminate + call os_terminate } ;; The code in this macro is placed at the end of each Forth word. When we are @@ -118,7 +137,7 @@ main: cld ; Clear direction flag so LODSQ does the right thing. mov rbp, return_stack_top ; Initialize return stack - call uefi_initialize + call os_initialize mov rax, MAIN jmp qword [rax] diff --git a/os/uefi.asm b/os/uefi.asm index d116b2c..4f8ce56 100644 --- a/os/uefi.asm +++ b/os/uefi.asm @@ -60,17 +60,12 @@ struct EFI_INPUT_KEY section '.text' code executable readable -uefi_initialize: +os_initialize: ; At program startup, RDX contains an EFI_SYSTEM_TABLE*. mov [system_table], rdx ret -;; Print a string of the given length. -;; -;; Inputs: -;; - RCX = String buffer -;; - RDX = String length -uefi_print_string: +os_print_string: ;; We take an input string of bytes without any terminator. We need to turn ;; this string into a string of words, terminated by a null character. @@ -133,11 +128,7 @@ uefi_print_string: add rsp, 32 ret -;; Read a character as an ASCII byte into the given buffer. -;; -;; Inputs: -;; - RCX = Character buffer (1 byte) -uefi_read_char: +os_read_char: mov r15, rcx .read_key: mov rcx, [system_table] ; EFI_SYSTEM_TABLE* rcx @@ -164,7 +155,7 @@ uefi_read_char: ;; Print the character mov rcx, r15 mov rdx, 1 - call uefi_print_string + call os_print_string ret @@ -172,10 +163,10 @@ uefi_read_char: ;; ;; Inputs: ;; - RCX = Error code -uefi_terminate: +os_terminate: mov rcx, terminated_msg mov rdx, terminated_msg.len - call uefi_print_string + call os_print_string jmp $ section '.data' readable writable @@ -185,7 +176,7 @@ system_table dq ? ; EFI_SYSTEM_TABLE* terminated_msg db 0xD, 0xA, '(The program has terminated.)', 0xD, 0xA .len = $ - terminated_msg -uefi_print_string.output_buffer rq 0x400 +os_print_string.output_buffer rq 0x400 char_buffer db ? -- 2.39.2