Message ID | ZRk3icxnMM2sCKLk@waldemar-brodkorb.de |
---|---|
State | Accepted |
Headers | show |
Series | [v2] package/glibc: enable for m68k with MMU | expand |
Hello Waldemar, Le 01/10/2023 à 11:10, Waldemar Brodkorb a écrit : > For qemu-system-m68k with emulates Q800 machine we need to add patches > for glibc to let it compile and run on m68k cpu m68040. > See here for discussions about the issue: > https://sourceware.org/bugzilla/show_bug.cgi?id=30740 > Thank you for your quick reply! Here is my test result: Welcome to Buildroot buildroot login: root # uname -a Linux buildroot 6.1.44 #1 Sun Oct 1 12:23:12 CEST 2023 m68k GNU/Linux > Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> > --- > v1 -> v2: > - refresh patches from glibc git, requested by Romain Naour > --- > ...d-with-mcpu-68040-or-higher-BZ-30740.patch | 57 ++++++++++++ > ...shift-and-__mpn_rshift-for-non-68020.patch | 47 ++++++++++ > ...ALE_AVAILABLE-on-__mpn_lshift-and-__.patch | 93 +++++++++++++++++++ > package/glibc/Config.in | 1 + > 4 files changed, 198 insertions(+) > create mode 100644 package/glibc/0001-m68k-Fix-build-with-mcpu-68040-or-higher-BZ-30740.patch > create mode 100644 package/glibc/0002-m68k-fix-__mpn_lshift-and-__mpn_rshift-for-non-68020.patch > create mode 100644 package/glibc/0003-m68k-Use-M68K_SCALE_AVAILABLE-on-__mpn_lshift-and-__.patch > > diff --git a/package/glibc/0001-m68k-Fix-build-with-mcpu-68040-or-higher-BZ-30740.patch b/package/glibc/0001-m68k-Fix-build-with-mcpu-68040-or-higher-BZ-30740.patch > new file mode 100644 > index 0000000000..61f48e5893 > --- /dev/null > +++ b/package/glibc/0001-m68k-Fix-build-with-mcpu-68040-or-higher-BZ-30740.patch > @@ -0,0 +1,57 @@ > +From b85880633f69b737050c22eede858f8c13bb2248 Mon Sep 17 00:00:00 2001 > +From: Adhemerval Zanella <adhemerval.zanella@linaro.org> > +Date: Fri, 18 Aug 2023 14:59:51 -0300 > +Subject: [PATCH] m68k: Fix build with -mcpu=68040 or higher (BZ 30740) > + > +GCC currently does not define __mc68020__ for -mcpu=68040 or higher, > +which memcpy/memmove assumptions. Since this memory copy optimization > +seems only intended for m68020, disable for other m680X0 variants. > + > +Checked on a build for m68k-linux-gnu target mc68020 and mc68040. > + > +Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> > +Upstream: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b85880633f69b737050c22eede858f8c13bb2248 We usually add the Upstream tag above the SoB line. (can be fixed while applying) > +--- > + sysdeps/m68k/m680x0/m68020/wordcopy.S | 1 - > + sysdeps/m68k/wordcopy.c | 21 +++++++++++++++++++++ > + 2 files changed, 21 insertions(+), 1 deletion(-) > + delete mode 100644 sysdeps/m68k/m680x0/m68020/wordcopy.S > + create mode 100644 sysdeps/m68k/wordcopy.c > + > +diff --git a/sysdeps/m68k/m680x0/m68020/wordcopy.S b/sysdeps/m68k/m680x0/m68020/wordcopy.S > +deleted file mode 100644 > +index 4fb1a4518f..0000000000 > +--- a/sysdeps/m68k/m680x0/m68020/wordcopy.S > ++++ /dev/null > +@@ -1 +0,0 @@ > +-/* Empty, not needed. */ > +diff --git a/sysdeps/m68k/wordcopy.c b/sysdeps/m68k/wordcopy.c > +new file mode 100644 > +index 0000000000..f12d5b7803 > +--- /dev/null > ++++ b/sysdeps/m68k/wordcopy.c > +@@ -0,0 +1,21 @@ > ++/* Definitions for memory copy functions. Motorola 680X0 version > ++ Copyright (C) 2023 Free Software Foundation, Inc. > ++ This file is part of the GNU C Library. > ++ > ++ The GNU C Library is free software; you can redistribute it and/or > ++ modify it under the terms of the GNU Lesser General Public > ++ License as published by the Free Software Foundation; either > ++ version 2.1 of the License, or (at your option) any later version. > ++ > ++ The GNU C Library is distributed in the hope that it will be useful, > ++ but WITHOUT ANY WARRANTY; without even the implied warranty of > ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > ++ Lesser General Public License for more details. > ++ > ++ You should have received a copy of the GNU Lesser General Public > ++ License along with the GNU C Library. If not, see > ++ <https://www.gnu.org/licenses/>. */ > ++ > ++#ifndef __mc68020__ > ++# include <string/wordcopy.c> > ++#endif > +-- > +2.39.2 > + > diff --git a/package/glibc/0002-m68k-fix-__mpn_lshift-and-__mpn_rshift-for-non-68020.patch b/package/glibc/0002-m68k-fix-__mpn_lshift-and-__mpn_rshift-for-non-68020.patch > new file mode 100644 > index 0000000000..256da58d66 > --- /dev/null > +++ b/package/glibc/0002-m68k-fix-__mpn_lshift-and-__mpn_rshift-for-non-68020.patch > @@ -0,0 +1,47 @@ > +From 464fd8249e8b791248cab7b0e0cd91757435fa9e Mon Sep 17 00:00:00 2001 > +From: Andreas Schwab <schwab@linux-m68k.org> > +Date: Thu, 17 Aug 2023 17:15:34 +0200 > +Subject: [PATCH] m68k: fix __mpn_lshift and __mpn_rshift for non-68020 > + > +From revision 03f3d275d0d6 in the gmp repository. > + > +Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> > +Upstream: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=464fd8249e8b791248cab7b0e0cd91757435fa9e > +--- > + sysdeps/m68k/m680x0/lshift.S | 4 ++-- > + sysdeps/m68k/m680x0/rshift.S | 4 ++-- > + 2 files changed, 4 insertions(+), 4 deletions(-) > + > +diff --git a/sysdeps/m68k/m680x0/lshift.S b/sysdeps/m68k/m680x0/lshift.S > +index 2aee10348e..4240738959 100644 > +--- a/sysdeps/m68k/m680x0/lshift.S > ++++ b/sysdeps/m68k/m680x0/lshift.S > +@@ -77,8 +77,8 @@ L(Lnormal:) > + #else /* not mc68000 */ > + movel R(s_size),R(d0) > + asll #2,R(d0) > +- addl R(s_size),R(s_ptr) > +- addl R(s_size),R(res_ptr) > ++ addl R(d0),R(s_ptr) > ++ addl R(d0),R(res_ptr) > + #endif > + movel MEM_PREDEC(s_ptr),R(d2) > + movel R(d2),R(d0) > +diff --git a/sysdeps/m68k/m680x0/rshift.S b/sysdeps/m68k/m680x0/rshift.S > +index d16bca9307..d56a2b4a44 100644 > +--- a/sysdeps/m68k/m680x0/rshift.S > ++++ b/sysdeps/m68k/m680x0/rshift.S > +@@ -127,8 +127,8 @@ L(Lspecial:) > + #else /* not mc68000 */ > + movel R(s_size),R(d0) > + asll #2,R(d0) > +- addl R(s_size),R(s_ptr) > +- addl R(s_size),R(res_ptr) > ++ addl R(d0),R(s_ptr) > ++ addl R(d0),R(res_ptr) > + #endif > + > + clrl R(d0) /* initialize carry */ > +-- > +2.39.2 > + > diff --git a/package/glibc/0003-m68k-Use-M68K_SCALE_AVAILABLE-on-__mpn_lshift-and-__.patch b/package/glibc/0003-m68k-Use-M68K_SCALE_AVAILABLE-on-__mpn_lshift-and-__.patch > new file mode 100644 > index 0000000000..2ea190eb5a > --- /dev/null > +++ b/package/glibc/0003-m68k-Use-M68K_SCALE_AVAILABLE-on-__mpn_lshift-and-__.patch > @@ -0,0 +1,93 @@ > +From 87ced255bdf2681f5bf6c89d7121e59f6f342161 Mon Sep 17 00:00:00 2001 > +From: Adhemerval Zanella <adhemerval.zanella@linaro.org> > +Date: Fri, 18 Aug 2023 14:49:31 -0300 > +Subject: [PATCH] m68k: Use M68K_SCALE_AVAILABLE on __mpn_lshift and > + __mpn_rshift > + > +This patch adds a new macro, M68K_SCALE_AVAILABLE, similar to gmp > +scale_available_p (mpn/m68k/m68k-defs.m4) that expand to 1 if a > +scale factor can be used in addressing modes. This is used > +instead of __mc68020__ for some optimization decisions. > + > +Checked on a build for m68k-linux-gnu target mc68020 and mc68040. > + > +Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> > +Upstream: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=87ced255bdf2681f5bf6c89d7121e59f6f342161 > +--- > + sysdeps/m68k/m680x0/lshift.S | 6 +++--- > + sysdeps/m68k/m680x0/rshift.S | 8 ++++---- > + sysdeps/m68k/m680x0/sysdep.h | 7 +++++++ > + 3 files changed, 14 insertions(+), 7 deletions(-) > + > +diff --git a/sysdeps/m68k/m680x0/lshift.S b/sysdeps/m68k/m680x0/lshift.S > +index 4240738959..74de90380b 100644 > +--- a/sysdeps/m68k/m680x0/lshift.S > ++++ b/sysdeps/m68k/m680x0/lshift.S > +@@ -57,9 +57,9 @@ ENTRY(__mpn_lshift) > + bne L(Lnormal) > + cmpl R(s_ptr),R(res_ptr) > + bls L(Lspecial) /* jump if s_ptr >= res_ptr */ > +-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) > ++#if M68K_SCALE_AVAILABLE > + lea MEM_INDX1(s_ptr,s_size,l,4),R(a2) > +-#else /* not mc68020 */ > ++#else > + movel R(s_size),R(d0) > + asll #2,R(d0) > + lea MEM_INDX(s_ptr,d0,l),R(a2) > +@@ -71,7 +71,7 @@ L(Lnormal:) > + moveql #32,R(d5) > + subl R(cnt),R(d5) > + > +-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) > ++#if M68K_SCALE_AVAILABLE > + lea MEM_INDX1(s_ptr,s_size,l,4),R(s_ptr) > + lea MEM_INDX1(res_ptr,s_size,l,4),R(res_ptr) > + #else /* not mc68000 */ > +diff --git a/sysdeps/m68k/m680x0/rshift.S b/sysdeps/m68k/m680x0/rshift.S > +index d56a2b4a44..d398d0287e 100644 > +--- a/sysdeps/m68k/m680x0/rshift.S > ++++ b/sysdeps/m68k/m680x0/rshift.S > +@@ -56,9 +56,9 @@ ENTRY(__mpn_rshift) > + bne L(Lnormal) > + cmpl R(res_ptr),R(s_ptr) > + bls L(Lspecial) /* jump if res_ptr >= s_ptr */ > +-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) > ++#if M68K_SCALE_AVAILABLE > + lea MEM_INDX1(res_ptr,s_size,l,4),R(a2) > +-#else /* not mc68020 */ > ++#else > + movel R(s_size),R(d0) > + asll #2,R(d0) > + lea MEM_INDX(res_ptr,d0,l),R(a2) > +@@ -121,10 +121,10 @@ L(Lend:) > + > + cfi_restore_state > + L(Lspecial:) > +-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) > ++#if M68K_SCALE_AVAILABLE > + lea MEM_INDX1(s_ptr,s_size,l,4),R(s_ptr) > + lea MEM_INDX1(res_ptr,s_size,l,4),R(res_ptr) > +-#else /* not mc68000 */ > ++#else > + movel R(s_size),R(d0) > + asll #2,R(d0) > + addl R(d0),R(s_ptr) > +diff --git a/sysdeps/m68k/m680x0/sysdep.h b/sysdeps/m68k/m680x0/sysdep.h > +index b31e101273..bee5b3391c 100644 > +--- a/sysdeps/m68k/m680x0/sysdep.h > ++++ b/sysdeps/m68k/m680x0/sysdep.h > +@@ -37,3 +37,10 @@ > + OP " " SRC "(" PC "), " DST > + > + #endif /* __ASSEMBLER__ */ > ++ > ++# if defined __mc68020__ || defined __mc68030__ || defined __mc68040__ \ > ++ || defined __mc68060__ > ++# define M68K_SCALE_AVAILABLE 1 > ++# else > ++# define M68K_SCALE_AVAILABLE 0 > ++# endif > +-- > +2.39.2 > + > diff --git a/package/glibc/Config.in b/package/glibc/Config.in > index d894507b89..81c64083f4 100644 > --- a/package/glibc/Config.in > +++ b/package/glibc/Config.in > @@ -5,6 +5,7 @@ config BR2_PACKAGE_GLIBC_ARCH_SUPPORTS > default y if BR2_aarch64 > default y if BR2_aarch64_be > default y if BR2_i386 > + default y if BR2_m68k_m68k Note: With this patch applied, the qemu_m68k_q800_defconfig will new use glibc instead of uClibc-ng. Best regards, Romain > default y if BR2_mips > default y if BR2_mipsel > default y if BR2_mips64
Hello Waldemar, Le 01/10/2023 à 12:34, Romain Naour a écrit : > Hello Waldemar, > > Le 01/10/2023 à 11:10, Waldemar Brodkorb a écrit : >> For qemu-system-m68k with emulates Q800 machine we need to add patches >> for glibc to let it compile and run on m68k cpu m68040. >> See here for discussions about the issue: >> https://sourceware.org/bugzilla/show_bug.cgi?id=30740 >> > > Thank you for your quick reply! > > Here is my test result: > > Welcome to Buildroot > buildroot login: root > # uname -a > Linux buildroot 6.1.44 #1 Sun Oct 1 12:23:12 CEST 2023 m68k GNU/Linux Applied to master, thanks. Best regards, Romain > >> Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> >> --- >> v1 -> v2: >> - refresh patches from glibc git, requested by Romain Naour >> --- >> ...d-with-mcpu-68040-or-higher-BZ-30740.patch | 57 ++++++++++++ >> ...shift-and-__mpn_rshift-for-non-68020.patch | 47 ++++++++++ >> ...ALE_AVAILABLE-on-__mpn_lshift-and-__.patch | 93 +++++++++++++++++++ >> package/glibc/Config.in | 1 + >> 4 files changed, 198 insertions(+) >> create mode 100644 package/glibc/0001-m68k-Fix-build-with-mcpu-68040-or-higher-BZ-30740.patch >> create mode 100644 package/glibc/0002-m68k-fix-__mpn_lshift-and-__mpn_rshift-for-non-68020.patch >> create mode 100644 package/glibc/0003-m68k-Use-M68K_SCALE_AVAILABLE-on-__mpn_lshift-and-__.patch >> >> diff --git a/package/glibc/0001-m68k-Fix-build-with-mcpu-68040-or-higher-BZ-30740.patch b/package/glibc/0001-m68k-Fix-build-with-mcpu-68040-or-higher-BZ-30740.patch >> new file mode 100644 >> index 0000000000..61f48e5893 >> --- /dev/null >> +++ b/package/glibc/0001-m68k-Fix-build-with-mcpu-68040-or-higher-BZ-30740.patch >> @@ -0,0 +1,57 @@ >> +From b85880633f69b737050c22eede858f8c13bb2248 Mon Sep 17 00:00:00 2001 >> +From: Adhemerval Zanella <adhemerval.zanella@linaro.org> >> +Date: Fri, 18 Aug 2023 14:59:51 -0300 >> +Subject: [PATCH] m68k: Fix build with -mcpu=68040 or higher (BZ 30740) >> + >> +GCC currently does not define __mc68020__ for -mcpu=68040 or higher, >> +which memcpy/memmove assumptions. Since this memory copy optimization >> +seems only intended for m68020, disable for other m680X0 variants. >> + >> +Checked on a build for m68k-linux-gnu target mc68020 and mc68040. >> + >> +Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> >> +Upstream: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b85880633f69b737050c22eede858f8c13bb2248 > > We usually add the Upstream tag above the SoB line. (can be fixed while applying) > >> +--- >> + sysdeps/m68k/m680x0/m68020/wordcopy.S | 1 - >> + sysdeps/m68k/wordcopy.c | 21 +++++++++++++++++++++ >> + 2 files changed, 21 insertions(+), 1 deletion(-) >> + delete mode 100644 sysdeps/m68k/m680x0/m68020/wordcopy.S >> + create mode 100644 sysdeps/m68k/wordcopy.c >> + >> +diff --git a/sysdeps/m68k/m680x0/m68020/wordcopy.S b/sysdeps/m68k/m680x0/m68020/wordcopy.S >> +deleted file mode 100644 >> +index 4fb1a4518f..0000000000 >> +--- a/sysdeps/m68k/m680x0/m68020/wordcopy.S >> ++++ /dev/null >> +@@ -1 +0,0 @@ >> +-/* Empty, not needed. */ >> +diff --git a/sysdeps/m68k/wordcopy.c b/sysdeps/m68k/wordcopy.c >> +new file mode 100644 >> +index 0000000000..f12d5b7803 >> +--- /dev/null >> ++++ b/sysdeps/m68k/wordcopy.c >> +@@ -0,0 +1,21 @@ >> ++/* Definitions for memory copy functions. Motorola 680X0 version >> ++ Copyright (C) 2023 Free Software Foundation, Inc. >> ++ This file is part of the GNU C Library. >> ++ >> ++ The GNU C Library is free software; you can redistribute it and/or >> ++ modify it under the terms of the GNU Lesser General Public >> ++ License as published by the Free Software Foundation; either >> ++ version 2.1 of the License, or (at your option) any later version. >> ++ >> ++ The GNU C Library is distributed in the hope that it will be useful, >> ++ but WITHOUT ANY WARRANTY; without even the implied warranty of >> ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >> ++ Lesser General Public License for more details. >> ++ >> ++ You should have received a copy of the GNU Lesser General Public >> ++ License along with the GNU C Library. If not, see >> ++ <https://www.gnu.org/licenses/>. */ >> ++ >> ++#ifndef __mc68020__ >> ++# include <string/wordcopy.c> >> ++#endif >> +-- >> +2.39.2 >> + >> diff --git a/package/glibc/0002-m68k-fix-__mpn_lshift-and-__mpn_rshift-for-non-68020.patch b/package/glibc/0002-m68k-fix-__mpn_lshift-and-__mpn_rshift-for-non-68020.patch >> new file mode 100644 >> index 0000000000..256da58d66 >> --- /dev/null >> +++ b/package/glibc/0002-m68k-fix-__mpn_lshift-and-__mpn_rshift-for-non-68020.patch >> @@ -0,0 +1,47 @@ >> +From 464fd8249e8b791248cab7b0e0cd91757435fa9e Mon Sep 17 00:00:00 2001 >> +From: Andreas Schwab <schwab@linux-m68k.org> >> +Date: Thu, 17 Aug 2023 17:15:34 +0200 >> +Subject: [PATCH] m68k: fix __mpn_lshift and __mpn_rshift for non-68020 >> + >> +From revision 03f3d275d0d6 in the gmp repository. >> + >> +Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> >> +Upstream: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=464fd8249e8b791248cab7b0e0cd91757435fa9e >> +--- >> + sysdeps/m68k/m680x0/lshift.S | 4 ++-- >> + sysdeps/m68k/m680x0/rshift.S | 4 ++-- >> + 2 files changed, 4 insertions(+), 4 deletions(-) >> + >> +diff --git a/sysdeps/m68k/m680x0/lshift.S b/sysdeps/m68k/m680x0/lshift.S >> +index 2aee10348e..4240738959 100644 >> +--- a/sysdeps/m68k/m680x0/lshift.S >> ++++ b/sysdeps/m68k/m680x0/lshift.S >> +@@ -77,8 +77,8 @@ L(Lnormal:) >> + #else /* not mc68000 */ >> + movel R(s_size),R(d0) >> + asll #2,R(d0) >> +- addl R(s_size),R(s_ptr) >> +- addl R(s_size),R(res_ptr) >> ++ addl R(d0),R(s_ptr) >> ++ addl R(d0),R(res_ptr) >> + #endif >> + movel MEM_PREDEC(s_ptr),R(d2) >> + movel R(d2),R(d0) >> +diff --git a/sysdeps/m68k/m680x0/rshift.S b/sysdeps/m68k/m680x0/rshift.S >> +index d16bca9307..d56a2b4a44 100644 >> +--- a/sysdeps/m68k/m680x0/rshift.S >> ++++ b/sysdeps/m68k/m680x0/rshift.S >> +@@ -127,8 +127,8 @@ L(Lspecial:) >> + #else /* not mc68000 */ >> + movel R(s_size),R(d0) >> + asll #2,R(d0) >> +- addl R(s_size),R(s_ptr) >> +- addl R(s_size),R(res_ptr) >> ++ addl R(d0),R(s_ptr) >> ++ addl R(d0),R(res_ptr) >> + #endif >> + >> + clrl R(d0) /* initialize carry */ >> +-- >> +2.39.2 >> + >> diff --git a/package/glibc/0003-m68k-Use-M68K_SCALE_AVAILABLE-on-__mpn_lshift-and-__.patch b/package/glibc/0003-m68k-Use-M68K_SCALE_AVAILABLE-on-__mpn_lshift-and-__.patch >> new file mode 100644 >> index 0000000000..2ea190eb5a >> --- /dev/null >> +++ b/package/glibc/0003-m68k-Use-M68K_SCALE_AVAILABLE-on-__mpn_lshift-and-__.patch >> @@ -0,0 +1,93 @@ >> +From 87ced255bdf2681f5bf6c89d7121e59f6f342161 Mon Sep 17 00:00:00 2001 >> +From: Adhemerval Zanella <adhemerval.zanella@linaro.org> >> +Date: Fri, 18 Aug 2023 14:49:31 -0300 >> +Subject: [PATCH] m68k: Use M68K_SCALE_AVAILABLE on __mpn_lshift and >> + __mpn_rshift >> + >> +This patch adds a new macro, M68K_SCALE_AVAILABLE, similar to gmp >> +scale_available_p (mpn/m68k/m68k-defs.m4) that expand to 1 if a >> +scale factor can be used in addressing modes. This is used >> +instead of __mc68020__ for some optimization decisions. >> + >> +Checked on a build for m68k-linux-gnu target mc68020 and mc68040. >> + >> +Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> >> +Upstream: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=87ced255bdf2681f5bf6c89d7121e59f6f342161 >> +--- >> + sysdeps/m68k/m680x0/lshift.S | 6 +++--- >> + sysdeps/m68k/m680x0/rshift.S | 8 ++++---- >> + sysdeps/m68k/m680x0/sysdep.h | 7 +++++++ >> + 3 files changed, 14 insertions(+), 7 deletions(-) >> + >> +diff --git a/sysdeps/m68k/m680x0/lshift.S b/sysdeps/m68k/m680x0/lshift.S >> +index 4240738959..74de90380b 100644 >> +--- a/sysdeps/m68k/m680x0/lshift.S >> ++++ b/sysdeps/m68k/m680x0/lshift.S >> +@@ -57,9 +57,9 @@ ENTRY(__mpn_lshift) >> + bne L(Lnormal) >> + cmpl R(s_ptr),R(res_ptr) >> + bls L(Lspecial) /* jump if s_ptr >= res_ptr */ >> +-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) >> ++#if M68K_SCALE_AVAILABLE >> + lea MEM_INDX1(s_ptr,s_size,l,4),R(a2) >> +-#else /* not mc68020 */ >> ++#else >> + movel R(s_size),R(d0) >> + asll #2,R(d0) >> + lea MEM_INDX(s_ptr,d0,l),R(a2) >> +@@ -71,7 +71,7 @@ L(Lnormal:) >> + moveql #32,R(d5) >> + subl R(cnt),R(d5) >> + >> +-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) >> ++#if M68K_SCALE_AVAILABLE >> + lea MEM_INDX1(s_ptr,s_size,l,4),R(s_ptr) >> + lea MEM_INDX1(res_ptr,s_size,l,4),R(res_ptr) >> + #else /* not mc68000 */ >> +diff --git a/sysdeps/m68k/m680x0/rshift.S b/sysdeps/m68k/m680x0/rshift.S >> +index d56a2b4a44..d398d0287e 100644 >> +--- a/sysdeps/m68k/m680x0/rshift.S >> ++++ b/sysdeps/m68k/m680x0/rshift.S >> +@@ -56,9 +56,9 @@ ENTRY(__mpn_rshift) >> + bne L(Lnormal) >> + cmpl R(res_ptr),R(s_ptr) >> + bls L(Lspecial) /* jump if res_ptr >= s_ptr */ >> +-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) >> ++#if M68K_SCALE_AVAILABLE >> + lea MEM_INDX1(res_ptr,s_size,l,4),R(a2) >> +-#else /* not mc68020 */ >> ++#else >> + movel R(s_size),R(d0) >> + asll #2,R(d0) >> + lea MEM_INDX(res_ptr,d0,l),R(a2) >> +@@ -121,10 +121,10 @@ L(Lend:) >> + >> + cfi_restore_state >> + L(Lspecial:) >> +-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) >> ++#if M68K_SCALE_AVAILABLE >> + lea MEM_INDX1(s_ptr,s_size,l,4),R(s_ptr) >> + lea MEM_INDX1(res_ptr,s_size,l,4),R(res_ptr) >> +-#else /* not mc68000 */ >> ++#else >> + movel R(s_size),R(d0) >> + asll #2,R(d0) >> + addl R(d0),R(s_ptr) >> +diff --git a/sysdeps/m68k/m680x0/sysdep.h b/sysdeps/m68k/m680x0/sysdep.h >> +index b31e101273..bee5b3391c 100644 >> +--- a/sysdeps/m68k/m680x0/sysdep.h >> ++++ b/sysdeps/m68k/m680x0/sysdep.h >> +@@ -37,3 +37,10 @@ >> + OP " " SRC "(" PC "), " DST >> + >> + #endif /* __ASSEMBLER__ */ >> ++ >> ++# if defined __mc68020__ || defined __mc68030__ || defined __mc68040__ \ >> ++ || defined __mc68060__ >> ++# define M68K_SCALE_AVAILABLE 1 >> ++# else >> ++# define M68K_SCALE_AVAILABLE 0 >> ++# endif >> +-- >> +2.39.2 >> + >> diff --git a/package/glibc/Config.in b/package/glibc/Config.in >> index d894507b89..81c64083f4 100644 >> --- a/package/glibc/Config.in >> +++ b/package/glibc/Config.in >> @@ -5,6 +5,7 @@ config BR2_PACKAGE_GLIBC_ARCH_SUPPORTS >> default y if BR2_aarch64 >> default y if BR2_aarch64_be >> default y if BR2_i386 >> + default y if BR2_m68k_m68k > > Note: With this patch applied, the qemu_m68k_q800_defconfig will new use glibc > instead of uClibc-ng. > > Best regards, > Romain > > >> default y if BR2_mips >> default y if BR2_mipsel >> default y if BR2_mips64 >
diff --git a/package/glibc/0001-m68k-Fix-build-with-mcpu-68040-or-higher-BZ-30740.patch b/package/glibc/0001-m68k-Fix-build-with-mcpu-68040-or-higher-BZ-30740.patch new file mode 100644 index 0000000000..61f48e5893 --- /dev/null +++ b/package/glibc/0001-m68k-Fix-build-with-mcpu-68040-or-higher-BZ-30740.patch @@ -0,0 +1,57 @@ +From b85880633f69b737050c22eede858f8c13bb2248 Mon Sep 17 00:00:00 2001 +From: Adhemerval Zanella <adhemerval.zanella@linaro.org> +Date: Fri, 18 Aug 2023 14:59:51 -0300 +Subject: [PATCH] m68k: Fix build with -mcpu=68040 or higher (BZ 30740) + +GCC currently does not define __mc68020__ for -mcpu=68040 or higher, +which memcpy/memmove assumptions. Since this memory copy optimization +seems only intended for m68020, disable for other m680X0 variants. + +Checked on a build for m68k-linux-gnu target mc68020 and mc68040. + +Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> +Upstream: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b85880633f69b737050c22eede858f8c13bb2248 +--- + sysdeps/m68k/m680x0/m68020/wordcopy.S | 1 - + sysdeps/m68k/wordcopy.c | 21 +++++++++++++++++++++ + 2 files changed, 21 insertions(+), 1 deletion(-) + delete mode 100644 sysdeps/m68k/m680x0/m68020/wordcopy.S + create mode 100644 sysdeps/m68k/wordcopy.c + +diff --git a/sysdeps/m68k/m680x0/m68020/wordcopy.S b/sysdeps/m68k/m680x0/m68020/wordcopy.S +deleted file mode 100644 +index 4fb1a4518f..0000000000 +--- a/sysdeps/m68k/m680x0/m68020/wordcopy.S ++++ /dev/null +@@ -1 +0,0 @@ +-/* Empty, not needed. */ +diff --git a/sysdeps/m68k/wordcopy.c b/sysdeps/m68k/wordcopy.c +new file mode 100644 +index 0000000000..f12d5b7803 +--- /dev/null ++++ b/sysdeps/m68k/wordcopy.c +@@ -0,0 +1,21 @@ ++/* Definitions for memory copy functions. Motorola 680X0 version ++ Copyright (C) 2023 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library. If not, see ++ <https://www.gnu.org/licenses/>. */ ++ ++#ifndef __mc68020__ ++# include <string/wordcopy.c> ++#endif +-- +2.39.2 + diff --git a/package/glibc/0002-m68k-fix-__mpn_lshift-and-__mpn_rshift-for-non-68020.patch b/package/glibc/0002-m68k-fix-__mpn_lshift-and-__mpn_rshift-for-non-68020.patch new file mode 100644 index 0000000000..256da58d66 --- /dev/null +++ b/package/glibc/0002-m68k-fix-__mpn_lshift-and-__mpn_rshift-for-non-68020.patch @@ -0,0 +1,47 @@ +From 464fd8249e8b791248cab7b0e0cd91757435fa9e Mon Sep 17 00:00:00 2001 +From: Andreas Schwab <schwab@linux-m68k.org> +Date: Thu, 17 Aug 2023 17:15:34 +0200 +Subject: [PATCH] m68k: fix __mpn_lshift and __mpn_rshift for non-68020 + +From revision 03f3d275d0d6 in the gmp repository. + +Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> +Upstream: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=464fd8249e8b791248cab7b0e0cd91757435fa9e +--- + sysdeps/m68k/m680x0/lshift.S | 4 ++-- + sysdeps/m68k/m680x0/rshift.S | 4 ++-- + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/sysdeps/m68k/m680x0/lshift.S b/sysdeps/m68k/m680x0/lshift.S +index 2aee10348e..4240738959 100644 +--- a/sysdeps/m68k/m680x0/lshift.S ++++ b/sysdeps/m68k/m680x0/lshift.S +@@ -77,8 +77,8 @@ L(Lnormal:) + #else /* not mc68000 */ + movel R(s_size),R(d0) + asll #2,R(d0) +- addl R(s_size),R(s_ptr) +- addl R(s_size),R(res_ptr) ++ addl R(d0),R(s_ptr) ++ addl R(d0),R(res_ptr) + #endif + movel MEM_PREDEC(s_ptr),R(d2) + movel R(d2),R(d0) +diff --git a/sysdeps/m68k/m680x0/rshift.S b/sysdeps/m68k/m680x0/rshift.S +index d16bca9307..d56a2b4a44 100644 +--- a/sysdeps/m68k/m680x0/rshift.S ++++ b/sysdeps/m68k/m680x0/rshift.S +@@ -127,8 +127,8 @@ L(Lspecial:) + #else /* not mc68000 */ + movel R(s_size),R(d0) + asll #2,R(d0) +- addl R(s_size),R(s_ptr) +- addl R(s_size),R(res_ptr) ++ addl R(d0),R(s_ptr) ++ addl R(d0),R(res_ptr) + #endif + + clrl R(d0) /* initialize carry */ +-- +2.39.2 + diff --git a/package/glibc/0003-m68k-Use-M68K_SCALE_AVAILABLE-on-__mpn_lshift-and-__.patch b/package/glibc/0003-m68k-Use-M68K_SCALE_AVAILABLE-on-__mpn_lshift-and-__.patch new file mode 100644 index 0000000000..2ea190eb5a --- /dev/null +++ b/package/glibc/0003-m68k-Use-M68K_SCALE_AVAILABLE-on-__mpn_lshift-and-__.patch @@ -0,0 +1,93 @@ +From 87ced255bdf2681f5bf6c89d7121e59f6f342161 Mon Sep 17 00:00:00 2001 +From: Adhemerval Zanella <adhemerval.zanella@linaro.org> +Date: Fri, 18 Aug 2023 14:49:31 -0300 +Subject: [PATCH] m68k: Use M68K_SCALE_AVAILABLE on __mpn_lshift and + __mpn_rshift + +This patch adds a new macro, M68K_SCALE_AVAILABLE, similar to gmp +scale_available_p (mpn/m68k/m68k-defs.m4) that expand to 1 if a +scale factor can be used in addressing modes. This is used +instead of __mc68020__ for some optimization decisions. + +Checked on a build for m68k-linux-gnu target mc68020 and mc68040. + +Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> +Upstream: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=87ced255bdf2681f5bf6c89d7121e59f6f342161 +--- + sysdeps/m68k/m680x0/lshift.S | 6 +++--- + sysdeps/m68k/m680x0/rshift.S | 8 ++++---- + sysdeps/m68k/m680x0/sysdep.h | 7 +++++++ + 3 files changed, 14 insertions(+), 7 deletions(-) + +diff --git a/sysdeps/m68k/m680x0/lshift.S b/sysdeps/m68k/m680x0/lshift.S +index 4240738959..74de90380b 100644 +--- a/sysdeps/m68k/m680x0/lshift.S ++++ b/sysdeps/m68k/m680x0/lshift.S +@@ -57,9 +57,9 @@ ENTRY(__mpn_lshift) + bne L(Lnormal) + cmpl R(s_ptr),R(res_ptr) + bls L(Lspecial) /* jump if s_ptr >= res_ptr */ +-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) ++#if M68K_SCALE_AVAILABLE + lea MEM_INDX1(s_ptr,s_size,l,4),R(a2) +-#else /* not mc68020 */ ++#else + movel R(s_size),R(d0) + asll #2,R(d0) + lea MEM_INDX(s_ptr,d0,l),R(a2) +@@ -71,7 +71,7 @@ L(Lnormal:) + moveql #32,R(d5) + subl R(cnt),R(d5) + +-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) ++#if M68K_SCALE_AVAILABLE + lea MEM_INDX1(s_ptr,s_size,l,4),R(s_ptr) + lea MEM_INDX1(res_ptr,s_size,l,4),R(res_ptr) + #else /* not mc68000 */ +diff --git a/sysdeps/m68k/m680x0/rshift.S b/sysdeps/m68k/m680x0/rshift.S +index d56a2b4a44..d398d0287e 100644 +--- a/sysdeps/m68k/m680x0/rshift.S ++++ b/sysdeps/m68k/m680x0/rshift.S +@@ -56,9 +56,9 @@ ENTRY(__mpn_rshift) + bne L(Lnormal) + cmpl R(res_ptr),R(s_ptr) + bls L(Lspecial) /* jump if res_ptr >= s_ptr */ +-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) ++#if M68K_SCALE_AVAILABLE + lea MEM_INDX1(res_ptr,s_size,l,4),R(a2) +-#else /* not mc68020 */ ++#else + movel R(s_size),R(d0) + asll #2,R(d0) + lea MEM_INDX(res_ptr,d0,l),R(a2) +@@ -121,10 +121,10 @@ L(Lend:) + + cfi_restore_state + L(Lspecial:) +-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) ++#if M68K_SCALE_AVAILABLE + lea MEM_INDX1(s_ptr,s_size,l,4),R(s_ptr) + lea MEM_INDX1(res_ptr,s_size,l,4),R(res_ptr) +-#else /* not mc68000 */ ++#else + movel R(s_size),R(d0) + asll #2,R(d0) + addl R(d0),R(s_ptr) +diff --git a/sysdeps/m68k/m680x0/sysdep.h b/sysdeps/m68k/m680x0/sysdep.h +index b31e101273..bee5b3391c 100644 +--- a/sysdeps/m68k/m680x0/sysdep.h ++++ b/sysdeps/m68k/m680x0/sysdep.h +@@ -37,3 +37,10 @@ + OP " " SRC "(" PC "), " DST + + #endif /* __ASSEMBLER__ */ ++ ++# if defined __mc68020__ || defined __mc68030__ || defined __mc68040__ \ ++ || defined __mc68060__ ++# define M68K_SCALE_AVAILABLE 1 ++# else ++# define M68K_SCALE_AVAILABLE 0 ++# endif +-- +2.39.2 + diff --git a/package/glibc/Config.in b/package/glibc/Config.in index d894507b89..81c64083f4 100644 --- a/package/glibc/Config.in +++ b/package/glibc/Config.in @@ -5,6 +5,7 @@ config BR2_PACKAGE_GLIBC_ARCH_SUPPORTS default y if BR2_aarch64 default y if BR2_aarch64_be default y if BR2_i386 + default y if BR2_m68k_m68k default y if BR2_mips default y if BR2_mipsel default y if BR2_mips64
For qemu-system-m68k with emulates Q800 machine we need to add patches for glibc to let it compile and run on m68k cpu m68040. See here for discussions about the issue: https://sourceware.org/bugzilla/show_bug.cgi?id=30740 Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> --- v1 -> v2: - refresh patches from glibc git, requested by Romain Naour --- ...d-with-mcpu-68040-or-higher-BZ-30740.patch | 57 ++++++++++++ ...shift-and-__mpn_rshift-for-non-68020.patch | 47 ++++++++++ ...ALE_AVAILABLE-on-__mpn_lshift-and-__.patch | 93 +++++++++++++++++++ package/glibc/Config.in | 1 + 4 files changed, 198 insertions(+) create mode 100644 package/glibc/0001-m68k-Fix-build-with-mcpu-68040-or-higher-BZ-30740.patch create mode 100644 package/glibc/0002-m68k-fix-__mpn_lshift-and-__mpn_rshift-for-non-68020.patch create mode 100644 package/glibc/0003-m68k-Use-M68K_SCALE_AVAILABLE-on-__mpn_lshift-and-__.patch