Hacker News new | past | comments | ask | show | jobs | submit login
Xv6 – A Simple Unix-Like Teaching Operating System (csail.mit.edu)
99 points by jcr on Nov 17, 2014 | hide | past | favorite | 28 comments



Combine this with one of those tiny self-compiling C compilers that were the subject of a few HN articles recently (e.g. https://news.ycombinator.com/item?id=8576068, https://news.ycombinator.com/item?id=8558822) and this could be one of the more interesting minimal self-hosting OSs someone could understand the entirety of in a relatively short amount of time. I like how it supports multiprocessing too, and the entire kernel is <100 pages in the source code PDF.

However, I wish they'd use something other than GAS for the Asm parts... a minimal self-assembling assembler (and a C-subset compiler written in it, to bootstrap the whole thing) would be nice.


None of the tiny self-compiling C compilers could possibly used to compile xv6, as none of them implement structures (arguably the hardest part of compiling C code).


The guy who did the C4 compiler also has a more fully featured one that does support structures:

https://github.com/rswier/swieros/blob/master/root/bin/c.c

It's part of an OS he's building based on xv6


Very cool, although this implementation is significantly less trivial than C4. The difference is over a thousand lines!


LICE is a public-domain C99 compiler in about 10 KLOC:

http://gmqcc.qc.to/cgit/cgit.cgi/LICE.git/tree/README.md


There's also TCC which at one point was able to compile (a somewhat patched version of) the Linux kernel. Also c99, but I thibk it might be closer to 20kloc these days?


Also F.Bellard mentioned that even if the kernel can boot userspace, he never investigated if they were bugs but was pretty sure they exist.


Perhaps Bruce Evans' C compiler, linker and assembler?

It worked well enough to compile early Linux kernels.


I suspect this is a common feeling, but boy did I waste my time at university. Spent it running a bar, chasing women instead of knuckling down and doing things like this - I would love to take a year off and go back and just learn again.

It's probably a case of the grass is greener, I could find more time if I really wanted. Anyway, I had a helluva great time. Should have attend some lectures though ...

Hmm, less than 10,000 lines of C (quite a lot less). Has anyone any experience of this OS/ course ? Could you comment?


Actually, if you had been the kind of person who read/studied a lot (like I did), you would probably regret not chasing women (like I do) :).

In the end, you only get one life and there will always be things you wish you had done.


You can keep learning, just slowly. But it works: I decided a while ago to go back and learn the parts of CS that I skipped that felt unreachably wizardly to me. I'm currently working, very slowly, through the excellent Coursera compilers class, 25 minutes at a time on the bus to and from work. I say go for it :-)


I recently started to bring my laptop when travelling on the subway. It’s very nice to see that one can actually make progress (albeit slowly) on a project even with just 50 minutes a day (or less). 'patio11 inspired me :)


I printed out a copy of the source into a spiral-bound notebook to read/annotate. It can boot on real hardware which is pretty neat. It can even do multiprocessing on multiple cores (processes, no threads).

It uses "ATA PIO Mode" for the disk driver which is very simple and available on all ATA drives, but horribly slow. The console output is similarly naive but easy to understand. It even has a stripped down user-space, shell, C library etc.

It's a really good top-to-bottom look at a simple OS.


If you are going to study this you should also read the Lion's Commentary of the Unix 6th Edition (kernel)[0]. It provides a line by line commentary of the whole kernel (minus some of the hardware specific drivers). Xv6 is a port of the edition 6 kernel to x86 (with some minor changes).

[0] http://www.amazon.com/Lions-Commentary-Unix-John/dp/15739801...


I was lucky enough to take 6.828 a few years ago, it was quite a bit of fun!

Oddly, we tended to use xv6 just as a reference rather than anything else, as we built a custom version of JoS[1], which turned out to actually be an exokernel[2].

[1]http://pdos.csail.mit.edu/6.828/2011/overview.html [2]http://en.wikipedia.org/wiki/Exokernel


You could always dive in to a Coursera course over the holidays.

Alternatively for those who studied too much in university/didn't enjoy the rigors of studying engineering much (me), I recommend taking a few months off to study at a language university abroad.


We used it for the operating systems course I took as a reference OS while building a microkernel. It really is quite good, reading the code is far more helpful than reading a textbook.


We're using JOS lab assignments in the master's OS class at University of Washington this quarter. I think the labs are quite good at illustrating basic OS principles through having you implement the core functionality (paging, interrupts/exceptions, user mode environments, scheduling and context switching, etc.). Some of the hairy x86 scaffolding C and assembly code is provided - you concentrate on the core OS functionality. The downside is you don't learn how to write an OS completely from scratch, and more reading of x86 manuals would be required.

I disagree that you completely wasted your time in college - sounds like you enjoyed yourself!


I managed to make myself sound like John Belushi's bigger roommate ... Definitely not true! But thanks to the surprising number of supportive comments.

I think what attracts me is the coherence of a real course of study again. I learn something every day but it's across economics, option pricing, handling profilers across threads, whatever is on fire or on the reading list this week. the subject matter and themes are there but I have to reach for them. It was nice reading through the text and thinking the hard work had already been done I just needed to follow on.

But thank you for commenting - probably biggest response for a while and very inspiring.


I am currently taking this course. It is a lot of work, but I've learned a lot about operating systems.

It's certainly more work than the 12 units it's rated for though.


The other part of this class is JOS, which is the other operating system from 6.828. xv6 is provided mostly complete while JOS has holes missing which students complete. You can find the labs where students complete the operating system online, and I'm sure you can probably find the source as well (though it's not officially provided like xv6).


> I'm sure you can probably find the source as well (though it's not officially provided like xv6).

Listed on some course webpage was this:

http://pdos.csail.mit.edu/6.828/2014-jos.git


That's the current repo for the skeleton code for the labs. It might get deleted when the semester ends (it also won't boot as is).


I see. How is it different from what students in 6828 have access to? Do they (you?) have access to skeleton code that boots?


This the current repo (I pull from this). The skeleton needs code that the students write in labs in order to boot.

You can find the labs right now under the lab tab of http://pdos.csail.mit.edu/6.828/2014/


Why not.. MINIX?


It wouldn't be a bad idea to use both. It could be nice to study a monolithic kernel-based OS (xv6) and a microkernel-based OS (MINIX). In 6.828, we read xv6, and we implemented parts of JOS, which is exokernel-based. Since exokernels are kind of like microkernels on steroids, I suppose it makes sense that we didn't focus on normal microkernels too much.


Quoting from the Xv6 web page, "Adding multiprocessor support requires handling concurrency head on with locks and threads (instead of using special-case solutions for uniprocessors such as enabling/disabling interrupts) and helps relevance."

MINIX didn't have multiprocessor support until MINIX 3. Unlike MINIX 2, MINIX 3 is not designed as a teaching OS.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: