All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] grub powerpc64 little-endian enablement
@ 2014-08-28 19:56 Paulo Flabiano Smorigo
  2014-08-28 19:56 ` [RFC PATCH 1/3] Add powerpc little-endian (ppc64le) flags Paulo Flabiano Smorigo
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Paulo Flabiano Smorigo @ 2014-08-28 19:56 UTC (permalink / raw)
  To: grub-devel; +Cc: Paulo Flabiano Smorigo

From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>

Hi,

At the beginning of the year we provide a patchset that enabled GRUB for
little-endian PowerPC. Our approach at the time was to build GRUB itself and
its tools in 64-bit little-endian. One of the reasons of build in 64-bit is
to avoid 32-bit dependencies in the distro and build a system entirely 64-bit.

This patchset was not welcomed at the time because it would bring a
high-maintainance-cost, without real gain since it could just be cross-compiled.

After that, Brent Baude, Vladmir (phcoder) and I started to work in a solution
that would cross-compile but without 32-bit dependencies. This patchset is the
result of this new approach. It's based on the work of Brent Baude, Vladimir
(phcoder), and Tomohiro.

It can be devided in two parts:

  1) Skip libgcc dependency just for ppc64el (patch 1 and 2);
  2) Check elf endianess and byteswap if necessary (patch 3);

The result is GRUB itself in 32-bit BE and its tools in 64-bit LE. This solution
satisfies the needs of the distros. I tested it in three different distros, in
both endianess and it's fine.

If thoses patches were accepted we will have an official solution. Nowadays,
distros are taking diffrent approachs. Some of then are using the original
solutions and others are using cross-compiler.

--
Paulo Flabiano Smorigo
IBM Linux Technology Center


Paulo Flabiano Smorigo (3):
  Add powerpc little-endian (ppc64le) flags
  Files reorganization and include some libgcc fuctions
  Suport for bi-endianess in elf file

 configure.ac                         |  17 ++++-
 grub-core/Makefile.am                |   2 +
 grub-core/Makefile.core.def          |   1 +
 grub-core/kern/elf.c                 |  60 +++++++++++++++-
 grub-core/kern/elfXX.c               |  73 ++++++++++++++++++++
 grub-core/kern/misc.c                | 107 ++++++++++++++++++++++++++++
 grub-core/kern/powerpc/compiler-rt.S | 130 +++++++++++++++++++++++++++++++++++
 include/grub/compiler.h              |  61 ++++++++++++++++
 include/grub/libgcc.h                |  67 ------------------
 9 files changed, 447 insertions(+), 71 deletions(-)
 create mode 100644 grub-core/kern/powerpc/compiler-rt.S

-- 
1.8.1.4



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [RFC PATCH 1/3] Add powerpc little-endian (ppc64le) flags
  2014-08-28 19:56 [RFC PATCH 0/3] grub powerpc64 little-endian enablement Paulo Flabiano Smorigo
@ 2014-08-28 19:56 ` Paulo Flabiano Smorigo
  2014-09-17 22:04   ` Paulo Flabiano Smorigo
  2014-08-28 19:56 ` [RFC PATCH 2/3] Files reorganization and include some libgcc fuctions Paulo Flabiano Smorigo
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Paulo Flabiano Smorigo @ 2014-08-28 19:56 UTC (permalink / raw)
  To: grub-devel; +Cc: Paulo Flabiano Smorigo

libgcc dependency was removed *just* for this target because
the distros that use ppc64el doesn't have 32-bit support on it.

* configure.ac: Add targets for powerpc64el and skip libgcc.
* Makefile.am: Likewise.
---
 configure.ac          | 17 +++++++++++++++--
 grub-core/Makefile.am |  2 ++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8888c2f..1364c8b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -119,6 +119,7 @@ if test "x$with_platform" = x; then
     x86_64-*) platform=pc ;;
     powerpc-*) platform=ieee1275 ;;
     powerpc64-*) platform=ieee1275 ;;
+    powerpc64le-*) platform=ieee1275 ;;
     sparc64-*) platform=ieee1275 ;;
     mipsel-*) platform=loongson ;;
     mips-*) platform=arc ;;
@@ -137,6 +138,7 @@ case "$target_cpu"-"$platform" in
   x86_64-xen) ;;
   x86_64-*) target_cpu=i386 ;;
   powerpc64-ieee1275) target_cpu=powerpc ;;
+  powerpc64le-ieee1275) target_cpu=powerpc ;;
 esac
 
 # Check if the platform is supported, make final adjustments.
@@ -581,6 +583,13 @@ if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
   TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
 fi
 
+if test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno; then
+	LD_FORCE_LE=1
+	TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian -DNO_LIBGCC=1"
+	TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
+	TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
+fi
+
 if test "x$target_m32" = x1; then
   # Force 32-bit mode.
   TARGET_CFLAGS="$TARGET_CFLAGS -m32"
@@ -1024,7 +1033,8 @@ else
 CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error"
 fi
 CPPFLAGS="$TARGET_CPPFLAGS"
-if test x$target_cpu = xi386 || test x$target_cpu = xx86_64 || test "x$grub_cv_cc_target_clang" = xyes ; then
+if test x$target_cpu = xi386 || test x$target_cpu = xx86_64 || test "x$grub_cv_cc_target_clang" = xyes \
+	|| ( test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno ); then
 TARGET_LIBGCC=
 else
 TARGET_LIBGCC=-lgcc
@@ -1608,7 +1618,9 @@ if test x"$enable_werror" != xno ; then
   HOST_CFLAGS="$HOST_CFLAGS -Werror"
 fi
 
-if test "x$grub_cv_cc_target_clang" = xno; then
+# if not clang or power LE, use static libgcc
+if test "x$grub_cv_cc_target_clang" = xno \
+   || ! ( test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno ); then
    TARGET_LDFLAGS_STATIC_LIBGCC="-static-libgcc"
 else
    TARGET_LDFLAGS_STATIC_LIBGCC=
@@ -1671,6 +1683,7 @@ AM_CONDITIONAL([COND_mips_arc], [test "(" x$target_cpu = xmips -o x$target_cpu =
 AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a x$platform = xieee1275])
 AM_CONDITIONAL([COND_sparc64_emu], [test x$target_cpu = xsparc64 -a x$platform = xemu])
 AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a x$platform = xieee1275])
+AM_CONDITIONAL([COND_powerpc_le], [test x$target_cpu = xpowerpc -a x$ac_cv_c_bigendian = xno])
 AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = xmipsel])
 AM_CONDITIONAL([COND_mipsel], [test x$target_cpu = xmipsel])
 AM_CONDITIONAL([COND_mipseb], [test x$target_cpu = xmips])
diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am
index 5c087c8..cb7fd9f 100644
--- a/grub-core/Makefile.am
+++ b/grub-core/Makefile.am
@@ -84,8 +84,10 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h
 if !COND_clang
+if !COND_powerpc_le
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h
 endif
+endif
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h
 
 if COND_i386_pc
-- 
1.8.1.4



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [RFC PATCH 2/3] Files reorganization and include some libgcc fuctions
  2014-08-28 19:56 [RFC PATCH 0/3] grub powerpc64 little-endian enablement Paulo Flabiano Smorigo
  2014-08-28 19:56 ` [RFC PATCH 1/3] Add powerpc little-endian (ppc64le) flags Paulo Flabiano Smorigo
@ 2014-08-28 19:56 ` Paulo Flabiano Smorigo
  2014-09-08  2:16   ` Colin Watson
  2014-08-28 19:56 ` [RFC PATCH 3/3] Suport for bi-endianess in elf file Paulo Flabiano Smorigo
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Paulo Flabiano Smorigo @ 2014-08-28 19:56 UTC (permalink / raw)
  To: grub-devel; +Cc: Paulo Flabiano Smorigo

As we avoid libgcc dependency for powerpc64el, we moved some functions
to other files and add the necessary ones.

* Makefile.core.def: Include compiler-rt.S.
* misc.c: Add the necessary libgcc functions.
* compiler-rt.S: New file.
* libgcc.h: Move some content from here ...
* compiler.h: ... to here.

Also-By: Brent Baude <bbaude@redhat.com>
Also-By: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
---
 grub-core/Makefile.core.def          |   1 +
 grub-core/kern/misc.c                | 107 ++++++++++++++++++++++++++++
 grub-core/kern/powerpc/compiler-rt.S | 130 +++++++++++++++++++++++++++++++++++
 include/grub/compiler.h              |  61 ++++++++++++++++
 include/grub/libgcc.h                |  67 ------------------
 5 files changed, 299 insertions(+), 67 deletions(-)
 create mode 100644 grub-core/kern/powerpc/compiler-rt.S

diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 42443bc..65858d9 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -252,6 +252,7 @@ kernel = {
 
   powerpc_ieee1275 = kern/powerpc/cache.S;
   powerpc_ieee1275 = kern/powerpc/dl.c;
+  powerpc_ieee1275 = kern/powerpc/compiler-rt.S;
 
   sparc64_ieee1275 = kern/sparc64/cache.S;
   sparc64_ieee1275 = kern/sparc64/dl.c;
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index c5c815d..353a207 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -1342,3 +1342,110 @@ grub_real_boot_time (const char *file,
   grub_error_pop ();
 }
 #endif
+
+#if defined (NO_LIBGCC)
+
+/* Based on libgcc2.c from gcc suite.  */
+int
+__ucmpdi2 (grub_uint64_t a, grub_uint64_t b)
+{
+  union component64 ac, bc;
+  ac.full = a;
+  bc.full = b;
+
+  if (ac.high < bc.high)
+    return 0;
+  else if (ac.high > bc.high)
+    return 2;
+
+  if (ac.low < bc.low)
+    return 0;
+  else if (ac.low > bc.low)
+    return 2;
+  return 1;
+}
+
+
+/* Based on libgcc2.c from gcc suite.  */
+grub_uint64_t
+__lshrdi3 (grub_uint64_t u, int b)
+{
+  if (b == 0)
+    return u;
+
+  const union component64 uu = {.full = u};
+  const int bm = 32 - b;
+  union component64 w;
+
+  if (bm <= 0)
+    {
+      w.high = 0;
+      w.low = (grub_uint32_t) uu.high >> -bm;
+    }
+  else
+    {
+      const grub_uint32_t carries = (grub_uint32_t) uu.high << bm;
+
+      w.high = (grub_uint32_t) uu.high >> b;
+      w.low = ((grub_uint32_t) uu.low >> b) | carries;
+    }
+
+  return w.full;
+}
+
+/* Based on libgcc2.c from gcc suite.  */
+grub_uint64_t
+__ashrdi3 (grub_uint64_t u, int b)
+{
+  if (b == 0)
+    return u;
+
+  const union component64 uu = {.full = u};
+  const int bm = 32 - b;
+  union component64 w;
+
+  if (bm <= 0)
+    {
+      /* w.high = 1..1 or 0..0 */
+      w.high = uu.high >> (32 - 1);
+      w.low = uu.high >> -bm;
+    }
+  else
+    {
+      const grub_uint32_t carries = (grub_uint32_t) uu.high << bm;
+
+      w.high = uu.high >> b;
+      w.low = ((grub_uint32_t) uu.low >> b) | carries;
+    }
+
+  return w.full;
+}
+
+/* Based on libgcc2.c from gcc suite.  */
+grub_uint64_t
+__ashldi3 (grub_uint64_t u, int b)
+{
+  if (b == 0)
+    return u;
+
+  const union component64 uu = {.full = u};
+  const int bm = 32 - b;
+  union component64 w;
+
+  if (bm <= 0)
+    {
+      w.low = 0;
+      w.high = (grub_uint32_t) uu.low << -bm;
+    }
+  else
+    {
+      const grub_uint32_t carries = (grub_uint32_t) uu.low >> bm;
+
+      w.low = (grub_uint32_t) uu.low << b;
+      w.high = ((grub_uint32_t) uu.high << b) | carries;
+    }
+
+  return w.full;
+}
+
+#endif
diff --git a/grub-core/kern/powerpc/compiler-rt.S b/grub-core/kern/powerpc/compiler-rt.S
new file mode 100644
index 0000000..63e3a0d
--- /dev/null
+++ b/grub-core/kern/powerpc/compiler-rt.S
@@ -0,0 +1,130 @@
+/*
+ * Special support for eabi and SVR4
+ *
+ *   Copyright (C) 1995-2014 Free Software Foundation, Inc.
+ *   Written By Michael Meissner
+ *   64-bit support written by David Edelsohn
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 3, or (at your option) any
+ * later version.
+ *
+ * This file 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
+ * General Public License for more details.
+ *
+ * Under Section 7 of GPL version 3, you are granted additional
+ * permissions described in the GCC Runtime Library Exception, version
+ * 3.1, as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * a copy of the GCC Runtime Library Exception along with this program;
+ * see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+/* Do any initializations needed for the eabi environment */
+
+#include <grub/symbol.h>
+#include <grub/dl.h>
+
+	.section ".text"
+
+#define CFI_RESTORE(reg)		.cfi_restore reg
+#define CFI_OFFSET(reg, off)		.cfi_offset reg, off
+#define CFI_DEF_CFA_REGISTER(reg)	.cfi_def_cfa_register reg
+#define CFI_STARTPROC			.cfi_startproc
+#define CFI_ENDPROC			.cfi_endproc
+
+/* Routines for restoring integer registers, called by the compiler.  */
+/* Called with r11 pointing to the stack header word of the caller of the */
+/* function, just beyond the end of the integer restore area.  */
+
+CFI_STARTPROC
+CFI_DEF_CFA_REGISTER (11)
+CFI_OFFSET (65, 4)
+CFI_OFFSET (14, -72)
+CFI_OFFSET (15, -68)
+CFI_OFFSET (16, -64)
+CFI_OFFSET (17, -60)
+CFI_OFFSET (18, -56)
+CFI_OFFSET (19, -52)
+CFI_OFFSET (20, -48)
+CFI_OFFSET (21, -44)
+CFI_OFFSET (22, -40)
+CFI_OFFSET (23, -36)
+CFI_OFFSET (24, -32)
+CFI_OFFSET (25, -28)
+CFI_OFFSET (26, -24)
+CFI_OFFSET (27, -20)
+CFI_OFFSET (28, -16)
+CFI_OFFSET (29, -12)
+CFI_OFFSET (30, -8)
+CFI_OFFSET (31, -4)
+FUNCTION(_restgpr_14_x)	lwz	14,-72(11)	/* restore gp registers */
+CFI_RESTORE (14)
+FUNCTION(_restgpr_15_x)	lwz	15,-68(11)
+CFI_RESTORE (15)
+FUNCTION(_restgpr_16_x)	lwz	16,-64(11)
+CFI_RESTORE (16)
+FUNCTION(_restgpr_17_x)	lwz	17,-60(11)
+CFI_RESTORE (17)
+FUNCTION(_restgpr_18_x)	lwz	18,-56(11)
+CFI_RESTORE (18)
+FUNCTION(_restgpr_19_x)	lwz	19,-52(11)
+CFI_RESTORE (19)
+FUNCTION(_restgpr_20_x)	lwz	20,-48(11)
+CFI_RESTORE (20)
+FUNCTION(_restgpr_21_x)	lwz	21,-44(11)
+CFI_RESTORE (21)
+FUNCTION(_restgpr_22_x)	lwz	22,-40(11)
+CFI_RESTORE (22)
+FUNCTION(_restgpr_23_x)	lwz	23,-36(11)
+CFI_RESTORE (23)
+FUNCTION(_restgpr_24_x)	lwz	24,-32(11)
+CFI_RESTORE (24)
+FUNCTION(_restgpr_25_x)	lwz	25,-28(11)
+CFI_RESTORE (25)
+FUNCTION(_restgpr_26_x)	lwz	26,-24(11)
+CFI_RESTORE (26)
+FUNCTION(_restgpr_27_x)	lwz	27,-20(11)
+CFI_RESTORE (27)
+FUNCTION(_restgpr_28_x)	lwz	28,-16(11)
+CFI_RESTORE (28)
+FUNCTION(_restgpr_29_x)	lwz	29,-12(11)
+CFI_RESTORE (29)
+FUNCTION(_restgpr_30_x)	lwz	30,-8(11)
+CFI_RESTORE (30)
+FUNCTION(_restgpr_31_x)	lwz	0,4(11)
+				lwz	31,-4(11)
+CFI_RESTORE (31)
+				mtlr	0
+CFI_RESTORE (65)
+				mr	1,11
+CFI_DEF_CFA_REGISTER (1)
+				blr
+CFI_ENDPROC
+
+CFI_STARTPROC
+FUNCTION(_savegpr_14)	stw	14,-72(11)	/* save gp registers */
+FUNCTION(_savegpr_15)	stw	15,-68(11)
+FUNCTION(_savegpr_16)	stw	16,-64(11)
+FUNCTION(_savegpr_17)	stw	17,-60(11)
+FUNCTION(_savegpr_18)	stw	18,-56(11)
+FUNCTION(_savegpr_19)	stw	19,-52(11)
+FUNCTION(_savegpr_20)	stw	20,-48(11)
+FUNCTION(_savegpr_21)	stw	21,-44(11)
+FUNCTION(_savegpr_22)	stw	22,-40(11)
+FUNCTION(_savegpr_23)	stw	23,-36(11)
+FUNCTION(_savegpr_24)	stw	24,-32(11)
+FUNCTION(_savegpr_25)	stw	25,-28(11)
+FUNCTION(_savegpr_26)	stw	26,-24(11)
+FUNCTION(_savegpr_27)	stw	27,-20(11)
+FUNCTION(_savegpr_28)	stw	28,-16(11)
+FUNCTION(_savegpr_29)	stw	29,-12(11)
+FUNCTION(_savegpr_30)	stw	30,-8(11)
+FUNCTION(_savegpr_31)	stw	31,-4(11)
+			blr
+CFI_ENDPROC
diff --git a/include/grub/compiler.h b/include/grub/compiler.h
index c9e1d7a..a9a684c 100644
--- a/include/grub/compiler.h
+++ b/include/grub/compiler.h
@@ -48,4 +48,65 @@
 #  define WARN_UNUSED_RESULT
 #endif
 
+#include "types.h"
+
+union component64
+{
+  grub_uint64_t full;
+  struct
+  {
+#ifdef GRUB_CPU_WORDS_BIGENDIAN
+    grub_uint32_t high;
+    grub_uint32_t low;
+#else
+    grub_uint32_t low;
+    grub_uint32_t high;
+#endif
+  };
+};
+
+#if defined (__powerpc__)
+grub_uint64_t EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b);
+grub_uint64_t EXPORT_FUNC (__ashrdi3) (grub_uint64_t u, int b);
+grub_uint64_t EXPORT_FUNC (__ashldi3) (grub_uint64_t u, int b);
+int EXPORT_FUNC(__ucmpdi2) (grub_uint64_t a, grub_uint64_t b);
+void EXPORT_FUNC (_restgpr_14_x) (void);
+void EXPORT_FUNC (_restgpr_15_x) (void);
+void EXPORT_FUNC (_restgpr_16_x) (void);
+void EXPORT_FUNC (_restgpr_17_x) (void);
+void EXPORT_FUNC (_restgpr_18_x) (void);
+void EXPORT_FUNC (_restgpr_19_x) (void);
+void EXPORT_FUNC (_restgpr_20_x) (void);
+void EXPORT_FUNC (_restgpr_21_x) (void);
+void EXPORT_FUNC (_restgpr_22_x) (void);
+void EXPORT_FUNC (_restgpr_23_x) (void);
+void EXPORT_FUNC (_restgpr_24_x) (void);
+void EXPORT_FUNC (_restgpr_25_x) (void);
+void EXPORT_FUNC (_restgpr_26_x) (void);
+void EXPORT_FUNC (_restgpr_27_x) (void);
+void EXPORT_FUNC (_restgpr_28_x) (void);
+void EXPORT_FUNC (_restgpr_29_x) (void);
+void EXPORT_FUNC (_restgpr_30_x) (void);
+void EXPORT_FUNC (_restgpr_31_x) (void);
+void EXPORT_FUNC (_savegpr_14) (void);
+void EXPORT_FUNC (_savegpr_15) (void);
+void EXPORT_FUNC (_savegpr_16) (void);
+void EXPORT_FUNC (_savegpr_17) (void);
+void EXPORT_FUNC (_savegpr_18) (void);
+void EXPORT_FUNC (_savegpr_19) (void);
+void EXPORT_FUNC (_savegpr_20) (void);
+void EXPORT_FUNC (_savegpr_21) (void);
+void EXPORT_FUNC (_savegpr_22) (void);
+void EXPORT_FUNC (_savegpr_23) (void);
+void EXPORT_FUNC (_savegpr_24) (void);
+void EXPORT_FUNC (_savegpr_25) (void);
+void EXPORT_FUNC (_savegpr_26) (void);
+void EXPORT_FUNC (_savegpr_27) (void);
+void EXPORT_FUNC (_savegpr_28) (void);
+void EXPORT_FUNC (_savegpr_29) (void);
+void EXPORT_FUNC (_savegpr_30) (void);
+void EXPORT_FUNC (_savegpr_31) (void);
+
+#endif
+
 #endif /* ! GRUB_COMPILER_HEADER */
