From: Jonas Hvid Date: Sun, 4 Oct 2020 00:14:04 +0000 (+0200) Subject: Add placeholder implementation of Linux backend X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=5224cfbc1856cd2f4c786f73223b1182acbc96cc;p=rrq%2Fjonasforth.git Add placeholder implementation of Linux backend --- diff --git a/.gitignore b/.gitignore index 5557c76..cef3077 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /out +/main /OVMF_CODE.fd /OVMF_VARS.fd diff --git a/Makefile b/Makefile index 362c429..c812dcc 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,9 @@ out/main: main.asm impl.asm bootstrap.asm sys.f os/uefi.asm mkdir -p out OS_INCLUDE=os/uefi.asm fasm $< $@ +main: main.asm impl.asm bootstrap.asm sys.f os/linux.asm + OS_INCLUDE=os/linux.asm fasm $< $@ + .PHONY: clean clean: rm -rf out OVMF_CODE.fd OVMF_VARS.fd diff --git a/impl.asm b/impl.asm index dd7fc9d..67d11b5 100644 --- a/impl.asm +++ b/impl.asm @@ -1,6 +1,4 @@ -;; vim: syntax=fasm - -section '.text' code readable executable +os_code_section macro printlen msg, len { push rsi @@ -186,7 +184,7 @@ parse_number: mov rax, 100 call os_terminate -section '.data' readable writable +os_data_section find.search_length dq ? find.search_buffer dq ? diff --git a/main.asm b/main.asm index 407d3a3..d1ff2b3 100644 --- a/main.asm +++ b/main.asm @@ -1,10 +1,16 @@ ;; vim: syntax=fasm ;; At compile-time we load the module given by the environment variable -;; OS_INCLUDE. This module should define the following macros: +;; OS_INCLUDE. All of the following these procedures should preserve the value +;; of RSI and RSP. They may use other registers as they like. ;; -;; Each of these functions should preserve the value of RSI and RSP. They may -;; use other registers as they like. +;; The module should provide the following: +;; +;; os_code_section +;; Macro to start the text segment. +;; +;; os_data_section +;; Macro to start the data segment. ;; ;; os_initialize ;; Called at initialization. @@ -78,7 +84,7 @@ macro forth_asm label, name, immediate { .start: } -section '.text' code readable executable +os_code_section include "impl.asm" ; Misc. subroutines include "bootstrap.asm" ; Forth words encoded in Assembly @@ -609,7 +615,7 @@ forth INPUT_LENGTH, 'INPUT-LENGTH' dq LIT, input_buffer_length dq EXIT -section '.data' readable writable +os_data_section ;; The LATEST variable holds a pointer to the word that was last added to the ;; dictionary. This pointer is updated as new words are added, and its value is @@ -657,6 +663,8 @@ return_stack_top: ;; We store some Forth code in sys.f that defined common words that the user ;; would expect to have available at startup. To execute these words, we just ;; include the file directly in the binary, and then interpret it at startup. -sysf file 'sys.f' +sysf: +file 'sys.f' +file 'example.f' sysf.len = $ - sysf diff --git a/os/linux.asm b/os/linux.asm new file mode 100644 index 0000000..1279597 --- /dev/null +++ b/os/linux.asm @@ -0,0 +1,22 @@ +format ELF64 executable + +macro os_code_section { + segment readable executable +} + +macro os_data_section { + segment readable writable +} + +os_initialize: + ret + +os_print_string: + ret + +os_read_char: + ret + +os_terminate: + ret + diff --git a/os/uefi.asm b/os/uefi.asm index 16fc85d..10c7627 100644 --- a/os/uefi.asm +++ b/os/uefi.asm @@ -58,6 +58,14 @@ struct EFI_INPUT_KEY ;; }}} +macro os_code_section { + section '.text' code readable executable +} + +macro os_data_section { + section '.data' readable writable +} + section '.text' code executable readable os_initialize: