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.
“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.
I 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.
Nice 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?
Thanks! 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.
I 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.
Sorry 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.
Nice 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?
Bizarre that the README.md does not specify that this is for RISC-V.
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...
I also tried to find what this is supposed to run on. Some of it looks like intel crap and most looks like it's just an application. Looking at the comments, this seems to be AI slop that doesn't actually run on anything or do anything.
- 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.
The project was made with an older version of Zig, which used strings as keys in zig.build.zon before but then it was changed to use enum literals in 0.14.0 IIRC.
I was hoping to get some commentary about the project and what lessons you learned from it. You wrote an OS in 1000 lines of Zig, but... So what? What should I take away from this? Are you posting this to encourage people to use the OS, or learn from the project? How was Zig helpful or a hindrance for this? Why limit to 1000 lines? Why did you post this?
You might want to look at the author's comment here (https://news.ycombinator.com/item?id=45290591) posted at about the same time as the link itself, which largely answers these questions.
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.
“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.
Bingo, 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.
> The project includes automated tests and validation scripts to ensure its correctness and stability
LLMs love writing this type of stuff.
Btw, the unicode arrows in Gp comment are dead giveaway of LLM use.
God 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.
I 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.
Nice 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?
There 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/ddc6842291e9cf4876729...
Thanks! 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.
I 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.
Sorry 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.
Hi 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!
Check the build.zig file. It defines the arguments for QEMU to run the OS.
You should be able to run zig build run.
Nice 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?
Curious: is it 1k lines of zig total with no libraries or 1k lines of zig with libraries?
I don't know zig but the only import I see here is std so my guess is there are no libraries here?
Bizarre that the README.md does not specify that this is for RISC-V.
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...
I also tried to find what this is supposed to run on. Some of it looks like intel crap and most looks like it's just an application. Looking at the comments, this seems to be AI slop that doesn't actually run on anything or do anything.
Sweet!
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
Cool projects!
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.
[0] https://ziglang.org/download/#release-0.10.0
How to build the OS? I'm on macOS with zig 0.15.1 installed.
`zig build` gave me this:
/Users/anta40/Lab/OSDev/OS-1000-lines-zig/build.zig.zon:9:13: error: expected enum literal .name = "zoros",
The project was made with an older version of Zig, which used strings as keys in zig.build.zon before but then it was changed to use enum literals in 0.14.0 IIRC.
I was hoping to get some commentary about the project and what lessons you learned from it. You wrote an OS in 1000 lines of Zig, but... So what? What should I take away from this? Are you posting this to encourage people to use the OS, or learn from the project? How was Zig helpful or a hindrance for this? Why limit to 1000 lines? Why did you post this?
You might want to look at the author's comment here (https://news.ycombinator.com/item?id=45290591) posted at about the same time as the link itself, which largely answers these questions.
Very cool! Mad props friend