Page 1 of 1

GCC new target os question

Posted: Wed May 02, 2007 5:39 pm
by lode
Could somebody who has added a new os target to gcc & binutils etc explain exactly what needs to be changed and where?
I seem to find only "adding a new cpu target for linux" tutorials by google.
(why on earth the stuff needs to be compiled inside the thing by default?)
Good links are also appreciated ;)

Posted: Wed May 02, 2007 5:45 pm
by Brynet-Inc
I only know of a one project (Now defunct?) that had a working binutils and gcc port (binutils ran natively.. gcc was used as a cross compiler as it didn't quite work well natively..)..

I made patches for the port, They might be useful for you to see what types of changes were made.. But the OS was considerably far along and was using newlib.

EDIT: Actually there might be others that have binutils ported now...

Posted: Wed May 02, 2007 6:03 pm
by lode
At this point I'd be happy to have a working cross-compiler, since I doubt I could get anything but most basic programs to run natively.

Have you got those patches? I'd be interested in seeing them.

Posted: Wed May 02, 2007 7:56 pm
by Brynet-Inc
Right, I can help you with the specifics but it should at least give you some information on how he ported binutils to his OS.

The binutils patch is for 2.17 and the gcc patch is for 4.1.1 (But it isn't hard to manually apply the changes to another..)

Posted: Wed May 02, 2007 7:56 pm
by binutils

Posted: Wed May 02, 2007 7:57 pm
by Brynet-Inc
How exactly is this in any way related... ?

Posted: Wed May 02, 2007 8:09 pm
by Alboin

Posted: Wed May 02, 2007 8:30 pm
by omin0us
Brynet-Inc wrote:I only know of a one project (Now defunct?) that had a working binutils and gcc port (binutils ran natively.. gcc was used as a cross compiler as it didn't quite work well natively..)..

I made patches for the port, They might be useful for you to see what types of changes were made.. But the OS was considerably far along and was using newlib.

EDIT: Actually there might be others that have binutils ported now...
The OS itself is dead, but the developer (Andrew Pammant) jumped onboard with my OS and has been contributing to it now. :]

Posted: Thu May 03, 2007 12:04 pm
by Candy
Am working on it. Will put the diff online when it works.

Code: Select all

diff -urb binutils-2.17/bfd/config.bfd binutils-2.17.atlantisos/bfd/config.bfd
--- binutils-2.17/bfd/config.bfd	2006-04-05 14:41:57.000000000 +0200
+++ binutils-2.17.atlantisos/bfd/config.bfd	2007-05-03 23:25:31.000000000 +0200
@@ -545,6 +546,11 @@
     targ_selvecs="i386linux_vec bfd_efi_app_ia32_vec"
     targ64_selvecs=bfd_elf64_x86_64_vec
     ;;
+  i[3-7]86-*-atlantisos-*)
+    targ_defvec=bfd_elf32_i386_vec
+    targ_selvecs=i386atlantisos_vec
+    targ64_selvecs=bfd_elf64_x86_64_vec
+    ;;
 #ifdef BFD64
   x86_64-*-elf*)
     targ_defvec=bfd_elf64_x86_64_vec
@@ -562,6 +568,10 @@
     targ_defvec=bfd_elf64_x86_64_vec
     targ_selvecs="bfd_elf32_i386_vec i386linux_vec bfd_efi_app_ia32_vec"
     ;;
+  x86_64-*-atlantisos-*)
+    targ_defvec=bfd_elf64_x86_64_vec
+    targ_selvecs="bfd_elf32_i386_vec i386atlantisos_vec"
+    ;;
 #endif
   i[3-7]86-*-lynxos*)
     targ_defvec=bfd_elf32_i386_vec
diff -urb binutils-2.17/bfd/configure.in binutils-2.17.atlantisos/bfd/configure.in
--- binutils-2.17/bfd/configure.in	2006-06-23 20:17:07.000000000 +0200
+++ binutils-2.17.atlantisos/bfd/configure.in	2007-05-03 23:25:31.000000000 +0200
@@ -727,6 +727,7 @@
     hp300bsd_vec)		tb="$tb hp300bsd.lo aout32.lo" ;;
     hp300hpux_vec)		tb="$tb hp300hpux.lo aout32.lo" ;;
     i386aout_vec)		tb="$tb i386aout.lo aout32.lo" ;;
+    i386atlantisos_vec)         tb="$tb i386atlantisos.lo aout32.lo" ;;
     i386bsd_vec)		tb="$tb i386bsd.lo aout32.lo" ;;
     i386coff_vec)		tb="$tb coff-i386.lo cofflink.lo" ;;
     i386dynix_vec)		tb="$tb i386dynix.lo aout32.lo" ;;
