Minimal x86 Kernel Zig(github.com) |
Minimal x86 Kernel Zig(github.com) |
Granted, the code writing to the VGA buffer will need to be in `unsafe` blocks, but yeah.
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?
The booloader and the kernel are separate stages; they're both interesting, but pick the part that interests you and work on that. With the multiboot standard and existing loaders like ipxe and grub, if you want to write a kernel, there's no need to write your own bootloader.
Otoh, if you want to write your own bootloader, you can do that too, there's plenty of existing kernels to boot.
And yeah, this kernel does nothing. But it would be a reasonable start to a kernel that does things, although you would need to write all the things.
Bare metal in qemu is a little fishy, but it's easier to take a screenshot of qemu than to take a screenshot of a full computer. I would expect this to run on a full computer as long as it supports BIOS booting, and then it would be a bare metal boot and halt kernel.
Maybe it's an in-group vs out-group thing: those in the group (i.e. have attempted this in the past) don't care about what the first stage bootloader is; you'll just use some existing bootloader (I used grub).
If you're in the out-group, you feel cheated that you still need a bootloader.
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)
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)
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.
https://wiki.osdev.org/Zig_Bare_Bones
Yes, just tried it.
> It boots on an x86 (i386) machine via the Multiboot 1 protocol
Yes, it does need a compliant bootloader on virtual or physical hardware.
It handles interrupts/traps and targets the aarch64 QEMU virt platform. It also features a HAL.
Also baremetal where the metal is virtual. LLVM uses this term for when an OS isn't available https://github.com/llvm/llvm-project/tree/main/libc/src/stdl...
Maybe in your real-world ;)
Building your game code around classes with virtual methods has been a bad idea since at least the early 2000s (but both static and dynamic polymorphism is something that Zig can do just fine when needed), and the only important use case for operator overloading in game-dev is vector/matrix math, where Zig is going down a different road (using builting vector types, which maybe one day will be extended with a builtin matrix type - there is some interest in using Zig for GPU code, and at least this use cases will require proper vector/matrix primitives - but not operator overloading).
Gee, this new C language and UNIX operating system sure seem cool but someone ought to tell those poor people at bell labs that they'll never catch on without them
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)
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
.
drnick1 says why "Zig" not C? [I took the quotation marks as dismissive of Zig, but I could be misreading that]
6r17 says why do it in C?
lelanthran says the language is mostly irrelevant, it's a fun experiment.
6r17 blows off the handle and starts calling people toxic and being really unpleasant.
Nothing in this comment chain seems to justify even 1/10th of the vitriol espoused.
(disclaimer: not sure if that's actually still the case, last I checked in detail was probably 2 years ago).
Also Zig always builds the entire project as a single compilation unit, which allows more optimization options because the compiler sees all function bodies. The closest equivalent in the C world is LTO, but this is usually also not enabled by default.
The same should be true for any compiled language sitting on top of LLVM btw, not just C vs Zig.
The rest, you can google yourself, but in short, sorry to tell you that it is sometimes faster. Often, sometimes, some portion of the time.