2015年3月27日 星期五

Build and boot a mini os kernel with VirtualBox

Environment: Ubuntu 14.04

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

沒有留言:

張貼留言

BlueTea螢幕錄影程式

  螢幕錄影新選擇:簡單、方便、免費 現在的螢幕錄影工具多樣,但安裝麻煩、操作複雜讓人卻步。我們推出了一款全新的螢幕錄影程式,專為追求簡單和效率的你設計。 1. 免安裝 無需安裝程式。解壓縮後點兩下就可以開始使用 2. 可選取錄影範圍 自由選擇全螢幕、特定視窗或自定義區域,靈活應...