gaf
User
 Platinum Osdever
| Posts: 153 |  | Karma: 10
|
Re:Something that cannot be described in a subject - 2006/09/05 10:06
I guess the guys at mega-tokyo are right when they suggest you to use a cross-compiler. If you just follow the instructions in the FAQ (only need step one for the moment) you should actually have your compiler in some 30-60 minutes. Most of the time is eaten up by download and compiling:
- Get the cygwin installer and set-up a basic cygwin system. During the installing process you'll have to choose which packages to include. It's necessary to at least add "make", "gcc-core" and "gcc-g++" (all in "development") to the list of packages. - After the cygwin installation has completed, you need to download some gcc source to build the cross-compiler (binutils (13.2 MiB ), gcc-core (16.3 MiB ), gcc-g++) (3.6 MiB ). - Now extract all archives to /cygwin/usr/src (or any other location that you think is appropriate). If your Zip program can't handle .bz2 archives, you might want to have a look at 7zip. - Start cygwin (click /cygwin/cygwin.bat) and type in the instructions from the FAQ to build the crosscompiler.
| Code: | export PREFIX=/usr/cross // target of the installation
export TARGET=i586-elf // pentium (i586) or pentium pro (i686) ?
cd /usr/src
mkdir build-binutils build-gcc
cd /usr/src/build-binutils
../binutils-2.17/configure --target=$TARGET --prefix=$PREFIX --disable-nls
make all install
cd /usr/src/build-gcc
export PATH=$PATH:$PREFIX/bin
../gcc-4.1.1/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,c++ --without-headers --with-newlib
make all-gcc install-gcc
|
If everything worked out, you should now have a cross-compiler. Don't forget deleting the source in /usr/src/ unless think that you might need them later.
To compile your kernel you'll now have to create an ld linker script (/home/user/OS/link.ld):
| Code: | OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x10000 :
{
*(.text)
*(.rodata*)
}
.data :
{
*(.data)
}
.bss :
{
*(.bss*)
*(.comment*)
}
}
|
Start must be a global symbol that points to the beginning of your assembler stub code. I've actually never used the binary format and thus can't be quite sure whether the script will already be sufficient. The idea is that ld detects that 'start' is the enrtypoint and thus makes sure that it's also the first instruction. If this doesn't work, and your assembler code gets moved somewhere else, you might have to add some more trickery to the script.
Compiling the OS should now be straight forward:
| Code: | i586-elf-gcc kernel.cpp -fno-builtin -nostdlib -nostdinc -fno-rtti -fno-exceptions -nostartfiles
i586-elf-gcc video.cpp -fno-builtin -nostdlib -nostdinc -fno-rtti -fno-exceptions -nostartfiles
nasm -f elf startup.asm
i586-elf-ld -T linker.ld startup.o kernel.o video.o
|
You could also create your own makefile to reduce the amount of typing needed..
regards,
gaf
|