Closed mheyer32 closed 6 years ago
Forgot to post the commandline I sused to build st_lib.c with: (remove -E)
matze@ubuntu-VirtualBox:~/adoom_git/adoom_src$ make st_lib.o
m68k-amigaos-gcc -v -E -Ofast -fstrength-reduce -fbaserel -mcrt=clib2 -m68030 -m68881 -fomit-frame-pointer -Werror -Wimplicit -Wstrict-prototypes -Wno-int-conversion -DVERBOSE -D__BIG_ENDIAN__ -DNORMALUNIX -DAMIGA -Diabs=abs -c st_lib.c -o st_lib.o
Using built-in specs.
COLLECT_GCC=m68k-amigaos-gcc
Target: m68k-amigaos
Configured with: /home/matze/amigatoolchain/gcc-6.2/amigaos-cross-toolchain/submodules/gcc-6/configure --prefix=/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos --infodir=/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/m68k-amigaos/info --mandir=/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/share/man --prefix=/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos --prefix=/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos --target=m68k-amigaos --enable-languages=c,c++,objc --enable-version-specific-runtime-libs --disable-libssp --with-headers=/home/matze/amigatoolchain/gcc-6.2/amigaos-cross-toolchain/.build-m68k/sources/ixemul-48.2/include
Thread model: single
gcc version 6.3.1b 20171229-105257 (GCC)
COLLECT_GCC_OPTIONS='-v' '-E' '-Ofast' '-fbaserel' '-mcrt=clib2' '-mcpu=68030' '-m68881' '-fomit-frame-pointer' '-Werror' '-Wimplicit' '-Wstrict-prototypes' '-Wno-int-conversion' '-D' 'VERBOSE' '-D' '__BIG_ENDIAN__' '-D' 'NORMALUNIX' '-D' 'AMIGA' '-D' 'iabs=abs' '-c' '-o' 'st_lib.o'
/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/libexec/gcc/m68k-amigaos/6.3.1b/cc1 -E -quiet -v -imultilib libb -D__HAVE_68881__ -isystem /home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/m68k-amigaos/clib2/include -DCLIB2 -D__CLIB2__ -D__CLIB2 -D VERBOSE -D __BIG_ENDIAN__ -D NORMALUNIX -D AMIGA -D iabs=abs st_lib.c -o st_lib.o -mcrt=clib2 -mcpu=68030 -m68881 -Werror -Wimplicit -Wstrict-prototypes -Wno-int-conversion -fbaserel -fomit-frame-pointer -Ofast
#include "..." search starts here:
#include <...> search starts here:
/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/m68k-amigaos/clib2/include
/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/lib/gcc/m68k-amigaos/6.3.1b/include
/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/lib/gcc/m68k-amigaos/6.3.1b/../../../../m68k-amigaos/sys-include/../../include
/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/lib/gcc/m68k-amigaos/6.3.1b/../../../../m68k-amigaos/sys-include
/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/lib/gcc/m68k-amigaos/6.3.1b/../../../../m68k-amigaos/include
End of search list.
COMPILER_PATH=/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/libexec/gcc/m68k-amigaos/6.3.1b/:/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/libexec/gcc/m68k-amigaos/6.3.1b/:/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/libexec/gcc/m68k-amigaos/:/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/lib/gcc/m68k-amigaos/6.3.1b/:/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/lib/gcc/m68k-amigaos/:/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/lib/gcc/m68k-amigaos/6.3.1b/../../../../m68k-amigaos/bin/
LIBRARY_PATH=/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/lib/gcc/m68k-amigaos/6.3.1b/libb/:/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/lib/gcc/m68k-amigaos/6.3.1b/../../../../m68k-amigaos/lib/libb/:/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/lib/gcc/m68k-amigaos/6.3.1b/:/home/matze/amigatoolchain/gcc-6.2/m68k-amigaos/lib/gcc/m68k-amigaos/6.3.1b/../../../../m68k-amigaos/lib/
COLLECT_GCC_OPTIONS='-v' '-E' '-Ofast' '-fbaserel' '-mcrt=clib2' '-mcpu=68030' '-m68881' '-fomit-frame-pointer' '-Werror' '-Wimplicit' '-Wstrict-prototypes' '-Wno-int-conversion' '-D' 'VERBOSE' '-D' '__BIG_ENDIAN__' '-D' 'NORMALUNIX' '-D' 'AMIGA' '-D' 'iabs=abs' '-c' '-o' 'st_lib.o'
matze@ubuntu-VirtualBox:~/adoom_git/adoom_src$
-Os produces working code
your version:
gcc version 6.3.1b 20171229-105257 (GCC)
please test the recent verison:
gcc version 6.4.1b 20180113-204200 (GCC)
.L88:
move.l 20(a2),a0
clr.l d2
move.l a3,d1
move.l a5,d0
jsr _V_DrawPatch
Hm, the code displayed by WinUAE seems really different. Thoughts:
It's wierd since there is an additional statement which is inserted - not overwriting some other statement.
Scrap that. I wanted to try the older 2.97 toolchain and had to undef FAR far. If I #define FAR to far with the 6.4.1b toolchain, I get it compiled and linked.
Sorry for the churn! Now let me check, if the 6.4.1 code is doing better :-)
Sad to report, but GCC 6.4.1.b is seriously borked.
With clib2 ADoom hangs at startup in an endless loop, regardless of optimization options chosen. With noixemul, ADoom crashes in the first OpenLibrary call. The same code worked before.
Even a simple test like this:
#include <stdio.h>
int main(void)
{
printf("%4x %4x %4x %4x\n", (int)0x0102, (int)(0xff01), (int)(0x7fff), (int)(0x8090));
}
Fails for CLIB2 by printing nonsense ("4x %x %x %x") instead of interpreting the format string correctly. The same test compiled with -noixemul works.
4x %x %x %x
UPS! ... found it:
jne .L46
move.l a6,d0 | 3. omitted since now d0 is not used.
addq.l #1,d0 | 1. falsly omitted since the operator is not honored.
move.b 1(a6),d5
ext.w d5
ext.l d5
jeq .L25
move.l d0,a6 | 2. omitted since now redundant.
moveq #0,d4
bogus code:
// do not clear if self assigned
int dregno = ii.get_dst_regno ();
if (dregno != ii.get_src_regno ())
fixed code:
// do not clear if self assigned unless there is an operator
int dregno = ii.get_dst_regno ();
if (dregno != ii.get_src_regno () || ii.get_src_op ())
and now:
102 ff01 7fff 8090
[devel1 58558869848]
Thanks, that fixed the CLIB2 startup problem. I can now start ADoom again, but different levels of -O result in different failures:
-O0 runs the game... there are still rendering errors, but I believe these are due to bugs in the game code -Os breaks the character placement in the main menu, but would eventually run the game -O1 shows main menu correctly, but then hangs in an infinite loop due to the original bug described here (i.e. pointer passed to V_DrawPatch function is broken) -O2 breaks main menu and hangs in V_DrawPatch -O3 same as O2 -Ofast same as O2/3
As a side note: I also managed to get the whole thing compile/link with -noixemul instead of -mcrt-clib2. There were only a few socket related typedefs different and I needed to link against '-lsocket' instead of '-lnet'. But as stated above, ADoom compiled with -noixemul won't even startup.
I uploaded the source to https://github.com/mheyer32/ADoom - give it a shot. I believe it may be a really good test case for the toolchain.
I just learnt about -fbbb=- Using this I can get into the game just like with -O0, even when using -Ofast
It doesn't help with the noixemul==no startup problem, though.
-fbbb= p seem to cause the hang in V_DrawPatch (messing up the parameters passed via registers into the assembly function)
-fbbb = r messes up the menu drawing in V_DrawPatchIndirect (a regular C function)
The only use op (p) is in st_stuff:
:bbb: in 'ST_loadGraphics'
:bbb: (p) propagate_moves condition met, moving regs d3, a0
:bbb: (p) propagate_moves condition met, moving regs d4, a0
And you can see what -fbbb=p does. Before:
.L219:
move.l d2,-(sp)
pea .LC19
move.l a2,-(sp)
jsr (a5)
pea 1.w
move.l a2,-(sp)
jsr (a3)
move.l d0,(a6)
move.l d3,a0
move.l (a0)+,4(a6)
move.l a0,d3
addq.l #1,d2
addq.l #8,a6
lea (20,sp),sp
moveq #8,d0
cmp.l d2,d0
jne .L219
After:
move.l d3,a0
.L219:
move.l d2,-(sp)
pea .LC19
move.l a2,-(sp)
jsr (a5)
pea 1.w
move.l a2,-(sp)
jsr (a3)
move.l d0,(a6)
move.l (a0)+,4(a6)
addq.l #1,d2
addq.l #8,a6
lea (20,sp),sp
moveq #8,d0
cmp.l d2,d0
jne .L219
move.l a0,d3
But you also see that it' not valid here since a0 is trashed during the calls...
Perfectly possible :-) I saw some issue where ST_loadGraphics either produced invalid lump-name-strings or passed the wrong string pointer to W_CacheLumpName.
-fbbb= p seems to work now.
-fbbb= r still messes up the main menu (all drawn menu items appear in the upper left corner)
-fbbb = r messes up the menu drawing in V_DrawPatchIndirect (a regular C function)
here an invalid rename causes emitting divsl.l d1,d1:d2
instead of divs.l d1,d2
trashing the d1 register.
please test
Confirmed, -fbbb = r does not mess up the menus anymore.
I think, all the concerns in this issue have been fixed. Very much obliged, bebbo! :-D
Closing.
ADoom is using a function declared as extern, implemented in assembly. Parameters are passed via registers:
void V_DrawPatch(REG(d0, int x), REG(d1, int y), REG(d2, int scrn), REG(a0, patch_t* patch));
But calling that function from C code caused me a lot of grief and debugging. I first thought that the assembly function contained broken code, but it does not. With -O0 the code will run. It turned out that the 'patch' pointer never arrived healthy in the assembler function.Looking at the gcc produced assembly code revealed nothing:
Looking at the disassembly produced by m68k-objdump didn't show anything interesting either:
I then used WinUAE to debug the issue. I found that it would always call V_DrawPatch with 0x4000600 in A0, so I set a breakpoint in that condition and waited. Et voila:
How in the world did the 403FF5DE 2070 0c00 MOVEA.L (A0, D0.L*4, $00) == $04000604,A0
line squeezed in there and why?
I also wonder how the code that objdump disassembled is so different from what is apparently running on the Amiga? One of the jsr's (to fflush?) seems to be missing... this is all very confusing. Attaching the preprocessed source: st_lib.txt