The most respected language and free compiler for creating a hobby of operating systems?

Hope this is a good quick answer.

What language is considered the deacto language for writing operating systems from scratch, which also supports the creation of boot sectors of 512 bytes? I guess simple 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 on alternative, but possibly superior languages ​​over time? Can others suggest a simple old assembler?

And, following your answer, what free (and possibly even open) compiler would you recommend for compiling source code into binary?

PS: I fully understand that writing an OS is a very difficult task, and I'm sure I will never finish. I am engaged in a research task for personal interests and would like to at least create an MBR and a very simple kernel with a simple console IO.

+6
source share
3 answers

I would say that C (and GCC specifically) is the most commonly used compiler for this purpose.

Most modern compilers no longer support segmented 16-bit ones, and none of them are very good at resolving restrictions such as β€œthis code must match 512 bytes” or handling things like processor mode switches and unusual situations. For these reasons, people who write their own boot loaders for the "PC BIOS" (as opposed to using something like GRUB) tend to use assembly dialects (NASM, FASM, GAS).

This does not mean that other languages ​​(and other compilers) cannot be used; and I saw how people write kernels in a wide variety of languages ​​(Pascal, C ++, C #, etc.). It is also limited to low-level code (for example, boot code and kernel). Once you go beyond that, you can use almost everything for the higher parts (drivers, file systems, GUI, applications). There are also some people who invent their own languages ​​for use in the kernel and / or higher parts of the OS.

I have an opinion on alternative, but possibly excellent languages. My opinion is that "potentially superior" does not justify the high costs of the Tower of Babel (where most programmers cannot read most of the source code due to language differences), that the existence of many different languages ​​is connected with the IT industry as a whole. For an OS project, an alternative language may have theoretical advantages, but in practice, these advantages are outweighed by the lack of a reduction in the number of people who are familiar with the language and can voluntarily help (either when you get stuck or need help with an error, etc. , or later, when you need volunteers to contribute thousands of drivers).

I use a simple old assembler (for boot code, kernel code, drivers, etc.). I do not recommend it; if you are much more experienced in collecting than any other language, and you have other reasons not to use a higher level language, and portability will not be a problem.

I would most likely recommend GCC (as free and open source code for compiling most of the various / separate binaries that make up the OS project). However, I also recommend avoiding the use of non-standard language extensions and any implementation-specific behavior (no matter which language and which compiler you use), so that you can switch to any other compiler at any time (for any mind) easier .

+4
source

C and assembly.

For the C compiler, I recommend the gcc compiler. For building X86, I recommend nasm assmebler. You can also use the gas that comes with gcc if you prefer the AT & T syntax over the intel syntax.

The boot sector must be recorded in the assembly.

The kernel can be written in any language. You probably need a build, but you can also use higher-level languages ​​(like C).

If you need something very simple, you can write it all in the assembly.

For more information: http://wiki.osdev.org/Main_Page

+3
source

I would start with linux because a lot of open source material has been written for this platform that you will need for the port for basic functionality.

"I got as much newlib as possible, http://sources.redhat.com/newlib/ , because it’s easier to implement than gclib, but not so good, and then I thought I built Linux again and switched to using other nations."

As for the free compiler, they are pretty much free for Linux. Since others here refer to gas as collectors, but setting up cross-compilation and choosing an executable format may need to be done before installing the final set of tools. For reasons of reliability, speed and porting of third-party applications, I would set the task to implement the build environment on my user OS, and this may prevent the appearance of higher-level encoding tools on the market. Therefore, you really need to look for tools that you can create from source code. Linux by Scratch ( http://www.linuxfromscratch.org/lfs/ ) - an excellent introduction to cross-compilation - the same architecture, in different (cross-environments).

There were serious obstacles to implementing gclib on OSs created from scratch, but it was my experience about 3 years ago, so everything could have changed, and the number of portable platform codes should have been aimed, of course, increased dramatically.

+1
source

Source: https://habr.com/ru/post/896116/


All Articles