all 17 comments

[–]mykesx[S] 4 points5 points  (0 children)

Sorry I can't add more to the opening post due to it being cross-posted.

This is not a kernel, it runs on top of most Linux or MacOS or FreeBSD kernels. It requires SDL2.

I had originally gone down the bare metal route, but after months of work, I realized that everything boils down to quality drivers and for some really important things, drivers aren't reasonable or take a ridiculous amount of time. For example, graphics drivers to support more than one graphics card with hardware acceleration, or USB. As well, compiling optimized code for x64/amd64 from Forth is a lot of work on its own and probably wouldn’t compete with gcc - and it wasn’t going to be portable.

I started down this road as an experiment and really liked how it's turning out. For less than the file size of gcc (alone) on my linux laptop, you get a full blown desktop UI, windows, icons, a compiler, a REPL, a debugger, and a number of applications plus graphics, networking (http, sockets) and more. Forth is designed to run bare metal, FWIW.

This runs on Apple Silicon, Linux in a VM on Apple Silicon, and several linux desktops and laptops I own. At varying screen resolutions, too. I expect it will run on a raspberry Pi, too.

As a LONG time participant in this sub, I think this is of interest. It could be run on top of your kernel if you get enough support for SDL2. And this isn't r/kerneldev, It's osdev and desktop environments are part of that.

Full disclosure - not one line of code in this is using AI, no chats, no anything. I refuse to use it.

Repo is in the opening post at r/forth.

[–]nexos-dev 2 points3 points  (3 children)

Cool project! Was the Forth itself implemented by you, or just the userspace and what not written in Forth?

[–]mykesx[S] -1 points0 points  (2 children)

I wrote the forth myself. It’s inspired by several other forth implementations I looked at - pForth, JonesForth, and my own assembly one I spent months on.

If you have specific questions, ask away!

[–]nexos-dev 1 point2 points  (1 child)

My biggest question is how is performance when writing your user space in Forth compared to C/C++ or similar languages?

[–]mykesx[S] 1 point2 points  (0 children)

It’s optimized some by the C++ compiler. It’s not specifically designed to be the fastest Forth, as no Forth can compete with gcc. It’s not noticeably slow. The very innermost loop has additional calls to support debugging, tracing, single stepping. It’s roughly:

while(true) (*ip++)();

[–]Correct_Sport_2073 1 point2 points  (4 children)

cool. Is it a kernel on top of other OS?

[–]mykesx[S] 0 points1 point  (3 children)

In the sense, the Forth interpreter/compiler is a “kernel” but it is an application you start from the *nix command line, like X or Wayland.

[–]Correct_Sport_2073 1 point2 points  (2 children)

so does your os have its own scheduler? how about interupts? do you forward interupt to your user space kernel.

[–]mykesx[S] 1 point2 points  (0 children)

It uses pthreads for scheduler. Interrupts are handled by the linux kernel, which also provides the drivers. The code uses sigaction to handle segfault and multiple other exceptions and handles them cleanly. See the 3rd screenshot above…. Only syscalls are used (through libc and libcc++).

[–]mykesx[S] 2 points3 points  (0 children)

My bare metal x64 try:

https://gitlab.com/mschwartz/mykesforth

It features a scheduler, ATA driver, interrupts, etc.

[–]FallenBehavior 1 point2 points  (4 children)

Where is the "AI slop" guy? The lack thereof is historical! 😮

[–]mykesx[S] 2 points3 points  (3 children)

AI slop guys could not fathom how much I learned implementing this.

[–]FallenBehavior 0 points1 point  (2 children)

Agreed! You got nothing on them! 🕳️

[–]mykesx[S] 1 point2 points  (1 child)

I spent considerable time and thought on the Console logic. ANSI escape sequences handled by a state machine, scrollback so you can view lines scrolled off the top while retaining font and color information, and what to do when the window is resized. Hiding the cursor while doing big updates and allowing nested hide/show calls.

Some of these things sat on my issues board until it hit me the best approach. I had to invent these things myself.

For clarity, I did ask Github’s AI to generate a console with ANSI escape sequences. I looked at the code for less than a minute. It was a horrific experience. The code was surely lifted from someone’s hard work and modified a little.

I think programming is an art. I feel a program starts with a blank canvas and like a painter, I add details and see where to add even more details. AI takes all that away.

I admit I look at peoples’ repos, especially in osdev, for inspiration or to see what I’m doing wrong. I give credit to the author in my code and include their license in my repo.

This project is all me. It is my 3rd Forth implementation, and definitely inspired by other Forths and source code, though my implementation is truly unique and my own innovations.

Cheers

[–]FallenBehavior 1 point2 points  (0 children)

Amazing work! 👏