Building Your Own Operating System?
sonictooth asks: "I have dreams of writing a toy operating system, as I know some people have already done in college. Unfortunately, I don't have that opportunity. I was wondering what books (as there are so many) and methods people [have used], either in college or on their own. Amazon is littered with books from varying authors, Tanenbaum in particular, and there are both positive and negative reviews of his books. Does anyone recommend a simple book to walk you through the early stages, and then explain the more complex theories later on."
Now, these books don't make for a how-to, and you don't get the source for the core OS with them, but if you start by learning the exec interface, then look over the exec headers, you'll quickly develop a thorough understanding of a simple multitasking kernel. From there, you can glom onto the basic device library with the library book, then the headers again, and repeat for the trackdisk library. Jump into console and other libraries as your interest dictates. Don't worry about learning these things in a linear fashion -- going with your interest first is critical for learning something as complex and intricately interconnected as the workings of an OS.
After seeing how some of these work together, if you've got your head on straight with C, implementing your own equivalent on the PC should be easy. Grab MS-DOS, which leaves protected mode entirely open to you, and build your own system on top of that. No need to start with your own bootstrapper if you can do it with a little DOS code. That way you have BIOS services for the parts you haven't written yet, and can replace bits a little at a time as your interest dictates. Make a simple OS shell first, using mostly wrappers, then drill down until it's time to start making your own device drivers.
From here, I went on to acquire the IP rights behind UNIX and develop from there, but you can take your own route.
~Darl
Congratulations you've got yet another monolithic kernel based hobby OS that no-one is interested in but you.
If you want something remotely interesting, try seperating as much of that junk in the kernel as you can into userland. Pentiums now have system calls that are 5 to 10 times faster than they used to be. Think about writing applications that communicate using shared memory pages. If one app writes a page and then instructs the kernel to map that page into another process, the kernel can do that rediculously fast. That's 4k (or more if you're using bigger pages) that has transfered from one process to another in the space of a single system call.
How we know is more important than what we know.
I'm taking an Operating Systems course right now. You could follow along with it (or a similar course at any university.) Obviously you'll miss the lectures, but read along in the book and you'll get the same content. (BTW, the book for this class is by Silberschatz; ISBN 0471250600. I only gave Tanenbaum's OS book a quick look over, but so far I like the style of this book more than Tanenbaum's writing that I saw in his Computer Organization book.)
The course starts you off with a very basic skeleton. From there, we'll add most of the parts of a basic OS in several individual programming projects. The class website is at http://www.cs.umd.edu/class/spring2004/cmsc412/ (won't work in IE) It has everything on it you should need to follow along.
But, again, he really just wants to know what the best college-level textbook is.
What I'm listening to now on Pandora...
I would highly recommend the book:
s /d evelopers-handbook/
The Design and Implementation of the 4.4 BSD Operating System
by Marshall Kirk McKusick
Keith Bostic
Micahel J. Karels
and John S. Quarterman
(ISBN 0201549794)
It's really a great book about a mature operating system and will give you some great technical insights into the hows and whys behind operating systems in my opinion.
Additionally, most *BSD distributions are a great study because their code tends to be very well organized and they come with *LOTS* of documentation.
Even reading the FreeBSD developer's handbook here:
http://www.freebsd.org/doc/en_US.ISO8859-1/book
or the KernelNewbies site here:
http://www.kernelnewbies.org/
May be of benefit to you.
Additionally, I hope you have a high level of reading comprehension. Be prepared to take several trips to your local library or bookstore and spend hours perusing texts to better understand the ins and outs, and quirks of hardware.
But lastly, even after you do all of the above, the best way to learn is to do! Install a copy of Boch's or if you're a little richer, buy VMWare or VirtualPC (VirtualPC's emulation tends to be better than VMWare's although a bit slower). Get brave and setup and old pc and install all kinds of different OS's on it. That's the best way in my opinion to learn...
Assuming you want to go bottom-up in designing the system and you're using a PC, the first things you'll need are a decent grip on x86 assembler and PC architecture. Then, you need to learn the BIOS interrupts/services, since that's about all that'll be available to you.
I'd think one of the first things you might want to write is a bootstrap routine.The Undocumented PC had a pretty good description of bootstrapping as I recall. Basically, the bootsector of the boot device (first sector on a floppy, the MBR/partition table on hard disk, etc.) gets loaded to 0:7c00 in real mode and gets executed - what you do from there is up to you. Some *really* old video games for PC's came as boot disks and did just that - in a sense, they provided their own simple operating systems.
After that, you'll get into the more fun stuff - filesystems, memory management, task switching, compilers, linkers and loaders, device drivers, etc. That's where you'll want to be reading your Tanenbaum book, a stack of others, and probably peeking at Linux and other open source operating systems to see how it's really done.
Good luck!
I write code.
Richard Burgess's "Developing Your Own 32-Bit Operating System": Used to be published by SAMS, but they no longer list it. Now available as an online download.
Don't really do it for any modern architecture. Visit 6502.org and look at the sample operating systems they have there.
Why? Because on your first (and second, and third, and forth...) you're not going to want to learn all about the inner workings of the Intel architecture. Segmented memory. *shudder*
The 6502 is still small enough that you can wrap your head around it easily. 6502 emulators are plentiful. An operating system for a 6502-based machine would be small and simple, but still a useful tool.
Once you get your head around that, then try the 6510 - same instruction set, but up to 16MB of memory.
Finally, when you feel good with all that, try Intel, or Sparc, or PPC. My personal favorite processor to code for (assembly-language speaking) is Motorola's 68k.
...but it's being eaten...by some...Linux or something...
Sigops How to Write an Operating System. This is a series that will walk you trough writing your own os. You'll have your own Hello World OS after you read the first chapter and you'll be multitasking by chapter five.
Win a signed Stephen Carpenter ESP Guitar from the Deftones: http://def-tag.com/?r=0008781
I have dreams of writing a toy operating system...
Linus, is that you?
So that Ask Slashdot you posted some time ago finally made it through the submission queue?
The benefits would be that porting the OS and all programs running on it to a new platform would consist of porting the virtual machine only.
Also, all code would be bounds-checked and stack-overflow protected, so a lot of today's security holes wouldn't be possible to create. With garbage collection, memory leaks would be a minor problem as well.
To get a lot for free, you could base it on IBM's JRVM, a virtual machine for Java, written in Java.
The drawback of not allowing C code to run natively is that there's a lot of software out there that'll be hard to support. This may be solvable, but I haven't given any thought to it so I don't know.
Installed the Bubblemon yet?