From: Jonas Hvid Date: Sun, 4 Oct 2020 01:07:25 +0000 (+0200) Subject: Implement Linux backend X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=1c75ba69173401f26034abf10e64f240977e215a;p=rrq%2Fjonasforth.git Implement Linux backend You can now run: make main && ./main To run the interpreter without needing to boot up a virtual machine. Note that this mode uses per-line buffering by default, so you may have to press enter where you would normally only need a space. --- diff --git a/main.asm b/main.asm index d1ff2b3..93e576f 100644 --- a/main.asm +++ b/main.asm @@ -84,11 +84,11 @@ macro forth_asm label, name, immediate { .start: } -os_code_section - include "impl.asm" ; Misc. subroutines include "bootstrap.asm" ; Forth words encoded in Assembly +os_code_section + main: cld ; Clear direction flag so LODSQ does the right thing. mov rbp, return_stack_top ; Initialize return stack diff --git a/os/linux.asm b/os/linux.asm index 1279597..2ea3d16 100644 --- a/os/linux.asm +++ b/os/linux.asm @@ -1,4 +1,5 @@ format ELF64 executable +entry main macro os_code_section { segment readable executable @@ -8,15 +9,37 @@ macro os_data_section { segment readable writable } +os_code_section + os_initialize: ret os_print_string: + push rsi + mov rax, 1 + mov rdi, 1 + mov rsi, rcx + syscall + pop rsi ret os_read_char: + push rsi + mov rax, 0 + mov rdi, 0 + mov rsi, .buffer + mov rdx, 1 + syscall + pop rsi + movzx rax, byte [.buffer] ret os_terminate: - ret + mov rdi, rax + mov rax, $3C + syscall + +os_data_section + +os_read_char.buffer db ?