Developing an operating system for the x86 architecture [closed]
Asked Answered
N

13

35

I am planning to develop an operating system for the x86 architecture.

  • What options of programming languages do I have?
  • What types of compilers are there available, preferably on a Windows environment?
  • Are there any good sources that will help me learn more about operating system development?
  • Is it better to test my operating system on a Virtual Machine or on physical hardware?

Any suggestions?

Nottingham answered 24/9, 2008 at 21:22 Comment(2)
What would be the best language to use? in X86 architecture, x86 assembly language and C is best chosen!Koheleth
Voting to close as too broad. See also: #254649Smtih
C
43

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:

https://github.com/stephenfewer/NoNameOS

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 matter 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.

Ultimately, the primary language you choose will depend on the type of OS you want to develop.

My development environment 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 environment 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 :)

Crocein answered 24/9, 2008 at 21:49 Comment(4)
I would recommend Qemu (don't know if it runs on windows) as the primary virtual machine as it is quite a bit faster than BOCHS! For the more nasty bugs i usually use BOCHS as it has great debug capabilities and integrates with gdb.Abbate
@QAZ, I understand this is quite a late post, but do you have a new link to your project? This link is dead.Audie
@QAZ, Could you please provide a new link to your project ?Turnkey
Hi, I have updated the link to the project in the answer above.Crocein
H
6

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.

Hodge answered 24/9, 2008 at 21:36 Comment(1)
I disagree to some extent. You learn quite a great deal by reinventing the wheel--assuming the goal here is to learn and not to make a product. Writing your own parser for a well-known programming language by hand is definitely reinventing the wheel, but it's still commonly used as a programming exercise because, by digging in, you learn a lot about how parsers work. Same applies with operating systems. It's great to see how others did it, but only after you've tried it yourself.Gruver
D
5

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!

Dissuade answered 28/9, 2008 at 4:56 Comment(7)
"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.Nica
how can you boot-up PC with Language other than ASM???Koheleth
@JesonPark: You cannot boot up a PC with ASM either. You can only boot it up with native machine code. So, you do it the same way you do it with ASM: you translate the program from the language to native machine code.Photocomposition
@JörgWMittag:I know ! but in all OS-Dev tutorial,first of all we write Bootloader using asm language Unless you want to play with mainboard wire!!!!!!Koheleth
@JesonPark: That's a very different statement. I have no idea why the people on OSDev use assembly. Maybe they like it. Maybe they don't know how to do it differently. Maybe they want to demonstrate their coolness. Maybe they want to discourage newbies. But that doesn't change the fact that it is not necessary.Photocomposition
whe i say "OS-Dev" I mean, not osdev.org....i mean Most of OS development article and books!Koheleth
@JörgWMittag I'd like to see you get an x86 operating system booted without using any assembly. (multiboot doesn't count.)Skepful
E
4

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.

Emmery answered 28/9, 2008 at 5:7 Comment(0)
R
3

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.

Rhodolite answered 24/9, 2008 at 21:29 Comment(0)
H
3

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.

Hygienics answered 24/9, 2008 at 21:44 Comment(1)
Andy... Is he your friend ?Vallievalliere
F
3

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

Fem answered 24/9, 2008 at 21:48 Comment(0)
O
2

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.

Outmost answered 24/9, 2008 at 21:36 Comment(0)
I
2

Be sure to check out the answers to my question:

How to get started in operating system development

Ill answered 28/9, 2008 at 5:17 Comment(0)
A
2

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.

Ankylosis answered 4/12, 2008 at 14:57 Comment(0)
H
1

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.

Heptamerous answered 24/9, 2008 at 21:26 Comment(4)
Why would you possibly need both C++ and C?Almemar
@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++.Heptamerous
@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".Chalco
@David: I will stand by 'need'.Heptamerous
P
1

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

Perpetrate answered 2/9, 2010 at 15:21 Comment(0)
B
-5

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.

Bucksaw answered 24/9, 2008 at 21:34 Comment(2)
Writing an OS is a standard project for CS undergraduates here. Only takes them a semester.Almemar
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.Kilovolt

© 2022 - 2024 — McMap. All rights reserved.