Port-amiga archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Patches to fix building m68k with CPUFLAGS



A few notes that I replied to John Klos that I thought might be
interesting to others:

I'm using FS-UAE, and yes, A2065 emulation is very poor and I've
seen it cause the emulator to silently quit when I FTP a big file.
That's actually high on my priority list of bugs to investigate right
now. I even found a "LanceTest" program for AmigaOS on Aminet that I'm
looking to use to see if that might help flush out the emulated bugs
(when I run the diags, it passes the RAM test, but fails the next
check). Good fun opportunity to play with Ghidra and this guy's Amiga
hunk loader plugin for it (YouTube does very nice Russian->English
realtime captions): https://youtu.be/1iEQD4CEcuE

Because I'm just trying to get through an "atf-test" run without the
kernel panicking, I haven't needed to worry about the buggy Ethernet
emulation just yet.

I'm going to try building with GCC 7 and the newer binutils and see
what happens. I've also been hoping to backport Bernd Schmidt's "cc0
to mode_cc" patches for the m68k backend to the GCC 8 in the NetBSD
tree: https://gcc.gnu.org/legacy-ml/gcc-patches/2019-11/msg01028.html

I looked at the "cc0" stuff a few years ago, for the VAX backend, and
it's an obsolete, confusing, buggy, and deprecated way of handling
condition flags. m68k and VAX are two backends that were slated for
deprecation and eventual removal because of CC0, so I'm very happy
that an expert has fixed the m68k backend, at least. I haven't pushed
my work in progress on that yet, because I'm getting duplicate symbols
in the generated asm code, right next to each other, when it tries to
build strstream.cc. Not sure what I did wrong there, yet.

