I’ve researched a bit existing Forth operating systems. In the Internet the following projects were done in the past: Diesel, Cy/VOS, iTV 4os, Graphical Forth Operating System. The similarity is, that in most cases the old websites or offline and the sourcecode is no longer available. According to the description of the Diesel project, it was realized with 1200 lines of code in Assembly language and implemented a minimalistic featureset. The difference between a Forth VM and a Forth OS is, that the later own boots natively in the qemu emulator and a Forth OS usually contains of tools like an assembler, a GUI, filesystem access and a multitasking environment.
So what is wrong with Forth based operating systems? Nothing, it is a great idea in doing so. The only problem is, that in the in the past too little energy was invensted into the direction. The idea is perhaps, that Linux is a great operating system and there is no need for a Linux clone in Forth. But this assumption is wrong. Suppose a Mini project gets started, not by a single person but by a small team. If they are familiar with Forth, they can create in a reasonable time a QNX like operating system written in Forth which comes with a browser, a shell, a Forth VM, a filesystem and a network stack. I would guess it takes more then 1000 lines of code. The only known example is the iTV 4os which fits in 128 kb ROM.
Let us compare a fictional Forth OS with a normal C based operating system, what is the difference? At first, a Forth based operating system is not faster. In most cases the speed will be the same or a bit slower because less optimization was done. It is not possible to let the CPU ran faster with the Forth language. Because internally a Forth VM is programmed in assembly language. But, an operating system written in Forth can be ported to non x86 cpus, for example the J1 cpu. This is not possible with a c based operating system. And a Forth CPUs is more efficient. That means, writing a Forth OS for the x86 CPU is the prestep to a more advanced project.
The second difference to a normal C based operating system is, that in a Forth OS no C software can be started. There is no C compiler available, that means, existing software written in C/C++ can’t be compiled for this architecture. All additional software has to be written from scratch in the Forth language. This allows the community to create better software from the beginning. It means, that no existing standard-c library will be available and no standard graphics library is there.
This will increase the entry barrier. It is no longer possible that everybody can contribute to the project, but the precondition is, that the programmer is familiar with Forth. Forth makes it more hard to write non-working code. Forth software has the tendency to become very efficient. A stackbased language is easier to control. That means, a single word is using the stack only and nothing else. It can be analyzed for correctness. And because the total amount of codelines is lower, it is possible to investigate the complete operating system by hand. That means, a single person can print out the complete sourcecode and go through every line for search for a bug and fix it. This is not possible with Linux or Windows based operating systems.
Perhaps a small calculation. 100 lines of code fits onto a single sheet of paper in the twocolumn layout. A program which contains of 10000 lines of code will need 100 sheet of paper. It is possible to optimize this amount of code for maximum speed and for error-free behavior.
The bottleneck for a Forth operating system is the integration into existing C codebase. A Forth os would be some kind of hard migration because the software from the past won’t work anymore. That means, software applications like databases, wordprocessors and so on have to be rewritten from scratch. A soft transition strategy would be to write first the applications (for example office software, database and a webbrowser) in Forth and compile them to run it under Linux/Windows. And only if a large software repository in Forth is already there, it make sense to write a dedicated operating system to let them run without Linux/Windows.
Writing an operating system not in Forth, why?
Apart from mainstream operating systems like Linux and Windows, many small projects were developed in the past with the aim to create an operating system from scratch. Github has surprisingly much entries in the list. Most of the examples are written in C, but some of them are using C++ and Rust. What all these projects have in common is, that they are providing OS features like a filesystem and multitasking and they can get booted in the qemu environment. Some of the more advanced examples even provide a GUI and a dedicated package manager.
It seems, that developing an OS with the C programming language is not very complicated and many developers have done in the past. But why haven they are choosen C and not Forth as the programming language? On the first look, the difference isn’t very much. On the other hand, github doesn’t have an extensive list of operating systems written in Forth, so it’s seems that a Forth OS is more complicated to write and is not the preferred choice. On the other hand, Forth would be the right programming language. Because Forth teaches a lot about computer science.
It seems, that the mainstream loves the C programming language. And the mainstream loves also to write a lot of new and unconventional operating systems from scratch. Sometimes, this is done even in Assembly. On the other hand, the mainstream hates Forth. Operating systems written in that language are rare. So it seems, that non-stackbased computers are better suited for the needs of developers?
OS development in Forth
On the first look, the idea sounds uncommon to write an operating system in the Forth programming language. Technically it seems possible, but the amount of projects which have done so in the past is very small. Most Forth VM like Gforth or win32forth are running on top of an existing operating system. But in theory, it is possible to write even the OS in Forth.
Like in the hen egg problem the problem of bootstrapping the development process can be overcome with adapting a partial solution from a similar domain. It is right, that no tutorials are available with the title “Create your own Forth OS from scratch”, on the other hand there are many (i would guess more than 100s) tutorials available with the title “create your own operating system with Netwide Assembler and with C”. The pleasant thing is, that in these tutorials lot of background knowledge is given about bootsectors, assembly coding and the BIOS of an IBM PC. What the Forth beginner can do is to take a mainstream “OS from scratch tutorial” and adapt the content to their needs. Instead of writing the OS in assembly language, he has to use a Forth VM.
For doing so, the user has to combine two different topics: First, his knowledge about Forth programming which is given in some books. This knowledge contains of stackbased language, Forth based virtual machines and threaded code execution. On the other hand, the user will need detail knowledge about operating system writing. This knowledge is given in tutorials too and was created by non-Forth programmers in the past. An example tutorial is https://www.cs.bham.ac.uk/~exr/lectures/opsys/10_11/lectures/os-dev.pdf but many similar examples are available. The common property in all of these tutorials is, that the Forth language wasn’t mentioned. The assumption is, that the Assembly language for the first steps, and for programming the higher layers of the OS a C compiler is in charge. The funny thing is, that operating systems are working in Forth the same way. That means, it is also bootsector programming and has to do with BIOS interaction.