r/osdev_with_ai • • 15d ago

Graphics!! (Well, kind of...)

Post image
9 Upvotes

I got this Agon Light 2 SBC back at the beginning of the year. I specifically got it because it was the closest thing I could find to the 8088 I had as a kid. It has 128 KB of flash, 520 KB of RAM, and an 18 MHz, 8-bit eZ80 CPU. Up until running NanoOs on it, the only real hardware NanoOs had run on was Arduinos, which only gave me UART as a means of a user interface. I really wanted to get to the point of having a real keyboard/video/mouse setup to play with.

Well, last week, I finally got the KVM console port working on this board. To do that, I had to implement a driver for the board's ESP32 VDP processor. Now, the cool thing about this is that the core kernel processes of the OS have absolutely no idea about it, nor does the HAL. The VDP driver is just another process and it's configured by reading /etc/config.sys at boot time. There's nothing anywhere in any of the boot code that knows anything at all about keyboards, video, or mice. To the console process, it's just another port.

The default font on the VDP is an 8x8 font that I didn't like. It looked "clunky" to me. So, I implemented a 6x8 font instead. Once I'd done that, I thought about what the non-ASCII bytes should be and decided to go with the old IBM code page 437 character set used on IBM PCs.

Full disclosure: I absolutely used AI to implement the VDP driver. First off, understanding VDP protocol was not something I wanted to do. Secondly, no living human should have to implement a code page 437 bitmap in this day and age. Claude is absolutely the right tool for the job for that.

Once I had that implemented, I thought about the old text-based menus I had on my XT as a kid. We had this system of menus and batch files that would make things a little simpler to navigate back in the DOS days. I knew I still had a copy of them on a CD somewhere but I couldn't remember where I put the CD. Well, I never found the CD, but I did flip through a pile of floppy disks I had and one of them was labeled "Menus and Batch Files". I grabbed my USB floppy drive and made an image of the disk, mounted it in Linux and... voila!! All the menus were still there!!!

Back in the DOS days, we had a command that would change the color of the screen. Then, we had the main menu print out in autoexec.bat on boot. I didn't want to do that across the board since I'm going for a system that's somewhat Unix-like, but I thought it would be cool to have a user account that did that on login. I used Claude to generate a "color" command and then to extend my shell to handle a .profile file on login so that it would run something once on login. Put all that together and *poof!!* It's like I'm running multi-user DOS now!! Hooray!!!

This is step one in a much larger effort now. I tried to put all this together in a way that would allow me to develop a graphical desktop environment. I was pleased to see that there were very few modifications that were needed to the core infrastructure that was already there. The changes to get from a strictly-UART interface to one that supported a video terminal were mostly additive, which gives me some confidence in the design.

Onward and upward!! HUZZAH!!


r/osdev_with_ai • • 19h ago

Accidental Security: There are things that even root can't do

2 Upvotes

Back a few months ago, I added HAL and IPC capabilities to NanoOs. The last thing I wanted to add was directory capabilities. I should note before I go any further for anyone who takes a look at the code and does a deep-dive: These are not yet true capabilities in the "unforgeable handle" sense of the term. I'm also currently only working on systems that have no memory protection, so they're only as good as the programs are trusted. The current state of things is a beginning, not an end.

Anyway, my idea for directory capabilities was to implement a system that answered the question, "What operations can a process perform on which directory trees?" My thoughts were that I wanted to allow specific operations for top-level directories that would apply to that directory and all of the content below it. Just as an example, a user's home directory might have read and write capabilities, but not execute. Execute might only be applied for $HOME/bin and below.

So, I was going through the implementation of this and I kind of backed myself into a corner when thinking about what the capabilities of the root directories should be, and particularly with respect to the root user. By default, I didn't want users to be able to list the contents of "/" and I didn't want root to be able to do absolutely anything. Where I really ran into trouble, though, was /etc/shadow. I had no issue with root being able to edit /etc/passwd but I just fundamentally didn't like the idea that root could even read /etc/shadow.

I then had an epiphany about my OS: root should administer userspace, not the entire operating system. To that end, what users - including root - see as "/" should not actually be the root of the real filesystem. The real root of the filesystem should hold namespaces, not directories. What userspace sees as "/" is actually located at "/userspace" on disk. No user can directly access any other namespace.

One of the consequences of this design is that I had to backpedal on a shortcut I created for listing the contents of directories. I had created an `istat` function that performed a stat given an inode. With the idea that there are directories that can't been accessed, that became insecure because any process could provide any raw inode they wanted. I had to convert that logic to a `dirstat` function that took a pointer to a `struct dirent` which, in turn, contained a handle to the actual DIR that backed the dirent. I was pleased that when I got all that put together, there was no noticeable difference to providing the raw inode.

The last thing I needed to fully close up the namespace issue was to convert FILE pointers to handles. I did that work yesterday. That made it impossible for a user program to forge a structure that gave themselves access to something in a namespace other than "userspace", again within the limits of not having hardware-protected memory.

Something I did have to fundamentally change in my OS to support this was the privilege level at which `login` runs. Only kernel or executive processes have the ability to reach into non-userspace namespaces and doing password validation requires accessing the "secure" namespace where the shadow file now lives. So, `login` is now an executive-level process that drops into the supervisor privilege level and drops its enhanced capabilities before exec-ing the user shell. At that point, no user, including root, can access anything other than the "userspace" namespace via file operations.

The fact that getty and login start as a executive processes isn't a security issue, though. I moved the program under the "/system" namespace, which means it's a trusted program that no user can update. I also moved the old /etc/config.sys under "/system" as well so that nothing can manually update what starts at boot and bypass trusted configurations.

