
Rustboot: a 32 bit kernel written in Rust - steveklabnik
https://github.com/charliesome/rustboot
======
jmgrosen
I saw zero.rs and said, "Hey, I know! I'm going to make a kernel!" Then after
showering... came back and saw this.

Well, in any case, great work! (Perhaps I'll use yours as a starting point.)

EDIT: One question. When I try to compile it, rustc gives me these errors:

    
    
        error: no item found for `modulo`
        error: no item found for `durable`
        error: aborting due to 2 previous errors
    

If I had to guess, it would be due to the fact that I'm trying to compile it
on OS X but have i386-intel-linux set as the target, but your screenshot shows
(at least it being emulated) on OS X. Did you have to build a special cross
compiler version of rustc?

~~~
charliesome
I use ELF as the object file format, but all the development was done on OS X.

Maybe try updating your version of Rust. I had trouble using zero.rs on 0.6,
but the latest from Git works well.

~~~
jmgrosen
Ah, that would explain it -- I'm trying it with 0.6. Building master now, have
a feeling that it'll be a while though.

~~~
steveklabnik
Beware, "the latest" usually means incoming, not master. That said, I'm not
sure which is actually meant above.

------
tmzt
If anybody is looking for something to do with this, consider writing a KVM-
like virtual machine host which is barebones enough to boot from coreboot.

I've dreamed of a checkpointed VM which could be used to press a key and fork
the running system, or instantly reboot to a usable state when a fault
occured, but was small enough to fit in a flash ROM and boot in milliseconds.

The last attempt was linux+QEMU and was to large for most boards supported by
coreboot.

~~~
steveklabnik
Yup, this kind of thing is one of the reasons I like exokernels so much.

------
andrewflnr
This is great, but I'm confused. Not that long ago, I remember reading that it
was explicitly not a goal of Rust to be able to write an OS kernel in it. Is
this done in spite of Rust not being designed/suited for it?

~~~
steveklabnik
I'm not sure that I've ever heard that as an implicit goal, but a 'runtime-
less Rust' hasn't existed yet. Now, you can't access arbitrary memory without
an unsafe block, that may be what you're thinking of.

Recently, zero.rs was released, which allows you to write some Rust programs
without the runtime. This is because Rust basically expects certain functions
to exist, so they have to be defined somewhere. That said, things like 'a GC'
aren't implementd, they just throw an error. Please see:
<https://news.ycombinator.com/item?id=5771173>

This is just one step further in demonstrating that these things work.

~~~
usea
A link to the HN thread on zero.rs

<https://news.ycombinator.com/item?id=5770212>

------
dysoco
Great to see new Rust news every day.

At first I was most interested in Go: But now it seems that Rust is much more
close to the metal than Go is, which I find more interesting.

------
shardling
>It paints the screen bright red and then hangs.

Well, it's a start, I guess. :) (The project is literally only half an hour
old.)

~~~
dysoco
Sounds better than Vista!

~~~
dysoco
Obviously didn't get the joke: <http://xkcd.com/528/>

~~~
qu4z-2
Or didn't consider the joke appropriate for Hacker News, I guess.

------
wfunction
Wow, if people like this, then maybe I should post my tiny 32-bit kernel in
C++ somewhere. It has a physical, virtual, and kernel memory manager and
support for text-mode I/O. And you can use pretty much anything C++ (even
Boost) that doesn't rely on exception handling...

~~~
trentmb
I'd like to see it if you don't mind.

~~~
wfunction
Hmm... since I'm not sure I want to share the code yet, here's a class diagram
instead that should still give you an idea what state it's currently in:

[http://picpaste.com/pics/21616b59902f2992e1e488af35acba20.13...](http://picpaste.com/pics/21616b59902f2992e1e488af35acba20.1369637934.png)

The Process class is just a dummy at the moment, it doesn't do anything.

------
nathell
Something similar I did with Clojure:

<https://news.ycombinator.com/item?id=5772632>

------
jamesaguilar
It's really impressive what people have done with rust. I don't know how they
do it because when I write short rust programs I get internal compiler errors.

~~~
steveklabnik
You should open up issues for those: <https://github.com/mozilla/rust/issues>

There's no reason for an internal compiler error, especially in a language
with safety as its focus.

~~~
jamesaguilar
Have done. Here are the ones I found in 300 loc.

<https://github.com/mozilla/rust/issues/6699>
<https://github.com/mozilla/rust/issues/6698>

Don't get me wrong. I'm super excited to learn rust once it stabilizes. But
right now I don't spend enough time on fun programming to deal with a language
that has this many errors.

~~~
steveklabnik
Great! Thank you. I've been mostly sticking to documentation myself, but you
can't fix what you don't know...

------
fmstephe
I find this a very exciting project. Rust is always in my peripheral vision.
To see a language operating at such a high level able to get down so low is
very compelling.

------
S4M
I am confused: if it's a kernel, why do we have the mac user interface? Is
this the screenshot from a VM or am I missing something else?

~~~
DanWaterworth
Yes, it's a VM. Note the title, "QEMU".

------
ginko
I guess this is kind of a factious question to ask, but why 32 bit and not 64
bit?

Are there any technical reasons for this?

~~~
steveklabnik
32 bit is waaaaaaay easier to write.

------
phoenix24
This is cool!

One request, Can you detail out the steps, for noobies to be able to re-
produce this effort? Thanks!

~~~
steveklabnik
Reproduce as in 'build a tiny kernel in something' or reproduce as in 'build
and run this example?'

If it's the first, OSDev has a great community, and some decent tutorials:
<http://wiki.osdev.org/Bare_Bones>

If it's the second, the answer is 'have edge Rust installed, have qemu
installed, then run `make`.'

------
pvnick
Wow, cool! Great job :)

------
topbanana
That isn't a kernel

~~~
brokenparser
Don´t know why this was downvoted, you hit the nail on its head. The fact that
it runs directly on hardware doesn't make it a kernel, it doesn't provide any
abstractions for applications to run unmodified without specific hardware
provisions.

~~~
steveklabnik
Exokernels provide no abstractions, just a few safety guarantees. So you could
argue that this is just an unsafe exokernel. ;)

That said, "is it really a kernel as per Wikipedia" is not particularly
interesting. It's a damn cool hack that could be the starting point for
something interesting and useful, that's all I care about.

~~~
topbanana
I was just a little disappointed Steve. Interesting post for sure. Would be
interested in seeing part 2 ;)

~~~
steveklabnik
My friends have been working on an exokernel in D for years, so that's been
our go-to for this kind of thing. It's only like 10 kloc, maybe we should port
it for fun...

