A sub-1KB, self-hosting, native code Forth without compromise
At the core of paraforth is a very small assembly program - just an association list of names to subroutines, and an input loop for invoking them. By pre-populating the list with just enough functionality to build a macro assembler, a self-extensible language kernel is born.
This project is a long-running exercise in building the smallest self-sufficient Forth possible, without ANY sacrifices in speed or usability. No inputting pre-assembled machine code at runtime, and no cobbling together logic operations from NAND.
The entire language, save for just 15 words and 756 bytes of machine code, is implemented in itself - legibly - and builds in place on startup. Additionally, support for full bootstrapping coming soon.
This is a plugin for the Flipper Zero that ports pForth.
Once started the plugin will add a forth command to the CLI that can be used to call up a basic forth shell.
Calling the forth command with a file path as parameter will cause that file to be executed as a forth script. Examples are provided under forth_scripts.
To use one of the provided scripts (for example notif_success.fth), copy it to your SD card. Then run the plugin and execute forth /ext/<path to your file> (for example forth /ext/notif_success.fth) on the CLI.
Portable Forth written in 'C' for most 32 and 64-bit platforms.
PForth is written in 'C' and can be easily ported to new 32 and 64-bit platforms. It only needs character input and output functions to operate and, therefore, does not require an operating system. This makes it handy for bringing up and testing embedded systems.
PForth also works on desktops including Windows, Mac and Linux and supports command line history. This lets you develop hardware tests on a desktop before trying them on your embedded system. But pForth is not a rich and friendly desktop programming environment. There are no GUI tools for developing desktop applications. PForth is lean and mean and optimized for portability.
PForth has a tool for compiling code on a desktop, then exporting the dictionary in big or little endian format as 'C' source code. This lets you compile tests for an embedded system that does not have file I/O.
PForth is based on ANSI-Forth but is not 100% compatible.
The Forth Interest Group (FIG) was a world-wide, non-profit organization for education in and the promotion of the Forth computer language. This website offers an on-line literature database, programming tools, reference works, public-domain and experimental implementations of the Forth programming language for various platforms, technical conferences, and connections to other Forth resources.
Although FIG as an organization has dissolved, this website will continue to reflect the on-going interest in Forth.
James Bowman's seminal paper on the J1 CPU was presented in 2010. At under 200 lines of Verilog, the J1 was a real breakthrough in simplicity. It also happens to be a very powerful Forth processor.
The Chad CPU, like the J1, has excellent semantic density. The application of the J1 was a UDP stack in a Xilinx FPGA. The code was 70% smaller than the equivalent C on a MicroBlaze. The code just wouldn't fit in memory, so the J1 was used instead. Admittedly, MicroBlaze is a hog. However J1 has a lot going for it. Calls and jumps take only a single cycle. Often a return is combined with an ALU instruction to cause a return in zero instructions. It's a little freaky to watch in simulation if you're used to control flow changes having to deal with pipelines.
The system can be understood and maintained by one person due to simplicity.
Built for security. The ISA doesn't support random read of code memory, which makes reverse engineering and hacking the code an exercise in chip probing if it can even be done. The MCU boots from SPI flash, which is encrypted using a stream cipher. The weak spot then becomes key management: How secure are keys, how hard can you make it to probe memory busses on the ASIC die, etc.
In-system programming (ISP) is handled by hardware state machines, not firmware. The SPI flash controller integrates a UART and processor memories so that the RAMs can be loaded from flash at boot time. The UART can also be used to program flash by any host computer with a serial port. It can also reset the processor.
miniforth is a real mode FORTH that fits in an MBR boot sector. The following standard words are available:
+ - ! @ c! c@ dup drop swap emit u. >r r> [ ] : ; load
Additionally, there is one non-standard word. s: ( buf -- buf+len )
will copy the rest of the current input buffer to buf, and terminate it with a null byte. The address of said null byte will be pushed onto the stack. This is designed for saving the code being ran to later put it in a disk block, when no block editor is available yet.
The dictionary is case-sensitive. If a word is not found, it is converted into a number with no error checking. For example, g results in the decimal 16, extending the 0123456789abcdef of hexadecimal. On boot, the number base is set to hexadecimal.
Backspace works, but doesn't erase the input with spaces, so until you write something else, the screen will look a bit weird.
See the blogpost, Fitting a FORTH in 512 bytes, for my motivation for writing this and the details of the code.