I’ve just configured an enviroment for developing an x86 kernel on MacosX. My enviroment is quite simple at the moment, just a cross compiler and an x86 emulator, in the case Bochs. In this post I’ll cover the process of configuring and building the cross compiler.
As the compiler I’ll be using Gcc, which will be used to target x86 architecture i686, I compile gcc as bootstrap only, as I don’t need to be able to compile any glibc source, kernels are not linked against glibc.
Requirements:
Binutils and gcc are needed, these are the versions I use:
binutils-2.15.92.0.2
gcc-3.4.3
Compiling
First of all I create the directory structure for the cross compiler. I put all the stuff in /home/crossdev/ .
I create /home/crossdev/src/ where I uncompress binutils and gcc. /home/crossdev/i686/ will hold all the binaries.
Untar binutils in /home/crossdev/src/, and enter the new binutils source directory. Create a build-i686 directory and execute the following script:
#!/bin/bash
echo “Configure Binutils for i686 from MacosX”
CROSS_CHOST=”i686-pc-linux-gnu”
MY_CHOST=”powerpc-unknown-linux-gnu”
MY_CFLAGS=”-mcpu=powerpc -mtune=powerpc”
CROSS_INSTALL=”/home/crossdev/i686/”
CFLAGS=”$MY_CFLAGS”
../configure \
–target=$CROSS_CHOST \
–host=$MY_CHOST \
–prefix=$CROSS_INSTALL \
–enable-shared \
–enable-64-bit-bfd \
echo “Compile Binutils”
make
echo “Install”
make install
Now do the same with gcc but execute the following script:
#!/bin/bash
echo “Configure GCC for i686 from MacosX”
CROSS_CHOST=”i686-pc-linux-gnu”
MY_CHOST=”powerpc-unknown-linux-gnu”
MY_CFLAGS=”-mcpu=powerpc -mtune=powerpc”
CROSS_INSTALL=”/home/crossdev/i686/”
export PATH=”$PATH:/home/crossdev/i686/bin/”
CFLAGS=”$MY_CFLAGS”
../configure \
–prefix=$CROSS_INSTALL \
–host=$MY_CHOST \
–target=$CROSS_CHOST \
–with-newlib \
–disable-shared \
–disable-threads \
–enable-languages=”c” \
–disable-multilib \
–disable-nls \
–enable-symvers=gnu \
–enable-__cxa_atexit \
–with-headers=/home/crossdev/i686/include \
–enable-static
echo “Compile Gcc”
make
echo “Install”
make install
Now we have a kernel cross compiler, we can compile x86-i686 kernel on MacosX. If we add /home/crossdev/i686/bin to our path, it will be easier to use it as to cross compile we just need to call i686-pc-linux-gnu-*** where *** is gcc, ld or any other of the usual gnu tools.