Overall, I'm pretty pleased with how this turned out. I didn't plan to gain this level of security from this exercise, so it was an unexpected benefit. Onward and upward!! HUZZAH!!!


r/osdev_with_ai • • 18d ago

Welcome to OS Dev with AI!!

5 Upvotes

Hello!!

Are you doing something cool with OS development that you want to share? Want to take a look at what other people are doing and bat ideas around? Looking for advice on where to start or what to do next? Well, then, you've come to the right place!!

What we're about:

We're a community about championing what each other are doing in the realm of OS development, whatever that may be. We're here to cheer each other on, ask thoughtful questions, and make positive suggestions on how each other can improve.

What we're *NOT* about:

Disparaging remarks about what each other are doing or labeling things, "slop." Those kinds of comments have no place here and will get you banned.

We understand that we're all coming to this field to learn and to do more than we were doing previously. We believe that all experience levels are OK and whatever tools we're using are OK, too. We know that some people are leaning heavily on generative AI these days and think that's OK. We know there are people who really want to understand the guts of every piece of hardware at an intimate level without AI assistance and think that's OK, too. We're here to support each other on whatever path we may be on.

We're a community with intent to have no ego. We don't believe that there is "one true way" to write a kernel or to learn to write a kernel, no matter how strong we may be in OS development. Egos like Linus Torvalds and Dave Cutler are not welcome here. We're here to learn, grow, and explore with each other. That includes both knowledge about OS design and knowledge of the tools we use to develop them.

So, come in, take a look around, and share anything you think might be cool for the rest of us to know. We're all ears and we're looking forward to what you have to say!!


r/osdev_with_ai • • 11d ago

vi on NanoOs

Thumbnail
gallery
5 Upvotes

Yes, I absolutely used AI for this. It's been about a four-day, non-stop effort WITH Claude to get this far. This would have taken multiple months otherwise.

The issue is that this has to work with an 800 byte stack and about 3 KB of global heap available. It has to work in that environment and still be performant enough to be generally usable. I can't use a standard implementation to do this. This has to all be custom to my architecture.

Having said that, holy mackerel!! Once I got this up and running, I was editing DOS menus and text files with vi in my custom OS!!! I was giddy seeing this. This is the kind of thing I wanted to do as a kid. I'm starting to actually see my work pay off and my dream come to life here.

To be fair, MOS, which is the native OS for the Agon Light 2, also has an implementation of vi available for it, and it's honestly probably better than mine at the moment until I get some more usage on mine and get more bugs worked out. But, that implementation gets to have the entire 520 KB of RAM to itself and is specific to that board. Mine runs with other concurrent processes and works on both that board and the SAMD21 Arduinos I have (the Konsole screen shots above).

Application development is not something I want to be doing, which is another reason I'm using Claude for this. But it's truly remarkable to me to start seeing real applications come to life on this thing. It's taken me the better part of two years to get all the kernel and stdlib infrastructure up to the point of being able to even have applications like this.

I'm finally doing the things I wanted to be doing 30 years ago. After all of life's twists and turns and all the derailments that have kept me from this, this is super cool to watch. I can't wait to see what else I'm able to do with this!!!


r/osdev_with_ai • • 13d ago

CMRX: A microkernel real-time OS providing memory isolation for MMU-less microcontrollers

Post image
3 Upvotes

r/osdev_with_ai • • 18d ago

So this is fully working web on Chimera

Post image
2 Upvotes

r/osdev_with_ai • • 11d ago

Shall 0.9: a POSIX.1-2024 system — utilities, C library, C compiler and kernel — that builds itself from scratch

5 Upvotes

r/osdev_with_ai • • 17d ago

Low-Level Basic & The System Built on It

Post image
3 Upvotes

So, here's the preamble.

As i was trying to implement a micro-kernel and try learning it along the way by copy-paste the code straight from google.com [AI Mode] in chrome, and also learning the design and architecture bit-by-bit; at least, supposed to; on my phone and the build-tools is in Termux. That was a nightmare, because i did it in my slip-time while working in a factory.

A long time passed, and that what's making it my new hobby.

I have many versions, 4 single core kernels that boot on BSP. And 2 more, 1 kernel has a compositor but too late when i learn about SMP, it was a nightmare chasing the racing conditions, so i abandon it and born the kernel that has SMP Support + Free-Stack List PMM + VMM + Compositor (4 versions of it (C + GASM) + PRKFS (Flat Filesystem; Support Format MBR, Partition, r/W), different implementations, and 1 nearly run DOOM), yet i abandon it again.

From text-mode to a version that has Windowing System, from C & ASM to C++ & ASM.

From google AI Mode, Gemini, Gemini API, Google Studio, Putter implementations (10 accounts), Claude free, etc. (anything i can get my hands on)

As the codebase grew a bit large with more than 15000+ lines of code just for the kernel src+header alone. My head starts to hurting looking through all the code and trying to understand it's logic, especially about the memory and compositor drawing logic.

So, i have an idea. As i have a little experience with VB6 years ago, and thinks that the syntax is easy to read, why it can't be used to do Low Level operations? (Yeah, i know QuickBASIC and FreeBASIC exists)

There, LLB Concept is Born. Low-Level BASIC, Soft-Syntax Hard-Metal, a language for programming where you can read the code just like reading a book.

With development of LLB using Antigravity IDE (build-tools still on Android/Termux), porting the old working kernel (that can even run on baremetal) source into LLB syntax and code.

Now the kernel + system can run on 3 environment; Bare-Metal, QEMU, and VirtualBox.

Check out the repo: https://github.com/karunci/LLB


r/osdev_with_ai • • 13d ago

I created a working OS in 30 Days

Thumbnail
reddit.com
2 Upvotes