"To master riding bicycles you have do ride bicycles"
started at 04/08/2025, agsb@ vide Changes and Notes
_STILL a STUB_
This is an implementation of milliForth (sectorforth) concept for ARM ISA.
Milliforth uses a minimal set of primitives and functions for make a Forth.
This version uses DJB2 hashes in headers, instead of size+flags+name+pads.
No human WORDS. The IMMEDIATE flag is the MSBit (31) of hash.
Options:
compiler suit of RISCV: gcc arm-unknown-elf-* -Oz
which memory map be used and pages size: default GCC
simulator of ARM: using raspberry pi
the heap and stack in memory: .heap at end of .bss, .stack elsewhere ?
systems calls of core functions: linux ecalls
the ARM is a 4 bytes (32-bit) cell CPU with 32-bit ISA in version ARMv7 and a 64-bit ISA in version ARMv8.
Focus in Raspberry PI 3 B, Cortex-A53, ARMv8, but using 32-bit ISA.
The milliForth is a program called by 'elsewhere alien operational system', and use registers ????.
Key Components for RP2040 Cross-Compilation
Compiler: arm-none-eabi-gcc Target CPU: -mcpu=cortex-m0plus Architecture: -march=armv6s-m QEMU Command: qemu-system-arm -machine raspi0 -kernel your_binary.elf -nographic
bash:
sudo apt install gcc-arm-none-eabi binutils-arm-none-eabi
arm-none-eabi-gcc -c -mcpu=cortex-m0plus -march=armv6s-m -mthumb --specs=nosys.specs -o main.o main.c
arm-none-eabi-gcc -mcpu=cortex-m0plus -march=armv6s-m -mthumb --specs=nosys.specs -T linker_script.ld -o main.elf main.o
qemu-system-arm -machine raspi0 -cpu cortex-m0plus -kernel main.elf -nographic
For assembler, use gcc style with pre-processor directives eg. #define.
For now, using linux system in a Raspberry PI and gcc suit for a single core minimal footprint Forth thread.
I hope it uses far less than 4k bytes, without a user dictionary.
The milliForth must use memory pointers for data stack and return stack, because does fetch and store from a special 'user structure', which contains the user variables for Forth (state, toin, last, here, spt, dpt, tout, once, heap, tail).
This version includes:
primitives:
s@ return the address of user structure
+ adds two values at top of data stack
nand logic not and the two values at top of data stack
@ fetch a value of cell wich address at top of data stack
! store a value into a cell wich address at top of data stack
0# test if top of data stack is not zero
: starts compilng a new word
; stops compiling a new word
exit ends a word
key get a char from default terminal (system dependent)
emit put a char into default terminal (system dependent)
only internals:
main, cold, warm, quit, djb2,
token, skip, scan, getline,
tick, find, compile, execute, comma, memcopy
unnest, next, nest, pick, jump,
ps. exit is unnest, next is not the NEXT of FOR loop
with externals:
_getc, _putc, _exit, _init,
extensions: (selectable)
2/ shift right one bit
exec jump to address at top of spt
:$ jump to (ipt)
;$ jump to next
extras: (selectable)
bye ends the Forth, return to system
abort restart the Forth
.S list cells in data stack
.R list cells in return stack
. show cell at top of data stack
words extended list the words in dictionary
dump list contents of dictionary in binary
A my_hello_world.FORTH alternate version with dictionary for use;
The sp@ and rp@ are now derived from s@ in the my_hello_world.FORTH
For Forth language primer see Starting Forth
For Forth from inside howto see JonasForth
For A Problem Oriented Language see POL
the originals files are edited for lines with less than 80 bytes
the bf.FORTH and hello_world.FORTH are from original milliForth1
the my_hello_world.FORTH is adapted for miiliforth-6502
:
Footnotes
-
The original milliForth: https://github.com/fuzzballcat/milliForth ↩