|
|
||
|---|---|---|
| arch | Add simple bootloader | |
| utils | Basic functionality is now working | |
| .gdbinit | Make our way to the L1 interpreter | |
| .gitignore | Fix some stack pushing bugs | |
| bootloader.f | Add simple bootloader | |
| core.f | Add simple bootloader | |
| Makefile | Add simple bootloader | |
| README.md | Add line numbers and memmap probe code | |
| test.sh | Finish tarball setup | |
forthstrap
forthstrap is a simple Forth with the goal of being used in the Linux
bootstrap process.
The goal of forthstrap is to be able to start from a small hex0 binary
image and then end with a Linux-esque operating system and a capable C
compiler. The overarching goal is to replace the early stages of the Linux
bootstrap process with something a little faster, easier to understand, and
with less code.
forthstrap starts from a hex0 loader image. This image is highly platform
dependent; however, it is only required to implement the Forth interpreter,
compiler and a small number of built-in words. In addition, the resulting
Forth interpreter is somewhat slow. From here, we eventually move to:
- Jumping to Protected Mode from Real Mode (where applicable).
- Moving to a more advanced interpreter with better performance.
- Implementing memory management, virtual memory, paging and file system access.
- Setting up a small operating system, with a user mode and basic drivers.
- Setting up a more advanced Forth compiler, used to compile userspace applications.
- A simple userspace with some Unix-like utilities, like an assembler and a linker.
- Setting up a C compiler.
Implementations of the base image exist for the following platforms:
- i386 on bare-metal BIOS
- In this case, the
hex0image also only takes up one sector of disk space.
Words
Only the following words are implemented:
Primitives
@(addr -- x)- Fetch memory contents at a specific address.!(x addr --)- Store a value at a specific address.sp@( -- addr)- Fetch the current stack pointer.rp@( -- addr)- Fetch the current return stack pointer.0=(x -- flag)- Compare a value to zero, -1 if the top of the stack is zero, 0 otherwise.+(x y -- z)- Add two numbers together.nand(x y -- z)- Perform a bitwise NAND operation on two numbers.exit(r:addr --)- Exit the current function and return to the caller.:( -- )- Start defining a new word.;( -- )- End defining a new word.key( -- c)- Read a character from the keyboard.
Variables
state-0to execute words,1to compile words.here- Pointer to the next free location in memory.latest- Pointer to the most recently defined word.
Constants
ws- Size of a word in bytes.
Inspiration
Inspiration is taken from sectorforth, jonesforth and eulex.