~vdupras/duskos

32-bit Forth OS with C compiler

cbcbd1b text/ed: add copy/paste capability

~vdupras pushed to ~vdupras/duskos git

5 hours ago

2c5bedb doc/design: add a few precisions

~vdupras pushed to ~vdupras/duskos git

6 hours ago

#Dusk OS

Dusk OS is a 32-bit Forth running on i386 and ARM CPUs and big brother to Collapse OS. Its primary purpose is to be maximally useful during the first stage of civilizational collapse, that is, when we can't produce modern computers anymore but that there's still many modern computers still around.

It does so by aggressively prioritizing simplicity at the cost of unorthodox constraints, while also aiming to make power users happy.

Dusk OS innovates by having an "almost C" compiler allowing it to piggy-back on UNIX C code, through a modest porting effort, to reach its goals and stay true to its design constraints with a minimal effort.

This is Dusk OS' source code and the rest of the README assumes that you want to run it. To read more about why this OS exists, see its website. To see where it's going, you can look at the roadmap.

#Build and run Dusk

Dusk is designed to run on bare metal and to build itself from itself. However, it's also possible to build Dusk from any POSIX platform using Dusk's C VM from posix/vm.c. This VM implements a Forth that can interpret the whole of Dusk's Forth code, but this VM is CPU-agnostic and has its own simplistic bytecode.

That is enough to generate bare metal images for any of its target platforms, so that's why it exists. To build this VM, you need:

  • GNU Make
  • A C compiler

Running make will yield a ./dusk binary which if opened, provides an interactive prompt.

Documentation lives in fs/doc. You can begin with doc/index. Type bye to quit.

Dusk OS expects a non-canonical raw input. With a regular TTY, your input will be buffered and echoed twice and reads to it will be blocking. We don't want that. To avoid that, you can invoke it like this:

(stty -icanon -echo min 0; ./dusk; stty icanon echo)

make run does this for you.

#Running on QEMU or bare metal

Running Dusk under the POSIX VM is fine, but severly limited: the filesystem is read-only and there is no Grid (text UI system) or Screen (graphical system).

To see a fully-featured Dusk, it's better to run it on an actual machine or, if you're in a hurry, under QEMU. You can do the latter with make pcrun.

Dusk is self-hosting and has the ability to create its own FAT. However, through the POSIX VM, this process is quite slow and after a few times, you might tire of waiting after this process. If you install mtools, things will speed up. If mcopy is present on the host, the Makefile will pick it up and use it instead of using Dusk's FAT tools. This is much faster.

To deploy Dusk on a real machine, it's a bit more involving and you should read doc/deploy.txt.

#Running on WASM

Dusk OS has a peculiar target: WASM on a modern browser. It's represented as a graphical console with a fully functional Dusk OS prompt in a browser tab.

To build, you need AssemblyScript, which needs, ahem, NPM. Build instructions:

  1. npm -g install assemblyscript
  2. make wasm.img
  3. cd wasm && make
  4. In a modern browser, open wasm/index.html.
  5. In the first file selection prompt, choose wasm/kernel.wasm.
  6. In the second one, select wasm.img
  7. After a few seconds, you'll have a Dusk OS prompt.

Note that the WASM target is much, much slower than other Dusk OS targets.

#See what it can do

Some Dusk OS targets, such as the PC and WASM targets, have graphical capabilities as well as varvara bindings for it. To have an idea of what graphics look like, you can try this on one of these targets:

f<< tests/manual/uxn/sprite.fs

This will:

  1. Compile DuskCC (in forth)
  2. Compile uxn (in C)
  3. Compile uxntal (the uxn assembler) (in C)
  4. Compile varvara (in forth)
  5. Compile tests/manual/uxn/sprite.tal (a copy of the official screen.tal)
  6. Put the system in graphical mode
  7. Run the compiled sprite.tal

You now have it running. There is also a mouse cursor that you can move around. Press Escape to return to prompt. You can try the same thing with:

  • tests/manual/uxn/mandel.fs
  • tests/manual/uxn/ctrl.fs
  • tests/manual/uxn/mouse.fs
  • text/left.fs

#Build Collapse OS images

The Collapse OS project lives inside Dusk OS which has a compatibility layer allowing it to run Forth code in "Collapse OS mode", which makes it the simplest way around to bootstrap a seed Collapse OS binary.

To be sure: Collapse OS is fully self-hosting and doesn't need Dusk OS to build itself, but if you don't already have a Collapse OS environment handy, then you need a way to craft your first Collapse OS image. Dusk OS is this way.

Collapse OS itself doesn't contain any machine-specific code so it can't, by itself, build an image for a real machine. That machine-specific code live in different repositories all around. This is the list of known Collapse OS ports to real machines:

If you know of other ports out there, please get in touch, we'll add links here.

The idea is eventually to have virtual machines (that is, machines with simplistic virtual hardware that doesn't map to anything that exists physically) for each supported CPU that is emulated from within Dusk OS, but this hasn't been done yet. These virtual machines will live directly in the "core" Collapse OS and will serve as development testbeds.