Overview Features Instructions Performance Forum Downloads Products OrderV4 Reseller Contact

Welcome to the Apollo Forum

This forum is for people interested in the APOLLO CPU.
Please read the forum usage manual.



All TopicsNewsPerformanceGamesDemosApolloVampireAROSWorkbenchATARIReleases
Performance and Benchmark Results!

Gcc/g++ Coding, Assembly Etc.

Denis Markovic

Posts 4
15 Apr 2020 10:41


Hi,

I thought I would play around with my V4 by learning a bit about how to interface gcc with some assembly, no serious work but really just for learning (not sure which category to put this to, please shift if this is the wrong one).

I thong it might be nice to e.g. port the newest version of dosBox and after porting start with some hand-optimisation (I know Novacoder did something similar for a previous version of dosBox so no expectation to get anything really useful out of it).

I ran into some trouble, maybe someone here in the forum knows about how
to solve certain beginner's problems or could give me a few hints how things are supposed to be done ...

After browsing here in the forum it seems like the most modern C/C++ compiler (which might be useful for porting and get medium to good performance output) is bebbo's gcc, but
the catch is it seems to be a pure cross compiler (https://github.com/bebbo/amiga-gcc).

After not being successful to install it on MacOS I created a virtual machine linux in VirtualBox (Mint) and with the excellent instructions on bebbo's webpage got it working
(I might donate a bit of money in the near future). So next step was to download the new
dosBox sources and try to get it compile.

1. Problem:
=========

I learned that a lot can be done by providing the right parameters to the configure script:
./configure CC=/opt/amiga/bin/m68k-amigaos-gcc CXX=/opt/amiga/bin/m68k-amigaos-g++ --includedir="/opt/amiga/m68k-amigaos/include /opt/amiga/m68k-amigaos/sys-include" --host=m68k-amigaos --prefix=/opt/amiga/m68k-amigaos sdlconf_args="--prefix=/opt/amiga/m68k-amigaos --exec-prefix=/opt/amiga/m68k-amigaos" CXXFLAGS="-o2 -g

My first problem was this error message:

/opt/amiga/bin/m68k-amigaos-g++ -DHAVE_CONFIG_H -I. -I../..  -I../../include -I/opt/amiga/m68k-amigaos/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT  -o2 -g  -c -o cpu.o cpu.cpp
In file included from /opt/amiga/m68k-amigaos/sys-include/dirent.h:7:0,
                from ../../include/cross.h:40,
                from ../../include/dos_system.h:29,
                from ../../include/dos_inc.h:25,
                from ../../include/programs.h:28,
                from cpu.cpp:29:
/opt/amiga/m68k-amigaos/sys-include/sys/dirent.h:10:2: error: #error "<dirent.h> not supported"
#error "<dirent.h> not supported"
  ^~~~~
In file included from ../../include/dos_system.h:29:0,
                from ../../include/dos_inc.h:25,
                from ../../include/programs.h:28,
                from cpu.cpp:29:
../../include/cross.h:97:2: error: 'DIR' does not name a type
  DIR*  dir;
 

So obviously there was some functionality (from posix?) which is not supported per default, so I found two possible solutions for that: use the -noixemul or use the
clib2 (-mcrt=clib2):

-noixemul fixed this problem for me, I just got a double declaration of the Segment
  struct (one defined in dosBox the other from the amiga include files), I could just
  rename the dosBox version which solved the problem

2. Problem:
=========

As said before, I was able to compile using -noixemul but it is still interesting how to
resolve the other way with clib2. If I use the clib2 way, I get following error message
because of double declaration:

/opt/amiga/bin/m68k-amigaos-g++ -DHAVE_CONFIG_H -I. -I../..  -I../../include -I/opt/amiga/m68k-amigaos/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT  -o2 -g -mcrt=clib2  -c -o cpu.o cpu.cpp
In file included from /opt/amiga/m68k-amigaos/sys-include/stdlib.h:31:0,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/cstdlib:75,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/ext/string_conversions.h:41,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/bits/basic_string.h:5429,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/string:52,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/bits/locale_classes.h:40,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/bits/ios_base.h:41,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/ios:42,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/istream:38,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/sstream:38,
                from cpu.cpp:22:
/opt/amiga/m68k-amigaos/sys-include/xlocale.h:10:28: error: conflicting declaration 'typedef struct __locale_t* locale_t'
typedef struct __locale_t *locale_t;
                            ^~~~~~~~
In file included from /opt/amiga/m68k-amigaos/clib2/include/wchar.h:67:0,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/cwchar:44,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/bits/postypes.h:40,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/iosfwd:40,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/ios:38,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/istream:38,
                from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/sstream:38,
                from cpu.cpp:22:
/opt/amiga/m68k-amigaos/clib2/include/locale.h:62:15: note: previous declaration as 'typedef void* locale_t'
typedef void *locale_t;

So in this case is looks like local_t is defined very similar one from the clib2 and another
time only slightly different in the amiga system includes. However, not sure what the
easiest way to avoid this clash would be without changing any of the clib2 or system includes? The problem seems to originate from the ios include file which then uses different includes which in the end lead to the double declaration. Any good ideas/suggestions here?

For the moment I will stick with the -noixemul way, which lead me to the next problem:

3. Problem:
=========

Compiling into libraries went well but the last linking step did not go well, I got
following error message:

/opt/amiga/bin/m68k-amigaos-g++ -DHAVE_CONFIG_H -I. -I..  -I../include -I/opt/amiga/m68k-amigaos/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT  -o2 -g -noixemul  -c -o dosbox.o dosbox.cpp
/opt/amiga/bin/m68k-amigaos-g++  -o2 -g -noixemul    -o dosbox dosbox.o  cpu/libcpu.a debug/libdebug.a dos/libdos.a fpu/libfpu.a  hardware/libhardware.a gui/libgui.a ints/libints.a misc/libmisc.a shell/libshell.a hardware/mame/libmame.a hardware/serialport/libserial.a libs/gui_tk/libgui_tk.a -L/opt/amiga/m68k-amigaos/lib -Wl,-rpath,/usr/local/lib -lSDL -lpthread
/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: cpu/libcpu.a: error adding symbols: archive has no index; run ranlib to add one

I figured out that I can run the mentioned ran lib manually and the link manually:

/opt/amiga/bin/m68k-amigaos-ranlib cpu/libcpu.a debug/libdebug.a dos/libdos.a fpu/libfpu.a hardware/libhardware.a gui/libgui.a ints/libints.a misc/libmisc.a shell/libshell.a hardware/mame/libmame.a hardware/serialport/libserial.a libs/gui_tk/libgui_tk.a

/opt/amiga/bin/m68k-amigaos-g++  -o2 -g -noixemul    -o dosbox dosbox.o  cpu/libcpu.a debug/libdebug.a dos/libdos.a fpu/libfpu.a  hardware/libhardware.a gui/libgui.a ints/libints.a misc/libmisc.a shell/libshell.a hardware/mame/libmame.a hardware/serialport/libserial.a libs/gui_tk/libgui_tk.a -L/opt/amiga/m68k-amigaos/lib -Wl,-rpath,/opt/amiga/m68k-amigaos/lib -lSDL -lpthread

However, that is not a nice way. Any ideas how to fix this/is there any parameter to the config script or similar to fix that? Also strange that this happens with the amiga gcc cross compiler but not with native linux compilers. I currently do not understand why things react so differently, does anybody has some hints to this?

Finally I was able to compile and link all, when starting this from (unfortunately currently
UAE) Amiga, the SDL window opens but I run into a guru (none recoverable division by 0, 80000005), I guess I have to debug this part myself.

Assuming that I might get through it and get this program running in UAE (and then on V4),
my next problem would be:

4. Problem:
=========

Optimization. I think I have an idea how to optimize in C, but for Apollo the most obvious
optimisation is to compile with the right compiler flags to get better optimisation than
compiling for pure 68000. I assume there are no Apollo-specific optimisation flags so
maybe best to compile for 68040, just, which compiler flags do I use in this case?

5. Problem:
=========
It would be nice to play around with assembly. I read that I think only vasm today provides support for the apollo core special instructions, so this seems the way to go. Is there any
tutorial or example anywhere how to interface vast output with bebbo's gcc? I would
basically want to replace entire functions, so the idea is to write a function in vasm,
build it to e.g. an object file, then somehow include it into the main build and call
the asm function from C; for this I would obviously need to know:

5.1 What is the caller/callee policy (i.e. when calling from C in which registers would
  gcc put the parameters, where would it expect the return value, which registers are
  assumed to be scratch, which do I have to store/restore from asm when I use them
  etc.). I guess this is as it has always been on Amiga, but the last time I programmed
  for Amiga it was in pure assembly to at least on Amiga I never had to look into those
  things so any hints would be really appreciated.

5.2 How do I call the different tools, i.e. generate vasm .o output or library and how
    do I correctly add that to the gcc build? Again, probably simple but still any hint
    would be very helpful to save time.

/Br

Denis



Stefan "Bebbo" Franke

Posts 136
15 Apr 2020 23:23


with the m68k-amigaos-* binaries in the search path, this would be how I start:


git clone EXTERNAL LINK  cd dosbox
libtoolize --force
aclocal
autoheader
automake --force-missing --add-missing
autoconf
CFLAGS="-O2 -noixemul -m68080" ./configure --host=m68k-amigaos --with-sdl-prefix=/opt/amiga/
...

if I find the time, I'll look into it.

/cheers

posts 2