Skip to content
agsbPublic

About

A Forth for RISCV using minimal indirect thread code. Expanded from MilliForth-RISCV, proof of concept.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

108 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aeForth for RiscV

"To master riding bicycles you have do ride bicycles"

started at 12/04/2026

vide Changes and Notes

This is an implementation of Forth concept for RISCV ISA, using Minimal Indirect Thread Code.

No human WORDS. It uses 31-bits DJB2 hash in headers.

No Terminal Input Buffer, just one-by-one-key input, and a token-to-hash ascii parser.

Only use a IMMEDIATE flag, at MSBit (32) of hash, also 0x80000000 is indicator of errors and Not a Number.

Uses SP, RP, IP and TOS, keeped in dedicated registers.

There are some primitive words in native code, some in pre-compiled code and a file to compile with more forth words.

** STILL NOT FOR USE **

** NEEDS REVIEW OF DOCUMENTATION **

For use

**cat t0.f t1.f t2.f - | sh doit.sh | tee output**

Add a hyphen at end of cat files list to allow terminal I/O
        cat t0.f t1.f t2.f - > sh doit.sh 
        
Some esoteric bug makes the first word to have hash error.

The memory management is done by extend the dictionary 
    into .bss, by reserve .skip bytes, defaults to 64k * 4
    no linux calls for memory allocation. (Anyone ?)

Compiler Options

compiler suit of RISCV: gcc riscv64-unknown-elf-* -Oz

which memory map be used and pages size: default GCC

simulator of RISCV: qemu 

besides primitives at .text, all aeForth lives at .bss.

systems calls of core functions: linux ecalls

system stack pointer: not used by Forth.

ISA

the RISCV is a 4 bytes (32-bit) cell CPU with 32-bit ISA or ISA

The aeForth is a ELF program called by 'elsewhere operational system', depends on systems, and use registers r0, ra, sp, s0, s1, a0-a7, s2, s3, t0-t2.

Coding

"qemu -kernel loads the kernel at 0x80000000 and causes each hart (i.e. core of CPU) to jump there."

For assembler, use standart Risc-V style with pre-processor directives eg. #define.

For now, using riscv-unknown-elf-gcc suit with qemu emulator for a single core minimal footprint Forth thread.

For now, aeForth 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, last, heap, sptr, dptr ).

Colon and Semis

AeForth does not uses SMUDGE.

The colon : makes a header by:

  1. copy HERE to PIKE
  2. copy LATEST to first cell;
  3. calculate the djb2 hash of the following token;
  4. copy hash to second cell;
  5. change STATE to compile (1);

In compile state, a immediate words is executed, otherwise is compiled,

The semis ; ends the word by:

  1. place a reference to 'EXIT into last cell
  2. copy PIKE to LATEST
  3. change STATE to execute (0);

When the compilation of a word breaks, the LATEST are keepd in order but HERE was advanced with references of words compiled, that junk stays lost in heap.

To clean it just copy PIKE to HERE at error or missing.

Dictionary Internals

The header is composed with LINK, HASH, followed by code or list of references.

the LINK is a 32-bit reference to previous word entry.

The HASH only uses 31-bit DJB2 hash for dictionary entries.

The IMMEDIATE flag is at high 32-bit of HASH

the Language

For Forth language primer see Starting Forth

For Forth from inside howto see JonasForth

For A Problem Oriented Language see POL

Forth Style

References

About

A Forth for RISCV using minimal indirect thread code. Expanded from MilliForth-RISCV, proof of concept.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages