fredag 18 juni 2010

Compiling a C++ xen mini-os

# build newlib, minios, the pci and xen libraries.
cd /root/xen/xen-4.0-testing.hg/stubdom/c
make c-stubdom

# put all the minios object files into an archive
MO=/root/xen/xen-4.0-testing.hg/stubdom/mini-os-x86_32-c

ar cr /root/xen/xen-4.0-testing.hg/extras/mini-os/minios.a \
 $MO/blkfront.o $MO/events.o $MO/fbfront.o $MO/fs-front.o $MO/gntmap.o \
 $MO/gnttab.o $MO/hypervisor.o $MO/kernel.o $MO/lock.o $MO/main.o \
 $MO/mm.o $MO/netfront.o $MO/pcifront.o $MO/sched.o $MO/lib/ctype.o \
 $MO/lib/math.o $MO/lib/printf.o $MO/lib/stack_chk_fail.o \
 $MO/lib/string.o $MO/lib/sys.o $MO/lib/xmalloc.o $MO/lib/xs.o \
 $MO/xenbus/xenbus.o $MO/console/console.o $MO/console/xencons_ring.o 

############################

D=/root/xen/xen-4.0-testing.hg/stubdom

GPP=$D/cross-root-i686/bin/i686-xen-elf-g++
LD=$D/cross-root-i686/bin/i686-xen-elf-ld

$GPP c/main.cpp -c -o c/main.o
$GPP c/mi.cpp -c -o c/mi.o

$LD -r -d \
-m elf_i386 \
/root/xen/xen-4.0-testing.hg/stubdom/mini-os-x86_32-c/arch/x86/x86_32.o \
-\( \
/root/xen/xen-4.0-testing.hg/stubdom/c/main.o \
/root/xen/xen-4.0-testing.hg/stubdom/c/mi.o \
/root/xen/xen-4.0-testing.hg/extras/mini-os/app.lds \
--undefined main \
-\) \
-whole-archive \
/root/xen/xen-4.0-testing.hg/extras/mini-os/minios.a \
-no-whole-archive \
/root/xen/xen-4.0-testing.hg/stubdom/mini-os-x86_32-c/lwip.a \
/root/xen/xen-4.0-testing.hg/stubdom/libxc-x86_32/libxenguest.a \
/root/xen/xen-4.0-testing.hg/stubdom/libxc-x86_32/libxenctrl.a \
/root/xen/xen-4.0-testing.hg/stubdom/mini-os-x86_32-c/arch/x86/libx86_32.a \
-L$D/cross-root-i686/i686-xen-elf/lib \
 -lstdc++ \
 -lc -lm -lz -lpci \
 -L$D/cross-root-i686/lib/gcc/i686-xen-elf/4.5.0 \
 -lgcc \
-o /root/xen/xen-4.0-testing.hg/stubdom/mini-os-x86_32-c/mini-os.o

# move around code in .o files into their correct sections
$LD \
-m elf_i386 \
$D/mini-os-x86_32-c/mini-os.o  \
-T /root/xen/xen-4.0-testing.hg/extras/mini-os/arch/x86/minios-x86_32.lds \
-o $D/mini-os-x86_32-c/mini-os

gzip -f -9 -c $D/mini-os-x86_32-c/mini-os >$D/mini-os-x86_32-c/mini-os.gz

######
##  
##  The following has to be defined because newlib doesn't provide
##  lseek and fstat correctly after the xen patches (which renames them).
##
##  The domain crashes if linked with crt{begin,end}.o so instead
##  declare the missing variable __dso_handle.
##
  extern off_t lseek64(int a, off_t b, int c);
  off_t lseek(int a, off_t b, int c) {
    return lseek64 (a, b, c);
  }

  int fstat64(int a, struct stat* b);
  int fstat(int a, struct stat* b) {
    return fstat64(a,b);
  }

  void *__dso_handle = 0;

### 
#  I was using a cross compiler with a special libstdc++, built with the commands
#  below.  Note that the directories here are local to my machine.

cd /root/xen/xen-4.0-testing.hg/stubdom/build/binutils
/home/larsr/test/i486-none-elf/build/binutils-2.20/configure \
   --prefix=/root/xen/xen-4.0-testing.hg/stubdom/cross-root-i686 \
   --target=i686-xen-elf --enable-interwork \
   --enable-multilib --disable-nls --disable-shared --disable-threads \
   --with-sysroot=/root/xen/xen-4.0-testing.hg/stubdom/cross-root-i686/i686-xen-elf
   --with-gcc --with-gnu-as --with-gnu-ld
make -j8 && make install


cd /root/xen/xen-4.0-testing.hg/stubdom/build/gcc
/home/larsr/test/i486-none-elf/build/gcc-4.5.0/configure \
   --prefix=/root/xen/xen-4.0-testing.hg/stubdom/cross-root-i686 \
   --target=i686-xen-elf --enable-interwork \
   --disable-multilib --enable-languages=c,c++ --with-newlib --disable-nls \
   --disable-shared --disable-threads --with-gnu-as --with-gnu-ld \
   --with-gmp=/home/larsr/test/i486-none-elf/build/gmp \
   --with-mpfr=/home/larsr/test/i486-none-elf/build/mpfr \
   --with-mpc=/home/larsr/test/i486-none-elf/build/mpc \
   --with-sysroot=/root/xen/xen-4.0-testing.hg/extras/mini-os/include
make -j8 && make install
cd ../../

tisdag 15 juni 2010

Building a gcc cross compiler

This was based on an example from http://www.arklyffe.com/main/content/arm-gcc-toolchain-build, but I had to use --disable-multilib to get gcc to compile. Or else, it would fail some of its ./configuration steps (I think for instance libz failed).

Note that gcc is built twice, once to get a boot strap compiler that can compile newlib for the target platform, and then again to compile gcc to use newlib as its C library.

# build tool chain
TARGET=arm-none-eabi
TARGET=i486-none-elf
INSTALL=$HOME/test/$TARGET
GCC_VER=4.5.0
###

export PATH=$INSTALL/bin:$PATH

mkdir $INSTALL
cd $INSTALL
mkdir build
cd build

(
wget http://ftp.sunet.se/pub/gnu/gmp/gmp-5.0.1.tar.bz2 &
wget http://ftp.sunet.se/pub/gnu/mpfr/mpfr-2.4.2.tar.bz2 &
wget http://ftp.sunet.se/pub/gnu/gcc/infrastructure/mpc-0.8.1.tar.gz &
wait
)

tar -xjf gmp-5.0.1.tar.bz2
tar -xjf mpfr-2.4.2.tar.bz2
tar -xzf mpc-0.8.1.tar.gz

(
wget http://ftp.sunet.se/pub/gnu/binutils/binutils-2.20.tar.bz2 & 
wget http://ftp.sunet.se/pub/gnu/gcc/releases/gcc-$GCC_VER/gcc-core-$GCC_VER.tar.bz2 &
wget http://ftp.sunet.se/pub/gnu/gcc/releases/gcc-$GCC_VER/gcc-g++-$GCC_VER.tar.bz2 &
wget http://ftp.sunet.se/pub/gnu/gdb/gdb-7.1.tar.bz2 &
wait
)
tar -xjf binutils-2.20.tar.bz2
tar -xjf gcc-core-$GCC_VER.tar.bz2
tar -xjf gcc-g++-$GCC_VER.tar.bz2
tar -xjf gdb-7.1.tar.bz2

wget ftp://sources.redhat.com/pub/newlib/newlib-1.18.0.tar.gz
tar -xzf newlib-1.18.0.tar.gz

mkdir gmp-5.0.1/build; cd gmp-5.0.1/build
../configure --prefix=$INSTALL/build/gmp --disable-shared --enable-static
make -j8 && make install
cd ../../
mkdir mpfr-2.4.2/build; cd mpfr-2.4.2/build
../configure --prefix=$INSTALL/build/mpfr --with-gmp=$INSTALL/build/gmp \
   --disable-shared --enable-static
make -j8 && make install
cd ../../
mkdir mpc-0.8.1/build; cd mpc-0.8.1/build
../configure --prefix=$INSTALL/build/mpc --with-gmp=$INSTALL/build/gmp \
   --with-mpfr=$INSTALL/build/mpfr --disable-shared --enable-static
make -j8 && make install
cd ../../

patch -l -p0 <<EOF
--- binutils-2.20/gas/as.h      2010-06-15 18:49:19.771279712 +0000
+++ binutils-2.20/gas/as.h      2010-06-15 18:50:10.400278790 +0000
@@ -238,7 +238,7 @@
 #define know(p) gas_assert(p)  /* Verify our assumptions!  */
 #endif /* not yet defined */
 #else
-#define know(p)                        /* know() checks are no-op.ed  */
+#define know(p)        do {} while(0)  /* know() checks are no-op.ed  */
 #endif
 
 /* input_scrub.c */
EOF

mkdir binutils-2.20/build; cd binutils-2.20/build
../configure --prefix=$INSTALL --target=$TARGET --enable-interwork \
   --enable-multilib --disable-nls --disable-shared --disable-threads \
   --with-gcc --with-gnu-as --with-gnu-ld
make -j8 && make install
cd ../../

mkdir gcc-$GCC_VER/build; cd gcc-$GCC_VER/build
../configure --prefix=$INSTALL --target=$TARGET --enable-interwork \
   --disable-multilib --enable-languages=c --with-newlib --disable-nls \
   --disable-shared --disable-threads --with-gnu-as --with-gnu-ld \
   --with-gmp=$INSTALL/build/gmp --with-mpfr=$INSTALL/build/mpfr \
   --with-mpc=$INSTALL/build/mpc --without-headers
make -j8 all-gcc && make install-gcc
cd ../../

mkdir newlib-1.18.0/build; cd newlib-1.18.0/build
../configure --prefix=$INSTALL --target=$TARGET --enable-interwork \
   --enable-multilib --with-gnu-as --with-gnu-ld --disable-nls 
make -j8 && make install
cd ../../

rm -rf gcc-$GCC_VER/build
mkdir gcc-$GCC_VER/build; cd gcc-$GCC_VER/build
../configure --prefix=$INSTALL --target=$TARGET --enable-interwork \
   --disable-multilib --enable-languages=c,c++ --with-newlib --disable-nls \
   --disable-shared --disable-threads --with-gnu-as --with-gnu-ld \
   --with-gmp=$INSTALL/build/gmp --with-mpfr=$INSTALL/build/mpfr \
   --with-mpc=$INSTALL/build/mpc
make -j8 && make install
cd ../../

tisdag 1 juni 2010

Building umip on Ubuntu Lucid

umip is a mobile IPv6 daemon

apt-get install autoconf byacc flex indent
wget 'http://www.umip.org/gitweb?p=umip.git;a=snapshot;h=d1c240f3deb690af902ce1ff128780551ff6141c;sf=tgz'  -O umip.tgz
tar xfz umip.tgz
cd umip
autoreconf -fiv
./configure
make