From aa9b4da2c96b0d6c90d51de4b3bb6c4590083365 Mon Sep 17 00:00:00 2001 From: kotorifan Date: Thu, 26 Mar 2026 23:31:22 +0100 Subject: Whatever... --- src/kernel/forth.asm | 159 +++++++++++++++++++++++++++++++++++--------------- src/kernel/kernel.asm | 10 +++- 2 files changed, 122 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/kernel/forth.asm b/src/kernel/forth.asm index 05f254f..5ac0496 100644 --- a/src/kernel/forth.asm +++ b/src/kernel/forth.asm @@ -5,96 +5,158 @@ %macro defword 2-3 0 word_%2: - dw link + dd link %define link word%2 %strlen %%len %1 db %3+%%len db %1 - %2 + align 4 + dd %2 %endmacro +;; Collection of useful macros to built on later %macro NEXT 0 lodsl jmp [eax] %endmacro -%macro STACK_PUSH 1 +%macro DATA_PUSH 1 lea ebp, [ebp - 4] mov ebp, %1 %endmacro -%macro STACK_POP 1 +%macro DATA_POP 1 mov %1, [ebp] lea ebp, [ebp + 4] %endmacro +%macro RET_PUSH 1 + mov %1, [edi] + lea edi, [edi + 4] +%endmacro + +%macro RET_POP 1 + lea edi, [edi - 4] + mov [edi], %1 +%endmacro + +%macro DOCOL 0 + RET_PUSH esi + lea esi, [ebx + 4] + NEXT +%endmacro + +;; Words related to the stack + defword "DROP", DROP - pop eax + DATA_POP eax NEXT defword "SWAP", SWAP - pop eax - pop ebx - push eax - push ebx + DATA_POP eax + DATA_POP ebx + DATA_PUSH eax + DATA_PUSH ebx NEXT defword "DUP", DUP - mov eax, [esp] - push eax + DATA_POP eax + DATA_PUSH eax + DATA_PUSH eax NEXT defword "OVER", OVER - mov eax, [esp + 4] - push eax + DATA_POP eax + DATA_POP ebx + DATA_PUSH ebx + DATA_PUSH eax + DATA_PUSH ebx NEXT defword "ROT", ROT - pop eax - pop ebx - pop ecx - push ebx - push eax - push ecx + DATA_POP eax + DATA_POP ebx + DATA_POP ecx + DATA_PUSH ebx + DATA_PUSH eax + DATA_PUSH ecx NEXT defword "-ROT", NROT - pop eax - pop ebx - pop ecx - push eax - push ecx - push ebx + DATA_POP eax + DATA_POP ebx + DATA_POP ecx + DATA_PUSH eax + DATA_PUSH ecx + DATA_PUSH ebx NEXT defword "2DROP", TWODROP - pop eax - pop eax + DATA_POP eax + DATA_POP eax NEXT defword "2DUP", TWODUP - mov eax, [esp] - mov ebx, [esp + 4] - push ebx - push eax + DATA_POP eax + DATA_POP ebx + DATA_PUSH ebx + DATA_PUSH eax + DATA_PUSH ebx + DATA_PUSH eax NEXT + defword "?DUP", QDUP + DATA_POP eax + test eax, eax + jz .done + DATA_PUSH eax + DATA_PUSH eax +.done: + NEXT + +;; Words related to memory + defword "@", FETCH - pop ebx - push [ebx] + DATA_POP ebx + mov eax, [ebx] + DATA_PUSH eax NEXT + defword "!", STORE + DATA_POP ebx + DATA_POP eax + mov [ebx], eax + NEXT + + defword "C@", CFETCH + DATA_POP ebx + movzx eax, byte [ebx] + DATA_PUSH eax + NEXT + + defword "C!", CSTORE + DATA_POP ebx + DATA_POP eax + mov [ebx], al + +;; Words related to the interpreter + defword "EXIT", EXIT_WORD - Pop Esi - Next + RET_POP esi + NEXT - Defword "LIT", LITERAL + defword "LIT", LITERAL lodsl - add esi, eax + DATA_PUSH eax NEXT + defword "BRANCH", branch + lodsl + add esi, eax + NEXT + defword "0BRANCH", ZERO_BRANCH - pop eax + DATA_POP eax test eax, eax jnz .skip lodsl @@ -104,14 +166,19 @@ add esi, 4 NEXT - defword "?DUP", QDUP - mov eax, esp - test eax, eax - jz .1 - push eax - .1: + defword "HERE", HERE + DATA_PUSH dword [here] NEXT - - defword + + defword "ALLOT", ALLOT + DATA_POP eax + add [here], eax + NEXT + + defword ",", COMMA + DATA_POP eax + mov ebx, [here] + mov [ebx], eax + add dword [here], 4 %endif diff --git a/src/kernel/kernel.asm b/src/kernel/kernel.asm index ca7339e..d09520a 100644 --- a/src/kernel/kernel.asm +++ b/src/kernel/kernel.asm @@ -2,12 +2,20 @@ [bits 32] [org 0x10000] +%include "common.asm" + _kernel_entry: cli ; No interrupts yet call _clear_screen mov esi, welcome_msg call _print_string_pm_vga + +;; Init Forth VM + mov ebp, FS_DATA_STACK + mov edi, FS_RET_STACK + + .halt: hlt jmp .halt @@ -15,6 +23,6 @@ _kernel_entry: welcome_msg: db "Welcome...", 0 -%include "common.asm" + %include "common.protmode.print.asm" %include "common.protmode.clear.asm" -- cgit v1.3