views:

452

answers:

5

I'd like to create a new operating system for x86 PC computers. I'd like it to be 64-bit but possibly run as 32-bit as well.

I have these kinds of questions:

What kinds of things do you start working on first? Knowing where to start in writing your own operating system seems to me to be a tricky subject, so I am interested in your input.

Generally how to go about making your own 32-bit/64-bit operating system, or good resources that mention useful information about going about writing your own operating system for x86 computers. I don't care how old sources are as long as they are still relevant and useful to what I am doing.

I know that I will want it to have kernel drivers that access peripheral hardware directly. Where should I look for advice and documentation for programming and understanding the interface to peripheral hardware the operating system will communicate with? I will need to understand how the operating system will receive input and interact with keyboards, mice, computer monitors, hard drives, USB, etc. etc. This is probably the area I know least about.

I have the Intel instruction set manuals and have been getting more familiar with assembly programming, so the CPU side of things is what I know the most about.

At this point I'm thinking that I'd like to implement the Linux system calls within my operating system so that programs that run on Linux can run on my operating system. I want my operating system to use the ELF binary format. I wonder what obstacles I have to overcome to achieve this Linux compatibility. Are the main things implementing the system calls that Linux provides, and using the ELF format? What else?

I am also interested in people's thoughts about why it might not be a good idea to make your own operating system, and why it is a good idea to make your own operating system.

Thank you for any input.

+2  A: 

You'll be wanting this book:

alt text

Ignacio Vazquez-Abrams
I concur. I would also recommend writing a few kernel drivers for Linux (plenty of tutorials, source-code on the net), so you can get a taste of the huge amount of effort you may be getting into...
tucuxi
+1  A: 

You'll have to implement several kinds of descriptor tables to enable 32-bit mode. Enabling multi-threading isn't an easy task and will almost certainly be a prerequisite. You would probably also want to develop file system support early on to get off a floppy image or whatever you're currently using.

I'm sure you'll have come across this website in the past http://wiki.osdev.org/Main_Page but it has a lot of great articles.

You might also find this book useful for the stage of development you're at: http://www.amazon.com/exec/obidos/ASIN/0201596164/osnews-20/ it goes into great detail and has lots of diagrams, as well as some code snippets.

Steven Jackson
+2  A: 

I would recommend first study a small OS like Minix1 which was build for educational purpose or Minix3 which is POSIX compliant.

stacker
+5  A: 

You'll probably just want to get it running inside of a virtual machine to begin with. It's a PITA trying to develop an OS on actual hardware (with the constant rebooting and debugging-over-serial-cable).

Inside a VM you've usually got a simplified (and relatively standardised) set of hardware to support which can ease initial development as well. In particular, if you want to show someone else your OS you just give them a .vhd file and be reasonably confident that if it works for you then it'll work for them as well.

You might also want to start with something that's already up & running initially (for example, Microsoft's Singularity is pretty neat). That'll let you get all of the boring boot loader and basic device drivers out of the way and you can get onto the "meaty" stuff more quickly.

Dean Harding
Awesome. An emulator like bochs http://bochs.sourceforge.net/ ?
mudge
Bochs is quite popular amoungst OS devers, yeah. VMWare, Virtual PC and VirtualBox would all suffice, too (though Bochs has great support for OS debugging)
Dean Harding
+4  A: 

It is better that you take a look at Linux 0.01 source code. it is the first version of the OS. it is very simple and informative. It is a good place to start

SysAdmin