forth

A WIP implementation of Forth targeting UEFI x86-64.
git clone git://git.christianermann.dev/forth
Log | Files | Refs

commit 0b544320f42ecdd1b105aff22b56de2f80d4ecfa
parent 97f0001d189e7a4d65182e9f85f801ea2e2a66f3
Author: Christian Ermann <christianermann@gmail.com>
Date:   Sun, 16 Jun 2024 17:19:50 -0400

Add efi.forth and word for loading into dictionary

Diffstat:
MDockerfile | 1+
Aefi.forth | 159+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mforth.asm | 16++++++++++++++--
3 files changed, 174 insertions(+), 2 deletions(-)

diff --git a/Dockerfile b/Dockerfile @@ -10,6 +10,7 @@ RUN apt-get update && apt-get -y upgrade && \ COPY forth.asm / COPY efi.asm / COPY base.forth / +COPY efi.forth / COPY run.sh / RUN fasm forth.asm BOOTX64.EFI diff --git a/efi.forth b/efi.forth @@ -0,0 +1,159 @@ + +: STRUCT 0 ; +: ENDSTRUCT FIELD DROP ; + +: EFI:int32 4 + ; +: EFI:int64 8 + ; + +STRUCT +FIELD EFI:TableHeader:Signature EFI:int64 +FIELD EFI:TableHeader:Revision EFI:int32 +FIELD EFI:TableHeader:HeaderSize EFI:int32 +FIELD EFI:TableHeader:CRC32 EFI:int32 +FIELD EFI:TableHeader:Reserved EFI:int32 +ENDSTRUCT EFI:TableHeader + +STRUCT +FIELD EFI:SystemTable:Hdr EFI:TableHeader +FIELD EFI:SystemTable:FirmwareVendor EFI:int64 +FIELD EFI:SystemTable:FirmwareRevision EFI:int64 +FIELD EFI:SystemTable:ConsoleInHandle EFI:int64 +FIELD EFI:SystemTable:ConIn EFI:int64 +FIELD EFI:SystemTable:ConsoleOutHandle EFI:int64 +FIELD EFI:SystemTable:ConOut EFI:int64 +FIELD EFI:SystemTable:StandardErrorHandle EFI:int64 +FIELD EFI:SystemTable:StdErr EFI:int64 +FIELD EFI:SystemTable:RuntimeServices EFI:int64 +FIELD EFI:SystemTable:BootServices EFI:int64 +FIELD EFI:SystemTable:NumberOfTableEntries EFI:int64 +FIELD EFI:SystemTable:ConfigurationTable EFI:int64 +ENDSTRUCT EFI:SystemTable + +STRUCT +FIELD EFI:TextOutput:Reset EFI:int64 +FIELD EFI:TextOutput:OutputString EFI:int64 +FIELD EFI:TextOutput:TestString EFI:int64 +FIELD EFI:TextOutput:QueryMode EFI:int64 +FIELD EFI:TextOutput:SetMode EFI:int64 +FIELD EFI:TextOutput:SetAttribute EFI:int64 +FIELD EFI:TextOutput:ClearScreen EFI:int64 +FIELD EFI:TextOutput:SetCursorPosition EFI:int64 +FIELD EFI:TextOutput:EnableCursor EFI:int64 +FIELD EFI:TextOutput:Mode EFI:int64 +ENDSTRUCT EFI:TextOutput + +STRUCT +FIELD EFI:TextInput:Reset EFI:int64 +FIELD EFI:TextInput:ReadKeyStroke EFI:int64 +FIELD EFI:TextInput:WaitForKey EFI:int64 +FIELD EFI:TextInput:SetState EFI:int64 +FIELD EFI:TextInput:RegisterKeyNotify EFI:int64 +FIELD EFI:TextInput:UnregisterKeyNotify EFI:int64 +ENDSTRUCT EFI:TextInput + +STRUCT +FIELD EFI:BootServices:Hdr EFI:TableHeader +FIELD EFI:BootServices:RaiseTPL EFI:int64 +FIELD EFI:BootServices:RestoreTPL EFI:int64 +FIELD EFI:BootServices:AllocatePages EFI:int64 +FIELD EFI:BootServices:FreePages EFI:int64 +FIELD EFI:BootServices:GetMemoryMap EFI:int64 +FIELD EFI:BootServices:AllocatePool EFI:int64 +FIELD EFI:BootServices:FreePool EFI:int64 +FIELD EFI:BootServices:CreateEvent EFI:int64 +FIELD EFI:BootServices:SetTimer EFI:int64 +FIELD EFI:BootServices:WaitForEvent EFI:int64 +FIELD EFI:BootServices:SignalEvent EFI:int64 +FIELD EFI:BootServices:CloseEvent EFI:int64 +FIELD EFI:BootServices:CheckEvent EFI:int64 +FIELD EFI:BootServices:InstallProtocolInterface EFI:int64 +FIELD EFI:BootServices:ReinstallProtocolInterface EFI:int64 +FIELD EFI:BootServices:UninstallProtocolInterface EFI:int64 +FIELD EFI:BootServices:HandleProtocol EFI:int64 +FIELD EFI:BootServices:Reserved EFI:int64 +FIELD EFI:BootServices:RegisterProtocolNotify EFI:int64 +FIELD EFI:BootServices:LocateHandle EFI:int64 +FIELD EFI:BootServices:LocateDevicePath EFI:int64 +FIELD EFI:BootServices:InstallConfigurationTable EFI:int64 +FIELD EFI:BootServices:LoadImage EFI:int64 +FIELD EFI:BootServices:StartImage EFI:int64 +FIELD EFI:BootServices:Exit EFI:int64 +FIELD EFI:BootServices:UnloadImage EFI:int64 +FIELD EFI:BootServices:ExitBootServices EFI:int64 +FIELD EFI:BootServices:GetNextMonotonicCount EFI:int64 +FIELD EFI:BootServices:Stall EFI:int64 +FIELD EFI:BootServices:SetWatchdogTimer EFI:int64 +FIELD EFI:BootServices:ConnectController EFI:int64 +FIELD EFI:BootServices:DisconnectController EFI:int64 +FIELD EFI:BootServices:OpenProtocol EFI:int64 +FIELD EFI:BootServices:CloseProtocol EFI:int64 +FIELD EFI:BootServices:OpenProtocolInformation EFI:int64 +FIELD EFI:BootServices:ProtocolsPerHandle EFI:int64 +FIELD EFI:BootServices:LocateHandleBuffer EFI:int64 +FIELD EFI:BootServices:LocateProtocol EFI:int64 +FIELD EFI:BootServices:InstallMultipleProtocolInterfaces EFI:int64 +FIELD EFI:BootServices:UninstallMultipleProtocolInterfaces EFI:int64 +FIELD EFI:BootServices:CalculateCrc32 EFI:int64 +FIELD EFI:BootServices:CopyMem EFI:int64 +FIELD EFI:BootServices:SetMem EFI:int64 +FIELD EFI:BootServices:CreateEventEx EFI:int64 +ENDSTRUCT EFI:BootServices + +STRUCT +FIELD EFI:RuntimeServices:Hdr EFI:int64 +FIELD EFI:RuntimeServices:GetTime EFI:int64 +FIELD EFI:RuntimeServices:SetTime EFI:int64 +FIELD EFI:RuntimeServices:GetWakeupTime EFI:int64 +FIELD EFI:RuntimeServices:SetWakeupTime EFI:int64 +FIELD EFI:RuntimeServices:SetVirtualAddressMap EFI:int64 +FIELD EFI:RuntimeServices:ConvertPointer EFI:int64 +FIELD EFI:RuntimeServices:GetVariable EFI:int64 +FIELD EFI:RuntimeServices:GetNextVariableName EFI:int64 +FIELD EFI:RuntimeServices:SetVariable EFI:int64 +FIELD EFI:RuntimeServices:GetNextHighMonotonicCount EFI:int64 +FIELD EFI:RuntimeServices:ResetSystem EFI:int64 +FIELD EFI:RuntimeServices:UpdateCapsule EFI:int64 +FIELD EFI:RuntimeServices:QueryCapsuleCapabilities EFI:int64 +FIELD EFI:RuntimeServices:QueryVariableInfo EFI:int64 +ENDSTRUCT EFI:RuntimeServices + +CODE EFI:CALL0 + RAX POP + RAX CALL-INDIRECT + RAX PUSH +;CODE + +CODE EFI:CALL1 + RCX POP + RAX POP + RAX CALL-INDIRECT + RAX PUSH +;CODE + +CODE EFI:CALL2 + RDX POP + RCX POP + RAX POP + RAX CALL-INDIRECT + RAX PUSH +;CODE + +CODE EFI:CALL3 + R8 POP + RDX POP + RCX POP + RAX POP + RAX CALL-INDIRECT + RAX PUSH +;CODE + +CODE EFI:CALL4 + R9 POP + R8 POP + RDX POP + RCX POP + RAX POP + RAX CALL-INDIRECT + RAX PUSH +;CODE + diff --git a/forth.asm b/forth.asm @@ -268,8 +268,6 @@ main: initialize_stack mov rbp, return_stack_top mov rsi, program - mov [input_buffer], forth_base - mov [input_buffer.len], forth_base.len NEXT } @@ -1169,6 +1167,16 @@ defcode "(", 1, 0, LEFT_PAREN .end: NEXT +defcode "LOAD_BASE", 9, 0, LOAD_BASE + mov [input_buffer], forth_base + mov [input_buffer.len], forth_base.len + NEXT + +defcode "LOAD_EFI", 8, 0, LOAD_EFI + mov [input_buffer], forth_efi + mov [input_buffer.len], forth_efi.len + NEXT + section '.data' data readable writable version_string db 'soup forth v0.1', 0xA @@ -1211,6 +1219,10 @@ forth_base: file './base.forth' forth_base.len = $ - forth_base +forth_efi: +file './efi.forth' +forth_efi.len = $ - forth_efi + align 4096 return_stack rb 8192 return_stack_top: