Raw compilation

I'm currently building my own operating system. It's just a small test system to learn about operating systems. The operating system is designed to run in x86 protected mode. Anyhow I would like to write the kernel in either C or C++, as writing the entire kernel in assembly is a bit tedious. Are there any C or C++ compilers that can compile such code (either by default or with specific options)? The compiler should not link to any standard library.

The compiler should run on either Windows (64-bit Windows 10) or Linux (Ubuntu 14.04).
> Are there any C or C++ compilers that can compile such code (either by default or with specific options)?

-ffreestanding
Assert that compilation targets a freestanding environment. This implies -fno-builtin. A freestanding environment is one in which the standard library may not exist, and program startup may not necessarily be at main. The most obvious example is an OS kernel. This is equivalent to -fno-hosted.
https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/C-Dialect-Options.html#C-Dialect-Options


> The compiler should not link to any standard library.

A freestanding implementation has an implementation-defined set of headers. This set shall include at least the headers shown in Table 16.

The supplied version of the header <cstdlib> shall declare at least the functions abort, atexit, at_quick_exit, exit, and quick_exit (18.5). The other headers listed in this table shall meet the same requirements as for a hosted implementation.

Table 16 — C ++ headers for freestanding implementations
Subclause Header(s)
<ciso646>
18.2 Types <cstddef>
18.3 Implementation properties <cfloat> <limits> <climits>
18.4 Integer types <cstdint>
18.5 Start and termination <cstdlib>
18.6 Dynamic memory management <new>
18.7 Type identification <typeinfo>
18.8 Exception handling <exception>
18.9 Initializer lists <initializer_list>
18.10 Other runtime support <cstdalign> <cstdarg> <cstdbool>
20.10 Type traits <type_traits>
29 Atomics <atomic>
-IS
Thank you for those references. It looks like it's time for me to start implementing a few headers then, and probably the rest of the C library after it.

It looks like I need to create a linker script to specify where the kernel will be loaded too. Are there any examples on how to do this?
> It looks like I need to create a linker script to specify where the kernel will be loaded too.
> Are there any examples on how to do this?

http://wiki.osdev.org/C%2B%2B_Bare_Bones#Linking_the_Kernel

Start here: http://wiki.osdev.org/Main_Page
Thank you for those links. That should be enough to get the kernel loaded by the bootloader. Thank you for your help.
Topic archived. No new replies allowed.