diff --git a/include/grub/libgcc.h b/include/grub/libgcc.h
index 8e93b67..5bdb8fb 100644
--- a/include/grub/libgcc.h
+++ b/include/grub/libgcc.h
@@ -16,73 +16,6 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* We need to include config-util.h.in for HAVE_*.  */
-#ifndef __STDC_VERSION__
-#define __STDC_VERSION__ 0
-#endif
-#include <config-util.h>
-
-/* On x86 these functions aren't really needed. Save some space.  */
-#if !defined (__i386__) && !defined (__x86_64__)
-# ifdef HAVE___ASHLDI3
-void EXPORT_FUNC (__ashldi3) (void);
-# endif
-# ifdef HAVE___ASHRDI3
-void EXPORT_FUNC (__ashrdi3) (void);
-# endif
-# ifdef HAVE___LSHRDI3
-void EXPORT_FUNC (__lshrdi3) (void);
-# endif
-# ifdef HAVE___UCMPDI2
-void EXPORT_FUNC (__ucmpdi2) (void);
-# endif
-# ifdef HAVE___BSWAPSI2
-void EXPORT_FUNC (__bswapsi2) (void);
-# endif
-# ifdef HAVE___BSWAPDI2
-void EXPORT_FUNC (__bswapdi2) (void);
-# endif
-#endif
-
-#ifdef HAVE__RESTGPR_14_X
-void EXPORT_FUNC (_restgpr_14_x) (void);
-void EXPORT_FUNC (_restgpr_15_x) (void);
-void EXPORT_FUNC (_restgpr_16_x) (void);
-void EXPORT_FUNC (_restgpr_17_x) (void);
-void EXPORT_FUNC (_restgpr_18_x) (void);
-void EXPORT_FUNC (_restgpr_19_x) (void);
-void EXPORT_FUNC (_restgpr_20_x) (void);
-void EXPORT_FUNC (_restgpr_21_x) (void);
-void EXPORT_FUNC (_restgpr_22_x) (void);
-void EXPORT_FUNC (_restgpr_23_x) (void);
-void EXPORT_FUNC (_restgpr_24_x) (void);
-void EXPORT_FUNC (_restgpr_25_x) (void);
-void EXPORT_FUNC (_restgpr_26_x) (void);
-void EXPORT_FUNC (_restgpr_27_x) (void);
-void EXPORT_FUNC (_restgpr_28_x) (void);
-void EXPORT_FUNC (_restgpr_29_x) (void);
-void EXPORT_FUNC (_restgpr_30_x) (void);
-void EXPORT_FUNC (_restgpr_31_x) (void);
-void EXPORT_FUNC (_savegpr_14) (void);
-void EXPORT_FUNC (_savegpr_15) (void);
-void EXPORT_FUNC (_savegpr_16) (void);
-void EXPORT_FUNC (_savegpr_17) (void);
-void EXPORT_FUNC (_savegpr_18) (void);
-void EXPORT_FUNC (_savegpr_19) (void);
-void EXPORT_FUNC (_savegpr_20) (void);
-void EXPORT_FUNC (_savegpr_21) (void);
-void EXPORT_FUNC (_savegpr_22) (void);
-void EXPORT_FUNC (_savegpr_23) (void);
-void EXPORT_FUNC (_savegpr_24) (void);
-void EXPORT_FUNC (_savegpr_25) (void);
-void EXPORT_FUNC (_savegpr_26) (void);
-void EXPORT_FUNC (_savegpr_27) (void);
-void EXPORT_FUNC (_savegpr_28) (void);
-void EXPORT_FUNC (_savegpr_29) (void);
-void EXPORT_FUNC (_savegpr_30) (void);
-void EXPORT_FUNC (_savegpr_31) (void);
-#endif
-
 #if defined (__arm__)
 void EXPORT_FUNC (__aeabi_lasr) (void);
 void EXPORT_FUNC (__aeabi_llsl) (void);
-- 
1.8.1.4



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [RFC PATCH 3/3] Suport for bi-endianess in elf file
  2014-08-28 19:56 [RFC PATCH 0/3] grub powerpc64 little-endian enablement Paulo Flabiano Smorigo
  2014-08-28 19:56 ` [RFC PATCH 1/3] Add powerpc little-endian (ppc64le) flags Paulo Flabiano Smorigo
  2014-08-28 19:56 ` [RFC PATCH 2/3] Files reorganization and include some libgcc fuctions Paulo Flabiano Smorigo
@ 2014-08-28 19:56 ` Paulo Flabiano Smorigo
  2015-06-16 16:44   ` Andrei Borzenkov
  2014-09-21 13:58 ` [RFC PATCH 0/3] grub powerpc64 little-endian enablement Andrei Borzenkov
  2015-06-15 17:15 ` Andrei Borzenkov
  4 siblings, 1 reply; 19+ messages in thread
From: Paulo Flabiano Smorigo @ 2014-08-28 19:56 UTC (permalink / raw)
  To: grub-devel; +Cc: Paulo Flabiano Smorigo

* grub-core/kern/elf.c: check and switch endianess with grub_{be,le}_to
  cpu functions.
* grub-core/kern/elfXX.c: Likewise.

Also-by: Tomohiro B Berry <tbberry@us.ibm.com>
---
 grub-core/kern/elf.c   | 60 +++++++++++++++++++++++++++++++++++++++--
 grub-core/kern/elfXX.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 131 insertions(+), 2 deletions(-)

diff --git a/grub-core/kern/elf.c b/grub-core/kern/elf.c
index 5f99c43..de90811 100644
--- a/grub-core/kern/elf.c
+++ b/grub-core/kern/elf.c
@@ -28,6 +28,11 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
+void grub_elf32_check_endianess (grub_elf_t elf);
+void grub_elf64_check_endianess (grub_elf_t elf);
+grub_err_t grub_elf32_check_version (grub_elf_t elf);
+grub_err_t grub_elf64_check_version (grub_elf_t elf);
+
 /* Check if EHDR is a valid ELF header.  */
 static grub_err_t
 grub_elf_check_header (grub_elf_t elf)
@@ -38,10 +43,22 @@ grub_elf_check_header (grub_elf_t elf)
       || e->e_ident[EI_MAG1] != ELFMAG1
       || e->e_ident[EI_MAG2] != ELFMAG2
       || e->e_ident[EI_MAG3] != ELFMAG3
-      || e->e_ident[EI_VERSION] != EV_CURRENT
-      || e->e_version != EV_CURRENT)
+      || e->e_ident[EI_VERSION] != EV_CURRENT)
     return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF magic"));
 
+  if (grub_elf_is_elf32 (elf))
+    {
+      grub_elf32_check_endianess (elf);
+      grub_elf32_check_version (elf);
+    }
+  else if (grub_elf_is_elf64 (elf))
+    {
+      grub_elf64_check_endianess (elf);
+      grub_elf64_check_version (elf);
+    }
+  else
+    return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
+
   return GRUB_ERR_NONE;
 }
 
@@ -127,7 +144,20 @@ grub_elf_open (const char *name)
 #define grub_elf_is_elfXX grub_elf_is_elf32
 #define grub_elfXX_load_phdrs grub_elf32_load_phdrs
 #define ElfXX_Phdr Elf32_Phdr
+#define ElfXX_Ehdr Elf32_Ehdr
 #define grub_uintXX_t grub_uint32_t
+#define grub_be_to_halfXX grub_be_to_cpu16
+#define grub_be_to_wordXX grub_be_to_cpu32
+#define grub_be_to_addrXX grub_be_to_cpu32
+#define grub_be_to_offXX grub_be_to_cpu32
+#define grub_be_to_XwordXX grub_be_to_wordXX
+#define grub_le_to_halfXX grub_le_to_cpu16
+#define grub_le_to_wordXX grub_le_to_cpu32
+#define grub_le_to_addrXX grub_le_to_cpu32
+#define grub_le_to_offXX grub_le_to_cpu32
+#define grub_le_to_XwordXX grub_le_to_wordXX
+#define grub_elfXX_check_endianess grub_elf32_check_endianess
+#define grub_elfXX_check_version grub_elf32_check_version
 
 #include "elfXX.c"
 
@@ -140,7 +170,20 @@ grub_elf_open (const char *name)
 #undef grub_elf_is_elfXX
 #undef grub_elfXX_load_phdrs
 #undef ElfXX_Phdr
+#undef ElfXX_Ehdr
 #undef grub_uintXX_t
+#undef grub_be_to_halfXX
+#undef grub_be_to_wordXX
+#undef grub_be_to_addrXX
+#undef grub_be_to_offXX
+#undef grub_be_to_XwordXX
+#undef grub_le_to_halfXX
+#undef grub_le_to_wordXX
+#undef grub_le_to_addrXX
+#undef grub_le_to_offXX
+#undef grub_le_to_XwordXX
+#undef grub_elfXX_check_endianess
+#undef grub_elfXX_check_version
 
 \f
 /* 64-bit */
@@ -153,6 +196,19 @@ grub_elf_open (const char *name)
 #define grub_elf_is_elfXX grub_elf_is_elf64
 #define grub_elfXX_load_phdrs grub_elf64_load_phdrs
 #define ElfXX_Phdr Elf64_Phdr
+#define ElfXX_Ehdr Elf64_Ehdr
 #define grub_uintXX_t grub_uint64_t
+#define grub_be_to_halfXX grub_be_to_cpu16
+#define grub_be_to_wordXX grub_be_to_cpu32
+#define grub_be_to_addrXX grub_be_to_cpu64
+#define grub_be_to_offXX grub_be_to_cpu64
+#define grub_be_to_XwordXX grub_be_to_cpu64
+#define grub_le_to_halfXX grub_le_to_cpu16
+#define grub_le_to_wordXX grub_le_to_cpu32
+#define grub_le_to_addrXX grub_le_to_cpu64
+#define grub_le_to_offXX grub_le_to_cpu64
+#define grub_le_to_XwordXX grub_le_to_cpu64
+#define grub_elfXX_check_endianess grub_elf64_check_endianess
+#define grub_elfXX_check_version grub_elf64_check_version
 
 #include "elfXX.c"
diff --git a/grub-core/kern/elfXX.c b/grub-core/kern/elfXX.c
index 1d09971..ecf9df6 100644
--- a/grub-core/kern/elfXX.c
+++ b/grub-core/kern/elfXX.c
@@ -154,3 +154,76 @@ grub_elfXX_load (grub_elf_t elf, const char *filename,
 
   return grub_errno;
 }
+
+void
+grub_elfXX_check_endianess (grub_elf_t elf)
+{
+  ElfXX_Ehdr *e = &(elf->ehdr.ehdrXX);
+  ElfXX_Phdr *phdr;
+
+  if (e->e_ident[EI_DATA] == ELFDATA2MSB)
+    {
+      e->e_type = grub_be_to_halfXX (e->e_type);
+      e->e_machine = grub_be_to_halfXX (e->e_machine);
+      e->e_version = grub_be_to_wordXX (e->e_version);
+      e->e_entry = grub_be_to_addrXX (e->e_entry);
+      e->e_phoff = grub_be_to_offXX (e->e_phoff);
+      e->e_shoff = grub_be_to_offXX (e->e_shoff);
+      e->e_flags = grub_be_to_wordXX (e->e_flags);
+      e->e_ehsize = grub_be_to_halfXX (e->e_ehsize);
+      e->e_phentsize = grub_be_to_halfXX (e->e_phentsize);
+      e->e_phnum = grub_be_to_halfXX (e->e_phnum);
+      e->e_shentsize = grub_be_to_halfXX (e->e_shentsize);
+      e->e_shnum = grub_be_to_halfXX (e->e_shnum);
+      e->e_shstrndx = grub_be_to_halfXX (e->e_shstrndx);
+
+      FOR_ELFXX_PHDRS (elf,phdr)
+        {
+          phdr->p_type = grub_be_to_wordXX (phdr->p_type);
+          phdr->p_flags = grub_be_to_wordXX (phdr->p_flags);
+          phdr->p_offset = grub_be_to_offXX (phdr->p_offset);
+          phdr->p_vaddr = grub_be_to_addrXX (phdr->p_vaddr);
+          phdr->p_paddr = grub_be_to_addrXX (phdr->p_paddr);
+          phdr->p_filesz = grub_be_to_XwordXX (phdr->p_filesz);
+          phdr->p_memsz = grub_be_to_XwordXX (phdr->p_memsz);
+          phdr->p_align = grub_be_to_XwordXX (phdr->p_align);
+        }
+    }
+  else if (e->e_ident[EI_DATA] == ELFDATA2LSB)
+    {
+      e->e_type = grub_le_to_halfXX (e->e_type);
+      e->e_machine = grub_le_to_halfXX (e->e_machine);
+      e->e_version = grub_le_to_wordXX (e->e_version);
+      e->e_entry = grub_le_to_addrXX (e->e_entry);
+      e->e_phoff = grub_le_to_offXX (e->e_phoff);
+      e->e_shoff = grub_le_to_offXX (e->e_shoff);
+      e->e_flags = grub_le_to_wordXX (e->e_flags);
+      e->e_ehsize = grub_le_to_halfXX (e->e_ehsize);
+      e->e_phentsize = grub_le_to_halfXX (e->e_phentsize);
+      e->e_phnum = grub_le_to_halfXX (e->e_phnum);
+      e->e_shentsize = grub_le_to_halfXX (e->e_shentsize);
+      e->e_shnum = grub_le_to_halfXX (e->e_shnum);
+      e->e_shstrndx = grub_le_to_halfXX (e->e_shstrndx);
+
+      FOR_ELFXX_PHDRS (elf,phdr)
+        {
+          phdr->p_type = grub_le_to_wordXX (phdr->p_type);
+          phdr->p_flags = grub_le_to_wordXX (phdr->p_flags);
+          phdr->p_offset = grub_le_to_offXX (phdr->p_offset);
+          phdr->p_vaddr = grub_le_to_addrXX (phdr->p_vaddr);
+          phdr->p_paddr = grub_le_to_addrXX (phdr->p_paddr);
+          phdr->p_filesz = grub_le_to_XwordXX (phdr->p_filesz);
+          phdr->p_memsz = grub_le_to_XwordXX (phdr->p_memsz);
+          phdr->p_align = grub_le_to_XwordXX (phdr->p_align);
+        }
+    }
+}
+
+grub_err_t
+grub_elfXX_check_version (grub_elf_t elf)
+{
+  if (elf->ehdr.ehdrXX.e_version != EV_CURRENT)
+    return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF magic"));
+
+  return GRUB_ERR_NONE;
+}
-- 
1.8.1.4



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 2/3] Files reorganization and include some libgcc fuctions
  2014-08-28 19:56 ` [RFC PATCH 2/3] Files reorganization and include some libgcc fuctions Paulo Flabiano Smorigo
@ 2014-09-08  2:16   ` Colin Watson
  2014-09-17 21:43     ` Paulo Flabiano Smorigo
  0 siblings, 1 reply; 19+ messages in thread
From: Colin Watson @ 2014-09-08  2:16 UTC (permalink / raw)
  To: grub-devel

On Thu, Aug 28, 2014 at 04:56:04PM -0300, Paulo Flabiano Smorigo wrote:
> diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
> index c5c815d..353a207 100644
> --- a/grub-core/kern/misc.c
> +++ b/grub-core/kern/misc.c
> @@ -1342,3 +1342,110 @@ grub_real_boot_time (const char *file,
>    grub_error_pop ();
>  }
>  #endif
> +
> +#if defined (NO_LIBGCC)

Should this perhaps be restricted to __powerpc__ as well?
Alternatively, the prototypes in include/grub/compiler.h (or
include/grub/misc.h; see below) should be used on other architectures
too.  Either way, the declarations and definitions should match.

> diff --git a/include/grub/compiler.h b/include/grub/compiler.h
> index c9e1d7a..a9a684c 100644
> --- a/include/grub/compiler.h
> +++ b/include/grub/compiler.h
> @@ -48,4 +48,65 @@
>  #  define WARN_UNUSED_RESULT
>  #endif
>  
> +#include "types.h"

Shouldn't this be #include <grub/types.h>, assuming that you need this
for grub_uint*_t?  Also, includes should generally be grouped at the top
of the file.

> +union component64
> +{
> +  grub_uint64_t full;
> +  struct
> +  {
> +#ifdef GRUB_CPU_WORDS_BIGENDIAN
> +    grub_uint32_t high;
> +    grub_uint32_t low;
> +#else
> +    grub_uint32_t low;
> +    grub_uint32_t high;
> +#endif
> +  };
> +};

This is only used by grub-core/kern/misc.c.  Please move it there rather
than putting it somewhere that's included by everything in GRUB.

> +#if defined (__powerpc__)

Should this be #if defined (__powerpc__) && defined (NO_LIBGCC) or
something similar, to match the general way things are set up in
configure.ac?  (Also see comment above about declarations matching
definitions.)

Relatedly, have you tested this patch set with a native build on a
32-bit BE powerpc system, as opposed to 32-bit BE built on a 64-bit LE
system?  This looks like a potential problem there.

> +grub_uint64_t EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b);
> +grub_uint64_t EXPORT_FUNC (__ashrdi3) (grub_uint64_t u, int b);
> +grub_uint64_t EXPORT_FUNC (__ashldi3) (grub_uint64_t u, int b);
> +int EXPORT_FUNC(__ucmpdi2) (grub_uint64_t a, grub_uint64_t b);
> +void EXPORT_FUNC (_restgpr_14_x) (void);
[...]

These aren't compiler features, so don't belong in
include/grub/compiler.h.  Other architectures seem to have this kind of
thing in include/grub/misc.h inside a big #ifndef GRUB_UTIL conditional,
so please move all this to there.

> diff --git a/include/grub/libgcc.h b/include/grub/libgcc.h
> index 8e93b67..5bdb8fb 100644
> --- a/include/grub/libgcc.h
> +++ b/include/grub/libgcc.h
> @@ -16,73 +16,6 @@
>   *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
>   */
>  
> -/* We need to include config-util.h.in for HAVE_*.  */
> -#ifndef __STDC_VERSION__
> -#define __STDC_VERSION__ 0
> -#endif
> -#include <config-util.h>
> -
> -/* On x86 these functions aren't really needed. Save some space.  */
> -#if !defined (__i386__) && !defined (__x86_64__)
> -# ifdef HAVE___ASHLDI3
> -void EXPORT_FUNC (__ashldi3) (void);
> -# endif
> -# ifdef HAVE___ASHRDI3
> -void EXPORT_FUNC (__ashrdi3) (void);
> -# endif
> -# ifdef HAVE___LSHRDI3
> -void EXPORT_FUNC (__lshrdi3) (void);
> -# endif
> -# ifdef HAVE___UCMPDI2
> -void EXPORT_FUNC (__ucmpdi2) (void);
> -# endif
> -# ifdef HAVE___BSWAPSI2
> -void EXPORT_FUNC (__bswapsi2) (void);
> -# endif
> -# ifdef HAVE___BSWAPDI2
> -void EXPORT_FUNC (__bswapdi2) (void);
> -# endif
> -#endif
> -
> -#ifdef HAVE__RESTGPR_14_X
> -void EXPORT_FUNC (_restgpr_14_x) (void);
> -void EXPORT_FUNC (_restgpr_15_x) (void);
> -void EXPORT_FUNC (_restgpr_16_x) (void);
> -void EXPORT_FUNC (_restgpr_17_x) (void);
> -void EXPORT_FUNC (_restgpr_18_x) (void);
> -void EXPORT_FUNC (_restgpr_19_x) (void);
> -void EXPORT_FUNC (_restgpr_20_x) (void);
> -void EXPORT_FUNC (_restgpr_21_x) (void);
> -void EXPORT_FUNC (_restgpr_22_x) (void);
> -void EXPORT_FUNC (_restgpr_23_x) (void);
> -void EXPORT_FUNC (_restgpr_24_x) (void);
> -void EXPORT_FUNC (_restgpr_25_x) (void);
> -void EXPORT_FUNC (_restgpr_26_x) (void);
> -void EXPORT_FUNC (_restgpr_27_x) (void);
> -void EXPORT_FUNC (_restgpr_28_x) (void);
> -void EXPORT_FUNC (_restgpr_29_x) (void);
> -void EXPORT_FUNC (_restgpr_30_x) (void);
> -void EXPORT_FUNC (_restgpr_31_x) (void);
> -void EXPORT_FUNC (_savegpr_14) (void);
> -void EXPORT_FUNC (_savegpr_15) (void);
> -void EXPORT_FUNC (_savegpr_16) (void);
> -void EXPORT_FUNC (_savegpr_17) (void);
> -void EXPORT_FUNC (_savegpr_18) (void);
> -void EXPORT_FUNC (_savegpr_19) (void);
> -void EXPORT_FUNC (_savegpr_20) (void);
> -void EXPORT_FUNC (_savegpr_21) (void);
> -void EXPORT_FUNC (_savegpr_22) (void);
> -void EXPORT_FUNC (_savegpr_23) (void);
> -void EXPORT_FUNC (_savegpr_24) (void);
> -void EXPORT_FUNC (_savegpr_25) (void);
> -void EXPORT_FUNC (_savegpr_26) (void);
> -void EXPORT_FUNC (_savegpr_27) (void);
> -void EXPORT_FUNC (_savegpr_28) (void);
> -void EXPORT_FUNC (_savegpr_29) (void);
> -void EXPORT_FUNC (_savegpr_30) (void);
> -void EXPORT_FUNC (_savegpr_31) (void);
> -#endif
> -
>  #if defined (__arm__)
>  void EXPORT_FUNC (__aeabi_lasr) (void);
>  void EXPORT_FUNC (__aeabi_llsl) (void);

I don't think you should touch this file at all.  I don't know precisely
how it's used, but it only seems to be used to generate symbol lists;
furthermore, you're removing some things from it that are not clearly
powerpc-specific and either making them powerpc-specific (__ashldi3,
__ashrdi3, __lshrdi3, __ucmpdi2) or dropping them altogether
(__bswapsi2, __bswapdi2).  This is worrisome and suggests the
possibility that this will break other architectures.  Does your patch
work if you just leave include/grub/libgcc.h unmodified?

Thanks,

-- 
Colin Watson                                       [cjwatson@ubuntu.com]


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 2/3] Files reorganization and include some libgcc fuctions
  2014-09-08  2:16   ` Colin Watson
@ 2014-09-17 21:43     ` Paulo Flabiano Smorigo
  2014-09-19 14:03       ` Colin Watson
  2014-09-21 16:07       ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 2 replies; 19+ messages in thread
From: Paulo Flabiano Smorigo @ 2014-09-17 21:43 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 7182 bytes --]

Colin, I changed the patches following your suggestions and making it
more likely to the no-libgcc branch from Vladimir. In this branch,
phcoder added compiler-rt.{c,h,S} with the necessary code in it.

My approach is very minimalist and only for powerpc. I tried to avoid
change the behavior for other architecture since we are in code freeze.

In the future we can think in spread this approach for all archs and use
all implementation that phcoder is doing in the no-libgcc branch.

