views:

2187

answers:

14
+20  Q: 

OS Development

I want to make my own operating system for the X86 architecture.

What would be the best language to use? (Along with assem of course)

What would the best compiler for the language be on a windows environment?

Are there any good tutorials on this subject?

Is it better to test it using an emulator or physical pc?

+2  A: 

If you are making a full OS, you will need to use a range of languages. I would expect Assembly, C and C++ at the very least.

I would use a Virtual Machine for most of the testing.

Geoffrey Chetwood
Why would you possibly need both C++ and C?
Daniel Papasian
@Daniel: While C is great for high performance, low level programming near the hardware level, I would recommend C++ for all the other higher level stuff.Not sure why you /wouldn't/ need C and C++.
Geoffrey Chetwood
@Rich: You don't need more than one language. You may well want to use more than one. Let's not confuse "need" with "want very much for good reasons".
David Thornley
@David: I will stand by 'need'.
Geoffrey Chetwood
+1  A: 

You might want to look up XINU. it's a tiny OS for x86 that isn't really used for anything other than to be dissected by students.

shoosh
A: 

If you want write an OS then you need a couple of people. A OS can not write a single people. I think it is better to work on existing OS projects

This is only a short list of OS projects. How you can see there is a project for every possible language.

Horcrux7
Writing an OS is a standard project for CS undergraduates here. Only takes them a semester.
Daniel Papasian
An OS can most definitely be written by a single person. How many features it has and how polished it can be may be realatively limited, but it is definitely possible.
Cristián Romo
+1  A: 

I've done that once for a 386SX, which was on a PCI board. A good source on how to start a X86 cpu in protected mode is the source code of linux. It's just a few assembly statements. After that you can use gcc to compile your C code. The result is objectcode in ELF format. I wrote my own linker, to make a program out of the objectcode. And yes, it worked! Good luck.

Frans
+4  A: 

Language and compiler depend entirely on what you're attempting to accomplish. I would suggest, though, that you might be approaching the problem from too low a level.

There are materials out there on operating system fundamentals. MIT has OpenCourseware on the subject. Read through Andrew Tannenbaum's Operating Systems series, and look at things like Minix.

Get an idea for what's out there. Start tinkering with things. Borrow ideas, and see where they go. You can reinvent the wheel if you really want, but you'll learn more by building on the works of others.

Darcy Casselman
+2  A: 

Use ANSI C, and start off with an emulator. When you port over to a real machine, there will be some assembler code. Context switching and interrupt handling (for instance) is easier to write in assembler.

Andy Tannenbaum has written a good book on OS. Many other good ones exist.

Good luck! There is nothing quite like haveing written your own OS, however small.

denonde
A: 

Also check out the OSDev.org which have all information you need to get started.

Jonas Gulle
+24  A: 

Hello

For my final year project in collage I developed a small x86 OS with a virtual memory manager, a virtual file system and fully preemptive multitasking. I made it open source and the code is heavily commented, check out its source forge page at:

http://sourceforge.net/projects/osamos

From my experience I can recommend the following:

You will need x86 assembly language for various parts, this in unavoidable, but can be kept to a minimum. Fairly quickly you will get running C code, which is a proven choice for OS development. Once you have some sort of memory manager available you can go into C++ if you like (you need some kind of memory manager for things like new and delete).

No mater what language you choose you will still need assembly & C to bring a system from boot where the BIOS leaves you into any useable form.

Ultimatly what primary language you choose will depend on the type of OS you want to develope.

My development enviroment was the Windows port of the GNU development tools DJGPP along with the NASM assembler. For my IDE I used IBM's Eclipse with the CDT plugin which provides a C/C++ development enviroment within Eclipse.

For testing I recommend BOCHS, an open source x86 PC emulator. It lets you boot up your OS quickly which is great for testing and can be integrated into eclipse so you can build and run your OS at the push of a button. I would also recommend using both VMWare and a physical PC occasionally as you can pick up on some subtle bugs that way.

P.S. OS development is really fun but is very intensive, mine took the best part of 12 months. My advice is to plan well and your design is key! enjoy :)

QAZ
+5  A: 

It doesn't really matter, what language you choose. If the language is Turing-complete, then you can write an OS in it.

However, the expressiveness of the language will make certain kinds of designs very easy or very hard to implement. For example, the "liveliness" and dynamism of the old Smalltalk OSs depends on the fact that they are implemented in Smalltalk. You could do that in C, too, but it would probably be so hard that you wouldn't even think about it. JavaScript or Ruby OTOH would probably be a great fit.

Microsoft Research's Singularity is another example. It simply couldn't be implemented in anything other than Sing#, Spec# and C# (or similar languages), because so much of the architecture is dependent on the static type safety and static verifiability of those languages.

One thing to keep in mind: the design space for OSs implemented in C is pretty much fully explored. There's literally thousands of them. In other languages, however, you might actually discover something that nobody has discovered before! There's only about a dozen or so OSs written in Java, about half a dozen in C#, something on the order of two OSs in Haskell, only one in Python and none in Ruby or JavaScript.

Try writing an OS in Erlang or Io, and see how that influences your thinking about Operating Systems!

Jörg W Mittag
"If the language is Turing-complete, then you can write an OS in it." This is not true. Java is Turing-complete but there are parts of an OS which cannot be done in Java (eg port I/O). Being Turing-complete does *not* mean you can do everything with it.
Job
+2  A: 

There is an OS course offered at the University of Maryland that utilizes GeekOS. This is a small, extensively commented OS designed for educational purposes which can be run using the Bochs or QEMU emulators.

For an example of how it is used in a course, check out a previous offering of the course at the class webpage. There, you will find assignments where you have to add different functionality to GeekOS.

Its a great way to get familiar with a small and simple OS that runs on the x86 architecture.

posulliv
+1  A: 

Be sure to check out the answers to my question:

How to get started in operating system development

Giovanni Galbo
A: 

Without a doubt, I'd use Ada. It's the best general-purpose systems-programming language I have come across, bar none. One example, Ada's much better for specifying bit layout of objects in a record than C. Ada also supports overlaying records on specific memory locations. C requires you to play with pointers to acheive the same effect. That works, but is more error-prone. Ada also has language support for interrupts.

Another: Safety. Ada defaults to bound checking array assignments, but allows you to turn it off when you need it. C "defaults" to no bound checking on arrays,so you have to do it yourself manually whenever you want it. Time has shown that this is not the right default. You will forget one where it is needed. Buffer overflow exploits are the single most common security flaw used by crackers. They have whole websites explainng how to find and use them.

As for learning about doing this, the two books I'm aware of are XINU (Unix backwards, nothing to do with Scientology), and Project Oberon. The first was used in my Operating Systems graduate course, and the second was written by Nikalus Wirth, creator of Pascal.

T.E.D.
A: 

C most probably...all major OS-es have been written in C/C++ or Objective-C(Apple)

Alexander Ivanov