

I now have Rust code for executing executables - jvns
http://jvns.ca/blog/2013/12/19/day-45-reading-elf-headers/

======
jerf
The enthusiasm is infectious. I find it helpful to step back every so often
and remember just how staggeringly much it is we take for granted.

------
sitharus
This whole series has been fascinating. I've never had the inclination to
write my own OS, but I love seeing what it entails.

~~~
frik
Yes, really interesting blog articles. An OS written in Rust sounds like a
good idea. I am seeing forward to her next articles :)

Btw. the OSDev.org Wiki might be helpful:
[http://wiki.osdev.org/Main_Page](http://wiki.osdev.org/Main_Page)

------
skywhopper
Wow. The openness about the learning process and the daily progress updates
make for thrilling reading. And I'm learning something at the same time! I
genuinely admire the tone of the posts and wish I took the same attitude to
learning new things. Going from "I don't know how to do something" one day to
"here's how I figured that out" a few days later is infectiously fun to read.
Can't wait to read more!

------
dnautics
> I could also make up my own convention for system calls, but that seems
> unnecessary.

Is there possibly a utility in at least using your own interrupt for system
calls, so that you could implement a linux compatibility layer down the line?
Linux syscalls are a little bit odd relative to what you would generally do in
the modern era of tons of memory.

~~~
jvns
Maybe! Why are Linux syscalls odd? How would you do it instead?

~~~
dnautics
I could be wrong about this but if my memory serves me correctly, linux
syscalls put the first argument in AX, second argument in BX, third argument
in CX, and fourth argument in DX. BSD syscalls do the saner thing and just put
everything on the stack.

~~~
darkf
>BSD syscalls do the saner thing and just put everything on the stack.

Is that not slower (requiring a memory store and a SUB, then a load and an ADD
to pop) than just MOVing a register?

------
gwu78
Like the others, I'm really enjoying these posts. She seems to have a healthy
curiousity for how things work, and a nice low level focus. This seems so rare
these days.

But I have a suggestion.

Instead of writing your own kernel, what about stripping down someone else's?
I imagine their would be great value, not to mention great fun, in reducing
the size of, say, the Linux kernel, taking out things that are not absolutely
necessary.

As Professor McIlroy, the man behind pipes and tr, I believe once said, "The
hero is the negative coder." What that means is it's not the coder who adds
features that is a hero. It is the one who fixes bugs and removes unneeded
code.

I know someone, who is probably one of the best C coders alive today, who has
asked for a Linux kernel under 200K. Wanna be a hero? Reduce the size of a
large executable, e.g., a kernel. It's a challenge and a worthy goal.

~~~
lmkg
She wants to learn kernels, and she wants to learn Rust. There are no extant
kernels written in Rust, so she's making one.

Contributing to an existing program (positively or negatively) may be more
valuable, but I would say this project is more ambitious. Also, if her goal is
knowledge of the system, it's more instructive to build from the ground up
rather than start with a system where you can always take parts of it for
granted.

~~~
gwu78
"... where you can always take parts of it for granted."

A truly curious person tends not to do this. The point of using a system is
that you can take it apart to see how it works.

------
thinkpad20
Very cool stuff. But do I understand correctly, that Rust doesn't have any
built-in functionality for starting executables? How did a language which the
start was meant for low-level systems programming, go so long without having
that built in? I guess one could call into C libraries to do that, but that
seems quite unpleasant...

~~~
Ygg2
As makomk noted, you can't call OS from the OS itself. She probably had to
throw away most of libstd like zero.rs does for Rust to work at this low
level.

~~~
jvns
Yup, all the standard library. If you look at the top of main.rs [1], you'll
see

#[no_std]

which means "don't use the standard library"

Instead of the standard library, I use rust-core [2], which provides some of
the standard library's features (like the ability to allocate memory).

[1]
[https://github.com/jvns/puddle/blob/master/src/main.rs](https://github.com/jvns/puddle/blob/master/src/main.rs)

[2] [https://github.com/thestinger/rust-
core](https://github.com/thestinger/rust-core)

------
groby_b
This is so much fun to read. I've written/contributed to a few OS's, and it's
so awesome to re-experience the joy of doing this for the first time again.

You know you're hooked once you start thinking "I wonder if she accepts pull
requests" ;)

~~~
jvns
I do!

The main issue there is that my build process is a bit broken -- my version of
clang is not quite right somehow, and so I can't build properly without making
some janky changes to rust-core.

