From a391c86c2800f3b776bef167b7d43e33a03ec673 Mon Sep 17 00:00:00 2001 From: Jonas Hvid Date: Mon, 5 Oct 2020 03:33:07 +0200 Subject: [PATCH] Support calling EFI functions directly from Forth Obviously, this doesn't work with the Linux backend. Maybe we'll have to remove that again, since it would basically require a UEFI emulator. --- main.asm | 23 ++++++++++++++++++++++- uefi.f | 7 +++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 uefi.f diff --git a/main.asm b/main.asm index 93e576f..54b2a5d 100644 --- a/main.asm +++ b/main.asm @@ -588,6 +588,27 @@ forth MAIN, 'MAIN' dq BRANCH, -8 * 2 dq TERMINATE +;; EFI: + +forth EFI_SYSTEM_TABLE_CONSTANT, 'SystemTable' + dq LIT, system_table, GET + dq EXIT + +forth_asm EFICALL2, 'EFICALL2' + pop rax ; function pointer + pop rdx ; 2nd argument + pop rcx ; 1st argument + + push rsi + + sub rsp, 32 + call rax + add rsp, 32 + + pop rsi + + next + ;; Built-in variables: forth STATE, 'STATE' @@ -665,6 +686,6 @@ return_stack_top: ;; include the file directly in the binary, and then interpret it at startup. sysf: file 'sys.f' -file 'example.f' +file 'uefi.f' sysf.len = $ - sysf diff --git a/uefi.f b/uefi.f new file mode 100644 index 0000000..bc030d1 --- /dev/null +++ b/uefi.f @@ -0,0 +1,7 @@ +: ConOut SystemTable 64 + @ ; +: ConOut.OutputString ConOut 8 + @ ; +: ConOut.OutputString() ConOut SWAP ConOut.OutputString EFICALL2 ; + +HERE @ + 97 C, 0 C, 98 C, 0 C, 99 C, 0 C, \ "ABC\0" +ConOut.OutputString() -- 2.39.2