One more note on the "libgcc/config/m68k/lb1sf68.S" patches (to gcc
and gcc.old): only the second of the two lines needs to be patched
(the first of the two lines that I changed, in each file, is only for
"__uClinux__", so that first change doesn't need to be there). Like I
said, I'm not sure if the 16-bit relocations that get generated for
"bra     \addr@PLTPC" that the binutils linker can't deal with are
handled properly on uClinux, but I'm guessing that they are handled
properly, because uClinux seems to have some special cases for their
calling conventions and linking. The reason you only see a failure
here with CPUFLAGS set is because, I suspect, "defined (__mcoldfire__)
&& !defined (__mcfisab__)" must be defined in the default
configuration, and not if you use, e.g. "-m68040" or "-m68020-60"
(which should be the ideal default build flag for targets like Atari
ST and Amiga).

Cheers,
Jake

On Sun, Jul 19, 2020 at 10:38 AM Jake Hamby <jake.hamby%gmail.com@localhost> wrote:
>
> Oops, I meant "changes to *not* add CPUFLAGS to AFLAGS (for m68k). At
> least it looks like Gmail didn't word wrap my patches, but it did word
> wrap the text I put at the top (because I tried to add my own line
> breaks, something I won't do this time).
>
> BTW, here's the GitHub repo where I'm keeping my local fork of the
> src. I didn't want to deal with CVS, and this is a nice way to avoid
> doing so. https://github.com/jhamby/netbsd-src
>
> Best regards,
> Jake
>
> On Sun, Jul 19, 2020 at 10:35 AM Jake Hamby <jake.hamby%gmail.com@localhost> wrote:
> >
> > Hi all,
> >
> > I've been spending some time getting reacquainted with NetBSD/amiga, thanks to
> > emulation, and I just fixed some annoying bugs that were preventing anyone from
> > setting CPUFLAGS in their NetBSD build (e.g. to optimize for m68060 or m68040.
> > I also switched my build to use GCC 8.4.0 and binutils 2.34.
> >
> > The biggest problem with CPUFLAGS had to do with a whitespace bug in
> > external/gpl3/gcc/dist/gcc/config/m68k/m68k.h (and in "gcc.old"),
> > which is the last
> > patch in the email. The bug is still in GCC, so the fix can be
> > upstreamed right away.
> > The changes to now add CPUFLAGS to AFLAGS are because GAS doesn't
> > recognize, e.g. "-m68020-60", so we can't ever pass CPUFLAGS directly (on m68k).
> >
> > The patch to libgcc/config/m68k/lb1sf68.S (in gcc and gcc.old) is
> > because otherwise
> > the linker fails trying to handle unsupported 16-bit relocations. I'm
> > not sure if wrapping
> > the unworking code with !defined("__ELF__") is the correct fix, or if
> > this is a bug
> > that's specific to NetBSD. Either way, it got me past the build break.
> >
> > As for switching to the new GCC and binutils, I'm still testing that.
> > I'm seeing some
> > kernel panics in UVM, but I think they may be related to instability
> > in NetBSD-current.
> > I'll have to build a kernel with GCC 7 and compare, and also with the
> > older binutils.
> > I wanted to email the list with the patches I have so far, since I
> > know a lot of people
> > are blocked from making builds for their 68060 or 68040 because CPUFLAGS
> > has been broken on m68k. If the mailing list breaks any of the patches, I also
> > put a PR at: https://github.com/NetBSD/src/pull/13
> >
> > I'll delete the GitHub PR after the patches get merged. Thanks for reviewing!
> >
> > Subject: [PATCH 1/2] Switch m68k to new GCC and binutils, fix CPUFLAGS.
> >
> > - Change m68k build to use GCC 8.4.0 and binutils 2.34.
> > - Update binutils config files to define TARGET_BYTES_BIG_ENDIAN.
> > - Fix libgcc/config/m68k/lb1sf68.S to work around linker error
> >   when using CPUFLAGS (normally masked by default CPU options).
> > - Don't add CPUFLAGS to AFLAGS, to fix several build failures:
> >   - Amiga kernel locore.s uses opcodes not present in 68040/060
> >   - Amiga bootblocks use custom make rule that calls gas directly,
> >     and gas doesn't understand all m68k CPUFLAGS recognized by GCC.
> >   - m68060 kernel support package also doesn't like CPUFLAGS.
> > ---
> >  external/gpl3/binutils.old/usr.bin/gas/arch/m68k/config.h | 2 +-
> >  external/gpl3/binutils/usr.bin/gas/arch/m68k/config.h     | 2 +-
> >  external/gpl3/gcc.old/dist/libgcc/config/m68k/lb1sf68.S   | 4 ++--
> >  external/gpl3/gcc/dist/libgcc/config/m68k/lb1sf68.S       | 4 ++--
> >  share/mk/bsd.own.mk                                       | 5 +----
> >  share/mk/bsd.sys.mk                                       | 4 ++++
> >  6 files changed, 11 insertions(+), 10 deletions(-)
> >
> > diff --git a/external/gpl3/binutils.old/usr.bin/gas/arch/m68k/config.h
> > b/external/gpl3/binutils.old/usr.bin/gas/arch/m68k/config.h
> > index 63afe83d1be4..181f0bbe08fc 100644
> > --- a/external/gpl3/binutils.old/usr.bin/gas/arch/m68k/config.h
> > +++ b/external/gpl3/binutils.old/usr.bin/gas/arch/m68k/config.h
> > @@ -298,7 +298,7 @@
> >  #define TARGET_ALIAS "m68k--netbsdelf"
> >
> >  /* Define as 1 if big endian. */
> > -/* #undef TARGET_BYTES_BIG_ENDIAN */
> > +#define TARGET_BYTES_BIG_ENDIAN 1
> >
> >  /* Canonical target. */
> >  #define TARGET_CANONICAL "m68k--netbsdelf"
> > diff --git a/external/gpl3/binutils/usr.bin/gas/arch/m68k/config.h
> > b/external/gpl3/binutils/usr.bin/gas/arch/m68k/config.h
> > index eddab29535cb..c4087fdff09c 100644
> > --- a/external/gpl3/binutils/usr.bin/gas/arch/m68k/config.h
> > +++ b/external/gpl3/binutils/usr.bin/gas/arch/m68k/config.h
> > @@ -317,7 +317,7 @@
> >  #define TARGET_ALIAS "m68k--netbsdelf"
> >
> >  /* Define as 1 if big endian. */
> > -/* #undef TARGET_BYTES_BIG_ENDIAN */
> > +#define TARGET_BYTES_BIG_ENDIAN 1
> >
> >  /* Canonical target. */
> >  #define TARGET_CANONICAL "m68k--netbsdelf"
> > diff --git a/external/gpl3/gcc.old/dist/libgcc/config/m68k/lb1sf68.S
> > b/external/gpl3/gcc.old/dist/libgcc/config/m68k/lb1sf68.S
> > index 0c367428ceff..472f4d94a9da 100644
> > --- a/external/gpl3/gcc.old/dist/libgcc/config/m68k/lb1sf68.S
> > +++ b/external/gpl3/gcc.old/dist/libgcc/config/m68k/lb1sf68.S
> > @@ -172,7 +172,7 @@ see the files COPYING3 and COPYING.RUNTIME
> > respectively.  If not, see
> >   /* ISA C has no bra.l instruction, and since this assembly file
> >     gets assembled into multiple object files, we avoid the
> >     bra instruction entirely.  */
> > -#if defined (__mcoldfire__) && !defined (__mcfisab__)
> > +#if defined (__ELF__) || (defined (__mcoldfire__) && !defined (__mcfisab__))
> >   lea \addr-.-8,a0
> >   jmp pc@(a0)
> >  #else
> > @@ -211,7 +211,7 @@ see the files COPYING3 and COPYING.RUNTIME
> > respectively.  If not, see
> >   /* ISA C has no bra.l instruction, and since this assembly file
> >     gets assembled into multiple object files, we avoid the
> >     bra instruction entirely.  */
> > -#if defined (__mcoldfire__) && !defined (__mcfisab__)
> > +#if defined (__ELF__) || (defined (__mcoldfire__) && !defined (__mcfisab__))
> >   lea \addr-.-8,a0
> >   jmp pc@(a0)
> >  #else
> > diff --git a/external/gpl3/gcc/dist/libgcc/config/m68k/lb1sf68.S
> > b/external/gpl3/gcc/dist/libgcc/config/m68k/lb1sf68.S
> > index 3784f4323961..2b3ff490a2a1 100644
> > --- a/external/gpl3/gcc/dist/libgcc/config/m68k/lb1sf68.S
> > +++ b/external/gpl3/gcc/dist/libgcc/config/m68k/lb1sf68.S
> > @@ -172,7 +172,7 @@ see the files COPYING3 and COPYING.RUNTIME
> > respectively.  If not, see
> >   /* ISA C has no bra.l instruction, and since this assembly file
> >     gets assembled into multiple object files, we avoid the
> >     bra instruction entirely.  */
> > -#if defined (__mcoldfire__) && !defined (__mcfisab__)
> > +#if defined (__ELF__) || (defined (__mcoldfire__) && !defined (__mcfisab__))
> >   lea \addr-.-8,a0
> >   jmp pc@(a0)
> >  #else
> > @@ -211,7 +211,7 @@ see the files COPYING3 and COPYING.RUNTIME
> > respectively.  If not, see
> >   /* ISA C has no bra.l instruction, and since this assembly file
> >     gets assembled into multiple object files, we avoid the
> >     bra instruction entirely.  */
> > -#if defined (__mcoldfire__) && !defined (__mcfisab__)
> > +#if defined (__ELF__) || (defined (__mcoldfire__) && !defined (__mcfisab__))
> >   lea \addr-.-8,a0
> >   jmp pc@(a0)
> >  #else
> > diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk
> > index 3d4850e22e52..efaadde72aaa 100644
> > --- a/share/mk/bsd.own.mk
> > +++ b/share/mk/bsd.own.mk
> > @@ -63,9 +63,6 @@ TOOLCHAIN_MISSING?= no
> >  #
> >  # What GCC is used?
> >  #
> > -.if ${MACHINE_CPU} == "m68k"
> > -HAVE_GCC?= 7
> > -.endif
> >  HAVE_GCC?= 8
> >
> >  #
> > @@ -163,7 +160,7 @@ EXTERNAL_GDB_SUBDIR= /does/not/exist
> >      ${MACHINE_ARCH} == "powerpc64" || ${MACHINE_ARCH} == "powerpc" || \
> >      ${MACHINE_CPU} == "aarch64" || ${MACHINE_CPU} == "arm" || \
> >      ${MACHINE_ARCH} == "hppa" || ${MACHINE_ARCH} == "sparc64" || \
> > -    ${MACHINE} == "sun2" || ${MACHINE} == "alpha"
> > +    ${MACHINE_CPU} == "m68k" || ${MACHINE} == "alpha"
> >  HAVE_BINUTILS?= 234
> >  .else
> >  HAVE_BINUTILS?= 231
> > diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk
> > index 758ab3485d4a..ba7f0f4d3cbc 100644
> > --- a/share/mk/bsd.sys.mk
> > +++ b/share/mk/bsd.sys.mk
> > @@ -234,7 +234,11 @@ CPUFLAGS+= -Wa,--fatal-warnings
> >  #CPUFLAGS+= -mno-abicalls -fno-PIC
> >  #.endif
> >  CFLAGS+= ${CPUFLAGS}
> > +
> > +# GNU assembler doesn't like some m68k flags, esp. for kernel locore.s, etc.
> > +.if ${MACHINE_CPU} != "m68k"
> >  AFLAGS+= ${CPUFLAGS}
> > +.endif
> >
> >  .if ${KCOV:U0} > 0
> >  KCOVFLAGS= -fsanitize-coverage=trace-pc,trace-cmp
> >
> > Subject: [PATCH 2/2] Insert missing whitespace for assembler flag rules.
> >
> > Fixes assembler errors like "unrecognized option -m68040-mcpu=68040".
> > ---
> >  external/gpl3/gcc/dist/gcc/config/m68k/m68k.h | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/external/gpl3/gcc/dist/gcc/config/m68k/m68k.h
> > b/external/gpl3/gcc/dist/gcc/config/m68k/m68k.h
> > index 506fa4e50e76..8c688a4156cc 100644
> > --- a/external/gpl3/gcc/dist/gcc/config/m68k/m68k.h
> > +++ b/external/gpl3/gcc/dist/gcc/config/m68k/m68k.h
> > @@ -36,9 +36,9 @@ along with GCC; see the file COPYING3.  If not see
> >     and .arch directives.  */
> >
> >  #define ASM_CPU_SPEC "\
> > -%{m68851}%{mno-68851} %{m68881}%{mno-68881} %{msoft-float:-mno-float} \
> > -%{m68020-40:-m68040}%{m68020-60:-m68040}\
> > -%{mcpu=*:-mcpu=%*}%{march=*:-march=%*}\
> > + %{m68851} %{mno-68851} %{m68881} %{mno-68881} %{msoft-float:-mno-float}\
> > + %{m68020-40:-m68040} %{m68020-60:-m68040}\
> > + %{mcpu=*:-mcpu=%*} %{march=*:-march=%*}\
> >  "
> >  #define ASM_PCREL_SPEC "%{" FPIE_OR_FPIC_SPEC ":--pcrel} \
> >   %{mpcrel:%{" NO_FPIE_AND_FPIC_SPEC ":--pcrel}} \


Home | Main Index | Thread Index | Old Index