diff -urb binutils-2.17/gas/configure.tgt binutils-2.17.atlantisos/gas/configure.tgt
--- binutils-2.17/gas/configure.tgt	2006-04-05 14:41:57.000000000 +0200
+++ binutils-2.17.atlantisos/gas/configure.tgt	2007-05-03 23:25:31.000000000 +0200
@@ -162,6 +162,7 @@
 
   i386-ibm-aix*)			fmt=coff em=i386aix ;;
   i386-sequent-bsd*)			fmt=aout em=dynix ;;
+  i386-*-atlantisos*)                   fmt=elf ;;
   i386-*-beospe*)			fmt=coff em=pe ;;
   i386-*-beos*)				fmt=elf ;;
   i386-*-coff)				fmt=coff ;;
diff -urb binutils-2.17/ld/Makefile.am binutils-2.17.atlantisos/ld/Makefile.am
--- binutils-2.17/ld/Makefile.am	2006-06-03 06:45:50.000000000 +0200
+++ binutils-2.17.atlantisos/ld/Makefile.am	2007-05-03 23:25:37.000000000 +0200
@@ -227,6 +227,7 @@
 	ehppanbsd.o \
 	ehppaobsd.o \
 	ei386aout.o \
+	ei386atlantisos.o \
 	ei386beos.o \
 	ei386bsd.o \
 	ei386coff.o \
@@ -1045,6 +1046,9 @@
 ei386linux.c: $(srcdir)/emulparams/i386linux.sh \
   $(srcdir)/emultempl/linux.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386linux "$(tdir_i386linux)"
+ei386atlantisos.c: $(srcdir)/emulparams/i386atlantisos.sh \
+  $(srcdir)/emultempl/atlantisos.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+	${GENSCRIPTS} i386atlantisos "$(tdir_i386atlantisos)"
 ei386lynx.c: $(srcdir)/emulparams/i386lynx.sh \
   $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386lynx "$(tdir_i386lynx)"
diff -urb binutils-2.17/ld/configure.tgt binutils-2.17.atlantisos/ld/configure.tgt
--- binutils-2.17/ld/configure.tgt	2006-04-05 14:41:57.000000000 +0200
+++ binutils-2.17.atlantisos/ld/configure.tgt	2007-05-03 23:25:37.000000000 +0200
@@ -160,6 +160,9 @@
 			targ_extra_libpath=elf_i386
 			tdir_i386linux=`echo ${targ_alias}aout | sed -e 's/x86_64/i386/'`
 			tdir_elf_i386=`echo ${targ_alias} | sed -e 's/x86_64/i386/'` ;;
+i[3-7]86-*-atlantisos-*)targ_emul=elf_i386 ;;
+x86_64-*-atlantisos-*)  targ_emul=elf_x86_64
+			targ_extra_emuls=elf_i386 ;;
 i[3-7]86-*-sysv[45]*)	targ_emul=elf_i386 ;;
 i[3-7]86-*-solaris2*)	targ_emul=elf_i386_ldso
                         targ_extra_emuls="elf_i386 elf_x86_64"
The diff. You need to rerun aclocal, autoconf and automake in the respective directories after, and then rebuild with the i686-atlantisos-elf target. Of course, you can probably just do a text substitution in the diff to make it your OS.

You need to add one file to the LD output configuration too:
binutils-2.17.atlantisos/ld/emulparams/i386atlantisos.sh

Code: Select all

SCRIPT_NAME=elf
OUTPUT_FORMAT="out.elf-i386-atlantisos"
TARGET_PAGE_SIZE=0x1000
TEXT_START_ADDR=0x1000
NONPAGED_TEXT_START_ADDR=0
ARCH=i386
TEMPLATE_NAME=atlantisos
Making it output PE or COFF should be fairly easy to do. I haven't tried to run any output executables but I'm fairly sure this is about it for binutils. I'm off to try GCC now.

Enjoy!

Posted: Thu May 03, 2007 3:42 pm
by Candy

Code: Select all

candy@blackbox:~/atlantisos/port/build-gcc$ ../gcc-4.3-20070427/configure --pref
ix=$PREFIX --target=$TARGET --disable-nls
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-atlantisos-elf
checking for a BSD-compatible install... /usr/bin/ginstall -c
Looking good so far :)

(oh, this is a svn snapshot... somebody moved variadic templates to 4.3, so I had to move along. 4.2 isn't even out so I would really disrecommend this :))