1
0
Fork
You've already forked forthstrap
0
A small Forth-based operating system
Forth 59.6%
Assembly 20%
Python 18.9%
Makefile 1.3%
Shell 0.2%
John Nunley 56b154636c Add simple bootloader
Signed-off-by: John Nunley <dev@notgull.net>
2025年12月14日 21:08:55 +00:00
arch Add simple bootloader 2025年12月14日 21:08:55 +00:00
utils Basic functionality is now working 2025年11月02日 21:06:21 -08:00
.gdbinit Make our way to the L1 interpreter 2025年11月10日 23:44:55 -08:00
.gitignore Fix some stack pushing bugs 2025年10月21日 21:26:31 -07:00
bootloader.f Add simple bootloader 2025年12月14日 21:08:55 +00:00
core.f Add simple bootloader 2025年12月14日 21:08:55 +00:00
Makefile Add simple bootloader 2025年12月14日 21:08:55 +00:00
README.md Add line numbers and memmap probe code 2025年11月16日 11:23:26 -08:00
test.sh Finish tarball setup 2025年12月14日 20:21:46 +00:00

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 hex0 image 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 - 0 to execute words, 1 to 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.