7 ms·
Writing an OS in Rust: Remap the Kernel
- phil-opp 11y agoMaybe it's a good time to say a little bit about this project. I started it because I was unhappy with the existing documentation. Most resources were mainly for 32-bit and there was hardly any documentation about Rust OS development. One day I decided to do a clean rewrite of my experimental rust kernel and had to look up all the required information again (since I had forgotten the details). So I decided to create the missing documentation myself and write some tutorials about booting a Rust kernel. I wrote the first posts over the summer and it was kind of fun. I never wrote a blog post before and English is not my native language, so it was pretty challenging. I spent a lot of time rewriting and improving them until I was more or less satisfied. Eventually I had the guts to post it in the rust subreddit. I never expected that it would be useful for many people (who would want to write an OS in Rust?), but it totally took off. Someone posted it on hacker news and it even was the top post for a short time. I was completely stunned :D. I really love writing these posts. It takes much time but it's a great way to really understand the code since you need to explain every detail. It also helps to make the code as simple and straightforward as possible. I still don't know where this will lead. But I will keep on writing as long as people want to read it :). For the short term the plan is to explore interrupts and to add keyboard support. After that, I'm open to new ideas :).
- deleted 11y ago[deleted]
- abrodersen 11y agoThank you for doing this! I find this kind of stuff very entertaining. I also hope to try writing my own kernel some day, and this blog series will be a huge help when doing so !
- phil-opp 11y agoThanks! Glad you enjoyed it :)
- l00mer 11y agoThank you for writing this series. I love learning the high-level OS concepts alongside real, working code. It's like proof that what you're talking about actually works! Doing it in a fresh, up-and-coming language like Rust is icing on the cake. Keep it up!
- phil-opp 11y agoI will! Thanks for the kind words :)
- lachgr 11y agoSeeing this for the first time today and it looks great! You explain things in depth and also focus on the tools that make it work (not only the pure Rust code). Keep it up, learning Rust is on my todo list and this seems a great project to use it.
- phil-opp 11y agoThanks :) Yes, Rust is a great language for kernel development. I can really recommend learning it this way (I've done the same).
- mitchtbaum 11y ago> who would want to write an OS in Rust? It looks like there are a lot of fast moving projects on this now[0], namely Redox[1], and a lot of research and study demo codes. Looking forward to seeing how these efforts come together. 0: http://wiki.osdev.org/Rust http://wiki.osdev.org/Rust 1: https://github.com/redox-os/redox https://github.com/redox-os/redox
- nanoojaboo 11y agohow would you compare this to Steve Klabnik's project intermezzOS
- steveklabnik 11y agoI discuss it in the preface http://intermezzos.github.io/book/ http://intermezzos.github.io/book/
- phil-opp 11y agoI think Steve's goal is it to make OS development more accessible to newcomers. Even people from dynamic languages who never heard of stack/heap should be able to follow it. It's a really great project that dispels the myth that OS development is too hard for the average programmer. AFAIK it will roughly follow the first posts of Writing an OS in Rust, but at a much slower pace and with more extensive explanations. After the Set Up Rust post, it will diverge from the series and explore keyboard input instead of memory management. Steve is a dang awesome writer (he wrote most of the Rust book) and intermezzOS looks pretty great already. I think it will bring new people with new ideas into OSdev and thus I'm really excited about it.
- vans 11y agoThat's the kind of rust article i needed, thanks man :)
- phil-opp 11y agoGlad you like it :)
- arthurcolle 11y agoWhat exactly makes Rust attractive for low level stuff like this? Just wondering why Rust/D get lumped into OS and low level development in general when it seems more syntactic than anything else. Do you have to manually manage memory in Rust?
- xenadu02 11y agoBecause the Rust type system is memory-safe by default. It aims to have similar performance characteristics as C, but support higher level abstractions without compromising safety. If you don't understand why that is critically needed, I'd like to introduce you to /almost every RCE, buffer overflow, and stack smashing bug/ that has plagued us for the past 20 years.
- DonaldFisk 11y agoThese are problems limited to C, C++, and assembly language. Even C programs can be kept reasonably secure by following the MISRA-C standard. Very secure and reliable operating systems have been written in existing languages such as ESPOL (MCP) and PL1 (MULTICS). There's also Zetalisp (Genera) and Oberon (Oberon), though they might not appeal if you dislike garbage collection. You might also consider Ada, designed with type and memory safety in mind and used in defence and avionics.
- pcwalton 11y ago> Even C programs can be kept reasonably secure by following the MISRA-C standard. You might also consider Ada, designed with type and memory safety in mind and used in defence and avionics. The problem with these older systems is that they don't support heap allocation while remaining memory-safe. (A quick Google search seems to confirm that MISRA-C is in this category.) Or, if they do support heap allocation, they use a GC to manage it. Both of these restrictions are often considered undesirable for a kernel, except in specific embedded situations in which you can get away with statically allocating all your variables. Rust's lifetime system can ensure that you use malloc/free correctly, so it doesn't have to wall dynamic memory allocation off into unsafe code.
- TerryADavis 11y agoIntel is my bitch. They are going to make a highly optimized long mode with no paging.