| ▲ | Minimal x86 Kernel Zig(github.com) |
| 103 points by lopespm 10 hours ago | 35 comments |
| |
|
| ▲ | WD-42 4 hours ago | parent | next [-] |
| Here's one for Risc-V that's a little more fleshed out, also in Zig: https://github.com/Fingel/aeros-v/blob/main/src/kernel.zig |
|
| ▲ | 6r17 5 hours ago | parent | prev | next [-] |
| I'm very surprised it's *that* short - handling one in rust i'm surprised by the very low amount of code to get that up. Thanks or sharing that was a first time reading some Zig for me ! |
| |
| ▲ | pmarreck 4 hours ago | parent [-] | | what you’re experiencing is more or less why I am building some stuff in Zig instead of Rust | | |
| ▲ | simonask 14 minutes ago | parent [-] | | Looking at the code, I'm not really sure what part of this would be more verbose in Rust. This kernel does close to nothing, not even page table setup. Granted, the code writing to the VGA buffer will need to be in `unsafe` blocks, but yeah. |
|
|
|
| ▲ | boricj an hour ago | parent | prev | next [-] |
| I wrote something similar a while ago: https://github.com/boricj/hang-os It handles interrupts/traps and targets the aarch64 QEMU virt platform. It also features a HAL. |
|
| ▲ | csense 7 hours ago | parent | prev | next [-] |
| Very neat. To clarify, Qemu can boot it, but I'm pretty sure you need some bootloader (e.g. Grub) to boot it on a physical system. |
| |
| ▲ | toast0 6 hours ago | parent | next [-] | | Looks like it's multiboot compliant, so you can pick your favorite multiboot loader. ipxe, grub, pretty sure there's some other ones out there. As it's multiboot, it should likely run on v86 too. It's always fun to have an in browser demo of a little OS like this. | |
| ▲ | anta40 6 hours ago | parent | prev | next [-] | | If you want to use Grub, this tutorial works (see "Booting the kernel"): https://wiki.osdev.org/Zig_Bare_Bones Yes, just tried it. | |
| ▲ | flopsamjetsam 6 hours ago | parent | prev [-] | | From the GitHub page: > It boots on an x86 (i386) machine via the Multiboot 1 protocol Yes, it does need a compliant bootloader on virtual or physical hardware. |
|
|
| ▲ | kunley 2 hours ago | parent | prev | next [-] |
| Why to spread confusion and call it bare metal when it's run under QEMU? Then it's not bare metal at all. In order to be run on bare metal it's needing another bootloader which the documentation only barely mentions. More on the naming: why to call it kernel? |
| |
| ▲ | cies an hour ago | parent [-] | | I agree, I'd not call this a kernel. It does not allow any software to be run on top of it. It just prints text to screen and halts. Even saying it "runs" on QEMU is a far stretch: it "halts", that's all it does. :) (it does run on hardware as per other commenters in this HN convo) | | |
| ▲ | kunley 32 minutes ago | parent [-] | | Ok, I am not saying it doesn't run on hardware, but the primary example runs (for the somehow stretched definition of "run", as you say) on QEMU but displays a message that it's bare metal. Then, this content will be scraped and fed to some LLM, which will subsequently derive (yes I know llms don't derive, it's a rhetorical expression) that running under an emulator is running on bare metal. Confusion for the masses!
(Not to mention confusion for a reader already now) | | |
|
|
|
| ▲ | drnick1 5 hours ago | parent | prev | next [-] |
| What's the point of doing this in "Zig" instead of C, the traditional choice for this kind of thing? |
| |
| ▲ | toast0 5 hours ago | parent | next [-] | | Because you can is a pretty traditional reason. Zig is supposed to be an improvement upon C, so doing C things with it seems reasonable. Kind of neat that there's no need for a separate assembly file although there is inline assembly. Might get better (or worse) syntax support for separate assembly files? But it doesn't make a big difference until there's more features that need it (interrupts, threads/processes and maintaining their stacks, syscalls, starting other processors, etc) | |
| ▲ | kunley 2 hours ago | parent | prev | next [-] | | I guess one of good reasons is easy cross-compilation. But also, I can see some amount of weird hooray optimism in this project, like: totally confusing claim that the thing is bare metal when it's still being run under an emulator; also, calling it a kernel is a huge overstatement | |
| ▲ | flohofwoe 2 hours ago | parent | prev | next [-] | | In this case, better tooling and consistency. E.g. the small block of inline assembly would already be trouble for some C compilers. | |
| ▲ | jandrewrogers 3 hours ago | parent | prev | next [-] | | Zig is essentially a substantially improved and enhanced C, both in character and intent. There is a lot to recommend it for applications where you might otherwise use C. | |
| ▲ | mitchellh 5 hours ago | parent | prev | next [-] | | Fun? | |
| ▲ | pmarreck 4 hours ago | parent | prev | next [-] | | because Zig is simply a better C, often faster (normally at least as fast), but with way more safety guarantees or at least things preventing the vast majority of traditional C footguns from happening | | | |
| ▲ | 6r17 5 hours ago | parent | prev | next [-] | | What's the point writing another kernel in C ??? | |
| ▲ | moonlion_eth 3 hours ago | parent | prev [-] | | because zig is lower level than c |
|
|
| ▲ | ajxs 8 hours ago | parent | prev | next [-] |
| See also: https://wiki.osdev.org/Zig_Bare_Bones |
| |
|
| ▲ | aryalaadi 4 hours ago | parent | prev | next [-] |
| thats not a kernel |
| |
|
| ▲ | throwaway27448 6 hours ago | parent | prev | next [-] |
| Why choose intel? Let's build bootable software in 2026 |
| |
| ▲ | xx__yy 6 hours ago | parent [-] | | I'm not that cluey, but from the README it sounds like it can be compiled for a bunch of arches | | |
| ▲ | asQuirreL an hour ago | parent [-] | | It can be (cross-)compiled on whatever architectures the Zig compiler is available for, but the source contains inline x86 assembly, so you're not going to be able to build this for ARM or RISC-V. |
|
|
|
| ▲ | messe 4 hours ago | parent | prev | next [-] |
| Minimal slop. |
|
| ▲ | gethly 2 hours ago | parent | prev | next [-] |
| wtf? 10 lines of hello world code is not a kernel. |
|
| ▲ | xx__yy 6 hours ago | parent | prev [-] |
| Gold! I see Zig, I upvote! |