Mon, Sep 08, 2014 at 03:16:21AM +0100, Colin Watson wrote:
> On Thu, Aug 28, 2014 at 04:56:04PM -0300, Paulo Flabiano Smorigo wrote:
> > diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
> > index c5c815d..353a207 100644
> > --- a/grub-core/kern/misc.c
> > +++ b/grub-core/kern/misc.c
> > @@ -1342,3 +1342,110 @@ grub_real_boot_time (const char *file,
> >    grub_error_pop ();
> >  }
> >  #endif
> > +
> > +#if defined (NO_LIBGCC)
> 
> Should this perhaps be restricted to __powerpc__ as well?
> Alternatively, the prototypes in include/grub/compiler.h (or
> include/grub/misc.h; see below) should be used on other architectures
> too.  Either way, the declarations and definitions should match.

Yes, now I only use __powerpc__

> 
> > diff --git a/include/grub/compiler.h b/include/grub/compiler.h
> > index c9e1d7a..a9a684c 100644
> > --- a/include/grub/compiler.h
> > +++ b/include/grub/compiler.h
> > @@ -48,4 +48,65 @@
> >  #  define WARN_UNUSED_RESULT
> >  #endif
> >  
> > +#include "types.h"
> 
> Shouldn't this be #include <grub/types.h>, assuming that you need this
> for grub_uint*_t?  Also, includes should generally be grouped at the top
> of the file.

All in the compile-rt.c now

> 
> > +union component64
> > +{
> > +  grub_uint64_t full;
> > +  struct
> > +  {
> > +#ifdef GRUB_CPU_WORDS_BIGENDIAN
> > +    grub_uint32_t high;
> > +    grub_uint32_t low;
> > +#else
> > +    grub_uint32_t low;
> > +    grub_uint32_t high;
> > +#endif
> > +  };
> > +};
> 
> This is only used by grub-core/kern/misc.c.  Please move it there rather
> than putting it somewhere that's included by everything in GRUB.
> 
> > +#if defined (__powerpc__)
> 
> Should this be #if defined (__powerpc__) && defined (NO_LIBGCC) or
> something similar, to match the general way things are set up in
> configure.ac?  (Also see comment above about declarations matching
> definitions.)

Fixed.

> 
> Relatedly, have you tested this patch set with a native build on a
> 32-bit BE powerpc system, as opposed to 32-bit BE built on a 64-bit LE
> system?  This looks like a potential problem there.
> 

Yes. I tested it in both BE and LE systems. No problem found. I did
another round of test with this changes and will do some more this week.

> > +grub_uint64_t EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b);
> > +grub_uint64_t EXPORT_FUNC (__ashrdi3) (grub_uint64_t u, int b);
> > +grub_uint64_t EXPORT_FUNC (__ashldi3) (grub_uint64_t u, int b);
> > +int EXPORT_FUNC(__ucmpdi2) (grub_uint64_t a, grub_uint64_t b);
> > +void EXPORT_FUNC (_restgpr_14_x) (void);
> [...]
>
> These aren't compiler features, so don't belong in
> include/grub/compiler.h.  Other architectures seem to have this kind of
> thing in include/grub/misc.h inside a big #ifndef GRUB_UTIL conditional,
> so please move all this to there.

Yes, I follow what phcoder did in no-libgcc branch. This lines are in
the compiler-rt.c file.

> 
> > diff --git a/include/grub/libgcc.h b/include/grub/libgcc.h
> > index 8e93b67..5bdb8fb 100644
> > --- a/include/grub/libgcc.h
> > +++ b/include/grub/libgcc.h
> > @@ -16,73 +16,6 @@
> >   *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
> >   */
> >  
> > -/* We need to include config-util.h.in for HAVE_*.  */
> > -#ifndef __STDC_VERSION__
> > -#define __STDC_VERSION__ 0
> > -#endif
> > -#include <config-util.h>
> > -
> > -/* On x86 these functions aren't really needed. Save some space.  */
> > -#if !defined (__i386__) && !defined (__x86_64__)
> > -# ifdef HAVE___ASHLDI3
> > -void EXPORT_FUNC (__ashldi3) (void);
> > -# endif
> > -# ifdef HAVE___ASHRDI3
> > -void EXPORT_FUNC (__ashrdi3) (void);
> > -# endif
> > -# ifdef HAVE___LSHRDI3
> > -void EXPORT_FUNC (__lshrdi3) (void);
> > -# endif
> > -# ifdef HAVE___UCMPDI2
> > -void EXPORT_FUNC (__ucmpdi2) (void);
> > -# endif
> > -# ifdef HAVE___BSWAPSI2
> > -void EXPORT_FUNC (__bswapsi2) (void);
> > -# endif
> > -# ifdef HAVE___BSWAPDI2
> > -void EXPORT_FUNC (__bswapdi2) (void);
> > -# endif
> > -#endif
> > -
> > -#ifdef HAVE__RESTGPR_14_X
> > -void EXPORT_FUNC (_restgpr_14_x) (void);
> > -void EXPORT_FUNC (_restgpr_15_x) (void);
> > -void EXPORT_FUNC (_restgpr_16_x) (void);
> > -void EXPORT_FUNC (_restgpr_17_x) (void);
> > -void EXPORT_FUNC (_restgpr_18_x) (void);
> > -void EXPORT_FUNC (_restgpr_19_x) (void);
> > -void EXPORT_FUNC (_restgpr_20_x) (void);
> > -void EXPORT_FUNC (_restgpr_21_x) (void);
> > -void EXPORT_FUNC (_restgpr_22_x) (void);
> > -void EXPORT_FUNC (_restgpr_23_x) (void);
> > -void EXPORT_FUNC (_restgpr_24_x) (void);
> > -void EXPORT_FUNC (_restgpr_25_x) (void);
> > -void EXPORT_FUNC (_restgpr_26_x) (void);
> > -void EXPORT_FUNC (_restgpr_27_x) (void);
> > -void EXPORT_FUNC (_restgpr_28_x) (void);
> > -void EXPORT_FUNC (_restgpr_29_x) (void);
> > -void EXPORT_FUNC (_restgpr_30_x) (void);
> > -void EXPORT_FUNC (_restgpr_31_x) (void);
> > -void EXPORT_FUNC (_savegpr_14) (void);
> > -void EXPORT_FUNC (_savegpr_15) (void);
> > -void EXPORT_FUNC (_savegpr_16) (void);
> > -void EXPORT_FUNC (_savegpr_17) (void);
> > -void EXPORT_FUNC (_savegpr_18) (void);
> > -void EXPORT_FUNC (_savegpr_19) (void);
> > -void EXPORT_FUNC (_savegpr_20) (void);
> > -void EXPORT_FUNC (_savegpr_21) (void);
> > -void EXPORT_FUNC (_savegpr_22) (void);
> > -void EXPORT_FUNC (_savegpr_23) (void);
> > -void EXPORT_FUNC (_savegpr_24) (void);
> > -void EXPORT_FUNC (_savegpr_25) (void);
> > -void EXPORT_FUNC (_savegpr_26) (void);
> > -void EXPORT_FUNC (_savegpr_27) (void);
> > -void EXPORT_FUNC (_savegpr_28) (void);
> > -void EXPORT_FUNC (_savegpr_29) (void);
> > -void EXPORT_FUNC (_savegpr_30) (void);
> > -void EXPORT_FUNC (_savegpr_31) (void);
> > -#endif
> > -
> >  #if defined (__arm__)
> >  void EXPORT_FUNC (__aeabi_lasr) (void);
> >  void EXPORT_FUNC (__aeabi_llsl) (void);
> 
> I don't think you should touch this file at all.  I don't know precisely
> how it's used, but it only seems to be used to generate symbol lists;
> furthermore, you're removing some things from it that are not clearly
> powerpc-specific and either making them powerpc-specific (__ashldi3,
> __ashrdi3, __lshrdi3, __ucmpdi2) or dropping them altogether
> (__bswapsi2, __bswapdi2).  This is worrisome and suggests the
> possibility that this will break other architectures.  Does your patch
> work if you just leave include/grub/libgcc.h unmodified?

Please, check this new patchset. libgcc.h is intact.

> 
> Thanks,
> 
> -- 
> Colin Watson                                       [cjwatson@ubuntu.com]
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> 

-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center

[-- Attachment #2: 0002-Skip-libgcc-dependency-for-powerpc.patch --]
[-- Type: text/plain, Size: 15103 bytes --]

From 45cd4be413b1ef318406480deb69ab8e9bb8fe45 Mon Sep 17 00:00:00 2001
From: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
Date: Wed, 17 Sep 2014 14:44:30 -0300
Subject: [PATCH 2/2] Skip libgcc dependency for powerpc

* configure.ac: Add conditions to avoid libgcc dependency.
* Makefile.am: Likewise.
* Makefile.core.def: Include compiler-rt.S and compiler-rt.c.
* compiler-rt.c: New file.
* compiler-rt.S: Likewise.
* compiler-rt.h: Likewise.

Also-By: Brent Baude <bbaude@redhat.com>
Also-By: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
---
 configure.ac                         |  10 ++-
 grub-core/Makefile.am                |   1 +
 grub-core/Makefile.core.def          |   2 +
 grub-core/kern/compiler-rt.c         | 166 +++++++++++++++++++++++++++++++++++
 grub-core/kern/powerpc/compiler-rt.S | 130 +++++++++++++++++++++++++++
 include/grub/compiler-rt.h           |  82 +++++++++++++++++
 6 files changed, 387 insertions(+), 4 deletions(-)
 create mode 100644 grub-core/kern/compiler-rt.c
 create mode 100644 grub-core/kern/powerpc/compiler-rt.S
 create mode 100644 include/grub/compiler-rt.h

diff --git a/configure.ac b/configure.ac
index 25193de..354aec1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1033,7 +1033,7 @@ else
 CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error"
 fi
 CPPFLAGS="$TARGET_CPPFLAGS"
-if test x$target_cpu = xi386 || test x$target_cpu = xx86_64 || test "x$grub_cv_cc_target_clang" = xyes ; then
+if test x$target_cpu = xi386 || test x$target_cpu = xx86_64 || test x$target_cpu = xpowerpc || test "x$grub_cv_cc_target_clang" = xyes; then
 TARGET_LIBGCC=
 else
 TARGET_LIBGCC=-lgcc
@@ -1051,8 +1051,10 @@ fi
 CFLAGS="$TARGET_CFLAGS -nostdlib $DEFSYM"
 fi
 
-# Check for libgcc symbols
-AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __ucmpdi2 _restgpr_14_x)
+if ! test x$target_cpu = xpowerpc; then
+  # Check for libgcc symbols
+  AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __ucmpdi2 _restgpr_14_x)
+fi
 
 if test "x$TARGET_APPLE_LINKER" = x1 ; then
 CFLAGS="$TARGET_CFLAGS -nostdlib -static"
@@ -1617,7 +1619,7 @@ if test x"$enable_werror" != xno ; then
   HOST_CFLAGS="$HOST_CFLAGS -Werror"
 fi
 
-if test "x$grub_cv_cc_target_clang" = xno; then
+if test "x$grub_cv_cc_target_clang" = xno && test x$target_cpu != xpowerpc; then
    TARGET_LDFLAGS_STATIC_LIBGCC="-static-libgcc"
 else
    TARGET_LDFLAGS_STATIC_LIBGCC=
diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am
index 5c087c8..845f132 100644
--- a/grub-core/Makefile.am
+++ b/grub-core/Makefile.am
@@ -76,6 +76,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i18n.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/kernel.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/list.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/misc.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/compiler-rt.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/parser.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 42443bc..0287fa7 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -132,6 +132,7 @@ kernel = {
   common = kern/rescue_reader.c;
   common = kern/term.c;
 
+  noemu = kern/compiler-rt.c;
   noemu = kern/mm.c;
   noemu = kern/time.c;
   noemu = kern/generic/millisleep.c;
@@ -252,6 +253,7 @@ kernel = {
 
   powerpc_ieee1275 = kern/powerpc/cache.S;
   powerpc_ieee1275 = kern/powerpc/dl.c;
+  powerpc_ieee1275 = kern/powerpc/compiler-rt.S;
 
   sparc64_ieee1275 = kern/sparc64/cache.S;
   sparc64_ieee1275 = kern/sparc64/dl.c;
diff --git a/grub-core/kern/compiler-rt.c b/grub-core/kern/compiler-rt.c
new file mode 100644
index 0000000..42689c0
--- /dev/null
+++ b/grub-core/kern/compiler-rt.c
@@ -0,0 +1,166 @@
+/* compiler-rt.c - compiler helpers. */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010-2014  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/misc.h>
+#include <grub/compiler-rt.h>
+
+#if defined (__powerpc__)
+
+union component64
+{
+  grub_uint64_t full;
+  struct
+  {
+#ifdef GRUB_CPU_WORDS_BIGENDIAN
+    grub_uint32_t high;
+    grub_uint32_t low;
+#else
+    grub_uint32_t low;
+    grub_uint32_t high;
+#endif
+  };
+};
+
+/* Based on libgcc2.c from gcc suite.  */
+grub_uint64_t
+__lshrdi3 (grub_uint64_t u, int b)
+{
+  if (b == 0)
+    return u;
+
+  const union component64 uu = {.full = u};
+  const int bm = 32 - b;
+  union component64 w;
+
+  if (bm <= 0)
+    {
+      w.high = 0;
+      w.low = (grub_uint32_t) uu.high >> -bm;
+    }
+  else
+    {
+      const grub_uint32_t carries = (grub_uint32_t) uu.high << bm;
+
+      w.high = (grub_uint32_t) uu.high >> b;
+      w.low = ((grub_uint32_t) uu.low >> b) | carries;
+    }
+
+  return w.full;
+}
+
+/* Based on libgcc2.c from gcc suite.  */
+grub_uint64_t
+__ashrdi3 (grub_uint64_t u, int b)
+{
+  if (b == 0)
+    return u;
+
+  const union component64 uu = {.full = u};
+  const int bm = 32 - b;
+  union component64 w;
+
+  if (bm <= 0)
+    {
+      /* w.high = 1..1 or 0..0 */
+      w.high = uu.high >> (32 - 1);
+      w.low = uu.high >> -bm;
+    }
+  else
+    {
+      const grub_uint32_t carries = (grub_uint32_t) uu.high << bm;
+
+      w.high = uu.high >> b;
+      w.low = ((grub_uint32_t) uu.low >> b) | carries;
+    }
+
+  return w.full;
+}
+
+/* Based on libgcc2.c from gcc suite.  */
+grub_uint64_t
+__ashldi3 (grub_uint64_t u, int b)
+{
+  if (b == 0)
+    return u;
+
+  const union component64 uu = {.full = u};
+  const int bm = 32 - b;
+  union component64 w;
+
+  if (bm <= 0)
+    {
+      w.low = 0;
+      w.high = (grub_uint32_t) uu.low << -bm;
+    }
+  else
+    {
+      const grub_uint32_t carries = (grub_uint32_t) uu.low >> bm;
+
+      w.low = (grub_uint32_t) uu.low << b;
+      w.high = ((grub_uint32_t) uu.high << b) | carries;
+    }
+
+  return w.full;
+}
+
+/* Based on libgcc2.c from gcc suite.  */
+int
+__ucmpdi2 (grub_uint64_t a, grub_uint64_t b)
+{
+  union component64 ac, bc;
+  ac.full = a;
+  bc.full = b;
+
+  if (ac.high < bc.high)
+    return 0;
+  else if (ac.high > bc.high)
+    return 2;
+
+  if (ac.low < bc.low)
+    return 0;
+  else if (ac.low > bc.low)
+    return 2;
+  return 1;
+}
+
+/* Based on libgcc2.c from gcc suite.  */
+grub_uint32_t
+__bswapsi2 (grub_uint32_t u)
+{
+  return ((((u) & 0xff000000) >> 24)
+	  | (((u) & 0x00ff0000) >>  8)
+	  | (((u) & 0x0000ff00) <<  8)
+	  | (((u) & 0x000000ff) << 24));
+}
+
+/* Based on libgcc2.c from gcc suite.  */
+grub_uint64_t
+__bswapdi2 (grub_uint64_t u)
+{
+  return ((((u) & 0xff00000000000000ull) >> 56)
+	  | (((u) & 0x00ff000000000000ull) >> 40)
+	  | (((u) & 0x0000ff0000000000ull) >> 24)
+	  | (((u) & 0x000000ff00000000ull) >>  8)
+	  | (((u) & 0x00000000ff000000ull) <<  8)
+	  | (((u) & 0x0000000000ff0000ull) << 24)
+	  | (((u) & 0x000000000000ff00ull) << 40)
+	  | (((u) & 0x00000000000000ffull) << 56));
+}
+
+#endif
diff --git a/grub-core/kern/powerpc/compiler-rt.S b/grub-core/kern/powerpc/compiler-rt.S
new file mode 100644
index 0000000..63e3a0d
--- /dev/null
+++ b/grub-core/kern/powerpc/compiler-rt.S
@@ -0,0 +1,130 @@
+/*
+ * Special support for eabi and SVR4
+ *
+ *   Copyright (C) 1995-2014 Free Software Foundation, Inc.
+ *   Written By Michael Meissner
+ *   64-bit support written by David Edelsohn
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 3, or (at your option) any
+ * later version.
+ *
+ * This file 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
+ * General Public License for more details.
+ *
+ * Under Section 7 of GPL version 3, you are granted additional
+ * permissions described in the GCC Runtime Library Exception, version
+ * 3.1, as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * a copy of the GCC Runtime Library Exception along with this program;
+ * see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+/* Do any initializations needed for the eabi environment */
+
+#include <grub/symbol.h>
+#include <grub/dl.h>
+
+	.section ".text"
+
+#define CFI_RESTORE(reg)		.cfi_restore reg
+#define CFI_OFFSET(reg, off)		.cfi_offset reg, off
+#define CFI_DEF_CFA_REGISTER(reg)	.cfi_def_cfa_register reg
+#define CFI_STARTPROC			.cfi_startproc
+#define CFI_ENDPROC			.cfi_endproc
+
+/* Routines for restoring integer registers, called by the compiler.  */
+/* Called with r11 pointing to the stack header word of the caller of the */
+/* function, just beyond the end of the integer restore area.  */
+
+CFI_STARTPROC
+CFI_DEF_CFA_REGISTER (11)
+CFI_OFFSET (65, 4)
+CFI_OFFSET (14, -72)
+CFI_OFFSET (15, -68)
+CFI_OFFSET (16, -64)
+CFI_OFFSET (17, -60)
+CFI_OFFSET (18, -56)
+CFI_OFFSET (19, -52)
+CFI_OFFSET (20, -48)
+CFI_OFFSET (21, -44)
+CFI_OFFSET (22, -40)
+CFI_OFFSET (23, -36)
+CFI_OFFSET (24, -32)
+CFI_OFFSET (25, -28)
+CFI_OFFSET (26, -24)
+CFI_OFFSET (27, -20)
+CFI_OFFSET (28, -16)
+CFI_OFFSET (29, -12)
+CFI_OFFSET (30, -8)
+CFI_OFFSET (31, -4)
+FUNCTION(_restgpr_14_x)	lwz	14,-72(11)	/* restore gp registers */
+CFI_RESTORE (14)
+FUNCTION(_restgpr_15_x)	lwz	15,-68(11)
+CFI_RESTORE (15)
+FUNCTION(_restgpr_16_x)	lwz	16,-64(11)
+CFI_RESTORE (16)
+FUNCTION(_restgpr_17_x)	lwz	17,-60(11)
+CFI_RESTORE (17)
+FUNCTION(_restgpr_18_x)	lwz	18,-56(11)
+CFI_RESTORE (18)
+FUNCTION(_restgpr_19_x)	lwz	19,-52(11)
+CFI_RESTORE (19)
+FUNCTION(_restgpr_20_x)	lwz	20,-48(11)
+CFI_RESTORE (20)
+FUNCTION(_restgpr_21_x)	lwz	21,-44(11)
+CFI_RESTORE (21)
+FUNCTION(_restgpr_22_x)	lwz	22,-40(11)
+CFI_RESTORE (22)
+FUNCTION(_restgpr_23_x)	lwz	23,-36(11)
+CFI_RESTORE (23)
+FUNCTION(_restgpr_24_x)	lwz	24,-32(11)
+CFI_RESTORE (24)
+FUNCTION(_restgpr_25_x)	lwz	25,-28(11)
+CFI_RESTORE (25)
+FUNCTION(_restgpr_26_x)	lwz	26,-24(11)
+CFI_RESTORE (26)
+FUNCTION(_restgpr_27_x)	lwz	27,-20(11)
+CFI_RESTORE (27)
+FUNCTION(_restgpr_28_x)	lwz	28,-16(11)
+CFI_RESTORE (28)
+FUNCTION(_restgpr_29_x)	lwz	29,-12(11)
+CFI_RESTORE (29)
+FUNCTION(_restgpr_30_x)	lwz	30,-8(11)
+CFI_RESTORE (30)
+FUNCTION(_restgpr_31_x)	lwz	0,4(11)
+				lwz	31,-4(11)
+CFI_RESTORE (31)
+				mtlr	0
+CFI_RESTORE (65)
+				mr	1,11
+CFI_DEF_CFA_REGISTER (1)
+				blr
+CFI_ENDPROC
+
+CFI_STARTPROC
+FUNCTION(_savegpr_14)	stw	14,-72(11)	/* save gp registers */
+FUNCTION(_savegpr_15)	stw	15,-68(11)
+FUNCTION(_savegpr_16)	stw	16,-64(11)
+FUNCTION(_savegpr_17)	stw	17,-60(11)
+FUNCTION(_savegpr_18)	stw	18,-56(11)
+FUNCTION(_savegpr_19)	stw	19,-52(11)
+FUNCTION(_savegpr_20)	stw	20,-48(11)
+FUNCTION(_savegpr_21)	stw	21,-44(11)
+FUNCTION(_savegpr_22)	stw	22,-40(11)
+FUNCTION(_savegpr_23)	stw	23,-36(11)
+FUNCTION(_savegpr_24)	stw	24,-32(11)
+FUNCTION(_savegpr_25)	stw	25,-28(11)
+FUNCTION(_savegpr_26)	stw	26,-24(11)
+FUNCTION(_savegpr_27)	stw	27,-20(11)
+FUNCTION(_savegpr_28)	stw	28,-16(11)
+FUNCTION(_savegpr_29)	stw	29,-12(11)
+FUNCTION(_savegpr_30)	stw	30,-8(11)
+FUNCTION(_savegpr_31)	stw	31,-4(11)
+			blr
+CFI_ENDPROC
diff --git a/include/grub/compiler-rt.h b/include/grub/compiler-rt.h
new file mode 100644
index 0000000..7f76967
--- /dev/null
+++ b/include/grub/compiler-rt.h
@@ -0,0 +1,82 @@
+/* compiler.h - macros for various compiler features */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010,2014  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_COMPILER_RT_HEADER
+#define GRUB_COMPILER_RT_HEADER	1
+
+#if defined (__powerpc__)
+
+void EXPORT_FUNC (_restgpr_14_x) (void);
+void EXPORT_FUNC (_restgpr_15_x) (void);
+void EXPORT_FUNC (_restgpr_16_x) (void);
+void EXPORT_FUNC (_restgpr_17_x) (void);
+void EXPORT_FUNC (_restgpr_18_x) (void);
+void EXPORT_FUNC (_restgpr_19_x) (void);
+void EXPORT_FUNC (_restgpr_20_x) (void);
+void EXPORT_FUNC (_restgpr_21_x) (void);
+void EXPORT_FUNC (_restgpr_22_x) (void);
+void EXPORT_FUNC (_restgpr_23_x) (void);
+void EXPORT_FUNC (_restgpr_24_x) (void);
+void EXPORT_FUNC (_restgpr_25_x) (void);
+void EXPORT_FUNC (_restgpr_26_x) (void);
+void EXPORT_FUNC (_restgpr_27_x) (void);
+void EXPORT_FUNC (_restgpr_28_x) (void);
+void EXPORT_FUNC (_restgpr_29_x) (void);
+void EXPORT_FUNC (_restgpr_30_x) (void);
+void EXPORT_FUNC (_restgpr_31_x) (void);
+void EXPORT_FUNC (_savegpr_14) (void);
+void EXPORT_FUNC (_savegpr_15) (void);
+void EXPORT_FUNC (_savegpr_16) (void);
+void EXPORT_FUNC (_savegpr_17) (void);
+void EXPORT_FUNC (_savegpr_18) (void);
+void EXPORT_FUNC (_savegpr_19) (void);
+void EXPORT_FUNC (_savegpr_20) (void);
+void EXPORT_FUNC (_savegpr_21) (void);
+void EXPORT_FUNC (_savegpr_22) (void);
+void EXPORT_FUNC (_savegpr_23) (void);
+void EXPORT_FUNC (_savegpr_24) (void);
+void EXPORT_FUNC (_savegpr_25) (void);
+void EXPORT_FUNC (_savegpr_26) (void);
+void EXPORT_FUNC (_savegpr_27) (void);
+void EXPORT_FUNC (_savegpr_28) (void);
+void EXPORT_FUNC (_savegpr_29) (void);
+void EXPORT_FUNC (_savegpr_30) (void);
+void EXPORT_FUNC (_savegpr_31) (void);
+
+grub_uint64_t
+EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b);
+
+grub_uint64_t
+EXPORT_FUNC (__ashrdi3) (grub_uint64_t u, int b);
+
+grub_uint64_t
+EXPORT_FUNC (__ashldi3) (grub_uint64_t u, int b);
+
+int
+EXPORT_FUNC (__ucmpdi2) (grub_uint64_t a, grub_uint64_t b);
+
+grub_uint32_t
+EXPORT_FUNC (__bswapsi2) (grub_uint32_t u);
+
+grub_uint64_t
+EXPORT_FUNC (__bswapdi2) (grub_uint64_t u);
+
+#endif
+
+#endif /* ! GRUB_COMPILER_RT_HEADER */
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 1/3] Add powerpc little-endian (ppc64le) flags
  2014-08-28 19:56 ` [RFC PATCH 1/3] Add powerpc little-endian (ppc64le) flags Paulo Flabiano Smorigo
@ 2014-09-17 22:04   ` Paulo Flabiano Smorigo
  2014-09-19 13:48     ` Colin Watson
  2014-09-21 16:05     ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 2 replies; 19+ messages in thread
From: Paulo Flabiano Smorigo @ 2014-09-17 22:04 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 4219 bytes --]

Thu, Aug 28, 2014 at 04:56:03PM -0300, Paulo Flabiano Smorigo wrote:
> libgcc dependency was removed *just* for this target because
> the distros that use ppc64el doesn't have 32-bit support on it.
> 
> * configure.ac: Add targets for powerpc64el and skip libgcc.
> * Makefile.am: Likewise.
> ---
>  configure.ac          | 17 +++++++++++++++--
>  grub-core/Makefile.am |  2 ++
>  2 files changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 8888c2f..1364c8b 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -119,6 +119,7 @@ if test "x$with_platform" = x; then
>      x86_64-*) platform=pc ;;
>      powerpc-*) platform=ieee1275 ;;
>      powerpc64-*) platform=ieee1275 ;;
> +    powerpc64le-*) platform=ieee1275 ;;
>      sparc64-*) platform=ieee1275 ;;
>      mipsel-*) platform=loongson ;;
>      mips-*) platform=arc ;;
> @@ -137,6 +138,7 @@ case "$target_cpu"-"$platform" in
>    x86_64-xen) ;;
>    x86_64-*) target_cpu=i386 ;;
>    powerpc64-ieee1275) target_cpu=powerpc ;;
> +  powerpc64le-ieee1275) target_cpu=powerpc ;;
>  esac
> 
>  # Check if the platform is supported, make final adjustments.
> @@ -581,6 +583,13 @@ if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
>    TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
>  fi
> 
> +if test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno; then
> +	LD_FORCE_LE=1
> +	TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian -DNO_LIBGCC=1"
> +	TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
> +	TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
> +fi
> +
>  if test "x$target_m32" = x1; then
>    # Force 32-bit mode.
>    TARGET_CFLAGS="$TARGET_CFLAGS -m32"
> @@ -1024,7 +1033,8 @@ else
>  CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error"
>  fi
>  CPPFLAGS="$TARGET_CPPFLAGS"
> -if test x$target_cpu = xi386 || test x$target_cpu = xx86_64 || test "x$grub_cv_cc_target_clang" = xyes ; then
> +if test x$target_cpu = xi386 || test x$target_cpu = xx86_64 || test "x$grub_cv_cc_target_clang" = xyes \
> +	|| ( test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno ); then
>  TARGET_LIBGCC=
>  else
>  TARGET_LIBGCC=-lgcc
> @@ -1608,7 +1618,9 @@ if test x"$enable_werror" != xno ; then
>    HOST_CFLAGS="$HOST_CFLAGS -Werror"
>  fi
> 
> -if test "x$grub_cv_cc_target_clang" = xno; then
> +# if not clang or power LE, use static libgcc
> +if test "x$grub_cv_cc_target_clang" = xno \
> +   || ! ( test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno ); then
>     TARGET_LDFLAGS_STATIC_LIBGCC="-static-libgcc"
>  else
>     TARGET_LDFLAGS_STATIC_LIBGCC=
> @@ -1671,6 +1683,7 @@ AM_CONDITIONAL([COND_mips_arc], [test "(" x$target_cpu = xmips -o x$target_cpu =
>  AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a x$platform = xieee1275])
>  AM_CONDITIONAL([COND_sparc64_emu], [test x$target_cpu = xsparc64 -a x$platform = xemu])
>  AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a x$platform = xieee1275])
> +AM_CONDITIONAL([COND_powerpc_le], [test x$target_cpu = xpowerpc -a x$ac_cv_c_bigendian = xno])
>  AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = xmipsel])
>  AM_CONDITIONAL([COND_mipsel], [test x$target_cpu = xmipsel])
>  AM_CONDITIONAL([COND_mipseb], [test x$target_cpu = xmips])
> diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am
> index 5c087c8..cb7fd9f 100644
> --- a/grub-core/Makefile.am
> +++ b/grub-core/Makefile.am
> @@ -84,8 +84,10 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h
>  KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h
>  KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h
>  if !COND_clang
> +if !COND_powerpc_le
>  KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h
>  endif
> +endif
>  KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h
> 
>  if COND_i386_pc
> -- 
> 1.8.1.4
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> 

I just moved some part of this patch to the second one. Now this patch
only add the target and all libgcc stuff is in the second one.

-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center

[-- Attachment #2: 0001-Add-powerpc-little-endian-ppc64le-flags.patch --]
[-- Type: text/plain, Size: 1530 bytes --]

From 7a2e287e6ed00476c6760797541c3aff49dbeb40 Mon Sep 17 00:00:00 2001
From: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
Date: Wed, 17 Sep 2014 14:42:40 -0300
Subject: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags

* configure.ac: Add target for ppc64le (ppc64el).
---
 configure.ac | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/configure.ac b/configure.ac
index 8662bac..25193de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -119,6 +119,7 @@ if test "x$with_platform" = x; then
     x86_64-*) platform=pc ;;
     powerpc-*) platform=ieee1275 ;;
     powerpc64-*) platform=ieee1275 ;;
+    powerpc64le-*) platform=ieee1275 ;;
     sparc64-*) platform=ieee1275 ;;
     mipsel-*) platform=loongson ;;
     mips-*) platform=arc ;;
@@ -137,6 +138,7 @@ case "$target_cpu"-"$platform" in
   x86_64-xen) ;;
   x86_64-*) target_cpu=i386 ;;
   powerpc64-ieee1275) target_cpu=powerpc ;;
+  powerpc64le-ieee1275) target_cpu=powerpc ;;
 esac
 
 # Check if the platform is supported, make final adjustments.
@@ -581,6 +583,13 @@ if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
   TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
 fi
 
+if test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno; then
+	#LD_FORCE_LE=1
+	TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian"
+	TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
+	TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
+fi
+
 if test "x$target_m32" = x1; then
   # Force 32-bit mode.
   TARGET_CFLAGS="$TARGET_CFLAGS -m32"
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 1/3] Add powerpc little-endian (ppc64le) flags
  2014-09-17 22:04   ` Paulo Flabiano Smorigo
