top | item 21967668

Hobby x86 kernel written with Zig

355 points| netgusto | 6 years ago |github.com | reply

223 comments

order
[+] jackhalford|6 years ago|reply
Hi, author here! I've just finished writing the pre-emptive multitasking [0](only round robbin though, nothing fancy).

I'm currently writing an ATA driver [1], the idea is to implement ext2.

I used to do this in Rust but I switched to zig for maintainability and readability over Rust. It seems that with `comptime` I'm able to make a lot of things optimal.

Overall I have to say kernel programming is _hard_ but very rewarding when it finally works, it's really demystifying computers for me!

[0] https://wiki.osdev.org/Brendan%27s_Multi-tasking_Tutorial

[1] https://wiki.osdev.org/IDE

[+] guggle|6 years ago|reply
> I used to do this in Rust but I switched to zig for maintainability and readability over Rust.

Can you expand on this ? I'm asking out of curiosity because I want to learn a "system" programming language (for whatever definition there is to this term). So far I briefly tried Rust and Nim and found the former more difficult to read. I know nothing about Zig, how would you place it between these two ?

[+] joshbaptiste|6 years ago|reply
Author, if you decide to build more of this kernel any thoughts on providing live screencasts of the implementation like Andrew Kelly (Zig) and Andreas Kling (SerenityOS) on Youtube and/or Twitch. I never realized how effective it is for me to watch others go through the mental process of coding/debugging.
[+] ajxs|6 years ago|reply
Great work! I'm just behind you working on my own alternate language x86 kernel in Ada: https://github.com/ajxs/cxos

Admittedly I don't know much about Zig, but it's good to see people investigating languages other than C. I'm still not convinced of Rust's merits in this area, we'll see how this develops with time.

[+] fortran77|6 years ago|reply
Zig is so much better than Rust for these sorts of tasks. Readable and maintainable. The Rust astroturf-brigade tries hard to make it fit any situation. I'm glad you have provided a substantial concrete counterexample.
[+] rehemiau|6 years ago|reply
Looks awesome! Planning to do a similar thing in Jai once it comes out
[+] bambataa|6 years ago|reply
This looks really cool, well done. Do you mind sharing the resources you’ve used so far? I see many, many tutorials on OSDev...
[+] vkaku|6 years ago|reply
I'd rather you expose a FUSE interface first than expose ext2.... Just a totally random suggestion.
[+] ffwff|6 years ago|reply
Love the fact that people are developing kernels in new languages!
[+] anon767|6 years ago|reply
Are you planning to write up a Tutorial about this?
[+] teleforce|6 years ago|reply
Hi Jack, just wondering why not use Dlang since it's more stable than Zig and you can use the subset of D as better C if you wish to stay simple?
[+] knebulae|6 years ago|reply
I tried to do this with Zig about 13 months ago. It was not where it needed to be at that time; the biggest impediments were its rudimentary handling of C pointers to one vs pointers to many (which has long since been fixed), and its meta programming issues (lack of a macro language or pre-processor) that made OS development tedious. I have not revisited it as much as I would have liked simply because I chose to step back a bit on implementation and focus on theory.

I'm pulling for Andrew. He busts his rear-end, livestreams, and is generally a good dude. Zig has a TON of potential.

[+] Bekwnn|6 years ago|reply
I've been waiting for something that looks like a firm step forward in the domain of games programming and has ideals which align with the domain. I'm extremely excited for zig and have been messing around with getting a smallish simulation running with SDL on Windows.

At work in C++ I've switched from working on fairly isolated types, where my changes had fast recompile times to lower level changes which cause a good chunk of the engine to recompile. 10 minute compile times, with a lot of tech trying to get that time down as much as possible, are a huge killer to productivity and I can feel myself getting much less done than I was before.

Zig tossed away a lot of the constructs that make C++ slower to compile. I haven't had a chance to see its timings on large projects, but stuff like Jai compiling 90k LoC full commercial game project live on a laptop in 1.4 seconds (which caused Jonathan Blow to say "what? That's weirdly slower than it should be...") gives me hope that Zig is similar.

[+] FpUser|6 years ago|reply
I really wish Zig picks up and goes mainstream. I also wish it gets a little (not too much) of higher level features. Something in line of simple OOP.

I would even start using it now for some smaller projects that are not vital but I was stalled on Zig not being able to compile some C (it claims to do that and it does but not in my cases). Sure I could do import but would rather prefer for Zig feature to work

[+] aganame|6 years ago|reply
Check out zig's "Safety" project https://github.com/ziglang/zig/projects/3#card-27896159 to get a view of what sort of safety is being planned.

I'd like to state that after significant time and effort with Rust, I also think it's too complex for what it's protecting us from. Zero-cost indeed does not refer to the cognitive price. It's better than C++ though, in every way except popularity.

[+] rumanator|6 years ago|reply
Very interesting. Keep up the good work!
[+] blackrock|6 years ago|reply
It would be nice if you put up a design document.

I'd rather read that first to get my bearings, as opposed to opening up a folder full of gibberish code.

Usually a well written design document explains the high level constructs of the project. Then some mid-level documents ties in the design document, with the implementation code.

This makes the project more intelligible, and allows for a layman to jump in, and follow along.

[+] kburman|6 years ago|reply
I'm also trying to do something very similar. I can use it as a reference. Thanks for sharing!
[+] archsurface|6 years ago|reply
The hello world examples for master and 0.5.0 seem quite different - any trouble keeping up with the changes?
[+] jackhalford|6 years ago|reply
migration from 0.4 to 0.5 was ok. AFAICT there the big change for 0.6 syntax wise is the drop or varargs in favour of tuples. I'll take some time to do the switch when 0.6 hits but I'm confident it won't take long because of how concise the language is.