23 ms·
Hobby x86 kernel written with Zig
- kburman 7y agoI'm also trying to do something very similar. I can use it as a reference. Thanks for sharing!
- rumanator 7y agoVery interesting. Keep up the good work!
- jackhalford 7y agoHi, 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 https://wiki.osdev.org/Brendan%27s_Multi-tasking_Tutorial [1] https://wiki.osdev.org/IDE https://wiki.osdev.org/IDE
- ajxs 7y agoGreat work! I'm just behind you working on my own alternate language x86 kernel in Ada: https://github.com/ajxs/cxos 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.
- rehemiau 7y agoLooks awesome! Planning to do a similar thing in Jai once it comes out
- jackhalford 7y agoI don't follow JAI but maybe Jonathan Blow should try zig, it's a great fit for game development and I remember him mentioning that he wants a language that is fun to write in.
- deleted 7y ago[deleted]
- hippyhippo 7y agozig is following pretty much different path from jai afaik. zig prefers everything explicit and is very verbose whereas jai has many implicit things and also has macros or something similar. Anyways, more will be seen when it is released.
- andi999 7y agoMaybe you can enlighten me, but from my view it seems the biggest difference is that zig exists and jai doesnt (yet?); at least for practical purposes.
- gameswithgo 7y agoBlow is pretty familiar with Zig, there has been some collaboration between the two creators.
- adamrezich 7y agoThere's still zero evidence that the compiler or language ever have been or ever will be called "Jai," aside from the fact that it is the tenuous file extension being used in development streams.
- rehemiau 7y agoIt's the best short name we can use right now so it's the one we should use IMO. If it gets a different name, we'll start calling it differently, I don't mind.
- guggle 7y ago> 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 ?
- simias 7y agoI'm curious too, I'm quite familiar with Rust and never written any Zig in my life so I went digging through the source and I find the syntax remarkably similar for the most part. The only thing that stood out is that apparently you can drop the braces for single-line `if` bodies like in C whereas Rust makes them always mandatory but I'm firmly on Rust's side on this one. The part where Rust can get really messy is when you involve generic programing and traits, especially when lifetimes are involved, but I couldn't find any obviously generic code in this codebase. EDIT: after digging a bit deeper into Zig it looks like it uses C++'s style duck typing for metaprograming instead of a trait-based approach like Rust? It definitely removes some overhead to writing generic code but I'm not sure about readability and maintainability... But I'm going to stop here because I'm about to go full fanboy for Rust.
- dnautics 7y agoIt uses "comptime" which, loosely, is a compile time version of the language. I would say it's a huge improvement over C in that quite frankly string interpolation for a preprocessor is terrible. I can't compare to rust since my brain can't parse rust syntax; too many bells and whistles.
- sobeston 7y agoTraits are a part of the stdlib (under std.meta) as opposed to the language. This is unlikely to change
- swiley 7y agoIf you want more syntax weirdness: tab characters are illegal.
- steeve 7y agoGreat work!
- anon767 7y agoAre you planning to write up a Tutorial about this?
- jackhalford 7y agoI'm more on the reading end of tutorials right now. If I come up with something original that doesn't have an osdev page I'll contribute to the wiki.
- joshbaptiste 7y agoAuthor, 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.
- jackhalford 7y agoHi, that's a great idea, it would be a good exercise for me especially. I always enjoy watching Andy's live zig coding on youtube.
- bambataa 7y agoThis looks really cool, well done. Do you mind sharing the resources you’ve used so far? I see many, many tutorials on OSDev...
- jackhalford 7y agoOSDev can be hit or miss. All of the bootstrapping was done following this [0] tutorial for Rust, which translates easily to zig. For the more advanced parts you can find usefull ones in [1] or use the OSDev search bar. For even more advanced topics though you'll find that there are no tutorial and only a few open source implementations to take inspiration from! ps: I've updated my readme with a few references [0] https://os.phil-opp.com/ https://os.phil-opp.com/ [1] https://wiki.osdev.org/Tutorials https://wiki.osdev.org/Tutorials
- fortran77 7y agoZig 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.
- vkaku 7y agoI'd rather you expose a FUSE interface first than expose ext2.... Just a totally random suggestion.
- teleforce 7y agoHi 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?
- ffwff 7y agoLove the fact that people are developing kernels in new languages!
- saluuu 7y agodda
- FpUser 7y agoI 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
- archsurface 7y agoThe hello world examples for master and 0.5.0 seem quite different - any trouble keeping up with the changes?
- jackhalford 7y agomigration 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.
- AndyKelley 7y ago0.6.0 is scheduled for April 13, 2020. Let's make sure your project builds successfully and correctly with master branch 1-3 weeks before that, and I'll prioritize any bugs before the release that affect you. (This goes for all zig community members with active projects)
- maruko 7y agoaaa
- vips7L 7y agoHere is a microkernel written in Zig: https://github.com/AndreaOrru/zen https://github.com/AndreaOrru/zen
- knebulae 7y agoI 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 7y agoI'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.
- blackrock 7y agoIt 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.
- aganame 7y agoCheck out zig's "Safety" project https://github.com/ziglang/zig/projects/3#card-27896159 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.