@ 2014-09-19 13:48     ` Colin Watson
  2014-09-21 16:05     ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 19+ messages in thread
From: Colin Watson @ 2014-09-19 13:48 UTC (permalink / raw)
  To: The development of GNU GRUB

On Wed, Sep 17, 2014 at 07:04:44PM -0300, Paulo Flabiano Smorigo wrote:
> +if test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno; then
> +	#LD_FORCE_LE=1

You should probably either uncomment this or remove it.  We don't
normally leave commented-out bits of code lying around, at least not
without another comment explaining what's going on ...

Thanks,

-- 
Colin Watson                                       [cjwatson@ubuntu.com]


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 2/3] Files reorganization and include some libgcc fuctions
  2014-09-17 21:43     ` Paulo Flabiano Smorigo
@ 2014-09-19 14:03       ` Colin Watson
  2014-09-21 16:07       ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 19+ messages in thread
From: Colin Watson @ 2014-09-19 14:03 UTC (permalink / raw)
  To: The development of GNU GRUB

On Wed, Sep 17, 2014 at 06:43:44PM -0300, Paulo Flabiano Smorigo wrote:
> Colin, I changed the patches following your suggestions and making it
> more likely to the no-libgcc branch from Vladimir. In this branch,
> phcoder added compiler-rt.{c,h,S} with the necessary code in it.
> 
> My approach is very minimalist and only for powerpc. I tried to avoid
> change the behavior for other architecture since we are in code freeze.
> 
> In the future we can think in spread this approach for all archs and use
> all implementation that phcoder is doing in the no-libgcc branch.

Thanks, this looks much better now.  I don't feel comfortable pushing it
to master without Vladimir's signoff, but I'll apply this and patch 1/3
to Debian for the time being so that we can get rid of the
build-dependency on a cross-compiler.

Cheers,

-- 
Colin Watson                                       [cjwatson@ubuntu.com]


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 0/3] grub powerpc64 little-endian enablement
  2014-08-28 19:56 [RFC PATCH 0/3] grub powerpc64 little-endian enablement Paulo Flabiano Smorigo
                   ` (2 preceding siblings ...)
  2014-08-28 19:56 ` [RFC PATCH 3/3] Suport for bi-endianess in elf file Paulo Flabiano Smorigo
@ 2014-09-21 13:58 ` Andrei Borzenkov
  2014-09-21 14:24   ` Andrei Borzenkov
  2015-06-15 17:15 ` Andrei Borzenkov
  4 siblings, 1 reply; 19+ messages in thread
From: Andrei Borzenkov @ 2014-09-21 13:58 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Paulo Flabiano Smorigo, pfsmorigo

[-- Attachment #1: Type: text/plain, Size: 1981 bytes --]

В Thu, 28 Aug 2014 16:56:02 -0300
Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:

> From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
> 
> Hi,
> 
> At the beginning of the year we provide a patchset that enabled GRUB for
> little-endian PowerPC. Our approach at the time was to build GRUB itself and
> its tools in 64-bit little-endian. One of the reasons of build in 64-bit is
> to avoid 32-bit dependencies in the distro and build a system entirely 64-bit.
> 
> This patchset was not welcomed at the time because it would bring a
> high-maintainance-cost, without real gain since it could just be cross-compiled.
> 
> After that, Brent Baude, Vladmir (phcoder) and I started to work in a solution
> that would cross-compile but without 32-bit dependencies. This patchset is the
> result of this new approach. It's based on the work of Brent Baude, Vladimir
> (phcoder), and Tomohiro.
> 
> It can be devided in two parts:
> 
>   1) Skip libgcc dependency just for ppc64el (patch 1 and 2);
>   2) Check elf endianess and byteswap if necessary (patch 3);
> 
> The result is GRUB itself in 32-bit BE and its tools in 64-bit LE. This solution
> satisfies the needs of the distros. I tested it in three different distros, in
> both endianess and it's fine.
> 

Unfortunately I'm still not able to boot this version on QEMU. I build
on openSUSE for three acrhs - ppc, ppc64, ppc64le. First two are OK and
boot successfully. Third one does not work - it ends up in exception. I
get initial GRUB greeting and that's all.

Same problem I got with Vladimir libgcc patch series.

It could be toolkit issue of course; but still it would need fixing
before we can merge it.

Could you help in debugging this issue? I have near to zero experience
with PPC; I can do what you tell me, but not much more.

I run it with

qemu-system-ppc64 -M pseries -cdrom /tmp/grub2-ppc64le.iso -boot d

Attached is screenshot of error.



