Page 1 of 1

how to build kernels using gcc?

Posted: Fri Jan 28, 2011 3:06 pm
by piyush.neo
I am following the OS development tutorial on Ubuntu . Now how to build kernel using gcc on Linux environment. Any helpful links or if anybody has already done that on Linux?

Re: how to build kernels using gcc?

Posted: Sat Jan 29, 2011 1:21 pm
by piyush.neo
i have come across this article http://wiki.osdev.org/GCC_Cross-Compiler to make a binary for the OS. The article teaches to build cross-compiler in few steps. But i have a few question:
1. After step 1, it claims Now you have a "naked" cross-compiler. It does not have access to a C library or C runtime yet, so you cannot use any of the standard includes or create runnable binaries. But it is quite sufficient to compile your self-made kernel..
Is this what all i have to use or i have to build C library too given in 2nd step( i guess i have to build a freestanding environment too, right?).
2. In Visual c++ , we have a option to load program at 1 MB location. How do i set the base address here?
3.Since i have a binary now, do i still need to parse the file or direct start executing it?
4.In kernel setup section, there is a section at last Developing a C++ Runtime Envirenment for MSVC++. Do I still need to do this? If yes then how?

It will be great if anybody can answer my queries. If i will successfully compile my kernel image, i will be happy to contribute the full procedure for setup in gcc in order for others to use it easily.

Re: how to build kernels using gcc?

Posted: Sat Jan 29, 2011 4:52 pm
by Mike
Hello,

1.) You will be developing a C library, and/or equivalent, during the development of your OS. Because of this, you do not need to begin developing the library until you have a kernel running.

2.) Because that tutorial assumes GCC, I will have to assume that you are using the LD linker. The LD linker supports both command line options and a linker script, both which can be used for setting the base address.

3.) If your kernel is a flat binary, then there are no headers to parse so you can just execute it from the first byte onward. Do note, however, that many boot loaders cannot load flat binary kernels. Because of this, I recommend either a) not using flat binary, or b) supporting booting with multiboot loaders.

4.) The MSVC++ runtime will not apply for you if using GCC. Also, do note that the series uses C++, not C. You will need to make some modifications in order to compile it as C.

Re: how to build kernels using gcc?

Posted: Sat Jan 29, 2011 6:12 pm
by piyush.neo
Thanks.
I tried to find out the further detail for format cross-compiler generate etc...I think it will take some time to set this environment for a newbie like me. Its better for me to switch to some kernel development on linux environment, though i will always wish to use my own boot loader developed so far..:)
I will definitely share my experience if i happen to use cross compile successfully.
Thanks for this wonderful tutorial...:)