Skip to content

johnhw/minforth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raspberry Pi JonesFORTH O/S

Derived from [pijFORTHos], in turn based on Jonesforth-ARM.

Jonesforth-ARM is an ARM port, by M2IHP'13 class members listed in AUTHORS, of x86 JonesForth. Much of the bare metal code was modified from [dwelch67]'s excellent bare metal tutorials.

The major difference with pijFORTHos is a really minimal ASM kernel (just 3k), and no C code. The kernel does just enough to bootstrap FORTH.

Instructions

On an RPi you can just do

make clean ; make

Then copy kernel.img, start.elf, bootload.bin to a blank FAT32 formatted SD card.

Everything that works in pijFORTHos should also work here. But note that the bootloader can be called with UPLOAD, but expects a hex dump of the kernel. The makefile generates this as kernel.hex. You can simply paste (Ctrl-a Ctrl-y in Minicom) in after entering UPLOAD and the kernel will be transferred. BOOT will start the new kernel and reload it.

As in pijFORTHos, you can connect over serial with the port settings 115200-8-N-1. If you use minicom, the supplied script hex.scr recompiles, and then uses the bootloader to upload the new kernel and reboots. Configure minicom to use ANSI color, as minFORTH use ANSI codes to display colored text, clear the screen etc.

Running

                           ____    _____   ____    ______  __  __
                __        /\  _`\ /\  __`\/\  _`\ /\__  _\/\ \/\ \
       ___ ___ /\_\    ___\ \ \L\_\ \ \/\ \ \ \L\ \/_/\ \/\ \ \_\ \
     /' __` __`\/\ \ /' _ `\ \  _\/\ \ \ \ \ \ ,  /  \ \ \ \ \  _  \
     /\ \/\ \/\ \ \ \/\ \/\ \ \ \/  \ \ \_\ \ \ \\ \  \ \ \ \ \ \ \ \
     \ \_\ \_\ \_\ \_\ \_\ \_\ \_\   \ \_____\ \_\ \_\ \ \_\ \ \_\ \_\
      \/_/\/_/\/_/\/_/\/_/\/_/\/_/    \/_____/\/_/\/ /  \/_/  \/_/\/_/
    0x4183976 CELLS FREE
    HERE:0x21E80 LATEST:0x21E1C   R0:0xFD20 RSP:0xFD14   DSP:0x7CF4 S0:0x8000

Original pijFORTHos documentation:

pijFORTHos

x86 JonesForth is a Linux-hosted FORTH presented in a Literate Programming style by Richard W.M. Jones rich@annexia.org originally at http://annexia.org/forth. Comments embedded in the original provide an excellent FORTH implementation tutorial. See the /annexia/ directory for a copy of this original source.

The algorithm for our unsigned DIVMOD instruction is extracted from 'ARM Software Development Toolkit User Guide v2.50' published by ARM in 1997-1998

Firmware files to make bootable images are maintained at https://github.com/raspberrypi/firmware. See the /firmware/ directory for local copies used in the build process.

What is this ?

pijFORTHos is a bare-metal FORTH interpreter for the Raspberry Pi. It follows the general strategy given by David Welch's excellent examples. A simple bootloader is built in, supporting XMODEM uploads of new bare-metal kernel images.

The interpreter uses the RPi serial console (115200 baud, 8 data bits, no parity, 1 stop bit). If you have pijFORTHos on an SD card in the RPi, you can connect it to another machine (even another RPi) using a USB-to-Serial cable. When the RPi is powered on (I provide power through the cable), a terminal program on the host machine allows access to the FORTH console.

Build and run instructions

If you are building on the RPi, just type:

$ make clean all

If you can't compile (or cross-compile) from source, you can use the pre-built kernel.img file.

Next, copy the firmware and kernel to a blank SD card, for example:

$ cp firmware/* /media/<SD-card>/
$ cp kernel.img /media/<SD-card>/

The end state for the SD card is to have a FAT32 filesystem on it with the following files:

bootcode.bin
start.elf
kernel.img

Put the prepared SD card into the RPi, connect the USB-to-Serial cable (see RPi Serial Connection for more details), and power-up to the console.

To get to the console, you'll need to connect. Here are two ways to try:

$ minicom -b 115200 -o -D <device>

Where <device> is something like /dev/ttyUSB0 or similar (wherever you plugged in your USB-to-Serial cable).

Alternatively, if minicom is not working for you, try using screen:

$ screen <device> 115200

Where <device> is, again, something like /dev/ttyUSB0.

The console will be waiting for an input, press <ENTER>. You should then see:

pijFORTHos <version> sp=0x00008000

Where to go from HERE ?

With FORTH REPL running, try typing:

HEX 8000 DECIMAL 128 DUMP

You should see something like:

00008000  08 10 4f e2 01 d0 a0 e1  80 e0 9f e5 02 09 a0 e3  |..O.............|
00008010  01 00 50 e1 44 06 00 0a  00 e0 a0 e1 7f 2c a0 e3  |..P.D........,..|
00008020  f8 07 b1 e8 f8 07 a0 e8  20 20 52 e2 fb ff ff ca  |........  R.....|
00008030  1e ff 2f e1 fe ff ff ea  1e ff 2f e1 00 10 80 e5  |../......./.....|
00008040  1e ff 2f e1 00 00 90 e5  1e ff 2f e1 b0 10 c0 e1  |../......./.....|
00008050  1e ff 2f e1 b0 00 d0 e1  1e ff 2f e1 00 10 c0 e5  |../......./.....|
00008060  1e ff 2f e1 00 00 d0 e5  1e ff 2f e1 0e 00 a0 e1  |../......./.....|
00008070  1e ff 2f e1 10 ff 2f e1  ff 5f 2d e9 f8 07 b1 e8  |../.../.._-.....|

For something a little more interesting, try the GPIO Morse Code tutorial.

The FORTH reference page describes the FORTH words available in pijFORTHos.

The Bootloader page describes the memory layout and boot process.

There is a persistent thread on the Rasberry Pi forums with a useful collection of bare-metal resources, including ARM CPU programming references and peripheral register descriptions.

About

Minimal FORTH for bare-metal RPi, based on pijFORTHos

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published