[-- Attachment #2: QEMU_022.png --]
[-- Type: image/x-apple-ios-png, Size: 9292 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 0/3] grub powerpc64 little-endian enablement
  2014-09-21 13:58 ` [RFC PATCH 0/3] grub powerpc64 little-endian enablement Andrei Borzenkov
@ 2014-09-21 14:24   ` Andrei Borzenkov
  2014-09-25 22:48     ` Paulo Flabiano Smorigo
  0 siblings, 1 reply; 19+ messages in thread
From: Andrei Borzenkov @ 2014-09-21 14:24 UTC (permalink / raw)
  To: grub-devel, The development of GNU GRUB; +Cc: Paulo Flabiano Smorigo, pfsmorigo

В Sun, 21 Sep 2014 17:58:44 +0400
Andrei Borzenkov <arvidjaar@gmail.com> пишет:

> В Thu, 28 Aug 2014 16:56:02 -0300
> Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:
> 
> > From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
> > 
> > Hi,
> > 
> > At the beginning of the year we provide a patchset that enabled GRUB for
> > little-endian PowerPC. Our approach at the time was to build GRUB itself and
> > its tools in 64-bit little-endian. One of the reasons of build in 64-bit is
> > to avoid 32-bit dependencies in the distro and build a system entirely 64-bit.
> > 
> > This patchset was not welcomed at the time because it would bring a
> > high-maintainance-cost, without real gain since it could just be cross-compiled.
> > 
> > After that, Brent Baude, Vladmir (phcoder) and I started to work in a solution
> > that would cross-compile but without 32-bit dependencies. This patchset is the
> > result of this new approach. It's based on the work of Brent Baude, Vladimir
> > (phcoder), and Tomohiro.
> > 
> > It can be devided in two parts:
> > 
> >   1) Skip libgcc dependency just for ppc64el (patch 1 and 2);
> >   2) Check elf endianess and byteswap if necessary (patch 3);
> > 
> > The result is GRUB itself in 32-bit BE and its tools in 64-bit LE. This solution
> > satisfies the needs of the distros. I tested it in three different distros, in
> > both endianess and it's fine.
> > 
> 
> Unfortunately I'm still not able to boot this version on QEMU. I build
> on openSUSE for three acrhs - ppc, ppc64, ppc64le. First two are OK and
> boot successfully. Third one does not work - it ends up in exception. I
> get initial GRUB greeting and that's all.
> 
> Same problem I got with Vladimir libgcc patch series.
> 
> It could be toolkit issue of course; but still it would need fixing
> before we can merge it.
> 
> Could you help in debugging this issue? I have near to zero experience
> with PPC; I can do what you tell me, but not much more.
> 
> I run it with
> 
> qemu-system-ppc64 -M pseries -cdrom /tmp/grub2-ppc64le.iso -boot d
> 
> Attached is screenshot of error.
> 
> 

And here is the difference in generated code in case it helps (one
random module as example) ...

--- /tmp/a1	2014-09-21 18:19:59.316494117 +0400
+++ /tmp/a2	2014-09-21 18:20:06.169398736 +0400
@@ -1,5 +1,5 @@
 
-usr.ppc/lib/grub2/powerpc-ieee1275/ext2.mod:     file format elf32-powerpc
+usr.ppc64le/lib/grub2/powerpc-ieee1275/ext2.mod:     file format elf32-powerpc
 
 
 Disassembly of section .text:
@@ -18,15 +18,15 @@ Disassembly of section .text:
   28:	38 21 00 10 	addi    r1,r1,16
   2c:	7c 08 03 a6 	mtlr    r0
   30:	4e 80 00 20 	blr
-  34:	94 21 ff a0 	stwu    r1,-96(r1)
+  34:	94 21 ff 90 	stwu    r1,-112(r1)
   38:	38 e3 00 28 	addi    r7,r3,40
   3c:	7d 80 00 26 	mfcr    r12
   40:	39 23 00 14 	addi    r9,r3,20
   44:	7c 08 02 a6 	mflr    r0
   48:	39 43 00 18 	addi    r10,r3,24
-  4c:	bf 61 00 4c 	stmw    r27,76(r1)
-  50:	90 01 00 64 	stw     r0,100(r1)
-  54:	91 81 00 48 	stw     r12,72(r1)
+  4c:	bf 61 00 5c 	stmw    r27,92(r1)
+  50:	90 01 00 74 	stw     r0,116(r1)
+  54:	91 81 00 58 	stw     r12,88(r1)
   58:	3b c4 ff ff 	addi    r30,r4,-1
   5c:	7c 7f 1b 78 	mr      r31,r3
   60:	7c bc 2b 78 	mr      r28,r5
@@ -103,10 +103,10 @@ Disassembly of section .text:
  17c:	2f 83 00 00 	cmpwi   cr7,r3,0
  180:	41 9e 00 08 	beq     cr7,188 <grub_mod_init-0xd50>
  184:	81 3d 00 00 	lwz     r9,0(r29)
- 188:	81 81 00 48 	lwz     r12,72(r1)
- 18c:	39 61 00 60 	addi    r11,r1,96
+ 188:	81 81 00 58 	lwz     r12,88(r1)
+ 18c:	39 61 00 70 	addi    r11,r1,112
  190:	7d 23 4b 78 	mr      r3,r9
- 194:	7d 80 81 20 	mtcrf   8,r12
+ 194:	7d 90 81 20 	mtocrf  8,r12
  198:	48 00 00 00 	b       198 <grub_mod_init-0xd40>
  19c:	94 21 ff e0 	stwu    r1,-32(r1)
  1a0:	7c 08 02 a6 	mflr    r0
@@ -234,10 +234,10 @@ Disassembly of section .text:
  388:	39 61 00 20 	addi    r11,r1,32
  38c:	80 69 00 00 	lwz     r3,0(r9)
  390:	48 00 00 00 	b       390 <grub_mod_init-0xb48>
- 394:	94 21 ff b0 	stwu    r1,-80(r1)
+ 394:	94 21 ff a0 	stwu    r1,-96(r1)
  398:	7c 08 02 a6 	mflr    r0
- 39c:	be 61 00 1c 	stmw    r19,28(r1)
- 3a0:	90 01 00 54 	stw     r0,84(r1)
+ 39c:	be 61 00 2c 	stmw    r19,44(r1)
+ 3a0:	90 01 00 64 	stw     r0,100(r1)
  3a4:	7c df 33 78 	mr      r31,r6
  3a8:	7c be 2b 78 	mr      r30,r5
  3ac:	83 63 00 00 	lwz     r27,0(r3)
@@ -489,12 +489,12 @@ Disassembly of section .text:
  784:	48 00 00 0c 	b       790 <grub_mod_init-0x748>
  788:	7f c3 f3 78 	mr      r3,r30
  78c:	7f e4 fb 78 	mr      r4,r31
- 790:	39 61 00 50 	addi    r11,r1,80
+ 790:	39 61 00 60 	addi    r11,r1,96
  794:	48 00 00 00 	b       794 <grub_mod_init-0x744>
- 798:	94 21 ff e0 	stwu    r1,-32(r1)
+ 798:	94 21 ff d0 	stwu    r1,-48(r1)
  79c:	7c 08 02 a6 	mflr    r0
- 7a0:	bf a1 00 14 	stmw    r29,20(r1)
- 7a4:	90 01 00 24 	stw     r0,36(r1)
+ 7a0:	bf a1 00 24 	stmw    r29,36(r1)
+ 7a4:	90 01 00 34 	stw     r0,52(r1)
  7a8:	3f a0 00 00 	lis     r29,0
  7ac:	7c 9e 23 78 	mr      r30,r4
  7b0:	83 e3 00 00 	lwz     r31,0(r3)
@@ -525,7 +525,7 @@ Disassembly of section .text:
  814:	7f e3 fb 78 	mr      r3,r31
  818:	48 00 00 01 	bl      818 <grub_mod_init-0x6c0>
  81c:	3d 20 00 00 	lis     r9,0
- 820:	39 61 00 20 	addi    r11,r1,32
+ 820:	39 61 00 30 	addi    r11,r1,48
  824:	80 69 00 00 	lwz     r3,0(r9)
  828:	48 00 00 00 	b       828 <grub_mod_init-0x6b0>
  82c:	94 21 ff e0 	stwu    r1,-32(r1)
@@ -555,13 +555,13 @@ Disassembly of section .text:
  88c:	39 61 00 20 	addi    r11,r1,32
  890:	80 69 00 00 	lwz     r3,0(r9)
  894:	48 00 00 00 	b       894 <grub_mod_init-0x644>
- 898:	94 21 ff d0 	stwu    r1,-48(r1)
+ 898:	94 21 ff c0 	stwu    r1,-64(r1)
  89c:	7c 6b 1b 78 	mr      r11,r3
  8a0:	7c 08 02 a6 	mflr    r0
  8a4:	7c a6 2b 78 	mr      r6,r5
  8a8:	38 ab 00 08 	addi    r5,r11,8
- 8ac:	bf c1 00 28 	stmw    r30,40(r1)
- 8b0:	90 01 00 34 	stw     r0,52(r1)
+ 8ac:	bf c1 00 38 	stmw    r30,56(r1)
+ 8b0:	90 01 00 44 	stw     r0,68(r1)
  8b4:	3b cb 00 70 	addi    r30,r11,112
  8b8:	7c 80 23 78 	mr      r0,r4
  8bc:	80 63 00 00 	lwz     r3,0(r3)
@@ -584,7 +584,7 @@ Disassembly of section .text:
  900:	7d 64 5b 78 	mr      r4,r11
  904:	7c 05 03 78 	mr      r5,r0
  908:	48 00 00 01 	bl      908 <grub_mod_init-0x5d0>
- 90c:	39 61 00 30 	addi    r11,r1,48
+ 90c:	39 61 00 40 	addi    r11,r1,64
  910:	48 00 00 00 	b       910 <grub_mod_init-0x5c8>
  914:	7c 68 1b 78 	mr      r8,r3
  918:	80 63 00 44 	lwz     r3,68(r3)
@@ -596,10 +596,10 @@ Disassembly of section .text:
  930:	81 08 00 14 	lwz     r8,20(r8)
  934:	38 63 01 5c 	addi    r3,r3,348
  938:	4b ff ff 60 	b       898 <grub_mod_init-0x640>
- 93c:	94 21 fe c0 	stwu    r1,-320(r1)
+ 93c:	94 21 fe b0 	stwu    r1,-336(r1)
  940:	7c 08 02 a6 	mflr    r0
- 944:	be c1 01 18 	stmw    r22,280(r1)
- 948:	90 01 01 44 	stw     r0,324(r1)
+ 944:	be c1 01 28 	stmw    r22,296(r1)
+ 948:	90 01 01 54 	stw     r0,340(r1)
  94c:	7c 7f 1b 78 	mr      r31,r3
  950:	7c 9a 23 78 	mr      r26,r4
  954:	7c b9 2b 78 	mr      r25,r5
@@ -715,7 +715,7 @@ Disassembly of section .text:
  b0c:	2f 83 00 00 	cmpwi   cr7,r3,0
  b10:	41 9e fe b0 	beq     cr7,9c0 <grub_mod_init-0x518>
  b14:	38 60 00 01 	li      r3,1
- b18:	39 61 01 40 	addi    r11,r1,320
+ b18:	39 61 01 50 	addi    r11,r1,336
  b1c:	48 00 00 00 	b       b1c <grub_mod_init-0x3bc>
  b20:	94 21 ff d0 	stwu    r1,-48(r1)
  b24:	39 20 00 00 	li      r9,0
@@ -769,10 +769,10 @@ Disassembly of section .text:
  be4:	39 61 00 30 	addi    r11,r1,48
  be8:	80 7f 00 00 	lwz     r3,0(r31)
  bec:	48 00 00 00 	b       bec <grub_mod_init-0x2ec>
- bf0:	94 21 ff f0 	stwu    r1,-16(r1)
+ bf0:	94 21 ff e0 	stwu    r1,-32(r1)
  bf4:	7c 08 02 a6 	mflr    r0
- bf8:	bf c1 00 08 	stmw    r30,8(r1)
- bfc:	90 01 00 14 	stw     r0,20(r1)
+ bf8:	bf c1 00 18 	stmw    r30,24(r1)
+ bfc:	90 01 00 24 	stw     r0,36(r1)
  c00:	7c 7f 1b 78 	mr      r31,r3
  c04:	81 23 00 88 	lwz     r9,136(r3)
  c08:	2f 89 00 00 	cmpwi   cr7,r9,0
@@ -821,7 +821,7 @@ Disassembly of section .text:
  cb4:	7d 20 fc 2c 	lwbrx   r9,0,r31
  cb8:	7f c3 f3 78 	mr      r3,r30
  cbc:	7d 5e 49 ae 	stbx    r10,r30,r9
- cc0:	39 61 00 10 	addi    r11,r1,16
+ cc0:	39 61 00 20 	addi    r11,r1,32
  cc4:	48 00 00 00 	b       cc4 <grub_mod_init-0x214>
  cc8:	94 21 ff d0 	stwu    r1,-48(r1)
  ccc:	7c 08 02 a6 	mflr    r0
@@ -878,14 +878,14 @@ Disassembly of section .text:
  d98:	4e 80 04 21 	bctrl
  d9c:	39 61 00 30 	addi    r11,r1,48
  da0:	48 00 00 00 	b       da0 <grub_mod_init-0x138>
- da4:	94 21 ff d0 	stwu    r1,-48(r1)
+ da4:	94 21 ff c0 	stwu    r1,-64(r1)
  da8:	39 20 00 00 	li      r9,0
  dac:	7c 08 02 a6 	mflr    r0
- db0:	bf 41 00 18 	stmw    r26,24(r1)
+ db0:	bf 41 00 28 	stmw    r26,40(r1)
  db4:	3f a0 00 00 	lis     r29,0
  db8:	7c 7f 1b 78 	mr      r31,r3
  dbc:	80 7d 00 00 	lwz     r3,0(r29)
- dc0:	90 01 00 34 	stw     r0,52(r1)
+ dc0:	90 01 00 44 	stw     r0,68(r1)
  dc4:	7c 9a 23 78 	mr      r26,r4
  dc8:	91 21 00 08 	stw     r9,8(r1)
  dcc:	48 00 00 01 	bl      dcc <grub_mod_init-0x10c>
@@ -953,23 +953,23 @@ Disassembly of section .text:
  ec4:	80 7b 00 00 	lwz     r3,0(r27)
  ec8:	48 00 00 01 	bl      ec8 <grub_mod_init-0x10>
  ecc:	7f a3 eb 78 	mr      r3,r29
- ed0:	39 61 00 30 	addi    r11,r1,48
+ ed0:	39 61 00 40 	addi    r11,r1,64
  ed4:	48 00 00 00 	b       ed4 <grub_mod_init-0x4>
 
 00000ed8 <grub_mod_init>:
- ed8:	94 21 ff f0 	stwu    r1,-16(r1)
+ ed8:	94 21 ff e0 	stwu    r1,-32(r1)
  edc:	3c 80 00 00 	lis     r4,0
  ee0:	7c 08 02 a6 	mflr    r0
  ee4:	38 84 00 00 	addi    r4,r4,0
- ee8:	93 e1 00 0c 	stw     r31,12(r1)
+ ee8:	93 e1 00 1c 	stw     r31,28(r1)
  eec:	7c 7f 1b 78 	mr      r31,r3
  ef0:	3c 60 00 00 	lis     r3,0
- ef4:	90 01 00 14 	stw     r0,20(r1)
+ ef4:	90 01 00 24 	stw     r0,36(r1)
  ef8:	38 63 00 00 	addi    r3,r3,0
  efc:	48 00 00 01 	bl      efc <grub_mod_init+0x24>
  f00:	3d 20 00 00 	lis     r9,0
  f04:	93 e9 00 00 	stw     r31,0(r9)
- f08:	39 61 00 10 	addi    r11,r1,16
+ f08:	39 61 00 20 	addi    r11,r1,32
  f0c:	48 00 00 00 	b       f0c <grub_mod_init+0x34>
 
 00000f10 <grub_mod_fini>:



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 1/3] Add powerpc little-endian (ppc64le) flags
  2014-09-17 22:04   ` Paulo Flabiano Smorigo
  2014-09-19 13:48     ` Colin Watson
@ 2014-09-21 16:05     ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 19+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2014-09-21 16:05 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 484 bytes --]

On 18.09.2014 00:04, Paulo Flabiano Smorigo wrote:
> +if test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno; then
This should be done before endianness check as endianness check may have
other influences as well. Also I think you got the check from host, not
target. AFAIR target doesn't use endian check at all, which makes this
patch unsuitable for cross-compile.

Could you send your latest patch version in new thread? I'm pretty
confused with this thread.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 2/3] Files reorganization and include some libgcc fuctions
  2014-09-17 21:43     ` Paulo Flabiano Smorigo
  2014-09-19 14:03       ` Colin Watson
@ 2014-09-21 16:07       ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 19+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2014-09-21 16:07 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 7887 bytes --]

On 17.09.2014 23:43, Paulo Flabiano Smorigo wrote:
> Colin, I changed the patches following your suggestions and making it
> more likely to the no-libgcc branch from Vladimir. In this branch,
> phcoder added compiler-rt.{c,h,S} with the necessary code in it.
> 
compiler-rt.{c,S} fixes bunch of possible problems when libgcc doesn't
match the intended platform (e.g. because of SSE flags). So I think we
should have whole thing go in.
Biggest problem is the lack of tests for those functions.
> My approach is very minimalist and only for powerpc. I tried to avoid
> change the behavior for other architecture since we are in code freeze.
> 
> In the future we can think in spread this approach for all archs and use
> all implementation that phcoder is doing in the no-libgcc branch.
> 
> Mon, Sep 08, 2014 at 03:16:21AM +0100, Colin Watson wrote:
>> On Thu, Aug 28, 2014 at 04:56:04PM -0300, Paulo Flabiano Smorigo wrote:
>>> diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
>>> index c5c815d..353a207 100644
>>> --- a/grub-core/kern/misc.c
>>> +++ b/grub-core/kern/misc.c
>>> @@ -1342,3 +1342,110 @@ grub_real_boot_time (const char *file,
>>>    grub_error_pop ();
>>>  }
>>>  #endif
>>> +
>>> +#if defined (NO_LIBGCC)
>>
>> Should this perhaps be restricted to __powerpc__ as well?
>> Alternatively, the prototypes in include/grub/compiler.h (or
>> include/grub/misc.h; see below) should be used on other architectures
>> too.  Either way, the declarations and definitions should match.
> 
> Yes, now I only use __powerpc__
> 
>>
>>> diff --git a/include/grub/compiler.h b/include/grub/compiler.h
>>> index c9e1d7a..a9a684c 100644
>>> --- a/include/grub/compiler.h
>>> +++ b/include/grub/compiler.h
>>> @@ -48,4 +48,65 @@
>>>  #  define WARN_UNUSED_RESULT
>>>  #endif
>>>  
>>> +#include "types.h"
>>
>> Shouldn't this be #include <grub/types.h>, assuming that you need this
>> for grub_uint*_t?  Also, includes should generally be grouped at the top
>> of the file.
> 
> All in the compile-rt.c now
> 
>>
>>> +union component64
>>> +{
>>> +  grub_uint64_t full;
>>> +  struct
>>> +  {
>>> +#ifdef GRUB_CPU_WORDS_BIGENDIAN
>>> +    grub_uint32_t high;
>>> +    grub_uint32_t low;
>>> +#else
>>> +    grub_uint32_t low;
>>> +    grub_uint32_t high;
>>> +#endif
>>> +  };
>>> +};
>>
>> This is only used by grub-core/kern/misc.c.  Please move it there rather
>> than putting it somewhere that's included by everything in GRUB.
>>
>>> +#if defined (__powerpc__)
>>
>> Should this be #if defined (__powerpc__) && defined (NO_LIBGCC) or
>> something similar, to match the general way things are set up in
>> configure.ac?  (Also see comment above about declarations matching
>> definitions.)
> 
> Fixed.
> 
>>
>> Relatedly, have you tested this patch set with a native build on a
>> 32-bit BE powerpc system, as opposed to 32-bit BE built on a 64-bit LE
>> system?  This looks like a potential problem there.
>>
> 
> Yes. I tested it in both BE and LE systems. No problem found. I did
> another round of test with this changes and will do some more this week.
> 
>>> +grub_uint64_t EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b);
>>> +grub_uint64_t EXPORT_FUNC (__ashrdi3) (grub_uint64_t u, int b);
>>> +grub_uint64_t EXPORT_FUNC (__ashldi3) (grub_uint64_t u, int b);
>>> +int EXPORT_FUNC(__ucmpdi2) (grub_uint64_t a, grub_uint64_t b);
>>> +void EXPORT_FUNC (_restgpr_14_x) (void);
>> [...]
>>
>> These aren't compiler features, so don't belong in
>> include/grub/compiler.h.  Other architectures seem to have this kind of
>> thing in include/grub/misc.h inside a big #ifndef GRUB_UTIL conditional,
>> so please move all this to there.
> 
> Yes, I follow what phcoder did in no-libgcc branch. This lines are in
> the compiler-rt.c file.
> 
>>
>>> diff --git a/include/grub/libgcc.h b/include/grub/libgcc.h
>>> index 8e93b67..5bdb8fb 100644
>>> --- a/include/grub/libgcc.h
>>> +++ b/include/grub/libgcc.h
>>> @@ -16,73 +16,6 @@
>>>   *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
>>>   */
>>>  
>>> -/* We need to include config-util.h.in for HAVE_*.  */
>>> -#ifndef __STDC_VERSION__
>>> -#define __STDC_VERSION__ 0
>>> -#endif
>>> -#include <config-util.h>
>>> -
>>> -/* On x86 these functions aren't really needed. Save some space.  */
>>> -#if !defined (__i386__) && !defined (__x86_64__)
>>> -# ifdef HAVE___ASHLDI3
>>> -void EXPORT_FUNC (__ashldi3) (void);
>>> -# endif
>>> -# ifdef HAVE___ASHRDI3
>>> -void EXPORT_FUNC (__ashrdi3) (void);
>>> -# endif
>>> -# ifdef HAVE___LSHRDI3
>>> -void EXPORT_FUNC (__lshrdi3) (void);
>>> -# endif
>>> -# ifdef HAVE___UCMPDI2
>>> -void EXPORT_FUNC (__ucmpdi2) (void);
>>> -# endif
>>> -# ifdef HAVE___BSWAPSI2
>>> -void EXPORT_FUNC (__bswapsi2) (void);
>>> -# endif
>>> -# ifdef HAVE___BSWAPDI2
>>> -void EXPORT_FUNC (__bswapdi2) (void);
>>> -# endif
>>> -#endif
>>> -
>>> -#ifdef HAVE__RESTGPR_14_X
>>> -void EXPORT_FUNC (_restgpr_14_x) (void);
>>> -void EXPORT_FUNC (_restgpr_15_x) (void);
>>> -void EXPORT_FUNC (_restgpr_16_x) (void);
>>> -void EXPORT_FUNC (_restgpr_17_x) (void);
>>> -void EXPORT_FUNC (_restgpr_18_x) (void);
>>> -void EXPORT_FUNC (_restgpr_19_x) (void);
>>> -void EXPORT_FUNC (_restgpr_20_x) (void);
>>> -void EXPORT_FUNC (_restgpr_21_x) (void);
>>> -void EXPORT_FUNC (_restgpr_22_x) (void);
>>> -void EXPORT_FUNC (_restgpr_23_x) (void);
>>> -void EXPORT_FUNC (_restgpr_24_x) (void);
>>> -void EXPORT_FUNC (_restgpr_25_x) (void);
>>> -void EXPORT_FUNC (_restgpr_26_x) (void);
>>> -void EXPORT_FUNC (_restgpr_27_x) (void);
>>> -void EXPORT_FUNC (_restgpr_28_x) (void);
>>> -void EXPORT_FUNC (_restgpr_29_x) (void);
>>> -void EXPORT_FUNC (_restgpr_30_x) (void);
>>> -void EXPORT_FUNC (_restgpr_31_x) (void);
>>> -void EXPORT_FUNC (_savegpr_14) (void);
>>> -void EXPORT_FUNC (_savegpr_15) (void);
>>> -void EXPORT_FUNC (_savegpr_16) (void);
>>> -void EXPORT_FUNC (_savegpr_17) (void);
>>> -void EXPORT_FUNC (_savegpr_18) (void);
>>> -void EXPORT_FUNC (_savegpr_19) (void);
>>> -void EXPORT_FUNC (_savegpr_20) (void);
>>> -void EXPORT_FUNC (_savegpr_21) (void);
>>> -void EXPORT_FUNC (_savegpr_22) (void);
>>> -void EXPORT_FUNC (_savegpr_23) (void);
>>> -void EXPORT_FUNC (_savegpr_24) (void);
>>> -void EXPORT_FUNC (_savegpr_25) (void);
>>> -void EXPORT_FUNC (_savegpr_26) (void);
>>> -void EXPORT_FUNC (_savegpr_27) (void);
>>> -void EXPORT_FUNC (_savegpr_28) (void);
>>> -void EXPORT_FUNC (_savegpr_29) (void);
>>> -void EXPORT_FUNC (_savegpr_30) (void);
>>> -void EXPORT_FUNC (_savegpr_31) (void);
>>> -#endif
>>> -
>>>  #if defined (__arm__)
>>>  void EXPORT_FUNC (__aeabi_lasr) (void);
>>>  void EXPORT_FUNC (__aeabi_llsl) (void);
>>
>> I don't think you should touch this file at all.  I don't know precisely
>> how it's used, but it only seems to be used to generate symbol lists;
>> furthermore, you're removing some things from it that are not clearly
>> powerpc-specific and either making them powerpc-specific (__ashldi3,
>> __ashrdi3, __lshrdi3, __ucmpdi2) or dropping them altogether
>> (__bswapsi2, __bswapdi2).  This is worrisome and suggests the
>> possibility that this will break other architectures.  Does your patch
>> work if you just leave include/grub/libgcc.h unmodified?
> 
> Please, check this new patchset. libgcc.h is intact.
> 
>>
>> Thanks,
>>
>> -- 
>> Colin Watson                                       [cjwatson@ubuntu.com]
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>>
> 
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 0/3] grub powerpc64 little-endian enablement
  2014-09-21 14:24   ` Andrei Borzenkov
@ 2014-09-25 22:48     ` Paulo Flabiano Smorigo
  2014-09-26 15:52       ` Andrei Borzenkov
  0 siblings, 1 reply; 19+ messages in thread
From: Paulo Flabiano Smorigo @ 2014-09-25 22:48 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Paulo Flabiano Smorigo

Sun, Sep 21, 2014 at 06:24:25PM +0400, Andrei Borzenkov wrote:
> В Sun, 21 Sep 2014 17:58:44 +0400
> Andrei Borzenkov <arvidjaar@gmail.com> пишет:
> 
> > В Thu, 28 Aug 2014 16:56:02 -0300
> > Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:
> > 
> > > From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
> > > 
> > > Hi,
> > > 
> > > At the beginning of the year we provide a patchset that enabled GRUB for
> > > little-endian PowerPC. Our approach at the time was to build GRUB itself and
> > > its tools in 64-bit little-endian. One of the reasons of build in 64-bit is
> > > to avoid 32-bit dependencies in the distro and build a system entirely 64-bit.
> > > 
> > > This patchset was not welcomed at the time because it would bring a
> > > high-maintainance-cost, without real gain since it could just be cross-compiled.
> > > 
> > > After that, Brent Baude, Vladmir (phcoder) and I started to work in a solution
> > > that would cross-compile but without 32-bit dependencies. This patchset is the
> > > result of this new approach. It's based on the work of Brent Baude, Vladimir
> > > (phcoder), and Tomohiro.
> > > 
> > > It can be devided in two parts:
> > > 
> > >   1) Skip libgcc dependency just for ppc64el (patch 1 and 2);
> > >   2) Check elf endianess and byteswap if necessary (patch 3);
> > > 
> > > The result is GRUB itself in 32-bit BE and its tools in 64-bit LE. This solution
> > > satisfies the needs of the distros. I tested it in three different distros, in
> > > both endianess and it's fine.
> > > 
> > 
> > Unfortunately I'm still not able to boot this version on QEMU. I build
> > on openSUSE for three acrhs - ppc, ppc64, ppc64le. First two are OK and
> > boot successfully. Third one does not work - it ends up in exception. I
> > get initial GRUB greeting and that's all.
> > 
> > Same problem I got with Vladimir libgcc patch series.
> > 
> > It could be toolkit issue of course; but still it would need fixing
> > before we can merge it.
> > 
> > Could you help in debugging this issue? I have near to zero experience
> > with PPC; I can do what you tell me, but not much more.
> > 
> > I run it with
> > 
> > qemu-system-ppc64 -M pseries -cdrom /tmp/grub2-ppc64le.iso -boot d
> > 
> > Attached is screenshot of error.
> > 
> > 
> 
> And here is the difference in generated code in case it helps (one
> random module as example) ...
> 
> --- /tmp/a1	2014-09-21 18:19:59.316494117 +0400
> +++ /tmp/a2	2014-09-21 18:20:06.169398736 +0400
> @@ -1,5 +1,5 @@
>  
> -usr.ppc/lib/grub2/powerpc-ieee1275/ext2.mod:     file format elf32-powerpc
> +usr.ppc64le/lib/grub2/powerpc-ieee1275/ext2.mod:     file format elf32-powerpc
>  
>  
>  Disassembly of section .text:
> @@ -18,15 +18,15 @@ Disassembly of section .text:
>    28:	38 21 00 10 	addi    r1,r1,16
>    2c:	7c 08 03 a6 	mtlr    r0
>    30:	4e 80 00 20 	blr
> -  34:	94 21 ff a0 	stwu    r1,-96(r1)
> +  34:	94 21 ff 90 	stwu    r1,-112(r1)
>    38:	38 e3 00 28 	addi    r7,r3,40
>    3c:	7d 80 00 26 	mfcr    r12
>    40:	39 23 00 14 	addi    r9,r3,20
>    44:	7c 08 02 a6 	mflr    r0
>    48:	39 43 00 18 	addi    r10,r3,24
> -  4c:	bf 61 00 4c 	stmw    r27,76(r1)
> -  50:	90 01 00 64 	stw     r0,100(r1)
> -  54:	91 81 00 48 	stw     r12,72(r1)
> +  4c:	bf 61 00 5c 	stmw    r27,92(r1)
> +  50:	90 01 00 74 	stw     r0,116(r1)
> +  54:	91 81 00 58 	stw     r12,88(r1)
>    58:	3b c4 ff ff 	addi    r30,r4,-1
>    5c:	7c 7f 1b 78 	mr      r31,r3
>    60:	7c bc 2b 78 	mr      r28,r5
> @@ -103,10 +103,10 @@ Disassembly of section .text:
>   17c:	2f 83 00 00 	cmpwi   cr7,r3,0
>   180:	41 9e 00 08 	beq     cr7,188 <grub_mod_init-0xd50>
>   184:	81 3d 00 00 	lwz     r9,0(r29)
> - 188:	81 81 00 48 	lwz     r12,72(r1)
> - 18c:	39 61 00 60 	addi    r11,r1,96
> + 188:	81 81 00 58 	lwz     r12,88(r1)
> + 18c:	39 61 00 70 	addi    r11,r1,112
>   190:	7d 23 4b 78 	mr      r3,r9
> - 194:	7d 80 81 20 	mtcrf   8,r12
> + 194:	7d 90 81 20 	mtocrf  8,r12
>   198:	48 00 00 00 	b       198 <grub_mod_init-0xd40>
>   19c:	94 21 ff e0 	stwu    r1,-32(r1)
>   1a0:	7c 08 02 a6 	mflr    r0
> @@ -234,10 +234,10 @@ Disassembly of section .text:
>   388:	39 61 00 20 	addi    r11,r1,32
>   38c:	80 69 00 00 	lwz     r3,0(r9)
>   390:	48 00 00 00 	b       390 <grub_mod_init-0xb48>
> - 394:	94 21 ff b0 	stwu    r1,-80(r1)
> + 394:	94 21 ff a0 	stwu    r1,-96(r1)
>   398:	7c 08 02 a6 	mflr    r0
> - 39c:	be 61 00 1c 	stmw    r19,28(r1)
> - 3a0:	90 01 00 54 	stw     r0,84(r1)
> + 39c:	be 61 00 2c 	stmw    r19,44(r1)
> + 3a0:	90 01 00 64 	stw     r0,100(r1)
>   3a4:	7c df 33 78 	mr      r31,r6
>   3a8:	7c be 2b 78 	mr      r30,r5
>   3ac:	83 63 00 00 	lwz     r27,0(r3)
> @@ -489,12 +489,12 @@ Disassembly of section .text:
>   784:	48 00 00 0c 	b       790 <grub_mod_init-0x748>
>   788:	7f c3 f3 78 	mr      r3,r30
>   78c:	7f e4 fb 78 	mr      r4,r31
> - 790:	39 61 00 50 	addi    r11,r1,80
> + 790:	39 61 00 60 	addi    r11,r1,96
>   794:	48 00 00 00 	b       794 <grub_mod_init-0x744>
> - 798:	94 21 ff e0 	stwu    r1,-32(r1)
> + 798:	94 21 ff d0 	stwu    r1,-48(r1)
>   79c:	7c 08 02 a6 	mflr    r0
> - 7a0:	bf a1 00 14 	stmw    r29,20(r1)
> - 7a4:	90 01 00 24 	stw     r0,36(r1)
> + 7a0:	bf a1 00 24 	stmw    r29,36(r1)
> + 7a4:	90 01 00 34 	stw     r0,52(r1)
>   7a8:	3f a0 00 00 	lis     r29,0
>   7ac:	7c 9e 23 78 	mr      r30,r4
>   7b0:	83 e3 00 00 	lwz     r31,0(r3)
> @@ -525,7 +525,7 @@ Disassembly of section .text:
>   814:	7f e3 fb 78 	mr      r3,r31
>   818:	48 00 00 01 	bl      818 <grub_mod_init-0x6c0>
>   81c:	3d 20 00 00 	lis     r9,0
> - 820:	39 61 00 20 	addi    r11,r1,32
> + 820:	39 61 00 30 	addi    r11,r1,48
>   824:	80 69 00 00 	lwz     r3,0(r9)
>   828:	48 00 00 00 	b       828 <grub_mod_init-0x6b0>
>   82c:	94 21 ff e0 	stwu    r1,-32(r1)
> @@ -555,13 +555,13 @@ Disassembly of section .text:
>   88c:	39 61 00 20 	addi    r11,r1,32
>   890:	80 69 00 00 	lwz     r3,0(r9)
>   894:	48 00 00 00 	b       894 <grub_mod_init-0x644>
> - 898:	94 21 ff d0 	stwu    r1,-48(r1)
> + 898:	94 21 ff c0 	stwu    r1,-64(r1)
>   89c:	7c 6b 1b 78 	mr      r11,r3
>   8a0:	7c 08 02 a6 	mflr    r0
>   8a4:	7c a6 2b 78 	mr      r6,r5
>   8a8:	38 ab 00 08 	addi    r5,r11,8
> - 8ac:	bf c1 00 28 	stmw    r30,40(r1)
> - 8b0:	90 01 00 34 	stw     r0,52(r1)
> + 8ac:	bf c1 00 38 	stmw    r30,56(r1)
> + 8b0:	90 01 00 44 	stw     r0,68(r1)
>   8b4:	3b cb 00 70 	addi    r30,r11,112
>   8b8:	7c 80 23 78 	mr      r0,r4
>   8bc:	80 63 00 00 	lwz     r3,0(r3)
> @@ -584,7 +584,7 @@ Disassembly of section .text:
>   900:	7d 64 5b 78 	mr      r4,r11
>   904:	7c 05 03 78 	mr      r5,r0
>   908:	48 00 00 01 	bl      908 <grub_mod_init-0x5d0>
> - 90c:	39 61 00 30 	addi    r11,r1,48
> + 90c:	39 61 00 40 	addi    r11,r1,64
>   910:	48 00 00 00 	b       910 <grub_mod_init-0x5c8>
>   914:	7c 68 1b 78 	mr      r8,r3
>   918:	80 63 00 44 	lwz     r3,68(r3)
> @@ -596,10 +596,10 @@ Disassembly of section .text:
>   930:	81 08 00 14 	lwz     r8,20(r8)
>   934:	38 63 01 5c 	addi    r3,r3,348
>   938:	4b ff ff 60 	b       898 <grub_mod_init-0x640>
> - 93c:	94 21 fe c0 	stwu    r1,-320(r1)
> + 93c:	94 21 fe b0 	stwu    r1,-336(r1)
>   940:	7c 08 02 a6 	mflr    r0
> - 944:	be c1 01 18 	stmw    r22,280(r1)
> - 948:	90 01 01 44 	stw     r0,324(r1)
> + 944:	be c1 01 28 	stmw    r22,296(r1)
> + 948:	90 01 01 54 	stw     r0,340(r1)
>   94c:	7c 7f 1b 78 	mr      r31,r3
>   950:	7c 9a 23 78 	mr      r26,r4
>   954:	7c b9 2b 78 	mr      r25,r5
> @@ -715,7 +715,7 @@ Disassembly of section .text:
>   b0c:	2f 83 00 00 	cmpwi   cr7,r3,0
>   b10:	41 9e fe b0 	beq     cr7,9c0 <grub_mod_init-0x518>
>   b14:	38 60 00 01 	li      r3,1
> - b18:	39 61 01 40 	addi    r11,r1,320
> + b18:	39 61 01 50 	addi    r11,r1,336
>   b1c:	48 00 00 00 	b       b1c <grub_mod_init-0x3bc>
>   b20:	94 21 ff d0 	stwu    r1,-48(r1)
>   b24:	39 20 00 00 	li      r9,0
> @@ -769,10 +769,10 @@ Disassembly of section .text:
>   be4:	39 61 00 30 	addi    r11,r1,48
>   be8:	80 7f 00 00 	lwz     r3,0(r31)
>   bec:	48 00 00 00 	b       bec <grub_mod_init-0x2ec>
> - bf0:	94 21 ff f0 	stwu    r1,-16(r1)
> + bf0:	94 21 ff e0 	stwu    r1,-32(r1)
>   bf4:	7c 08 02 a6 	mflr    r0
> - bf8:	bf c1 00 08 	stmw    r30,8(r1)
> - bfc:	90 01 00 14 	stw     r0,20(r1)
> + bf8:	bf c1 00 18 	stmw    r30,24(r1)
> + bfc:	90 01 00 24 	stw     r0,36(r1)
>   c00:	7c 7f 1b 78 	mr      r31,r3
>   c04:	81 23 00 88 	lwz     r9,136(r3)
>   c08:	2f 89 00 00 	cmpwi   cr7,r9,0
> @@ -821,7 +821,7 @@ Disassembly of section .text:
>   cb4:	7d 20 fc 2c 	lwbrx   r9,0,r31
>   cb8:	7f c3 f3 78 	mr      r3,r30
>   cbc:	7d 5e 49 ae 	stbx    r10,r30,r9
> - cc0:	39 61 00 10 	addi    r11,r1,16
> + cc0:	39 61 00 20 	addi    r11,r1,32
>   cc4:	48 00 00 00 	b       cc4 <grub_mod_init-0x214>
>   cc8:	94 21 ff d0 	stwu    r1,-48(r1)
>   ccc:	7c 08 02 a6 	mflr    r0
> @@ -878,14 +878,14 @@ Disassembly of section .text:
>   d98:	4e 80 04 21 	bctrl
>   d9c:	39 61 00 30 	addi    r11,r1,48
>   da0:	48 00 00 00 	b       da0 <grub_mod_init-0x138>
> - da4:	94 21 ff d0 	stwu    r1,-48(r1)
> + da4:	94 21 ff c0 	stwu    r1,-64(r1)
>   da8:	39 20 00 00 	li      r9,0
>   dac:	7c 08 02 a6 	mflr    r0
> - db0:	bf 41 00 18 	stmw    r26,24(r1)
> + db0:	bf 41 00 28 	stmw    r26,40(r1)
>   db4:	3f a0 00 00 	lis     r29,0
>   db8:	7c 7f 1b 78 	mr      r31,r3
>   dbc:	80 7d 00 00 	lwz     r3,0(r29)
> - dc0:	90 01 00 34 	stw     r0,52(r1)
> + dc0:	90 01 00 44 	stw     r0,68(r1)
>   dc4:	7c 9a 23 78 	mr      r26,r4
>   dc8:	91 21 00 08 	stw     r9,8(r1)
>   dcc:	48 00 00 01 	bl      dcc <grub_mod_init-0x10c>
> @@ -953,23 +953,23 @@ Disassembly of section .text:
>   ec4:	80 7b 00 00 	lwz     r3,0(r27)
>   ec8:	48 00 00 01 	bl      ec8 <grub_mod_init-0x10>
>   ecc:	7f a3 eb 78 	mr      r3,r29
> - ed0:	39 61 00 30 	addi    r11,r1,48
> + ed0:	39 61 00 40 	addi    r11,r1,64
>   ed4:	48 00 00 00 	b       ed4 <grub_mod_init-0x4>
>  
>  00000ed8 <grub_mod_init>:
> - ed8:	94 21 ff f0 	stwu    r1,-16(r1)
> + ed8:	94 21 ff e0 	stwu    r1,-32(r1)
>   edc:	3c 80 00 00 	lis     r4,0
>   ee0:	7c 08 02 a6 	mflr    r0
>   ee4:	38 84 00 00 	addi    r4,r4,0
> - ee8:	93 e1 00 0c 	stw     r31,12(r1)
> + ee8:	93 e1 00 1c 	stw     r31,28(r1)
>   eec:	7c 7f 1b 78 	mr      r31,r3
>   ef0:	3c 60 00 00 	lis     r3,0
> - ef4:	90 01 00 14 	stw     r0,20(r1)
> + ef4:	90 01 00 24 	stw     r0,36(r1)
>   ef8:	38 63 00 00 	addi    r3,r3,0
>   efc:	48 00 00 01 	bl      efc <grub_mod_init+0x24>
>   f00:	3d 20 00 00 	lis     r9,0
>   f04:	93 e9 00 00 	stw     r31,0(r9)
> - f08:	39 61 00 10 	addi    r11,r1,16
> + f08:	39 61 00 20 	addi    r11,r1,32
>   f0c:	48 00 00 00 	b       f0c <grub_mod_init+0x34>
>  
>  00000f10 <grub_mod_fini>:
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel


