Developing an operating system for the x86 archite

2019-01-12 18:52发布

问题:

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?

回答1:

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 :)



回答2:

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.



回答3:

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!



回答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.



回答5:

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.



回答6:

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.



回答7:

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



回答8:

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.



回答9:

Be sure to check out the answers to my question:

How to get started in operating system development



回答10:

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.



回答11:

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.



回答12:

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



回答13:

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

  • Reactos --> C, Assembler
  • SharpOS --> C#
  • JNode --> Java

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