8 ms·
I wanted to understand what the bare minimum of an operating system looks like. So I built one in Zig, keeping the whole thing under 1000 lines of code. It ca
by botirk 1y ago
I wanted to understand what the bare minimum of an operating system looks like.
So I built one in Zig, keeping the whole thing under 1000 lines of code.
It can:
→ Boot from GRUB
→ Manage memory
→ Schedule simple tasks
→ Output text to VGA
The point was not to make it feature-rich, but to show how much is possible with just a few hundred lines if you strip everything down to the essentials.
- deleted 1y ago[deleted]
- noone_youknow 1y agoNice work! Looks like most of the basics are covered, and meanwhile in my current kernel the RISC-V entrypoint is >700 lines (of C) just to get to the arch-independent entrypoint! I was just looking around for your input/output code, I don’t know zig but I expected to find putChar in kernel.zig based on the import in common.zig, but I don’t see it, should I be looking somewhere else? I didn’t see any simple command line processing either as mentioned in the README? Mostly just looking around since your README mentioned VGA (and you seem to have a BIOS boot) which struck me as interesting on a RISC-V project, I was curious if you were actually using the SBI routines or had actually mapped in a VGA text mode buffer?
- WD-42 1y agoThere is a todo in the putchar stub. Looks like it’s not implemented yet. I have it implemented here in my own roughly 1k line zig kernel: https://github.com/Fingel/aeros-v/blob/ddc6842291e9cf4876729b73f8a7a5521a3234d9/src/common.zig#L9 https://github.com/Fingel/aeros-v/blob/ddc6842291e9cf4876729...
- noone_youknow 1y agoThanks! I see that you’re using the SBI routines, which is what I was expecting here but couldn’t find - the reference to “output text to VGA” in the post made me curious. I did see the putchar stub in the user.zig but, lacking understanding of zig, wasn’t sure how that could work given common.zig is looking for putChar in kernel.zig as far as I could tell. I just jumped through a couple of hoops to get zig 0.13 installed and see an error about “root struct of file ‘kernel’ had no member named ‘putchar’” so I guess maybe it’s not implemented here at all.
- WD-42 1y agoI don’t know what output to the VGA means from the OP. I suspect that entire project was vibe coded including the readme. It’s a common first step when writing an OS for x86 but for riscv you don’t use vga to get text output, you go through the UART. Are you saying you had trouble getting putchar working in my implementation? As far as I know common.console is fully implemented and working. Let me know if something is wrong.
- noone_youknow 1y agoSorry for the confusion, I was referring to the putchar not being implemented in OPs code, I got yours working right away (nice work btw). What you mention about VGA being common on x86 was what got me curious, since it’s not a thing on riscv. In my own OS project I’m using a framebuffer to show a graphical terminal on both x86 and riscv64 so I wondered if OP was doing similar or was really using SBI output.
- cyberclimb 1y agoHi botirk, really interesting project! If I build the project what is the output format and how could configure things to boot it? I know how to this with IMG and ISO files of course but not sure what to do with the build output if it's an executable? Also any insights into whether this would also boot on an ARM machine? Thanks!
- coffeeri 1y agoCheck the build.zig file. It defines the arguments for QEMU to run the OS. You should be able to run zig build run.
- hdjxjdjdkshsb 1y agoCurious: is it 1k lines of zig total with no libraries or 1k lines of zig with libraries?
- tjpnz 1y agoNice project! I'm more accustomed to building and running these using QEMU/VirtualBox (which I understand you can do with here). But what's going on when I build and execute it under the host OS? Is it also running in userspace?
- mmaunder 1y ago“Interact with the command-line interface to execute commands and view output” A command line interface has not been implemented. It just prints a bootup message. “Some basic examples of usage include: Running a simple "Hello World" program Viewing system information such as memory usage and process list” None of this has been implemented. Was this vibe coded? Asking because the README disconnect with the code is weird. Seems to be written in Zig 0.13. That’s about a year old. 0.15 has breaking changes so it’ll need to be ported if you’re going to do anything with this.
- reactordev 1y agoBingo, I was about to post the same but you hit all the things I was going to say. This is completely fake and only prints stuff out like it works.
- ko_pivot 1y ago> The project includes automated tests and validation scripts to ensure its correctness and stability LLMs love writing this type of stuff.
- never_inline 1y agoBtw, the unicode arrows in Gp comment are dead giveaway of LLM use.
- freetonik 1y agoGod damn it, I love using these arrows and have a special keyboard layout that allows me to quickly add them, and now I will subconsciously hesitate.
- nvlled 1y agoI die inside whenever I see something like this. Not even a word that this is a reference to the "Operating System in 1,000 Lines" which someone else linked in this thread. The worst part is that OP probably learned nothing about operating systems from this project.
- botirk 1y ago