Most respected language and free compiler for creating hobby operating systems? [closed]
Hopefully this is a nice quick question to answer.
Which language is considered to be the defacto language for writing hobbyish operating systems from scratch, that also supports the creation of 512 byte boot sectors? I'm assuming plain C is the answer, although I have this vague concept in my head that C++ can also be used. Do any of you have any opinions about alternative but potentially superior languages, given the passage of time? Would others highly suggest plain old assembler?
And, following on from your answer, what free (and perhaps even open source) compiler would you recommend for compiling the source code into binary?
PS: I am fully aware that writing an OS is a very challenging task and I'm sure I'll never finish. I am conducting a personal-interest research task and would like to at least create a MBR and very basic kernel with simple console IO.
I'd say C (and GCC specifically) is the most commonly used compiler for this purpose.
Most modern compilers don't support "segmented 16-bit" anymore, and none are really good for dealing with limitations like "this code must fit in 512 bytes" or handling things like CPU mode switches and unusual situations. For these reasons people that write their own boot loaders for "PC BIOS" (as opposed to using something like GRUB) tend to use a dialect of assembly (NASM, FASM, GAS).
This doesn't mean other languages (and other compilers) can't be used; and I have seen people write kernels in a wide variety of languages (Pascal, C++, C#, etc). It is also limited to the low-level code (e.g. boot code and kernel). Once you get beyond that, you can use almost anything for higher pieces (drivers, file systems, GUI, applications). There's also some people that invent their own languages to use for the kernel and/or higher pieces of the OS.
I do have an opinion about alternative but potentially superior languages. My opinion is that "potentially superior" doesn't justify the high "Tower of Babel" costs (where most programmers can't read most source code because of language differences) that the existence of many different languages is having on the IT industry as a whole. For an OS project, an alternative language might have theoretical advantages, but in practice those advantages are outweighed by the disadvantage of reducing the number of people who are familiar with the language and could volunteer to help (either when you get stuck and need help with bugs, etc; or later when you need volunteers to contribute thousands of drivers).
I do use plain old assembler (for boot code, kernel code, drivers, etc). I do not recommend it; unless you're much more experienced with assembly than any other language AND you have other reasons for not using a higher level language AND portability won't become an issue.
I'd probably recommend GCC (as a free and open source compiler to use for compiling most of the different/separate binaries that make up an OS project). However, I'd also recommend avoiding the use of non-standard language extensions and any "implementation defined" behaviour (regardless of which language and which compiler you use), so that you can switch to any other compiler at any time (for any reason) more easily.
C and Assembly.
For C compiler I recommend gcc compiler. For X86 assembly I recommend nasm assmebler. You can also use gas which comes with gcc, if you prefer AT&T syntax over intel syntax.
The boot sector has to be written in assembly.
The kernel can be written in any language. You probably need assembly there, but you can also use higher level languages (like C) if you like.
If you want something very simple you can write it all in assembly.
For more information: http://wiki.osdev.org/Main_Page
I'd start with linux because a lot of the open source stuff you will need to port for basic functionality will have been written for that platform.
I got as far getting newlib, http://sources.redhat.com/newlib/ because it is easier to implement than gclib but not as good and then thought, I am building Linux again and switched to using other peoples'.
As for free compiler, they are pretty much all free on Linux. As others here mentioned gas or as are assemblers but setting up cross compilation and choosing your executable format may well need to be accomplished before settling on a final tool set. For reasons of reliability, speed, and porting 3rd party apps over, I would aim to implement a build environment on my custom OS and this might prevent higher level coding tools coming to the fore. Hence you really need to be looking at tools that you can build yourself from source code. Linux from Scratch ( http://www.linuxfromscratch.org/lfs/ ) is a great introduction to cross compilation- same architecture, different (cross) environments.
There were serious obstacles to implementing gclib on a scratch built OS, but that was just my experience around about 3 years ago so things may have changed, and the number of platforms portable code would need to target has certainly increased dramatically.
精彩评论