1.
Download gcc and binutils source code from GNU (gnu mirror sites)
Also, apt-get install libgmp3-dev libmpfr-dev libmpc-dev texinfo
2.
create directory $HOME/opt and $HOME/opt/cross
export PREFIX="$HOME/opt/cross"
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"
3.
mkdir build-binutils
cd build-binutils
../binutils-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make MAKEINFO=true
make install MAKEINFO=true
4.
mkdir build-gcc
cd build-gcc
../gcc-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc
Now, we have a i686-elf-as and i686-elf-gcc as cross compiler.
5.
Make a boot.s as multiboot header and make function call to kernel_main at kernel.c
6.
Make a kernel.c to print a "Hello World!" string to the screen
7.
Make a linker.ld to combine boot.o and kernel.o to myos.bin
8.
Make bootable iso image
First, make a grub.cfg file
menuentry "myos" {
multiboot /boot/myos.bin
}
Second, make a directory structure as below
<isodir>/boot/
<isodir>/boot/myos.bin
<isodir>/boot/grub/
<isodir>/boot/grub/grub.cfg
Finally, we use grub-mkrescue to make a myos.iso as below
grub-mkrescue -o myos.iso isodir
References:
http://wiki.osdev.org/GCC_Cross-Compiler
http://wiki.osdev.org/Bare_Bones
沒有留言:
張貼留言