Show HN: I wrote an OS in 1000 lines of Zig
github.comSo 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.
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?
I have it implemented here in my own roughly 1k line zig kernel: https://github.com/Fingel/aeros-v/blob/ddc6842291e9cf4876729...
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.
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.
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.
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!
You should be able to run zig build run.
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.
This is completely fake and only prints stuff out like it works.
LLMs love writing this type of stuff.
A few suggestions:
- You're committing .zig-cache to git, but that's build output, so it shouldn't be under version control. You should add it to .gitignore (you already have zig-cache without leading dot).
- Your README.md refers to a CONTRIBUTING.md that doesn't exist
- It's helpful to say exactly which Zig compiler you need. It currently says "0.10.0 or later" but 0.10.0 is almost three years old now.[0] Most 0.10.0 code does not compile in 0.15.1.
Folks interested in this may also like "Operating System in 1,000 Lines" https://operating-system-in-1000-lines.vercel.app/en/
and the implementation in C https://github.com/nuta/operating-system-in-1000-lines
`zig build` gave me this:
/Users/anta40/Lab/OSDev/OS-1000-lines-zig/build.zig.zon:9:13: error: expected enum literal .name = "zoros",
I also went to look to see where "console output" was implemented, and ... it looks like it's just not? ConsoleWriter.write() calls kernel.putChar, which does not exist...