Hi Andrei,

I find out that VSX was the culprit. Can you please take a look at this
patch?
http://lists.gnu.org/archive/html/grub-devel/2014-09/msg00077.html


-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 0/3] grub powerpc64 little-endian enablement
  2014-09-25 22:48     ` Paulo Flabiano Smorigo
@ 2014-09-26 15:52       ` Andrei Borzenkov
  2014-09-26 18:18         ` Paulo Flabiano Smorigo
  0 siblings, 1 reply; 19+ messages in thread
From: Andrei Borzenkov @ 2014-09-26 15:52 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Paulo Flabiano Smorigo, pfsmorigo

В Thu, 25 Sep 2014 19:48:04 -0300
Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:

> Sun, Sep 21, 2014 at 06:24:25PM +0400, Andrei Borzenkov wrote:
> > В Sun, 21 Sep 2014 17:58:44 +0400
> > Andrei Borzenkov <arvidjaar@gmail.com> пишет:
> > 
> > > В Thu, 28 Aug 2014 16:56:02 -0300
> > > Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:
> > > 
> > > > From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
> > > > 
> > > > Hi,
> > > > 
> > > > At the beginning of the year we provide a patchset that enabled GRUB for
> > > > little-endian PowerPC. Our approach at the time was to build GRUB itself and
> > > > its tools in 64-bit little-endian. One of the reasons of build in 64-bit is
> > > > to avoid 32-bit dependencies in the distro and build a system entirely 64-bit.
> > > > 
> > > > This patchset was not welcomed at the time because it would bring a
> > > > high-maintainance-cost, without real gain since it could just be cross-compiled.
> > > > 
> > > > After that, Brent Baude, Vladmir (phcoder) and I started to work in a solution
> > > > that would cross-compile but without 32-bit dependencies. This patchset is the
> > > > result of this new approach. It's based on the work of Brent Baude, Vladimir
> > > > (phcoder), and Tomohiro.
> > > > 
> > > > It can be devided in two parts:
> > > > 
> > > >   1) Skip libgcc dependency just for ppc64el (patch 1 and 2);
> > > >   2) Check elf endianess and byteswap if necessary (patch 3);
> > > > 
> > > > The result is GRUB itself in 32-bit BE and its tools in 64-bit LE. This solution
> > > > satisfies the needs of the distros. I tested it in three different distros, in
> > > > both endianess and it's fine.
> > > > 
> > > 
> > > Unfortunately I'm still not able to boot this version on QEMU. I build
> > > on openSUSE for three acrhs - ppc, ppc64, ppc64le. First two are OK and
> > > boot successfully. Third one does not work - it ends up in exception. I
> > > get initial GRUB greeting and that's all.
> > > 
> > > Same problem I got with Vladimir libgcc patch series.
> > > 
> > > It could be toolkit issue of course; but still it would need fixing
> > > before we can merge it.
> > > 
> > > Could you help in debugging this issue? I have near to zero experience
> > > with PPC; I can do what you tell me, but not much more.
> > > 
> > > I run it with
> > > 
> > > qemu-system-ppc64 -M pseries -cdrom /tmp/grub2-ppc64le.iso -boot d
> > > 
> > > Attached is screenshot of error.
> > > 
> > > 
> > 
> > And here is the difference in generated code in case it helps (one
> > random module as example) ...
> > 
> > --- /tmp/a1	2014-09-21 18:19:59.316494117 +0400
> > +++ /tmp/a2	2014-09-21 18:20:06.169398736 +0400
> > @@ -1,5 +1,5 @@
> >  
> > -usr.ppc/lib/grub2/powerpc-ieee1275/ext2.mod:     file format elf32-powerpc
> > +usr.ppc64le/lib/grub2/powerpc-ieee1275/ext2.mod:     file format elf32-powerpc
> >  
> >  
> >  Disassembly of section .text:
> > @@ -18,15 +18,15 @@ Disassembly of section .text:
> >    28:	38 21 00 10 	addi    r1,r1,16
> >    2c:	7c 08 03 a6 	mtlr    r0
> >    30:	4e 80 00 20 	blr
> > -  34:	94 21 ff a0 	stwu    r1,-96(r1)
> > +  34:	94 21 ff 90 	stwu    r1,-112(r1)
> >    38:	38 e3 00 28 	addi    r7,r3,40
> >    3c:	7d 80 00 26 	mfcr    r12
> >    40:	39 23 00 14 	addi    r9,r3,20
> >    44:	7c 08 02 a6 	mflr    r0
> >    48:	39 43 00 18 	addi    r10,r3,24
> > -  4c:	bf 61 00 4c 	stmw    r27,76(r1)
> > -  50:	90 01 00 64 	stw     r0,100(r1)
> > -  54:	91 81 00 48 	stw     r12,72(r1)
> > +  4c:	bf 61 00 5c 	stmw    r27,92(r1)
> > +  50:	90 01 00 74 	stw     r0,116(r1)
> > +  54:	91 81 00 58 	stw     r12,88(r1)
> >    58:	3b c4 ff ff 	addi    r30,r4,-1
> >    5c:	7c 7f 1b 78 	mr      r31,r3
> >    60:	7c bc 2b 78 	mr      r28,r5
> > @@ -103,10 +103,10 @@ Disassembly of section .text:
> >   17c:	2f 83 00 00 	cmpwi   cr7,r3,0
> >   180:	41 9e 00 08 	beq     cr7,188 <grub_mod_init-0xd50>
> >   184:	81 3d 00 00 	lwz     r9,0(r29)
> > - 188:	81 81 00 48 	lwz     r12,72(r1)
> > - 18c:	39 61 00 60 	addi    r11,r1,96
> > + 188:	81 81 00 58 	lwz     r12,88(r1)
> > + 18c:	39 61 00 70 	addi    r11,r1,112
> >   190:	7d 23 4b 78 	mr      r3,r9
> > - 194:	7d 80 81 20 	mtcrf   8,r12
> > + 194:	7d 90 81 20 	mtocrf  8,r12
> >   198:	48 00 00 00 	b       198 <grub_mod_init-0xd40>
> >   19c:	94 21 ff e0 	stwu    r1,-32(r1)
> >   1a0:	7c 08 02 a6 	mflr    r0
> > @@ -234,10 +234,10 @@ Disassembly of section .text:
> >   388:	39 61 00 20 	addi    r11,r1,32
> >   38c:	80 69 00 00 	lwz     r3,0(r9)
> >   390:	48 00 00 00 	b       390 <grub_mod_init-0xb48>
> > - 394:	94 21 ff b0 	stwu    r1,-80(r1)
> > + 394:	94 21 ff a0 	stwu    r1,-96(r1)
> >   398:	7c 08 02 a6 	mflr    r0
> > - 39c:	be 61 00 1c 	stmw    r19,28(r1)
> > - 3a0:	90 01 00 54 	stw     r0,84(r1)
> > + 39c:	be 61 00 2c 	stmw    r19,44(r1)
> > + 3a0:	90 01 00 64 	stw     r0,100(r1)
> >   3a4:	7c df 33 78 	mr      r31,r6
> >   3a8:	7c be 2b 78 	mr      r30,r5
> >   3ac:	83 63 00 00 	lwz     r27,0(r3)
> > @@ -489,12 +489,12 @@ Disassembly of section .text:
> >   784:	48 00 00 0c 	b       790 <grub_mod_init-0x748>
> >   788:	7f c3 f3 78 	mr      r3,r30
> >   78c:	7f e4 fb 78 	mr      r4,r31
> > - 790:	39 61 00 50 	addi    r11,r1,80
> > + 790:	39 61 00 60 	addi    r11,r1,96
> >   794:	48 00 00 00 	b       794 <grub_mod_init-0x744>
> > - 798:	94 21 ff e0 	stwu    r1,-32(r1)
> > + 798:	94 21 ff d0 	stwu    r1,-48(r1)
> >   79c:	7c 08 02 a6 	mflr    r0
> > - 7a0:	bf a1 00 14 	stmw    r29,20(r1)
> > - 7a4:	90 01 00 24 	stw     r0,36(r1)
> > + 7a0:	bf a1 00 24 	stmw    r29,36(r1)
> > + 7a4:	90 01 00 34 	stw     r0,52(r1)
> >   7a8:	3f a0 00 00 	lis     r29,0
> >   7ac:	7c 9e 23 78 	mr      r30,r4
> >   7b0:	83 e3 00 00 	lwz     r31,0(r3)
> > @@ -525,7 +525,7 @@ Disassembly of section .text:
> >   814:	7f e3 fb 78 	mr      r3,r31
> >   818:	48 00 00 01 	bl      818 <grub_mod_init-0x6c0>
> >   81c:	3d 20 00 00 	lis     r9,0
> > - 820:	39 61 00 20 	addi    r11,r1,32
> > + 820:	39 61 00 30 	addi    r11,r1,48
> >   824:	80 69 00 00 	lwz     r3,0(r9)
> >   828:	48 00 00 00 	b       828 <grub_mod_init-0x6b0>
> >   82c:	94 21 ff e0 	stwu    r1,-32(r1)
> > @@ -555,13 +555,13 @@ Disassembly of section .text:
> >   88c:	39 61 00 20 	addi    r11,r1,32
> >   890:	80 69 00 00 	lwz     r3,0(r9)
> >   894:	48 00 00 00 	b       894 <grub_mod_init-0x644>
> > - 898:	94 21 ff d0 	stwu    r1,-48(r1)
> > + 898:	94 21 ff c0 	stwu    r1,-64(r1)
> >   89c:	7c 6b 1b 78 	mr      r11,r3
> >   8a0:	7c 08 02 a6 	mflr    r0
> >   8a4:	7c a6 2b 78 	mr      r6,r5
> >   8a8:	38 ab 00 08 	addi    r5,r11,8
> > - 8ac:	bf c1 00 28 	stmw    r30,40(r1)
> > - 8b0:	90 01 00 34 	stw     r0,52(r1)
> > + 8ac:	bf c1 00 38 	stmw    r30,56(r1)
> > + 8b0:	90 01 00 44 	stw     r0,68(r1)
> >   8b4:	3b cb 00 70 	addi    r30,r11,112
> >   8b8:	7c 80 23 78 	mr      r0,r4
> >   8bc:	80 63 00 00 	lwz     r3,0(r3)
> > @@ -584,7 +584,7 @@ Disassembly of section .text:
> >   900:	7d 64 5b 78 	mr      r4,r11
> >   904:	7c 05 03 78 	mr      r5,r0
> >   908:	48 00 00 01 	bl      908 <grub_mod_init-0x5d0>
> > - 90c:	39 61 00 30 	addi    r11,r1,48
> > + 90c:	39 61 00 40 	addi    r11,r1,64
> >   910:	48 00 00 00 	b       910 <grub_mod_init-0x5c8>
> >   914:	7c 68 1b 78 	mr      r8,r3
> >   918:	80 63 00 44 	lwz     r3,68(r3)
> > @@ -596,10 +596,10 @@ Disassembly of section .text:
> >   930:	81 08 00 14 	lwz     r8,20(r8)
> >   934:	38 63 01 5c 	addi    r3,r3,348
> >   938:	4b ff ff 60 	b       898 <grub_mod_init-0x640>
> > - 93c:	94 21 fe c0 	stwu    r1,-320(r1)
> > + 93c:	94 21 fe b0 	stwu    r1,-336(r1)
> >   940:	7c 08 02 a6 	mflr    r0
> > - 944:	be c1 01 18 	stmw    r22,280(r1)
> > - 948:	90 01 01 44 	stw     r0,324(r1)
> > + 944:	be c1 01 28 	stmw    r22,296(r1)
> > + 948:	90 01 01 54 	stw     r0,340(r1)
> >   94c:	7c 7f 1b 78 	mr      r31,r3
> >   950:	7c 9a 23 78 	mr      r26,r4
> >   954:	7c b9 2b 78 	mr      r25,r5
> > @@ -715,7 +715,7 @@ Disassembly of section .text:
> >   b0c:	2f 83 00 00 	cmpwi   cr7,r3,0
> >   b10:	41 9e fe b0 	beq     cr7,9c0 <grub_mod_init-0x518>
> >   b14:	38 60 00 01 	li      r3,1
> > - b18:	39 61 01 40 	addi    r11,r1,320
> > + b18:	39 61 01 50 	addi    r11,r1,336
> >   b1c:	48 00 00 00 	b       b1c <grub_mod_init-0x3bc>
> >   b20:	94 21 ff d0 	stwu    r1,-48(r1)
> >   b24:	39 20 00 00 	li      r9,0
> > @@ -769,10 +769,10 @@ Disassembly of section .text:
> >   be4:	39 61 00 30 	addi    r11,r1,48
> >   be8:	80 7f 00 00 	lwz     r3,0(r31)
> >   bec:	48 00 00 00 	b       bec <grub_mod_init-0x2ec>
> > - bf0:	94 21 ff f0 	stwu    r1,-16(r1)
> > + bf0:	94 21 ff e0 	stwu    r1,-32(r1)
> >   bf4:	7c 08 02 a6 	mflr    r0
> > - bf8:	bf c1 00 08 	stmw    r30,8(r1)
> > - bfc:	90 01 00 14 	stw     r0,20(r1)
> > + bf8:	bf c1 00 18 	stmw    r30,24(r1)
> > + bfc:	90 01 00 24 	stw     r0,36(r1)
> >   c00:	7c 7f 1b 78 	mr      r31,r3
> >   c04:	81 23 00 88 	lwz     r9,136(r3)
> >   c08:	2f 89 00 00 	cmpwi   cr7,r9,0
> > @@ -821,7 +821,7 @@ Disassembly of section .text:
> >   cb4:	7d 20 fc 2c 	lwbrx   r9,0,r31
> >   cb8:	7f c3 f3 78 	mr      r3,r30
> >   cbc:	7d 5e 49 ae 	stbx    r10,r30,r9
> > - cc0:	39 61 00 10 	addi    r11,r1,16
> > + cc0:	39 61 00 20 	addi    r11,r1,32
> >   cc4:	48 00 00 00 	b       cc4 <grub_mod_init-0x214>
> >   cc8:	94 21 ff d0 	stwu    r1,-48(r1)
> >   ccc:	7c 08 02 a6 	mflr    r0
> > @@ -878,14 +878,14 @@ Disassembly of section .text:
> >   d98:	4e 80 04 21 	bctrl
> >   d9c:	39 61 00 30 	addi    r11,r1,48
> >   da0:	48 00 00 00 	b       da0 <grub_mod_init-0x138>
> > - da4:	94 21 ff d0 	stwu    r1,-48(r1)
> > + da4:	94 21 ff c0 	stwu    r1,-64(r1)
> >   da8:	39 20 00 00 	li      r9,0
> >   dac:	7c 08 02 a6 	mflr    r0
> > - db0:	bf 41 00 18 	stmw    r26,24(r1)
> > + db0:	bf 41 00 28 	stmw    r26,40(r1)
> >   db4:	3f a0 00 00 	lis     r29,0
> >   db8:	7c 7f 1b 78 	mr      r31,r3
> >   dbc:	80 7d 00 00 	lwz     r3,0(r29)
> > - dc0:	90 01 00 34 	stw     r0,52(r1)
> > + dc0:	90 01 00 44 	stw     r0,68(r1)
> >   dc4:	7c 9a 23 78 	mr      r26,r4
> >   dc8:	91 21 00 08 	stw     r9,8(r1)
> >   dcc:	48 00 00 01 	bl      dcc <grub_mod_init-0x10c>
> > @@ -953,23 +953,23 @@ Disassembly of section .text:
> >   ec4:	80 7b 00 00 	lwz     r3,0(r27)
> >   ec8:	48 00 00 01 	bl      ec8 <grub_mod_init-0x10>
> >   ecc:	7f a3 eb 78 	mr      r3,r29
> > - ed0:	39 61 00 30 	addi    r11,r1,48
> > + ed0:	39 61 00 40 	addi    r11,r1,64
> >   ed4:	48 00 00 00 	b       ed4 <grub_mod_init-0x4>
> >  
> >  00000ed8 <grub_mod_init>:
> > - ed8:	94 21 ff f0 	stwu    r1,-16(r1)
> > + ed8:	94 21 ff e0 	stwu    r1,-32(r1)
> >   edc:	3c 80 00 00 	lis     r4,0
> >   ee0:	7c 08 02 a6 	mflr    r0
> >   ee4:	38 84 00 00 	addi    r4,r4,0
> > - ee8:	93 e1 00 0c 	stw     r31,12(r1)
> > + ee8:	93 e1 00 1c 	stw     r31,28(r1)
> >   eec:	7c 7f 1b 78 	mr      r31,r3
> >   ef0:	3c 60 00 00 	lis     r3,0
> > - ef4:	90 01 00 14 	stw     r0,20(r1)
> > + ef4:	90 01 00 24 	stw     r0,36(r1)
> >   ef8:	38 63 00 00 	addi    r3,r3,0
> >   efc:	48 00 00 01 	bl      efc <grub_mod_init+0x24>
> >   f00:	3d 20 00 00 	lis     r9,0
> >   f04:	93 e9 00 00 	stw     r31,0(r9)
> > - f08:	39 61 00 10 	addi    r11,r1,16
> > + f08:	39 61 00 20 	addi    r11,r1,32
> >   f0c:	48 00 00 00 	b       f0c <grub_mod_init+0x34>
> >  
> >  00000f10 <grub_mod_fini>:
> > 
> > 
> > _______________________________________________
> > Grub-devel mailing list
> > Grub-devel@gnu.org
> > https://lists.gnu.org/mailman/listinfo/grub-devel
> 
> 
> Hi Andrei,
> 
> I find out that VSX was the culprit. Can you please take a look at this
> patch?
> http://lists.gnu.org/archive/html/grub-devel/2014-09/msg00077.html
> 
> 



With this patch it works. I'm really surprised - the same sources built
on different platform (ppc BE) did work without problems. I do not
understand how this can be possible if the problem was in specific CPU
mode. It should have been the same in both cases ...


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 0/3] grub powerpc64 little-endian enablement
  2014-09-26 15:52       ` Andrei Borzenkov
