vivier / qemu-m68k

Other
40 stars 6 forks source link

Illegal instruction when trying to run Free Pascal Compiler (fpc) #24

Closed glaubitz closed 6 years ago

glaubitz commented 7 years ago

After a fresh bootstrap of fpc for m68k, trying to run ppc68k in qemu-m68k:

(sid-m68k-sbuild)root@stretch64:/# ./usr/lib/fpc/3.1.1/ppc68k 
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
Illegal instruction
(sid-m68k-sbuild)root@stretch64:/#

The binary works fine on Aranym:

root@mama:~# ./ppc68k 
Free Pascal Compiler version 3.1.1 [2017/05/28] for m68k
Copyright (c) 1993-2017 by Florian Klaempfl and others
/root/ppc68k [options] <inputfile> [options]
 Put + after a boolean switch option to enable it, - to disable it.
  @<x>   Read compiler options from <x> in addition to the default fpc.cfg
  -a     The compiler does not delete the generated assembler file
      -a5        Don't generate Big Obj COFF files for GNU Binutils older than 2.25 (Windows, NativeNT)
      -al        List sourcecode lines in assembler file
      -an        List node info in assembler file (-dEXTDEBUG compiler)
      -ao        Add an extra option to external assembler call (ignored for internal)
      -ap        Use pipes instead of creating temporary assembler files
      -ar        List register allocation/release info in assembler file
      -at        List temp allocation/release info in assembler file
  -A<x>  Output format:
      -Adefault  Use default assembler
      -Aas       Unix o-file using GNU AS
      -Agas      GNU Motorola assembler
      -Amit      MIT Syntax (old GAS)
      -Amot      Standard Motorola assembler
*** press enter ***
(...)
root@mama:~#

The offending binary can be found here:

https://people.debian.org/~glaubitz/ppc68k

fpc for m68k can be built on Debian with:

$ apt build-dep fpc
$ BINUTILSPREFIX=m68k-linux-gnu- make crossall crossinstall CPU_TARGET=m68k OS_TARGET=linux FPC=/usr/lib/fpc/3.0.0/ppcx64 INSTALL_PREFIX=/root/fpc-m68k/
$ BINUTILSPREFIX=m68k-linux-gnu- make compiler CPU_TARGET=m68k OS_TARGET=linux FPC=/root/fpc-m68k/lib/fpc/3.1.1/ppcross68k CROSSOPT="-Fu/root/fpc-m68k/lib/fpc/3.1.1/units/*"
vivier commented 7 years ago

Could you run the binary with logs: QEMU_LOG_FILENAME=qemu.log QEMU_LOG=in_asm,op,unimp ./usr/lib/fpc/3.1.1/ppc68k and attach the resulting file qemu.log?

glaubitz commented 7 years ago

I don't know how to attach files to a github issue, so here's the link:

https://people.debian.org/~glaubitz/qemu-ppc68k.log

vivier commented 7 years ago

"rtd" is not implemented:

Illegal instruction: 4e74 @ 800071e2---------------- IN: 0x800071d8: movel %fp@(-12),%d0 0x800071dc: movel %fp@(-16),%d2 0x800071e0: unlk %fp 0x800071e2: rtd #4

I prepare a fix.

glaubitz commented 7 years ago

Great. Then I can fully bootstrap fpc ;).

vivier commented 7 years ago

Could you try the attached patch. rtd.txt

glaubitz commented 7 years ago

Works:

(sid-m68k-sbuild)root@ikarus:/# ./ppc68k 
Free Pascal Compiler version 3.1.1 [2017/05/28] for m68k
Copyright (c) 1993-2017 by Florian Klaempfl and others
/ppc68k [options] <inputfile> [options]
 Put + after a boolean switch option to enable it, - to disable it.
  @<x>   Read compiler options from <x> in addition to the default fpc.cfg
  -a     The compiler does not delete the generated assembler file
      -a5        Don't generate Big Obj COFF files for GNU Binutils older than 2.25 (Windows, NativeNT)
      -al        List sourcecode lines in assembler file
      -an        List node info in assembler file (-dEXTDEBUG compiler)
      -ao        Add an extra option to external assembler call (ignored for internal)                                                                                                       
      -ap        Use pipes instead of creating temporary assembler files                                                                                                                     
      -ar        List register allocation/release info in assembler file                                                                                                                     
      -at        List temp allocation/release info in assembler file                                                                                                                         
  -A<x>  Output format:                                                                                                                                                                      
      -Adefault  Use default assembler                                                                                                                                                       
      -Aas       Unix o-file using GNU AS                                                                                                                                                    
      -Agas      GNU Motorola assembler                                                                                                                                                      
      -Amit      MIT Syntax (old GAS)                                                                                                                                                        
      -Amot      Standard Motorola assembler                                                                                                                                                 
*** press enter ***                                                                                                                                                                          
(...)                                                                                                                                                             
(sid-m68k-sbuild)root@ikarus:/#
muller-sourceware-org commented 7 years ago

Hi,

I also needed to manually apply the patch above to be able to run any Free Pascal executable compiled for m68k-linux.

Did you commit this fix to github, and, if yes, to which branch?

Pierre Muller member of the Free Pascal Core development team

vivier commented 7 years ago

This fix can be found on the master branch of QEMU repo as it has been merged. You can also find it in my m68k-dev branch (with a more complete m68k FPU emulation)

glaubitz commented 6 years ago

FPC has been building fine for a while now:

https://buildd.debian.org/status/logs.php?pkg=fpc&arch=m68k

We can therefore close this issue.