@ 2014-09-26 18:18         ` Paulo Flabiano Smorigo
  0 siblings, 0 replies; 19+ messages in thread
From: Paulo Flabiano Smorigo @ 2014-09-26 18:18 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Paulo Flabiano Smorigo

Fri, Sep 26, 2014 at 07:52:02PM +0400, Andrei Borzenkov wrote:
> В Thu, 25 Sep 2014 19:48:04 -0300
> Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:
> 
> > Sun, Sep 21, 2014 at 06:24:25PM +0400, Andrei Borzenkov wrote:
> > > В Sun, 21 Sep 2014 17:58:44 +0400
> > > Andrei Borzenkov <arvidjaar@gmail.com> пишет:
> > > 
> > > > В Thu, 28 Aug 2014 16:56:02 -0300
> > > > Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:
> > > > 
> > > > > From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
> > > > > 
> > > > > Hi,
> > > > > 
> > > > > At the beginning of the year we provide a patchset that enabled GRUB for
> > > > > little-endian PowerPC. Our approach at the time was to build GRUB itself and
> > > > > its tools in 64-bit little-endian. One of the reasons of build in 64-bit is
> > > > > to avoid 32-bit dependencies in the distro and build a system entirely 64-bit.
> > > > > 
> > > > > This patchset was not welcomed at the time because it would bring a
> > > > > high-maintainance-cost, without real gain since it could just be cross-compiled.
> > > > > 
> > > > > After that, Brent Baude, Vladmir (phcoder) and I started to work in a solution
> > > > > that would cross-compile but without 32-bit dependencies. This patchset is the
> > > > > result of this new approach. It's based on the work of Brent Baude, Vladimir
> > > > > (phcoder), and Tomohiro.
> > > > > 
> > > > > It can be devided in two parts:
> > > > > 
> > > > >   1) Skip libgcc dependency just for ppc64el (patch 1 and 2);
> > > > >   2) Check elf endianess and byteswap if necessary (patch 3);
> > > > > 
> > > > > The result is GRUB itself in 32-bit BE and its tools in 64-bit LE. This solution
> > > > > satisfies the needs of the distros. I tested it in three different distros, in
> > > > > both endianess and it's fine.
> > > > > 
> > > > 
> > > > Unfortunately I'm still not able to boot this version on QEMU. I build
> > > > on openSUSE for three acrhs - ppc, ppc64, ppc64le. First two are OK and
> > > > boot successfully. Third one does not work - it ends up in exception. I
> > > > get initial GRUB greeting and that's all.
> > > > 
> > > > Same problem I got with Vladimir libgcc patch series.
> > > > 
> > > > It could be toolkit issue of course; but still it would need fixing
> > > > before we can merge it.
> > > > 
> > > > Could you help in debugging this issue? I have near to zero experience
> > > > with PPC; I can do what you tell me, but not much more.
> > > > 
> > > > I run it with
> > > > 
> > > > qemu-system-ppc64 -M pseries -cdrom /tmp/grub2-ppc64le.iso -boot d
> > > > 
> > > > Attached is screenshot of error.
> > > > 
> > > > 
> > > 
> > > And here is the difference in generated code in case it helps (one
> > > random module as example) ...
> > > 
> > > --- /tmp/a1	2014-09-21 18:19:59.316494117 +0400
> > > +++ /tmp/a2	2014-09-21 18:20:06.169398736 +0400
> > > @@ -1,5 +1,5 @@
> > >  
> > > -usr.ppc/lib/grub2/powerpc-ieee1275/ext2.mod:     file format elf32-powerpc
> > > +usr.ppc64le/lib/grub2/powerpc-ieee1275/ext2.mod:     file format elf32-powerpc
> > >  
> > >  
> > >  Disassembly of section .text:
> > > @@ -18,15 +18,15 @@ Disassembly of section .text:
> > >    28:	38 21 00 10 	addi    r1,r1,16
> > >    2c:	7c 08 03 a6 	mtlr    r0
> > >    30:	4e 80 00 20 	blr
> > > -  34:	94 21 ff a0 	stwu    r1,-96(r1)
> > > +  34:	94 21 ff 90 	stwu    r1,-112(r1)
> > >    38:	38 e3 00 28 	addi    r7,r3,40
> > >    3c:	7d 80 00 26 	mfcr    r12
> > >    40:	39 23 00 14 	addi    r9,r3,20
> > >    44:	7c 08 02 a6 	mflr    r0
> > >    48:	39 43 00 18 	addi    r10,r3,24
> > > -  4c:	bf 61 00 4c 	stmw    r27,76(r1)
> > > -  50:	90 01 00 64 	stw     r0,100(r1)
> > > -  54:	91 81 00 48 	stw     r12,72(r1)
> > > +  4c:	bf 61 00 5c 	stmw    r27,92(r1)
> > > +  50:	90 01 00 74 	stw     r0,116(r1)
> > > +  54:	91 81 00 58 	stw     r12,88(r1)
> > >    58:	3b c4 ff ff 	addi    r30,r4,-1
> > >    5c:	7c 7f 1b 78 	mr      r31,r3
> > >    60:	7c bc 2b 78 	mr      r28,r5
> > > @@ -103,10 +103,10 @@ Disassembly of section .text:
> > >   17c:	2f 83 00 00 	cmpwi   cr7,r3,0
> > >   180:	41 9e 00 08 	beq     cr7,188 <grub_mod_init-0xd50>
> > >   184:	81 3d 00 00 	lwz     r9,0(r29)
> > > - 188:	81 81 00 48 	lwz     r12,72(r1)
> > > - 18c:	39 61 00 60 	addi    r11,r1,96
> > > + 188:	81 81 00 58 	lwz     r12,88(r1)
> > > + 18c:	39 61 00 70 	addi    r11,r1,112
> > >   190:	7d 23 4b 78 	mr      r3,r9
> > > - 194:	7d 80 81 20 	mtcrf   8,r12
> > > + 194:	7d 90 81 20 	mtocrf  8,r12
> > >   198:	48 00 00 00 	b       198 <grub_mod_init-0xd40>
> > >   19c:	94 21 ff e0 	stwu    r1,-32(r1)
> > >   1a0:	7c 08 02 a6 	mflr    r0
> > > @@ -234,10 +234,10 @@ Disassembly of section .text:
> > >   388:	39 61 00 20 	addi    r11,r1,32
> > >   38c:	80 69 00 00 	lwz     r3,0(r9)
> > >   390:	48 00 00 00 	b       390 <grub_mod_init-0xb48>
> > > - 394:	94 21 ff b0 	stwu    r1,-80(r1)
> > > + 394:	94 21 ff a0 	stwu    r1,-96(r1)
> > >   398:	7c 08 02 a6 	mflr    r0
> > > - 39c:	be 61 00 1c 	stmw    r19,28(r1)
> > > - 3a0:	90 01 00 54 	stw     r0,84(r1)
> > > + 39c:	be 61 00 2c 	stmw    r19,44(r1)
> > > + 3a0:	90 01 00 64 	stw     r0,100(r1)
> > >   3a4:	7c df 33 78 	mr      r31,r6
> > >   3a8:	7c be 2b 78 	mr      r30,r5
> > >   3ac:	83 63 00 00 	lwz     r27,0(r3)
> > > @@ -489,12 +489,12 @@ Disassembly of section .text:
> > >   784:	48 00 00 0c 	b       790 <grub_mod_init-0x748>
> > >   788:	7f c3 f3 78 	mr      r3,r30
> > >   78c:	7f e4 fb 78 	mr      r4,r31
> > > - 790:	39 61 00 50 	addi    r11,r1,80
> > > + 790:	39 61 00 60 	addi    r11,r1,96
> > >   794:	48 00 00 00 	b       794 <grub_mod_init-0x744>
> > > - 798:	94 21 ff e0 	stwu    r1,-32(r1)
> > > + 798:	94 21 ff d0 	stwu    r1,-48(r1)
> > >   79c:	7c 08 02 a6 	mflr    r0
> > > - 7a0:	bf a1 00 14 	stmw    r29,20(r1)
> > > - 7a4:	90 01 00 24 	stw     r0,36(r1)
> > > + 7a0:	bf a1 00 24 	stmw    r29,36(r1)
> > > + 7a4:	90 01 00 34 	stw     r0,52(r1)
> > >   7a8:	3f a0 00 00 	lis     r29,0
> > >   7ac:	7c 9e 23 78 	mr      r30,r4
> > >   7b0:	83 e3 00 00 	lwz     r31,0(r3)
> > > @@ -525,7 +525,7 @@ Disassembly of section .text:
> > >   814:	7f e3 fb 78 	mr      r3,r31
> > >   818:	48 00 00 01 	bl      818 <grub_mod_init-0x6c0>
> > >   81c:	3d 20 00 00 	lis     r9,0
> > > - 820:	39 61 00 20 	addi    r11,r1,32
> > > + 820:	39 61 00 30 	addi    r11,r1,48
> > >   824:	80 69 00 00 	lwz     r3,0(r9)
> > >   828:	48 00 00 00 	b       828 <grub_mod_init-0x6b0>
> > >   82c:	94 21 ff e0 	stwu    r1,-32(r1)
> > > @@ -555,13 +555,13 @@ Disassembly of section .text:
> > >   88c:	39 61 00 20 	addi    r11,r1,32
> > >   890:	80 69 00 00 	lwz     r3,0(r9)
> > >   894:	48 00 00 00 	b       894 <grub_mod_init-0x644>
> > > - 898:	94 21 ff d0 	stwu    r1,-48(r1)
> > > + 898:	94 21 ff c0 	stwu    r1,-64(r1)
> > >   89c:	7c 6b 1b 78 	mr      r11,r3
> > >   8a0:	7c 08 02 a6 	mflr    r0
> > >   8a4:	7c a6 2b 78 	mr      r6,r5
> > >   8a8:	38 ab 00 08 	addi    r5,r11,8
> > > - 8ac:	bf c1 00 28 	stmw    r30,40(r1)
> > > - 8b0:	90 01 00 34 	stw     r0,52(r1)
> > > + 8ac:	bf c1 00 38 	stmw    r30,56(r1)
> > > + 8b0:	90 01 00 44 	stw     r0,68(r1)
> > >   8b4:	3b cb 00 70 	addi    r30,r11,112
> > >   8b8:	7c 80 23 78 	mr      r0,r4
> > >   8bc:	80 63 00 00 	lwz     r3,0(r3)
> > > @@ -584,7 +584,7 @@ Disassembly of section .text:
> > >   900:	7d 64 5b 78 	mr      r4,r11
> > >   904:	7c 05 03 78 	mr      r5,r0
> > >   908:	48 00 00 01 	bl      908 <grub_mod_init-0x5d0>
> > > - 90c:	39 61 00 30 	addi    r11,r1,48
> > > + 90c:	39 61 00 40 	addi    r11,r1,64
> > >   910:	48 00 00 00 	b       910 <grub_mod_init-0x5c8>
> > >   914:	7c 68 1b 78 	mr      r8,r3
> > >   918:	80 63 00 44 	lwz     r3,68(r3)
> > > @@ -596,10 +596,10 @@ Disassembly of section .text:
> > >   930:	81 08 00 14 	lwz     r8,20(r8)
> > >   934:	38 63 01 5c 	addi    r3,r3,348
> > >   938:	4b ff ff 60 	b       898 <grub_mod_init-0x640>
> > > - 93c:	94 21 fe c0 	stwu    r1,-320(r1)
> > > + 93c:	94 21 fe b0 	stwu    r1,-336(r1)
> > >   940:	7c 08 02 a6 	mflr    r0
> > > - 944:	be c1 01 18 	stmw    r22,280(r1)
> > > - 948:	90 01 01 44 	stw     r0,324(r1)
> > > + 944:	be c1 01 28 	stmw    r22,296(r1)
> > > + 948:	90 01 01 54 	stw     r0,340(r1)
> > >   94c:	7c 7f 1b 78 	mr      r31,r3
> > >   950:	7c 9a 23 78 	mr      r26,r4
> > >   954:	7c b9 2b 78 	mr      r25,r5
> > > @@ -715,7 +715,7 @@ Disassembly of section .text:
> > >   b0c:	2f 83 00 00 	cmpwi   cr7,r3,0
> > >   b10:	41 9e fe b0 	beq     cr7,9c0 <grub_mod_init-0x518>
> > >   b14:	38 60 00 01 	li      r3,1
> > > - b18:	39 61 01 40 	addi    r11,r1,320
> > > + b18:	39 61 01 50 	addi    r11,r1,336
> > >   b1c:	48 00 00 00 	b       b1c <grub_mod_init-0x3bc>
> > >   b20:	94 21 ff d0 	stwu    r1,-48(r1)
> > >   b24:	39 20 00 00 	li      r9,0
> > > @@ -769,10 +769,10 @@ Disassembly of section .text:
> > >   be4:	39 61 00 30 	addi    r11,r1,48
> > >   be8:	80 7f 00 00 	lwz     r3,0(r31)
> > >   bec:	48 00 00 00 	b       bec <grub_mod_init-0x2ec>
> > > - bf0:	94 21 ff f0 	stwu    r1,-16(r1)
> > > + bf0:	94 21 ff e0 	stwu    r1,-32(r1)
> > >   bf4:	7c 08 02 a6 	mflr    r0
> > > - bf8:	bf c1 00 08 	stmw    r30,8(r1)
> > > - bfc:	90 01 00 14 	stw     r0,20(r1)
> > > + bf8:	bf c1 00 18 	stmw    r30,24(r1)
> > > + bfc:	90 01 00 24 	stw     r0,36(r1)
> > >   c00:	7c 7f 1b 78 	mr      r31,r3
> > >   c04:	81 23 00 88 	lwz     r9,136(r3)
> > >   c08:	2f 89 00 00 	cmpwi   cr7,r9,0
> > > @@ -821,7 +821,7 @@ Disassembly of section .text:
> > >   cb4:	7d 20 fc 2c 	lwbrx   r9,0,r31
> > >   cb8:	7f c3 f3 78 	mr      r3,r30
> > >   cbc:	7d 5e 49 ae 	stbx    r10,r30,r9
> > > - cc0:	39 61 00 10 	addi    r11,r1,16
> > > + cc0:	39 61 00 20 	addi    r11,r1,32
> > >   cc4:	48 00 00 00 	b       cc4 <grub_mod_init-0x214>
> > >   cc8:	94 21 ff d0 	stwu    r1,-48(r1)
> > >   ccc:	7c 08 02 a6 	mflr    r0
> > > @@ -878,14 +878,14 @@ Disassembly of section .text:
> > >   d98:	4e 80 04 21 	bctrl
> > >   d9c:	39 61 00 30 	addi    r11,r1,48
> > >   da0:	48 00 00 00 	b       da0 <grub_mod_init-0x138>
> > > - da4:	94 21 ff d0 	stwu    r1,-48(r1)
> > > + da4:	94 21 ff c0 	stwu    r1,-64(r1)
> > >   da8:	39 20 00 00 	li      r9,0
> > >   dac:	7c 08 02 a6 	mflr    r0
> > > - db0:	bf 41 00 18 	stmw    r26,24(r1)
> > > + db0:	bf 41 00 28 	stmw    r26,40(r1)
> > >   db4:	3f a0 00 00 	lis     r29,0
> > >   db8:	7c 7f 1b 78 	mr      r31,r3
> > >   dbc:	80 7d 00 00 	lwz     r3,0(r29)
> > > - dc0:	90 01 00 34 	stw     r0,52(r1)
> > > + dc0:	90 01 00 44 	stw     r0,68(r1)
> > >   dc4:	7c 9a 23 78 	mr      r26,r4
> > >   dc8:	91 21 00 08 	stw     r9,8(r1)
> > >   dcc:	48 00 00 01 	bl      dcc <grub_mod_init-0x10c>
> > > @@ -953,23 +953,23 @@ Disassembly of section .text:
> > >   ec4:	80 7b 00 00 	lwz     r3,0(r27)
> > >   ec8:	48 00 00 01 	bl      ec8 <grub_mod_init-0x10>
> > >   ecc:	7f a3 eb 78 	mr      r3,r29
> > > - ed0:	39 61 00 30 	addi    r11,r1,48
> > > + ed0:	39 61 00 40 	addi    r11,r1,64
> > >   ed4:	48 00 00 00 	b       ed4 <grub_mod_init-0x4>
> > >  
> > >  00000ed8 <grub_mod_init>:
> > > - ed8:	94 21 ff f0 	stwu    r1,-16(r1)
> > > + ed8:	94 21 ff e0 	stwu    r1,-32(r1)
> > >   edc:	3c 80 00 00 	lis     r4,0
> > >   ee0:	7c 08 02 a6 	mflr    r0
> > >   ee4:	38 84 00 00 	addi    r4,r4,0
> > > - ee8:	93 e1 00 0c 	stw     r31,12(r1)
> > > + ee8:	93 e1 00 1c 	stw     r31,28(r1)
> > >   eec:	7c 7f 1b 78 	mr      r31,r3
> > >   ef0:	3c 60 00 00 	lis     r3,0
> > > - ef4:	90 01 00 14 	stw     r0,20(r1)
> > > + ef4:	90 01 00 24 	stw     r0,36(r1)
> > >   ef8:	38 63 00 00 	addi    r3,r3,0
> > >   efc:	48 00 00 01 	bl      efc <grub_mod_init+0x24>
> > >   f00:	3d 20 00 00 	lis     r9,0
> > >   f04:	93 e9 00 00 	stw     r31,0(r9)
> > > - f08:	39 61 00 10 	addi    r11,r1,16
> > > + f08:	39 61 00 20 	addi    r11,r1,32
> > >   f0c:	48 00 00 00 	b       f0c <grub_mod_init+0x34>
> > >  
> > >  00000f10 <grub_mod_fini>:
> > > 
> > > 
> > > _______________________________________________
> > > Grub-devel mailing list
> > > Grub-devel@gnu.org
> > > https://lists.gnu.org/mailman/listinfo/grub-devel
> > 
> > 
> > Hi Andrei,
> > 
> > I find out that VSX was the culprit. Can you please take a look at this
> > patch?
> > http://lists.gnu.org/archive/html/grub-devel/2014-09/msg00077.html
> > 
> > 
> 
> 
> 
> With this patch it works. I'm really surprised - the same sources built
> on different platform (ppc BE) did work without problems. I do not
> understand how this can be possible if the problem was in specific CPU
> mode. It should have been the same in both cases ...

Check "gcc -v" for --with-cpu=power7. That flag enables VSX and Altivec.

> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 0/3] grub powerpc64 little-endian enablement
  2014-08-28 19:56 [RFC PATCH 0/3] grub powerpc64 little-endian enablement Paulo Flabiano Smorigo
                   ` (3 preceding siblings ...)
  2014-09-21 13:58 ` [RFC PATCH 0/3] grub powerpc64 little-endian enablement Andrei Borzenkov
@ 2015-06-15 17:15 ` Andrei Borzenkov
  2015-06-16 12:36   ` Paulo Flabiano Smorigo
  4 siblings, 1 reply; 19+ messages in thread
From: Andrei Borzenkov @ 2015-06-15 17:15 UTC (permalink / raw)
  To: Paulo Flabiano Smorigo; +Cc: grub-devel, Paulo Flabiano Smorigo

В Thu, 28 Aug 2014 16:56:02 -0300
Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:

> From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
> 
> Hi,
> 
> At the beginning of the year we provide a patchset that enabled GRUB for
> little-endian PowerPC. Our approach at the time was to build GRUB itself and
> its tools in 64-bit little-endian. One of the reasons of build in 64-bit is
> to avoid 32-bit dependencies in the distro and build a system entirely 64-bit.
> 
> This patchset was not welcomed at the time because it would bring a
> high-maintainance-cost, without real gain since it could just be cross-compiled.
> 
> After that, Brent Baude, Vladmir (phcoder) and I started to work in a solution
> that would cross-compile but without 32-bit dependencies. This patchset is the
> result of this new approach. It's based on the work of Brent Baude, Vladimir
> (phcoder), and Tomohiro.
> 
> It can be devided in two parts:
> 
>   1) Skip libgcc dependency just for ppc64el (patch 1 and 2);

This is now default for all platforms

>   2) Check elf endianess and byteswap if necessary (patch 3);
>

That's still pending.
 
> The result is GRUB itself in 32-bit BE and its tools in 64-bit LE. This solution
> satisfies the needs of the distros. I tested it in three different distros, in
> both endianess and it's fine.
> 
> If thoses patches were accepted we will have an official solution. Nowadays,
> distros are taking diffrent approachs. Some of then are using the original
> solutions and others are using cross-compiler.
>

Could you resend missing bits rebased to current head?


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 0/3] grub powerpc64 little-endian enablement
  2015-06-15 17:15 ` Andrei Borzenkov
@ 2015-06-16 12:36   ` Paulo Flabiano Smorigo
  0 siblings, 0 replies; 19+ messages in thread
From: Paulo Flabiano Smorigo @ 2015-06-16 12:36 UTC (permalink / raw)
  To: Andrei Borzenkov; +Cc: grub-devel, Paulo Flabiano Smorigo

On 2015-06-15 14:15, Andrei Borzenkov wrote:
> В Thu, 28 Aug 2014 16:56:02 -0300
> Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:
>
>> From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
>>
>> Hi,
>>
>> At the beginning of the year we provide a patchset that enabled GRUB for
>> little-endian PowerPC. Our approach at the time was to build GRUB itself and
>> its tools in 64-bit little-endian. One of the reasons of build in 64-bit is
>> to avoid 32-bit dependencies in the distro and build a system entirely 64-bit.
>>
>> This patchset was not welcomed at the time because it would bring a
>> high-maintainance-cost, without real gain since it could just be cross-compiled.
>>
>> After that, Brent Baude, Vladmir (phcoder) and I started to work in a solution
>> that would cross-compile but without 32-bit dependencies. This patchset is the
>> result of this new approach. It's based on the work of Brent Baude, Vladimir
>> (phcoder), and Tomohiro.
>>
>> It can be devided in two parts:
>>
>>    1) Skip libgcc dependency just for ppc64el (patch 1 and 2);
>
> This is now default for all platforms
>
>>    2) Check elf endianess and byteswap if necessary (patch 3);
>>
>
> That's still pending.

Yes, I'm aware of that. :)

>
>> The result is GRUB itself in 32-bit BE and its tools in 64-bit LE. This solution
>> satisfies the needs of the distros. I tested it in three different distros, in
>> both endianess and it's fine.
>>
>> If thoses patches were accepted we will have an official solution. Nowadays,
>> distros are taking diffrent approachs. Some of then are using the original
>> solutions and others are using cross-compiler.
>>
>
> Could you resend missing bits rebased to current head?
>
Sure thing. I'll review it once more and send it to the ML later this week.

-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH 3/3] Suport for bi-endianess in elf file
  2014-08-28 19:56 ` [RFC PATCH 3/3] Suport for bi-endianess in elf file Paulo Flabiano Smorigo
@ 2015-06-16 16:44   ` Andrei Borzenkov
  0 siblings, 0 replies; 19+ messages in thread
From: Andrei Borzenkov @ 2015-06-16 16:44 UTC (permalink / raw)
  To: The development of GNU GRUB

On Thu, Aug 28, 2014 at 10:56 PM, Paulo Flabiano Smorigo
<pfsmorigo@linux.vnet.ibm.com> wrote:
> * grub-core/kern/elf.c: check and switch endianess with grub_{be,le}_to
>   cpu functions.
> * grub-core/kern/elfXX.c: Likewise.
>

As a general comment - currently we need it for one platform only so
let's wrap additional code in #ifdef __powerpc__ until any more users
emerge, to avoid dead code on other platforms (especially size-critical
like i386-pc).


> Also-by: Tomohiro B Berry <tbberry@us.ibm.com>
> ---
>  grub-core/kern/elf.c   | 60 +++++++++++++++++++++++++++++++++++++++--
>  grub-core/kern/elfXX.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 131 insertions(+), 2 deletions(-)
>
> diff --git a/grub-core/kern/elf.c b/grub-core/kern/elf.c
> index 5f99c43..de90811 100644
> --- a/grub-core/kern/elf.c
> +++ b/grub-core/kern/elf.c
> @@ -28,6 +28,11 @@
>
>  GRUB_MOD_LICENSE ("GPLv3+");
>
> +void grub_elf32_check_endianess (grub_elf_t elf);
> +void grub_elf64_check_endianess (grub_elf_t elf);
> +grub_err_t grub_elf32_check_version (grub_elf_t elf);
> +grub_err_t grub_elf64_check_version (grub_elf_t elf);
> +
>  /* Check if EHDR is a valid ELF header.  */
>  static grub_err_t
>  grub_elf_check_header (grub_elf_t elf)
> @@ -38,10 +43,22 @@ grub_elf_check_header (grub_elf_t elf)
>        || e->e_ident[EI_MAG1] != ELFMAG1
>        || e->e_ident[EI_MAG2] != ELFMAG2
>        || e->e_ident[EI_MAG3] != ELFMAG3
> -      || e->e_ident[EI_VERSION] != EV_CURRENT
> -      || e->e_version != EV_CURRENT)
> +      || e->e_ident[EI_VERSION] != EV_CURRENT)
>      return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF magic"));
>
> +  if (grub_elf_is_elf32 (elf))
> +    {
> +      grub_elf32_check_endianess (elf);
> +      grub_elf32_check_version (elf);
> +    }
> +  else if (grub_elf_is_elf64 (elf))
> +    {
> +      grub_elf64_check_endianess (elf);
> +      grub_elf64_check_version (elf);
> +    }

This ignores any errors these functions may return. I would suggest

#if defined(__powerpc__)

if ((grub_elf_is_elf32 (elf))
  grub_elf32_check_endianess (elf);
...

> +  else
> +    return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
> +

It probably should be "Uknown ELF class" here.

#endif /* __powerpc__ */

if (e->e_version != EV_CURRENT)
  return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF
magic"));

>    return GRUB_ERR_NONE;
>  }
>
> @@ -127,7 +144,20 @@ grub_elf_open (const char *name)
>  #define grub_elf_is_elfXX grub_elf_is_elf32
>  #define grub_elfXX_load_phdrs grub_elf32_load_phdrs
>  #define ElfXX_Phdr Elf32_Phdr
> +#define ElfXX_Ehdr Elf32_Ehdr
>  #define grub_uintXX_t grub_uint32_t
> +#define grub_be_to_halfXX grub_be_to_cpu16
> +#define grub_be_to_wordXX grub_be_to_cpu32
> +#define grub_be_to_addrXX grub_be_to_cpu32
> +#define grub_be_to_offXX grub_be_to_cpu32
> +#define grub_be_to_XwordXX grub_be_to_wordXX

Only addr and off are different between 32/64. Do we really need to
define others?

> +#define grub_le_to_halfXX grub_le_to_cpu16
> +#define grub_le_to_wordXX grub_le_to_cpu32
> +#define grub_le_to_addrXX grub_le_to_cpu32
> +#define grub_le_to_offXX grub_le_to_cpu32
> +#define grub_le_to_XwordXX grub_le_to_wordXX
> +#define grub_elfXX_check_endianess grub_elf32_check_endianess
> +#define grub_elfXX_check_version grub_elf32_check_version
>
>  #include "elfXX.c"
>
> @@ -140,7 +170,20 @@ grub_elf_open (const char *name)
>  #undef grub_elf_is_elfXX
>  #undef grub_elfXX_load_phdrs
>  #undef ElfXX_Phdr
> +#undef ElfXX_Ehdr
>  #undef grub_uintXX_t
> +#undef grub_be_to_halfXX
> +#undef grub_be_to_wordXX
> +#undef grub_be_to_addrXX
> +#undef grub_be_to_offXX
> +#undef grub_be_to_XwordXX
> +#undef grub_le_to_halfXX
> +#undef grub_le_to_wordXX
> +#undef grub_le_to_addrXX
> +#undef grub_le_to_offXX
> +#undef grub_le_to_XwordXX
> +#undef grub_elfXX_check_endianess
> +#undef grub_elfXX_check_version
>
>
>  /* 64-bit */
> @@ -153,6 +196,19 @@ grub_elf_open (const char *name)
>  #define grub_elf_is_elfXX grub_elf_is_elf64
>  #define grub_elfXX_load_phdrs grub_elf64_load_phdrs
>  #define ElfXX_Phdr Elf64_Phdr
> +#define ElfXX_Ehdr Elf64_Ehdr
>  #define grub_uintXX_t grub_uint64_t
> +#define grub_be_to_halfXX grub_be_to_cpu16
> +#define grub_be_to_wordXX grub_be_to_cpu32
> +#define grub_be_to_addrXX grub_be_to_cpu64
> +#define grub_be_to_offXX grub_be_to_cpu64
> +#define grub_be_to_XwordXX grub_be_to_cpu64
> +#define grub_le_to_halfXX grub_le_to_cpu16
> +#define grub_le_to_wordXX grub_le_to_cpu32
> +#define grub_le_to_addrXX grub_le_to_cpu64
> +#define grub_le_to_offXX grub_le_to_cpu64
> +#define grub_le_to_XwordXX grub_le_to_cpu64
> +#define grub_elfXX_check_endianess grub_elf64_check_endianess
> +#define grub_elfXX_check_version grub_elf64_check_version
>
>  #include "elfXX.c"
> diff --git a/grub-core/kern/elfXX.c b/grub-core/kern/elfXX.c
> index 1d09971..ecf9df6 100644
> --- a/grub-core/kern/elfXX.c
> +++ b/grub-core/kern/elfXX.c
> @@ -154,3 +154,76 @@ grub_elfXX_load (grub_elf_t elf, const char *filename,
>
>    return grub_errno;
>  }
> +
> +void
> +grub_elfXX_check_endianess (grub_elf_t elf)
> +{
> +  ElfXX_Ehdr *e = &(elf->ehdr.ehdrXX);
> +  ElfXX_Phdr *phdr;
> +

This block is not needed on BE systems; and as of this writing there is
no LE system that needs it at all, so I suggest to leave it in place
but effectively ifdef out like

#if !defined(GRUB_CPU_WORDS_BIGENDIAN) && 0

> +  if (e->e_ident[EI_DATA] == ELFDATA2MSB)
> +    {
> +      e->e_type = grub_be_to_halfXX (e->e_type);
> +      e->e_machine = grub_be_to_halfXX (e->e_machine);
> +      e->e_version = grub_be_to_wordXX (e->e_version);
> +      e->e_entry = grub_be_to_addrXX (e->e_entry);
> +      e->e_phoff = grub_be_to_offXX (e->e_phoff);
> +      e->e_shoff = grub_be_to_offXX (e->e_shoff);
> +      e->e_flags = grub_be_to_wordXX (e->e_flags);
> +      e->e_ehsize = grub_be_to_halfXX (e->e_ehsize);
> +      e->e_phentsize = grub_be_to_halfXX (e->e_phentsize);
> +      e->e_phnum = grub_be_to_halfXX (e->e_phnum);
> +      e->e_shentsize = grub_be_to_halfXX (e->e_shentsize);
> +      e->e_shnum = grub_be_to_halfXX (e->e_shnum);
> +      e->e_shstrndx = grub_be_to_halfXX (e->e_shstrndx);
> +
> +      FOR_ELFXX_PHDRS (elf,phdr)
> +        {

I suggest split in two parts - first one to byteswap ELF headers and
second one for p-sections in grub_elfXX_load_phdrs. This makes error
handling easier - byteswap is always possible, and at the point it will
be called in grub_elfXX_load_phdrs all error checks are done. Also it is
not needed until version is validated and we actually decide to load
sections.

And please wrap them under #ifdef __powerpc__ as well.

> +          phdr->p_type = grub_be_to_wordXX (phdr->p_type);
> +          phdr->p_flags = grub_be_to_wordXX (phdr->p_flags);
> +          phdr->p_offset = grub_be_to_offXX (phdr->p_offset);
> +          phdr->p_vaddr = grub_be_to_addrXX (phdr->p_vaddr);
> +          phdr->p_paddr = grub_be_to_addrXX (phdr->p_paddr);
> +          phdr->p_filesz = grub_be_to_XwordXX (phdr->p_filesz);
> +          phdr->p_memsz = grub_be_to_XwordXX (phdr->p_memsz);
> +          phdr->p_align = grub_be_to_XwordXX (phdr->p_align);
> +        }
> +    }

#endif

#if defined(GRUB_CPU_WORDS_BIGENDIAN) && defined(__powerpc__) (or
whatever is needed to detect it) By the same logic code is needed on BE
platforms only and so far only on PPC.

> +  else if (e->e_ident[EI_DATA] == ELFDATA2LSB)
> +    {
> +      e->e_type = grub_le_to_halfXX (e->e_type);
> +      e->e_machine = grub_le_to_halfXX (e->e_machine);
> +      e->e_version = grub_le_to_wordXX (e->e_version);
> +      e->e_entry = grub_le_to_addrXX (e->e_entry);
> +      e->e_phoff = grub_le_to_offXX (e->e_phoff);
> +      e->e_shoff = grub_le_to_offXX (e->e_shoff);
> +      e->e_flags = grub_le_to_wordXX (e->e_flags);
> +      e->e_ehsize = grub_le_to_halfXX (e->e_ehsize);
> +      e->e_phentsize = grub_le_to_halfXX (e->e_phentsize);
> +      e->e_phnum = grub_le_to_halfXX (e->e_phnum);
> +      e->e_shentsize = grub_le_to_halfXX (e->e_shentsize);
> +      e->e_shnum = grub_le_to_halfXX (e->e_shnum);
> +      e->e_shstrndx = grub_le_to_halfXX (e->e_shstrndx);
> +
> +      FOR_ELFXX_PHDRS (elf,phdr)
> +        {
> +          phdr->p_type = grub_le_to_wordXX (phdr->p_type);
> +          phdr->p_flags = grub_le_to_wordXX (phdr->p_flags);
> +          phdr->p_offset = grub_le_to_offXX (phdr->p_offset);
> +          phdr->p_vaddr = grub_le_to_addrXX (phdr->p_vaddr);
> +          phdr->p_paddr = grub_le_to_addrXX (phdr->p_paddr);
> +          phdr->p_filesz = grub_le_to_XwordXX (phdr->p_filesz);
> +          phdr->p_memsz = grub_le_to_XwordXX (phdr->p_memsz);
> +          phdr->p_align = grub_le_to_XwordXX (phdr->p_align);
> +        }
> +    }
> +}
> +
> +grub_err_t
> +grub_elfXX_check_version (grub_elf_t elf)
> +{
> +  if (elf->ehdr.ehdrXX.e_version != EV_CURRENT)
> +    return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF magic"));
> +
> +  return GRUB_ERR_NONE;
> +}

This becomes redundant with suggested reorder.

> --
> 1.8.1.4
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2015-06-16 16:45 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-28 19:56 [RFC PATCH 0/3] grub powerpc64 little-endian enablement Paulo Flabiano Smorigo
2014-08-28 19:56 ` [RFC PATCH 1/3] Add powerpc little-endian (ppc64le) flags Paulo Flabiano Smorigo
2014-09-17 22:04   ` Paulo Flabiano Smorigo
2014-09-19 13:48     ` Colin Watson
2014-09-21 16:05     ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-08-28 19:56 ` [RFC PATCH 2/3] Files reorganization and include some libgcc fuctions Paulo Flabiano Smorigo
2014-09-08  2:16   ` Colin Watson
2014-09-17 21:43     ` Paulo Flabiano Smorigo
2014-09-19 14:03       ` Colin Watson
2014-09-21 16:07       ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-08-28 19:56 ` [RFC PATCH 3/3] Suport for bi-endianess in elf file Paulo Flabiano Smorigo
2015-06-16 16:44   ` Andrei Borzenkov
2014-09-21 13:58 ` [RFC PATCH 0/3] grub powerpc64 little-endian enablement Andrei Borzenkov
2014-09-21 14:24   ` Andrei Borzenkov
2014-09-25 22:48     ` Paulo Flabiano Smorigo
2014-09-26 15:52       ` Andrei Borzenkov
2014-09-26 18:18         ` Paulo Flabiano Smorigo
2015-06-15 17:15 ` Andrei Borzenkov
2015-06-16 12:36   ` Paulo Flabiano Smorigo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.