Skip to contentSkip to conversation

grub 64bit little-endian on power

RFC PATCH In review Ram Pai 4 participants 68 messages Feb 26, 2014 – Sep 28, 2014 1 message not in the archive Kbuild

lore
Share & tools
lore

Ram Pai

author
#0 lore raw

cover grub 64bit little-endian on power

The following patches enable grub to support
64bit Little Endian Power architecture.

Anton Blanchard (12):
Add IEEE1275_ADDR helper
Fix some more warnings when casting.
Add powerpc64 types
Fix warnings when building powerpc linux loader 64bit Fix powerpc setjmp/longjmp 64bit issues
Add powerpc64 ieee1275 trampoline
Add 64bit support to powerpc startup code
Add grub_dl_find_section_addr
Add ppc64 relocations
ppc64 doesn't need libgcc routines
Use FUNC_START/FUNC_END for powerpc function definitions powerpc64 is not necessarily BigEndian anymore! :)

Ram Pai (11):
Add a new architecture to the build process
Build grub as O1 until we add savegpr and restgpr routines powerpc64 LE's linker knows how to handle the undefined symbol .TOC.
in grub modules. So just ignore that symbol during build.
grub-install can now recognize and install a LE grub boot loader set the ABI version to 0x02 in the e_flag of the PPC64LE ELF image. GRUB_ELF_R_PPC_* processing is applicable only for 32 bit bootloader. .TOC. symbol is special in ppc64le . It maps to the address of the
.toc section.
the .toc section in powerpc64le modules are sometimes not aligned on a
four byte boundary. This fails the module linker especially when
processing R_PPC64_TOC16_LO_DS, since the addresses are expected
to be aligned on 4byte boundary.
all parameter to firmware calls should to be BigEndian and the results
should be CPU endian.
grub segfaults if initrd is specified before specifying the kernel.
The problem is the initrd module sees that kernel is not specified
and takes the fail path. In the fail path it checks if anything
has be malloc'ed. Unfortunately the variable that it looks to
check for is a uninitialized stack variable. The stack variable
can incorrectly indicate something is malloced, which leads the
module to free some unallocated memory. This patch fixes the
problem by initializing the stack variable.
Power7 cannot handle VSX instructions correctly. It segfaults.
This patch is applicable only for power7 systems.

Thomas Falcon (1):
Add a new architecture to the build process

Tomohiro B Berry (1):
Add a new architecture to the build process

 Makefile.am                               |   4 +
 config.h.in                               |   4 +
 configure.ac                              |  17 ++-
 gentpl.py                                 |   7 +-
 grub-core/Makefile.am                     |   7 ++
 grub-core/Makefile.core.def               |  20 ++++
 grub-core/disk/ieee1275/nand.c            |  41 +++----
 grub-core/disk/ieee1275/ofdisk.c          |  28 +++--
 grub-core/fs/fshelp.c                     |  10 ++
 grub-core/gensyminfo.sh.in                |   7 +-
 grub-core/kern/dl.c                       |  66 +++++++++++-
 grub-core/kern/ieee1275/ieee1275.c        | 162 ++++++++++++++++------------
 grub-core/kern/ieee1275/openfw.c          |  25 ++---
 grub-core/kern/powerpc/cache.S            |   6 +-
 grub-core/kern/powerpc/dl.c               | 172 +++++++++++++++++++++++++++++-
 grub-core/kern/powerpc/ieee1275/entry.S   | 150 ++++++++++++++++++++++++++
 grub-core/kern/powerpc/ieee1275/startup.S |  30 +++++-
 grub-core/kern/term.c                     |  11 ++
 grub-core/lib/ieee1275/datetime.c         |  36 +++----
 grub-core/lib/powerpc/relocator.c         |   8 +-
 grub-core/lib/powerpc/setjmp.S            | 102 ++++++++++--------
 grub-core/loader/powerpc/ieee1275/linux.c |  10 +-
 grub-core/net/drivers/ieee1275/ofnet.c    |   8 +-
 grub-core/normal/term.c                   |  42 ++++++++
 include/grub/dl.h                         |   2 +
 include/grub/elf.h                        |   4 +
 include/grub/ieee1275/ieee1275.h          |   8 +-
 include/grub/libgcc.h                     |   2 +-
 include/grub/offsets.h                    |   5 +
 include/grub/powerpc/ieee1275/ieee1275.h  |   6 ++
 include/grub/powerpc/types.h              |  16 ++-
 include/grub/powerpc64le                  |   1 +
 include/grub/util/install.h               |   1 +
 util/grub-install-common.c                |   1 +
 util/grub-install.c                       |  15 ++-
 util/grub-mkimagexx.c                     |   4 +
 util/mkimage.c                            |  19 ++++
 37 files changed, 843 insertions(+), 214 deletions(-)
 create mode 100644 grub-core/kern/powerpc/ieee1275/entry.S
 create mode 120000 include/grub/powerpc64le
Signature · 1 line
1.8.5.3
author
#1 lore raw

RFC PATCH 1/23 Add a new architecture to the build process

Add a new architecture to the build process

---
 Makefile.am                 |  4 ++++
 config.h.in                 |  4 ++++
 configure.ac                | 10 +++++++---
 gentpl.py                   |  7 ++++---
 grub-core/Makefile.am       |  7 +++++++
 grub-core/Makefile.core.def | 18 ++++++++++++++++++
 include/grub/powerpc64le    |  1 +
 7 files changed, 45 insertions(+), 6 deletions(-)
 create mode 120000 include/grub/powerpc64le
Makefile.am +4 -0
index f02ae0a..8aad803 100644
@@ -383,6 +383,10 @@ if COND_powerpc_ieee1275
 BOOTCHECKS = bootcheck-linux-ppc
 endif
 
+if COND_powerpc64le_ieee1275
+BOOTCHECKS = bootcheck-linux-ppc
+endif
+
 EXTRA_DIST += grub-core/tests/boot/kbsd.init-i386.S grub-core/tests/boot/kbsd.init-x86_64.S grub-core/tests/boot/kbsd.spec.txt grub-core/tests/boot/kernel-8086.S grub-core/tests/boot/kernel-i386.S grub-core/tests/boot/kfreebsd-aout.cfg grub-core/tests/boot/kfreebsd.cfg grub-core/tests/boot/kfreebsd.init-i386.S grub-core/tests/boot/kfreebsd.init-x86_64.S grub-core/tests/boot/knetbsd.cfg grub-core/tests/boot/kopenbsd.cfg grub-core/tests/boot/kopenbsdlabel.txt grub-core/tests/boot/linux16.cfg grub-core/tests/boot/linux.cfg grub-core/tests/boot/linux.init-i386.S grub-core/tests/boot/linux.init-mips.S grub-core/tests/boot/linux.init-ppc.S grub-core/tests/boot/linux.init-x86_64.S grub-core/tests/boot/linux-ppc.cfg grub-core/tests/boot/multiboot2.cfg grub-core/tests/boot/multiboot.cfg grub-core/tests/boot/ntldr.cfg grub-core/tests/boot/pc-chainloader.cfg grub-core/tests/boot/qemu-shutdown-x86.S
 
 .PHONY: bootcheck-linux-i386 bootcheck-linux-x86_64 \
config.h.in +4 -0
index 4b63014..1d71e35 100644
@@ -6,6 +6,10 @@
 #define __powerpc__ 1
 #endif
 
+#if defined(__PPC64__) && defined(__LITTLE_ENDIAN__)
+#define __powerpc64le__ 1
+#endif
+
 #define GCRYPT_NO_DEPRECATED 1
 
 /* Define to 1 to enable disk cache statistics.  */
configure.ac +7 -3
index 8888c2f..09e9dfb 100644
@@ -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=powerpc64le ;;
 esac
 
 # Check if the platform is supported, make final adjustments.
@@ -152,6 +154,7 @@ case "$target_cpu"-"$platform" in
   i386-ieee1275) ;;
   i386-qemu) ;;
   powerpc-ieee1275) ;;
+  powerpc64le-ieee1275) ;;
   sparc64-ieee1275) ;;
   ia64-efi) ;;
   mips-qemu_mips) ;;
@@ -173,7 +176,7 @@ esac
 if test x$platform != xemu ; then
    case "$target_cpu" in
 	i386 | powerpc) target_m32=1 ;;
-	x86_64 | sparc64) target_m64=1 ;;
+	x86_64 | sparc64 | powerpc64le) target_m64=1 ;;
    esac
 fi
 
@@ -557,7 +560,7 @@ if test "x$grub_cv_cc_target_clang" = xyes && ( test "x$target_cpu" = xi386 \
    TARGET_CCASFLAGS="$TARGET_CCASFLAGS -no-integrated-as"
 fi
 
-if test "x$grub_cv_cc_target_clang" = xyes && test "x$target_cpu" = xpowerpc; then
+if test "x$grub_cv_cc_target_clang" = xyes && (test "x$target_cpu" = xpowerpc || test "x$target_cpu" = xpowerpc64le ); then
 AC_CACHE_CHECK([if clang can handle ame instruction], [grub_cv_cc_target_clang_ame]
 [
 CFLAGS="$TARGET_CFLAGS"
@@ -1428,7 +1431,7 @@ if test x"$enable_build_grub_mkfont" = xno ; then
   FONT_SOURCE=
 fi
 
-if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$target_cpu"-"$platform" = xpowerpc-ieee1275 || test "x$platform" = xcoreboot ); then
+if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$target_cpu"-"$platform" = xpowerpc-ieee1275 || test "x$target_cpu"-"$platform" = xpowerpc64le-ieee1275 || test "x$platform" = xcoreboot ); then
   if test x"$grub_build_mkfont_excuse" = x ; then
     AC_MSG_ERROR([qemu, powerpc-ieee1275, coreboot and loongson ports need unifont])
   else
@@ -1671,6 +1674,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_powerpc64le_ieee1275], [test x$target_cpu = xpowerpc64le -a x$platform = xieee1275])
 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])
gentpl.py +4 -3
index bdcae1a..744bed0 100644
@@ -30,7 +30,7 @@ GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
                    "i386_multiboot", "i386_ieee1275", "x86_64_efi",
                    "i386_xen", "x86_64_xen",
                    "mips_loongson", "sparc64_ieee1275",
-                   "powerpc_ieee1275", "mips_arc", "ia64_efi",
+                   "powerpc_ieee1275", "powerpc64le_ieee1275", "mips_arc", "ia64_efi",
                    "mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi" ]
 
 GROUPS = {}
@@ -44,12 +44,13 @@ GROUPS["x86"]      = GROUPS["i386"] + GROUPS["x86_64"]
 GROUPS["mips"]     = [ "mips_loongson", "mips_qemu_mips", "mips_arc" ]
 GROUPS["sparc64"]  = [ "sparc64_ieee1275" ]
 GROUPS["powerpc"]  = [ "powerpc_ieee1275" ]
+GROUPS["powerpc64le"]  = [ "powerpc64le_ieee1275" ]
 GROUPS["arm"]      = [ "arm_uboot", "arm_efi" ]
 GROUPS["arm64"]    = [ "arm64_efi" ]
 
 # Groups based on firmware
 GROUPS["efi"]  = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi" ]
-GROUPS["ieee1275"]   = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ]
+GROUPS["ieee1275"]   = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275", "powerpc64le_ieee1275" ]
 GROUPS["uboot"] = [ "arm_uboot" ]
 GROUPS["xen"]  = [ "i386_xen", "x86_64_xen" ]
 
@@ -58,7 +59,7 @@ GROUPS["noemu"]   = GRUB_PLATFORMS[:]; GROUPS["noemu"].remove("emu")
 
 # Groups based on hardware features
 GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_loongson", "mips_qemu_mips",
-                                     "sparc64_ieee1275", "powerpc_ieee1275"]
+                                     "sparc64_ieee1275", "powerpc_ieee1275", "powerpc64le_ieee1275" ]
 GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi");
 GROUPS["pci"]      = GROUPS["x86"] + ["mips_loongson"]
 GROUPS["usb"]      = GROUPS["pci"]
grub-core/Makefile.am +7 -0
index 5c087c8..d9034c1 100644
@@ -210,6 +210,13 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
 endif
 
+if COND_powerpc64le_ieee1275
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
+endif
+
 if COND_sparc64_ieee1275
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sparc64/ieee1275/ieee1275.h
grub-core/Makefile.core.def +18 -0
index 42443bc..c6e70bb 100644
@@ -35,6 +35,7 @@ script = {
   name = grub.chrp;
   common = boot/powerpc/grub.chrp.in;
   enable = powerpc_ieee1275;
+  enable = powerpc64le_ieee1275;
 };
 
 script = {
@@ -42,6 +43,7 @@ script = {
   name = bootinfo.txt;
   common = boot/powerpc/bootinfo.txt.in;
   enable = powerpc_ieee1275;
+  enable = powerpc64le_ieee1275;
 };
 
 kernel = {
@@ -87,6 +89,7 @@ kernel = {
 
   mips_loongson_ldflags    = '-Wl,-Ttext,0x80200000';
   powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000';
+  powerpc64le_ieee1275_ldflags = '-Wl,-Ttext,0x200000';
   sparc64_ieee1275_ldflags = '-Wl,-Ttext,0x4400';
   mips_arc_ldflags    = '-Wl,-Ttext,$(TARGET_LINK_ADDR)';
   mips_qemu_mips_ldflags    = '-Wl,-Ttext,0x80200000';
@@ -110,6 +113,7 @@ kernel = {
   mips_startup = kern/mips/startup.S;
   sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S;
   powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S;
+  powerpc64le_ieee1275_startup = kern/powerpc/ieee1275/startup.S;
   arm_uboot_startup = kern/arm/uboot/startup.S;
   arm_efi_startup = kern/arm/efi/startup.S;
   arm64_efi_startup = kern/arm64/efi/startup.S;
@@ -253,6 +257,9 @@ kernel = {
   powerpc_ieee1275 = kern/powerpc/cache.S;
   powerpc_ieee1275 = kern/powerpc/dl.c;
 
+  powerpc64le_ieee1275 = kern/powerpc/cache.S;
+  powerpc64le_ieee1275 = kern/powerpc/dl.c;
+
   sparc64_ieee1275 = kern/sparc64/cache.S;
   sparc64_ieee1275 = kern/sparc64/dl.c;
   sparc64_ieee1275 = kern/sparc64/ieee1275/ieee1275.c;
@@ -754,6 +761,7 @@ module = {
   enable = emu;
   enable = sparc64_ieee1275;
   enable = powerpc_ieee1275;
+  enable = powerpc64le_ieee1275;
   enable = mips_arc;
   enable = ia64_efi;
   enable = arm_efi;
@@ -855,6 +863,7 @@ module = {
   arm_efi = lib/efi/reboot.c;
   arm64_efi = lib/efi/reboot.c;
   powerpc_ieee1275 = lib/ieee1275/reboot.c;
+  powerpc64le_ieee1275 = lib/ieee1275/reboot.c;
   sparc64_ieee1275 = lib/ieee1275/reboot.c;
   mips_arc = lib/mips/arc/reboot.c;
   mips_loongson = lib/mips/loongson/reboot.c;
@@ -1027,12 +1036,14 @@ module = {
   ieee1275 = commands/ieee1275/suspend.c;
   enable = i386_ieee1275;
   enable = powerpc_ieee1275;
+  enable = powerpc64le_ieee1275;
 };
 
 module = {
   name = escc;
   ieee1275 = term/ieee1275/escc.c;
   enable = powerpc_ieee1275;
+  enable = powerpc64le_ieee1275;
 };
 
 module = {
@@ -1537,6 +1548,8 @@ module = {
   mips = lib/mips/relocator.c;
   powerpc = lib/powerpc/relocator_asm.S;
   powerpc = lib/powerpc/relocator.c;
+  powerpc64le = lib/powerpc/relocator_asm.S;
+  powerpc64le = lib/powerpc/relocator.c;
   xen = lib/xen/relocator.c;
   i386_xen = lib/i386/xen/relocator.S;
   x86_64_xen = lib/x86_64/xen/relocator.S;
@@ -1548,6 +1561,7 @@ module = {
 
   enable = mips;
   enable = powerpc;
+  enable = powerpc64le;
   enable = x86;
   enable = xen;
 };
@@ -1559,8 +1573,10 @@ module = {
   uboot = lib/uboot/datetime.c;
   sparc64_ieee1275 = lib/ieee1275/datetime.c;
   powerpc_ieee1275 = lib/ieee1275/datetime.c;
+  powerpc64le_ieee1275 = lib/ieee1275/datetime.c;
   sparc64_ieee1275 = lib/ieee1275/cmos.c;
   powerpc_ieee1275 = lib/ieee1275/cmos.c;
+  powerpc64le_ieee1275 = lib/ieee1275/cmos.c;
   xen = lib/xen/datetime.c;
   xen_cppflags = '$(CPPFLAGS_XEN)';
 
@@ -1669,6 +1685,7 @@ module = {
   i386_pc = lib/i386/pc/vesa_modes_table.c;
   mips = loader/mips/linux.c;
   powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c;
+  powerpc64le_ieee1275 = loader/powerpc/ieee1275/linux.c;
   sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
   ia64_efi = loader/ia64/efi/linux.c;
   arm = loader/arm/linux.c;
@@ -2057,6 +2074,7 @@ module = {
   name = ieee1275_fb;
   ieee1275 = video/ieee1275.c;
   enable = powerpc_ieee1275;
+  enable = powerpc64le_ieee1275;
 };
 
 module = {
include/grub/powerpc64le new file +1 -0
new file mode 120000
index 0000000..9a47ca9
@@ -0,0 +1 @@
+powerpc
\ No newline at end of file
Signature · 1 line
1.8.5.3
author
#2 lore raw

RFC PATCH 2/23 Build LE grub as O1

In reply to Ram Pai

Build LE grub as O1 until we add savegpr and restgpr

From: Anton Blanchard <[email protected]>

---
 configure.ac | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
configure.ac +6 -1
index 09e9dfb..10856be 100644
@@ -73,7 +73,12 @@ grub_TRANSFORM([grub-file])
 
 # Optimization flag.  Allow user to override.
 if test "x$TARGET_CFLAGS" = x; then
-  TARGET_CFLAGS="$TARGET_CFLAGS -Os"
+  if test "x$target_cpu" = xpowerpc64le; then
+     #HACK till savegpr/addgpr is supported
+     TARGET_CFLAGS="$TARGET_CFLAGS -O1"
+  else
+     TARGET_CFLAGS="$TARGET_CFLAGS -Os"
+  fi
 fi
 
 # Default HOST_CPPFLAGS
Signature · 1 line
1.8.5.3
author
#3 lore raw

RFC PATCH 3/23 ignore .TOC. symbol

In reply to Ram Pai

powerpc64 LE's linker knows how to handle the undefined symbol .TOC. in grub modules. So just ignore that symbol during build.

---
 grub-core/gensyminfo.sh.in | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
grub-core/gensyminfo.sh.in +6 -1
index 2e8716b..cad5af3 100644
@@ -34,4 +34,9 @@ else
 fi
 
 # Print all undefined symbols used by module
-@TARGET_NM@ -u @TARGET_NMFLAGS_MINUS_P@ -p $module | sed "s@^\([^ ]*\).*@undefined $modname \1@g"
+if test x"@GRUB_TARGET_CPU@" = xpowerpc64le; then
+    #ignore the special .TOC. symbol on powerpc64le
+    @TARGET_NM@ -u @TARGET_NMFLAGS_MINUS_P@ -p $module | grep -w -v '.TOC.' 
+else
+    @TARGET_NM@ -u @TARGET_NMFLAGS_MINUS_P@ -p $module
+fi  | sed "s@^\([^ ]*\).*@undefined $modname \1@g"
Signature · 1 line
1.8.5.3
#4 lore raw

Re: [RFC PATCH 03/23] ignore .TOC. symbol

В Wed, 26 Feb 2014 10:31:02 -0800
Ram Pai <[email protected]> пишет:

Quoted 13 lines

powerpc64 LE's linker knows how to handle the undefined symbol .TOC. in grub modules. So just ignore that symbol during build.

---
 grub-core/gensyminfo.sh.in | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
grub-core/gensyminfo.sh.in +0 -0
index 2e8716b..cad5af3 100644

grub-core/gensyminfo.sh.in else · line 39

Quoted 7 lines
grub-core/gensyminfo.sh.in +3 -1
@@ -34,4 +34,9 @@ else
 fi
 
 # Print all undefined symbols used by module
-@TARGET_NM@ -u @TARGET_NMFLAGS_MINUS_P@ -p $module | sed "s@^\([^ ]*\).*@undefined $modname \1@g"
+if test x"@GRUB_TARGET_CPU@" = xpowerpc64le; then
+    #ignore the special .TOC. symbol on powerpc64le
+    @TARGET_NM@ -u @TARGET_NMFLAGS_MINUS_P@ -p $module | grep -w -v '.TOC.' 

If I understand it correctly, it should rather be grep -F -w; just in case someone adds something like RTOCN?

Quoted 3 lines
grub-core/gensyminfo.sh.in +3 -0
+else
+    @TARGET_NM@ -u @TARGET_NMFLAGS_MINUS_P@ -p $module
+fi  | sed "s@^\([^ ]*\).*@undefined $modname \1@g"
author
#5 lore raw

RFC PATCH 4/23 grub-install can now recognize and install a LE grub boot loader

In reply to Ram Pai

grub-install can now recognize and install a LE grub boot loader

---
 include/grub/offsets.h      |  5 +++++
 include/grub/util/install.h |  1 +
 util/grub-install-common.c  |  1 +
 util/grub-install.c         | 15 +++++++++++++--
 util/mkimage.c              | 19 +++++++++++++++++++
 5 files changed, 39 insertions(+), 2 deletions(-)
include/grub/offsets.h +5 -0
index 85e7401..b6acd02 100644
@@ -63,6 +63,9 @@
 #define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ALIGN 4
 #define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ADDR 0x200000
 
+#define GRUB_KERNEL_POWERPC64LE_IEEE1275_LINK_ALIGN 4
+#define GRUB_KERNEL_POWERPC64LE_IEEE1275_LINK_ADDR 0x200000
+
 #define GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR         0x80200000
 
 #define GRUB_KERNEL_MIPS_LOONGSON_LINK_ALIGN  32
@@ -111,6 +114,7 @@
 #define GRUB_KERNEL_ARM_UBOOT_MOD_GAP 0x0
 
 #define GRUB_KERNEL_POWERPC_IEEE1275_MOD_ALIGN 0x1000
+#define GRUB_KERNEL_POWERPC64LE_IEEE1275_MOD_ALIGN 0x1000
 #define GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN 3
 #define GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN (1 << GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN)
 
@@ -126,6 +130,7 @@
    for PowerMac to prevent "CLAIM failed" error.  The real fix is to
    rewrite grub-mkimage to generate valid ELF files.  */
 #define GRUB_KERNEL_POWERPC_IEEE1275_MOD_GAP 0x8000
+#define GRUB_KERNEL_POWERPC64LE_IEEE1275_MOD_GAP 0x8000
 
 #ifdef GRUB_MACHINE
 #define GRUB_OFFSETS_CONCAT_(a,b,c) a ## b ## c
include/grub/util/install.h +1 -0
index aedcd29..3f32cd3 100644
@@ -89,6 +89,7 @@ enum grub_install_plat
     GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON,
     GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275,
     GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275,
+    GRUB_INSTALL_PLATFORM_POWERPC64LE_IEEE1275,
     GRUB_INSTALL_PLATFORM_MIPSEL_ARC,
     GRUB_INSTALL_PLATFORM_MIPS_ARC,
     GRUB_INSTALL_PLATFORM_IA64_EFI,
util/grub-install-common.c +1 -0
index c8bedcb..a1f18fc 100644
@@ -661,6 +661,7 @@ static struct
     [GRUB_INSTALL_PLATFORM_MIPS_ARC] =         { "mips",    "arc"       },
     [GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275] = { "sparc64", "ieee1275"  },
     [GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275] = { "powerpc", "ieee1275"  },
+    [GRUB_INSTALL_PLATFORM_POWERPC64LE_IEEE1275] = { "powerpc64le", "ieee1275"  },
     [GRUB_INSTALL_PLATFORM_IA64_EFI] =         { "ia64",    "efi"       },
     [GRUB_INSTALL_PLATFORM_ARM_EFI] =          { "arm",     "efi"       },
     [GRUB_INSTALL_PLATFORM_ARM64_EFI] =        { "arm64",   "efi"       },
util/grub-install.c +13 -2
index 2e6226a..994af24 100644
@@ -311,6 +311,8 @@ get_default_platform (void)
 {
 #ifdef __powerpc__
    return "powerpc-ieee1275";
+#elif __powerpc64le__
+   return "powerpc64le-ieee1275";
 #elif defined (__sparc__) || defined (__sparc64__)
    return "sparc64-ieee1275";
 #elif defined (__MIPSEL__)
@@ -475,6 +477,7 @@ have_bootdev (enum grub_install_plat pl)
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
     case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
     case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
+    case GRUB_INSTALL_PLATFORM_POWERPC64LE_IEEE1275:
     case GRUB_INSTALL_PLATFORM_MIPSEL_ARC:
     case GRUB_INSTALL_PLATFORM_MIPS_ARC:
       return 1;
@@ -897,6 +900,7 @@ main (int argc, char *argv[])
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
     case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
     case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
+    case GRUB_INSTALL_PLATFORM_POWERPC64LE_IEEE1275:
     case GRUB_INSTALL_PLATFORM_MIPSEL_ARC:
     case GRUB_INSTALL_PLATFORM_MIPS_ARC:
     case GRUB_INSTALL_PLATFORM_ARM_UBOOT:
@@ -926,6 +930,7 @@ main (int argc, char *argv[])
 	grub_util_error ("%s", _("install device isn't specified"));
       break;
     case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
+    case GRUB_INSTALL_PLATFORM_POWERPC64LE_IEEE1275:
       if (install_device)
 	is_prep = 1;
       break;
@@ -1138,7 +1143,8 @@ main (int argc, char *argv[])
       grub_install_mkdir_p (efidir);
     }
 
-  if (platform == GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275)
+  if (platform == GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275 ||
+      platform ==  GRUB_INSTALL_PLATFORM_POWERPC64LE_IEEE1275)
     {
       int is_guess = 0;
       if (!macppcdir)
@@ -1340,7 +1346,8 @@ main (int argc, char *argv[])
       if ((disk_module && grub_strcmp (disk_module, "biosdisk") != 0)
 	  || grub_drives[1]
 	  || (!install_drive
-	      && platform != GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275)
+	      && platform != GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275
+	      && platform != GRUB_INSTALL_PLATFORM_POWERPC64LE_IEEE1275)
 	  || (install_drive && !is_same_disk (grub_drives[0], install_drive))
 	  || !have_bootdev (platform))
 	{
@@ -1433,6 +1440,7 @@ main (int argc, char *argv[])
 		    break;
 		  case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
 		  case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
+		  case GRUB_INSTALL_PLATFORM_POWERPC64LE_IEEE1275:
 		  case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
 		    {
 		      const char * ofpath = grub_util_devname_to_ofpath (*curdev);
@@ -1539,6 +1547,7 @@ main (int argc, char *argv[])
     case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT:
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
     case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
+    case GRUB_INSTALL_PLATFORM_POWERPC64LE_IEEE1275:
     case GRUB_INSTALL_PLATFORM_I386_XEN:
     case GRUB_INSTALL_PLATFORM_X86_64_XEN:
       core_name = "core.elf";
@@ -1598,6 +1607,7 @@ main (int argc, char *argv[])
 
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
     case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
+    case GRUB_INSTALL_PLATFORM_POWERPC64LE_IEEE1275:
       {
 	char *dst = grub_util_path_concat (2, grubdir, "grub");
 	grub_install_copy_file (imgfile, dst, 1);
@@ -1700,6 +1710,7 @@ main (int argc, char *argv[])
       }
 
     case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
+    case GRUB_INSTALL_PLATFORM_POWERPC64LE_IEEE1275:
       if (macppcdir)
 	{
 	  char *core_services = grub_util_path_concat (4, macppcdir,
util/mkimage.c +19 -0
index 26d9816..baf5fdc 100644
@@ -371,6 +371,25 @@ static const struct grub_install_image_target_desc image_targets[] =
       .link_align = 4
     },
     {
+      .dirname = "powerpc64le-ieee1275",
+      .names = { "powerpc64le-ieee1275", NULL },
+      .voidp_sizeof = 8,
+      .bigendian = 0,
+      .id = IMAGE_PPC, 
+      .flags = PLATFORM_FLAGS_NONE,
+      .total_module_size = TARGET_NO_FIELD,
+      .decompressor_compressed_size = TARGET_NO_FIELD,
+      .decompressor_uncompressed_size = TARGET_NO_FIELD,
+      .decompressor_uncompressed_addr = TARGET_NO_FIELD,
+      .section_align = 1,
+      .vaddr_offset = 0,
+      .link_addr = GRUB_KERNEL_POWERPC64LE_IEEE1275_LINK_ADDR,
+      .elf_target = EM_PPC64,
+      .mod_gap = GRUB_KERNEL_POWERPC64LE_IEEE1275_MOD_GAP,
+      .mod_align = GRUB_KERNEL_POWERPC64LE_IEEE1275_MOD_ALIGN,
+      .link_align = 4
+    },
+    {
       .dirname = "sparc64-ieee1275",
       .names = { "sparc64-ieee1275-raw", NULL },
       .voidp_sizeof = 8,
Signature · 1 line
1.8.5.3
author
#6 lore raw

RFC PATCH 5/23 set ABI version in e_flag of the PPC64LE ELF image.

In reply to Ram Pai

set the ABI version to 0x02 in the e_flag of the PPC64LE ELF image.

---
 include/grub/elf.h    | 1 +
 util/grub-mkimagexx.c | 4 ++++
 2 files changed, 5 insertions(+)
include/grub/elf.h +1 -0
index caa7963..bee7583 100644
@@ -1851,6 +1851,7 @@ typedef Elf32_Addr Elf32_Conflict;
 
 /* Values for Elf32/64_Ehdr.e_flags.  */
 #define EF_PPC_EMB		0x80000000	/* PowerPC embedded flag */
+#define EF_PPC64LE_ABIV2	0x00000002	/* PowerPC 64 LE flag */
 
 /* Cygnus local bits below */
 #define EF_PPC_RELOCATABLE	0x00010000	/* PowerPC -mrelocatable flag*/
util/grub-mkimagexx.c +4 -0
index 0a1ac9e..b1833a1 100644
@@ -141,11 +141,15 @@ SUFFIX (generate_elf) (const struct grub_install_image_target_desc *image_target
   phdr->p_vaddr = grub_host_to_target32 (target_addr);
   phdr->p_paddr = grub_host_to_target32 (target_addr);
   phdr->p_align = grub_host_to_target32 (align > image_target->link_align ? align : image_target->link_align);
+
   if (image_target->id == IMAGE_LOONGSON_ELF)
     ehdr->e_flags = grub_host_to_target32 (0x1000 | EF_MIPS_NOREORDER 
 					   | EF_MIPS_PIC | EF_MIPS_CPIC);
+  else if (image_target->id == IMAGE_PPC && image_target->bigendian == 0)
+    ehdr->e_flags = grub_host_to_target32 (EF_PPC64LE_ABIV2);
   else
     ehdr->e_flags = 0;
+
   if (image_target->id == IMAGE_LOONGSON_ELF)
     {
       phdr->p_filesz = grub_host_to_target32 (*core_size);
Signature · 1 line
1.8.5.3
author
#7 lore raw

RFC PATCH 6/23 Add IEEE1275_ADDR helper

In reply to Ram Pai

From: Anton Blanchard <[email protected]>

If the target pointer size doesn't match the IEEE1275 cell size, we need to cast twice to avoid a warning.

From: Anton Blanchard <[email protected]>

---
 grub-core/disk/ieee1275/ofdisk.c       |  4 ++--
 grub-core/kern/ieee1275/ieee1275.c     | 30 +++++++++++++++---------------
 grub-core/kern/ieee1275/openfw.c       |  6 +++---
 grub-core/lib/ieee1275/datetime.c      |  4 ++--
 grub-core/net/drivers/ieee1275/ofnet.c |  2 +-
 include/grub/ieee1275/ieee1275.h       |  4 +++-
 6 files changed, 26 insertions(+), 24 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +2 -2
index 6870b39..1b72f06 100644
@@ -224,7 +224,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
 	return;
     
       INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 3);
-      args.method = (grub_ieee1275_cell_t) "vscsi-report-luns";
+      args.method = IEEE1275_ADDR("vscsi-report-luns");
       args.ihandle = ihandle;
       args.table = 0;
       args.nentries = 0;
@@ -613,7 +613,7 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size)
     return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
 
   INIT_IEEE1275_COMMON (&args_ieee1275.common, "call-method", 2, 2);
-  args_ieee1275.method = (grub_ieee1275_cell_t) "block-size";
+  args_ieee1275.method = IEEE1275_ADDR("block-size");
   args_ieee1275.ihandle = last_ihandle;
   args_ieee1275.result = 1;
 
grub-core/kern/ieee1275/ieee1275.c +15 -15
index 9821702..f933c89 100644
@@ -38,7 +38,7 @@ grub_ieee1275_finddevice (const char *name, grub_ieee1275_phandle_t *phandlep)
   args;
 
   INIT_IEEE1275_COMMON (&args.common, "finddevice", 1, 1);
-  args.device = (grub_ieee1275_cell_t) name;
+  args.device = IEEE1275_ADDR(name);
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
     return -1;
@@ -66,8 +66,8 @@ grub_ieee1275_get_property (grub_ieee1275_phandle_t phandle,
 
   INIT_IEEE1275_COMMON (&args.common, "getprop", 4, 1);
   args.phandle = phandle;
-  args.prop = (grub_ieee1275_cell_t) property;
-  args.buf = (grub_ieee1275_cell_t) buf;
+  args.prop = IEEE1275_ADDR(property);
+  args.buf = IEEE1275_ADDR(buf);
   args.buflen = (grub_ieee1275_cell_t) size;
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
@@ -115,8 +115,8 @@ grub_ieee1275_next_property (grub_ieee1275_phandle_t phandle, char *prev_prop,
 
   INIT_IEEE1275_COMMON (&args.common, "nextprop", 3, 1);
   args.phandle = phandle;
-  args.prev_prop = (grub_ieee1275_cell_t) prev_prop;
-  args.next_prop = (grub_ieee1275_cell_t) prop;
+  args.prev_prop = IEEE1275_ADDR(prev_prop);
+  args.next_prop = IEEE1275_ADDR(prop);
   args.flags = (grub_ieee1275_cell_t) -1;
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
@@ -139,7 +139,7 @@ grub_ieee1275_get_property_length (grub_ieee1275_phandle_t phandle,
 
   INIT_IEEE1275_COMMON (&args.common, "getproplen", 2, 1);
   args.phandle = phandle;
-  args.prop = (grub_ieee1275_cell_t) prop;
+  args.prop = IEEE1275_ADDR(prop);
   args.length = (grub_ieee1275_cell_t) -1;
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
@@ -190,7 +190,7 @@ grub_ieee1275_package_to_path (grub_ieee1275_phandle_t phandle,
 
   INIT_IEEE1275_COMMON (&args.common, "package-to-path", 3, 1);
   args.phandle = phandle;
-  args.buf = (grub_ieee1275_cell_t) path;
+  args.buf = IEEE1275_ADDR(path);
   args.buflen = (grub_ieee1275_cell_t) len;
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
@@ -219,7 +219,7 @@ grub_ieee1275_instance_to_path (grub_ieee1275_ihandle_t ihandle,
 
   INIT_IEEE1275_COMMON (&args.common, "instance-to-path", 3, 1);
   args.ihandle = ihandle;
-  args.buf = (grub_ieee1275_cell_t) path;
+  args.buf = IEEE1275_ADDR(path);
   args.buflen = (grub_ieee1275_cell_t) len;
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
@@ -247,7 +247,7 @@ grub_ieee1275_write (grub_ieee1275_ihandle_t ihandle, const void *buffer,
 
   INIT_IEEE1275_COMMON (&args.common, "write", 3, 1);
   args.ihandle = ihandle;
-  args.buf = (grub_ieee1275_cell_t) buffer;
+  args.buf = IEEE1275_ADDR(buffer);
   args.len = (grub_ieee1275_cell_t) len;
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
@@ -273,7 +273,7 @@ grub_ieee1275_read (grub_ieee1275_ihandle_t ihandle, void *buffer,
 
   INIT_IEEE1275_COMMON (&args.common, "read", 3, 1);
   args.ihandle = ihandle;
-  args.buf = (grub_ieee1275_cell_t) buffer;
+  args.buf = IEEE1275_ADDR(buffer);
   args.len = (grub_ieee1275_cell_t) len;
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
@@ -401,7 +401,7 @@ grub_ieee1275_interpret (const char *command, grub_ieee1275_cell_t *catch)
     return -1;
 
   INIT_IEEE1275_COMMON (&args.common, "interpret", 1, 1);
-  args.command = (grub_ieee1275_cell_t) command;
+  args.command = IEEE1275_ADDR(command);
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
     return -1;
@@ -453,7 +453,7 @@ grub_ieee1275_open (const char *path, grub_ieee1275_ihandle_t *result)
   args;
 
   INIT_IEEE1275_COMMON (&args.common, "open", 1, 1);
-  args.path = (grub_ieee1275_cell_t) path;
+  args.path = IEEE1275_ADDR(path);
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
     return -1;
@@ -548,8 +548,8 @@ grub_ieee1275_set_property (grub_ieee1275_phandle_t phandle,
 
   INIT_IEEE1275_COMMON (&args.common, "setprop", 4, 1);
   args.size = (grub_ieee1275_cell_t) size;
-  args.buf = (grub_ieee1275_cell_t) buf;
-  args.propname = (grub_ieee1275_cell_t) propname;
+  args.buf = IEEE1275_ADDR(buf);
+  args.propname = IEEE1275_ADDR(propname);
   args.phandle = (grub_ieee1275_cell_t) phandle;
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
@@ -578,7 +578,7 @@ grub_ieee1275_set_color (grub_ieee1275_ihandle_t ihandle,
   args;
 
   INIT_IEEE1275_COMMON (&args.common, "call-method", 6, 1);
-  args.method = (grub_ieee1275_cell_t) "color!";
+  args.method = IEEE1275_ADDR("color!");
   args.ihandle = ihandle;
   args.index = index;
   args.r = r;
grub-core/kern/ieee1275/openfw.c +3 -3
index ddb7783..a8bbc71 100644
@@ -285,7 +285,7 @@ grub_ieee1275_map (grub_addr_t phys, grub_addr_t virt, grub_size_t size,
 			6,
 #endif
 			1);
-  args.method = (grub_ieee1275_cell_t) "map";
+  args.method = IEEE1275_ADDR("map");
   args.ihandle = grub_ieee1275_mmu;
 #ifdef __sparc__
   args.phys_high = 0;
@@ -543,8 +543,8 @@ grub_ieee1275_canonicalise_devname (const char *path)
 	return NULL;
 
       INIT_IEEE1275_COMMON (&args.common, "canon", 3, 1);
-      args.path = (grub_ieee1275_cell_t) path;
-      args.buf = (grub_ieee1275_cell_t) buf;
+      args.path = IEEE1275_ADDR(path);
+      args.buf = IEEE1275_ADDR(buf);
       args.inlen = (grub_ieee1275_cell_t) (bufsize - 1);
 
       if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
grub-core/lib/ieee1275/datetime.c +2 -2
index 74578f1..fa0d3b6 100644
@@ -84,7 +84,7 @@ grub_get_datetime (struct grub_datetime *datetime)
 
   INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 7);
   args.device = (grub_ieee1275_cell_t) ihandle;
-  args.method = (grub_ieee1275_cell_t) "get-time";
+  args.method = IEEE1275_ADDR("get-time");
 
   status = IEEE1275_CALL_ENTRY_FN (&args);
 
@@ -136,7 +136,7 @@ grub_set_datetime (struct grub_datetime *datetime)
 
   INIT_IEEE1275_COMMON (&args.common, "call-method", 8, 1);
   args.device = (grub_ieee1275_cell_t) ihandle;
-  args.method = (grub_ieee1275_cell_t) "set-time";
+  args.method = IEEE1275_ADDR("set-time");
 
   args.year = datetime->year;
   args.month = datetime->month;
grub-core/net/drivers/ieee1275/ofnet.c +1 -1
index eea8e71..ea6456f 100644
@@ -386,7 +386,7 @@ search_net_devices (struct grub_ieee1275_devalias *alias)
       args;
       INIT_IEEE1275_COMMON (&args.common, "interpret", 2, 2);
       args.len = card->txbufsize;
-      args.method = (grub_ieee1275_cell_t) "alloc-mem";
+      args.method = IEEE1275_ADDR("alloc-mem");
 
       if (IEEE1275_CALL_ENTRY_FN (&args) == -1
 	  || args.catch)
include/grub/ieee1275/ieee1275.h +3 -1
index 8e42513..2e5270c 100644
@@ -49,8 +49,10 @@ struct grub_ieee1275_common_hdr
   grub_ieee1275_cell_t nr_outs;
 };
 
+#define IEEE1275_ADDR(x)         (grub_uint32_t)(grub_addr_t)(x)
+
 #define INIT_IEEE1275_COMMON(p, xname, xins, xouts) \
-  (p)->name = (grub_ieee1275_cell_t) xname; \
+  (p)->name = (grub_ieee1275_cell_t) IEEE1275_ADDR(xname); \
   (p)->nr_ins = (grub_ieee1275_cell_t) xins; \
   (p)->nr_outs = (grub_ieee1275_cell_t) xouts
 
Signature · 1 line
1.8.5.3
#8 lore raw

Re: [RFC PATCH 06/23] Add IEEE1275_ADDR helper

В Wed, 26 Feb 2014 10:31:05 -0800
Ram Pai <[email protected]> пишет:

include/grub/ieee1275/ieee1275.h struct grub_ieee1275_common_hdr · line 53

Quoted 8 lines

From: Anton Blanchard <[email protected]>

If the target pointer size doesn't match the IEEE1275 cell size, we need to cast twice to avoid a warning.

Quoted 1 line
include/grub/ieee1275/ieee1275.h +2 -0
+#define IEEE1275_ADDR(x)         (grub_uint32_t)(grub_addr_t)(x)
+

Should not this be conditional on sizeof(grub_ieee1275_cell_t)? Otherwise it seems to truncate value on platform where it is 64 bit (sparc64)?

Is it possible that pointer does exceed 32 bits?

author
#9 lore raw

RFC PATCH 7/23 Fix some more warnings when casting.

In reply to Ram Pai

From: Anton Blanchard <[email protected]>

Fix some more warnings when casting.

From: Anton Blanchard <[email protected]>

---
 grub-core/disk/ieee1275/ofdisk.c       | 2 +-
 grub-core/lib/powerpc/relocator.c      | 8 ++++----
 grub-core/net/drivers/ieee1275/ofnet.c | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +1 -1
index 1b72f06..d785d6a 100644
@@ -244,7 +244,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
 	{
 	  grub_uint64_t *ptr;
 
-	  ptr = *(grub_uint64_t **) (args.table + 4 + 8 * i);
+	  ptr = *(grub_uint64_t **) ((grub_addr_t)args.table + 4 + 8 * i);
 	  while (*ptr)
 	    {
 	      grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr++);
grub-core/lib/powerpc/relocator.c +4 -4
index bdf2b11..4bac96f 100644
@@ -84,8 +84,8 @@ grub_cpu_relocator_backward (void *ptr0, void *src, void *dest,
 			     grub_size_t size)
 {
   void *ptr = ptr0;
-  write_reg (8, (grub_uint32_t) src, &ptr);
-  write_reg (9, (grub_uint32_t) dest, &ptr);
+  write_reg (8, (grub_uint32_t) (grub_addr_t) src, &ptr);
+  write_reg (9, (grub_uint32_t) (grub_addr_t) dest, &ptr);
   write_reg (10, (grub_uint32_t) size, &ptr);
   grub_memcpy (ptr, &grub_relocator_backward_start,
 	       RELOCATOR_SRC_SIZEOF (backward));
@@ -96,8 +96,8 @@ grub_cpu_relocator_forward (void *ptr0, void *src, void *dest,
 			     grub_size_t size)
 {
   void *ptr = ptr0;
-  write_reg (8, (grub_uint32_t) src, &ptr);
-  write_reg (9, (grub_uint32_t) dest, &ptr);
+  write_reg (8, (grub_uint32_t) (grub_addr_t) src, &ptr);
+  write_reg (9, (grub_uint32_t) (grub_addr_t) dest, &ptr);
   write_reg (10, (grub_uint32_t) size, &ptr);
   grub_memcpy (ptr, &grub_relocator_forward_start, 
 	       RELOCATOR_SRC_SIZEOF (forward));
grub-core/net/drivers/ieee1275/ofnet.c +1 -1
index ea6456f..07c8446 100644
@@ -395,7 +395,7 @@ search_net_devices (struct grub_ieee1275_devalias *alias)
 	  grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
 	}
       else
-	card->txbuf = (void *) args.result;
+	card->txbuf = (void *) (grub_addr_t) args.result;
     }
   else
     card->txbuf = grub_zalloc (card->txbufsize);
Signature · 1 line
1.8.5.3
author
#10 lore raw

RFC PATCH 8/23 Add powerpc64 types

In reply to Ram Pai

From: Anton Blanchard <[email protected]>

Add powerpc64 types

From: Anton Blanchard <[email protected]>

---
 include/grub/powerpc/types.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/grub/powerpc/types.h +8 -0
index a098ae6..7a2fc6b 100644
@@ -19,11 +19,19 @@
 #ifndef GRUB_TYPES_CPU_HEADER
 #define GRUB_TYPES_CPU_HEADER	1
 
+#ifdef __powerpc64le__
+/* The size of void *.  */
+#define GRUB_TARGET_SIZEOF_VOID_P	8
+
+/* The size of long.  */
+#define GRUB_TARGET_SIZEOF_LONG		8
+#else
 /* The size of void *.  */
 #define GRUB_TARGET_SIZEOF_VOID_P	4
 
 /* The size of long.  */
 #define GRUB_TARGET_SIZEOF_LONG		4
+#endif
 
 /* powerpc is big-endian.  */
 #define GRUB_TARGET_WORDS_BIGENDIAN	1
Signature · 1 line
1.8.5.3
#11 lore raw

Re: [RFC PATCH 08/23] Add powerpc64 types

В Wed, 26 Feb 2014 10:31:07 -0800
Ram Pai <[email protected]> пишет:

Quoted 24 lines

From: Anton Blanchard <[email protected]>

Add powerpc64 types

From: Anton Blanchard <[email protected]>

---
 include/grub/powerpc/types.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/grub/powerpc/types.h +6 -0
index a098ae6..7a2fc6b 100644
@@ -19,11 +19,19 @@
 #ifndef GRUB_TYPES_CPU_HEADER
 #define GRUB_TYPES_CPU_HEADER	1
 
+#ifdef __powerpc64le__
+/* The size of void *.  */
+#define GRUB_TARGET_SIZEOF_VOID_P	8
+
+/* The size of long.  */
+#define GRUB_TARGET_SIZEOF_LONG		8

include/grub/powerpc/types.h line 37

Quoted 10 lines
include/grub/powerpc/types.h +2 -0
+#else
 /* The size of void *.  */
 #define GRUB_TARGET_SIZEOF_VOID_P	4
 
 /* The size of long.  */
 #define GRUB_TARGET_SIZEOF_LONG		4
+#endif
 
 /* powerpc is big-endian.  */
 #define GRUB_TARGET_WORDS_BIGENDIAN	1

This sure can't be right on LE platform?

author
#12 lore raw

Re: [RFC PATCH 08/23] Add powerpc64 types

Quoted 31 lines · Andrey Borzenkov

В Wed, 26 Feb 2014 10:31:07 -0800
Ram Pai <[email protected]> пишет:

Quoted 28 lines

From: Anton Blanchard <[email protected]>

Add powerpc64 types

From: Anton Blanchard <[email protected]>

---
 include/grub/powerpc/types.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/grub/powerpc/types.h +7 -0
index a098ae6..7a2fc6b 100644
@@ -19,11 +19,19 @@
 #ifndef GRUB_TYPES_CPU_HEADER
 #define GRUB_TYPES_CPU_HEADER	1
 
+#ifdef __powerpc64le__
+/* The size of void *.  */
+#define GRUB_TARGET_SIZEOF_VOID_P	8
+
+/* The size of long.  */
+#define GRUB_TARGET_SIZEOF_LONG		8
+#else
 /* The size of void *.  */
 #define GRUB_TARGET_SIZEOF_VOID_P	4
 
Quoted 8 lines

include/grub/powerpc/types.h line 37

Quoted 6 lines
include/grub/powerpc/types.h +1 -0
 /* The size of long.  */
 #define GRUB_TARGET_SIZEOF_LONG		4
+#endif
 
 /* powerpc is big-endian.  */
 #define GRUB_TARGET_WORDS_BIGENDIAN	1

This sure can't be right on LE platform?

I have it updated later in the patch series. I think it is better to merge that patch with this one.

BTW: I have a new patch series, which simplifies the build, and takes out lot of duplication. Will send that out soon.

Thanks,

Signature · 1 line
Ram Pai
author
#13 lore raw

RFC PATCH 9/23 Fix warnings when building powerpc linux loader 64bit

In reply to Ram Pai

From: Anton Blanchard <[email protected]>

Fix warnings when building powerpc linux loader 64bit

From: Anton Blanchard <[email protected]>

---
 grub-core/loader/powerpc/ieee1275/linux.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
grub-core/loader/powerpc/ieee1275/linux.c +3 -3
index 4a14f66..3d6a61e 100644
@@ -141,8 +141,8 @@ grub_linux_boot (void)
   grub_ieee1275_set_property (grub_ieee1275_chosen, "bootargs", linux_args,
 			      grub_strlen (linux_args) + 1, &actual);
 
-  grub_dprintf ("loader", "Entry point: 0x%x\n", linux_entry);
-  grub_dprintf ("loader", "Initrd at: 0x%x, size 0x%x\n", initrd_addr,
+  grub_dprintf ("loader", "Entry point: 0x%lx\n", linux_entry);
+  grub_dprintf ("loader", "Initrd at: 0x%lx, size 0x%lx\n", initrd_addr,
 		initrd_size);
   grub_dprintf ("loader", "Boot arguments: %s\n", linux_args);
   grub_dprintf ("loader", "Jumping to Linux...\n");
@@ -360,7 +360,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
   if (addr == (grub_addr_t) -1)
      goto fail;
 
-  grub_dprintf ("loader", "Loading initrd at 0x%x, size 0x%x\n", addr, size);
+  grub_dprintf ("loader", "Loading initrd at 0x%lx, size 0x%lx\n", addr, size);
 
   if (grub_initrd_load (&initrd_ctx, argv, (void *) addr))
     goto fail;
Signature · 1 line
1.8.5.3
#14 lore raw

Re: [RFC PATCH 09/23] Fix warnings when building powerpc linux loader 64bit

В Wed, 26 Feb 2014 10:31:08 -0800
Ram Pai <[email protected]> пишет:

Quoted 15 lines

From: Anton Blanchard <[email protected]>

Fix warnings when building powerpc linux loader 64bit

From: Anton Blanchard <[email protected]>

---
 grub-core/loader/powerpc/ieee1275/linux.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
grub-core/loader/powerpc/ieee1275/linux.c +0 -0
index 4a14f66..3d6a61e 100644

grub-core/loader/powerpc/ieee1275/linux.c grub_linux_boot (void) · line 144

Quoted 6 lines
grub-core/loader/powerpc/ieee1275/linux.c +1 -2
@@ -141,8 +141,8 @@ grub_linux_boot (void)
   grub_ieee1275_set_property (grub_ieee1275_chosen, "bootargs", linux_args,
 			      grub_strlen (linux_args) + 1, &actual);
 
-  grub_dprintf ("loader", "Entry point: 0x%x\n", linux_entry);
-  grub_dprintf ("loader", "Initrd at: 0x%x, size 0x%x\n", initrd_addr,
+  grub_dprintf ("loader", "Entry point: 0x%lx\n", linux_entry);

I guess using PRIxGRUB_ADDR is more consistent - it can now be both 32 and 64 bits.

grub-core/loader/powerpc/ieee1275/linux.c grub_linux_boot (void) · line 146

Quoted 2 lines
grub-core/loader/powerpc/ieee1275/linux.c +1 -0
+  grub_dprintf ("loader", "Initrd at: 0x%lx, size 0x%lx\n", initrd_addr,
 		initrd_size);

Ditto and PRIuGRUB_SIZE.

grub-core/loader/powerpc/ieee1275/linux.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 364

Quoted 9 lines
grub-core/loader/powerpc/ieee1275/linux.c +1 -1
   grub_dprintf ("loader", "Boot arguments: %s\n", linux_args);
   grub_dprintf ("loader", "Jumping to Linux...\n");
@@ -360,7 +360,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
   if (addr == (grub_addr_t) -1)
      goto fail;
 
-  grub_dprintf ("loader", "Loading initrd at 0x%x, size 0x%x\n", addr, size);
+  grub_dprintf ("loader", "Loading initrd at 0x%lx, size 0x%lx\n", addr, size);
 

Ditto.

Quoted 2 lines
grub-core/loader/powerpc/ieee1275/linux.c +0 -0
   if (grub_initrd_load (&initrd_ctx, argv, (void *) addr))
     goto fail;
author
#15 lore raw

Re: [RFC PATCH 09/23] Fix warnings when building powerpc linux loader 64bit

Quoted 38 lines · Andrey Borzenkov

В Wed, 26 Feb 2014 10:31:08 -0800
Ram Pai <[email protected]> пишет:

Quoted 15 lines

From: Anton Blanchard <[email protected]>

Fix warnings when building powerpc linux loader 64bit

From: Anton Blanchard <[email protected]>

---
 grub-core/loader/powerpc/ieee1275/linux.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
grub-core/loader/powerpc/ieee1275/linux.c +0 -0
index 4a14f66..3d6a61e 100644

grub-core/loader/powerpc/ieee1275/linux.c grub_linux_boot (void) · line 144

Quoted 6 lines
grub-core/loader/powerpc/ieee1275/linux.c +1 -2
@@ -141,8 +141,8 @@ grub_linux_boot (void)
   grub_ieee1275_set_property (grub_ieee1275_chosen, "bootargs", linux_args,
 			      grub_strlen (linux_args) + 1, &actual);
 
-  grub_dprintf ("loader", "Entry point: 0x%x\n", linux_entry);
-  grub_dprintf ("loader", "Initrd at: 0x%x, size 0x%x\n", initrd_addr,
+  grub_dprintf ("loader", "Entry point: 0x%lx\n", linux_entry);

I guess using PRIxGRUB_ADDR is more consistent - it can now be both 32 and 64 bits.

grub-core/loader/powerpc/ieee1275/linux.c grub_linux_boot (void) · line 146

Quoted 2 lines
grub-core/loader/powerpc/ieee1275/linux.c +1 -0
+  grub_dprintf ("loader", "Initrd at: 0x%lx, size 0x%lx\n", initrd_addr,
 		initrd_size);

Ditto and PRIuGRUB_SIZE.

Quoted 6 lines
grub-core/loader/powerpc/ieee1275/linux.c +0 -0
   grub_dprintf ("loader", "Boot arguments: %s\n", linux_args);
   grub_dprintf ("loader", "Jumping to Linux...\n");
@@ -360,7 +360,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
   if (addr == (grub_addr_t) -1)
      goto fail;
 
Quoted 8 lines

grub-core/loader/powerpc/ieee1275/linux.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 364

Quoted 3 lines
grub-core/loader/powerpc/ieee1275/linux.c +1 -1
-  grub_dprintf ("loader", "Loading initrd at 0x%x, size 0x%x\n", addr, size);
+  grub_dprintf ("loader", "Loading initrd at 0x%lx, size 0x%lx\n", addr, size);
 

Ditto.

Quoted 2 lines
grub-core/loader/powerpc/ieee1275/linux.c +0 -0
   if (grub_initrd_load (&initrd_ctx, argv, (void *) addr))
     goto fail;

ok. will do.
RP

author
#16 lore raw

RFC PATCH 10/23 GRUB_ELF_R_PPC_* processing is applicable only for 32 bit bootloader.

In reply to Ram Pai

GRUB_ELF_R_PPC_* processing is applicable only for 32 bit bootloader.

---
 grub-core/kern/powerpc/dl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
grub-core/kern/powerpc/dl.c +6 -1
index 3a7fa3e..7677e5a 100644
@@ -94,6 +94,7 @@ grub_err_t
 grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
 			       Elf_Shdr *s, grub_dl_segment_t seg)
 {
+#ifdef powerpc
   Elf_Rela *rel, *max;
 
   for (rel = (Elf_Rela *) ((char *) ehdr + s->sh_offset),
@@ -155,7 +156,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
 	case GRUB_ELF_R_PPC_REL32:
 	  *addr = value - (Elf_Word) addr;
 	  break;
-
 	default:
 	  return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
 			     N_("relocation 0x%x is not implemented yet"),
@@ -164,4 +164,9 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
     }
 
   return GRUB_ERR_NONE;
+#else
+  return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+     N_("relocation is not implemented yet for module=%llx ehdr=%llx Elf_Shdr=%llx seg=%llx"), 
+     mod, ehdr, s, seg);
+#endif
 }
Signature · 1 line
1.8.5.3
author
#17 lore raw

RFC PATCH 11/23 Fix powerpc setjmp/longjmp 64bit issues

In reply to Ram Pai

From: Anton Blanchard <[email protected]>

Fix powerpc setjmp/longjmp 64bit issues

From: Anton Blanchard <[email protected]>

---
 grub-core/lib/powerpc/setjmp.S | 94 +++++++++++++++++++++++-------------------
 1 file changed, 52 insertions(+), 42 deletions(-)
grub-core/lib/powerpc/setjmp.S +52 -42
index 716b563..51fcae9 100644
@@ -25,33 +25,43 @@ GRUB_MOD_LICENSE "GPLv3+"
 
 	.text
 
+#if defined( __powerpc64__ ) || defined( __powerpc64le__ )
+#define LOAD	ld
+#define STORE	std
+#define SZ_LONG	8
+#else
+#define LOAD	lwz
+#define STORE	stw
+#define SZ_LONG	4
+#endif
+
 /*
  * int grub_setjmp (grub_jmp_buf env)
  */
 FUNCTION(grub_setjmp)
-	stw	1, 0(3)
-	stw	14, 4(3)
-	stw	15, 8(3)
-	stw	16, 12(3)
-	stw	17, 16(3)
-	stw	18, 20(3)
-	stw	19, 24(3)
-	stw	20, 28(3)
-	stw	21, 32(3)
-	stw	22, 36(3)
-	stw	23, 40(3)
-	stw	24, 44(3)
-	stw	25, 48(3)
-	stw	26, 52(3)
-	stw	27, 56(3)
-	stw	28, 60(3)
-	stw	29, 64(3)
-	stw	30, 68(3)
-	stw	31, 72(3)
+	STORE	1, 0(3)
+	STORE	14, 1*SZ_LONG(3)
+	STORE	15, 2*SZ_LONG(3)
+	STORE	16, 3*SZ_LONG(3)
+	STORE	17, 4*SZ_LONG(3)
+	STORE	18, 5*SZ_LONG(3)
+	STORE	19, 6*SZ_LONG(3)
+	STORE	20, 7*SZ_LONG(3)
+	STORE	21, 8*SZ_LONG(3)
+	STORE	22, 9*SZ_LONG(3)
+	STORE	23, 10*SZ_LONG(3)
+	STORE	24, 11*SZ_LONG(3)
+	STORE	25, 12*SZ_LONG(3)
+	STORE	26, 13*SZ_LONG(3)
+	STORE	27, 14*SZ_LONG(3)
+	STORE	28, 15*SZ_LONG(3)
+	STORE	29, 16*SZ_LONG(3)
+	STORE	30, 17*SZ_LONG(3)
+	STORE	31, 18*SZ_LONG(3)
 	mflr	4
-	stw	4, 76(3)
+	STORE	4, 19*SZ_LONG(3)
 	mfcr	4
-	stw	4, 80(3)
+	STORE	4, 20*SZ_LONG(3)
 	li	3, 0
 	blr
 
@@ -59,28 +69,28 @@ FUNCTION(grub_setjmp)
  * int grub_longjmp (grub_jmp_buf env, int val)
  */
 FUNCTION(grub_longjmp)
-	lwz	1, 0(3)
-	lwz	14, 4(3)
-	lwz	15, 8(3)
-	lwz	16, 12(3)
-	lwz	17, 16(3)
-	lwz	18, 20(3)
-	lwz	19, 24(3)
-	lwz	20, 28(3)
-	lwz	21, 32(3)
-	lwz	22, 36(3)
-	lwz	23, 40(3)
-	lwz	24, 44(3)
-	lwz	25, 48(3)
-	lwz	26, 52(3)
-	lwz	27, 56(3)
-	lwz	28, 60(3)
-	lwz	29, 64(3)
-	lwz	30, 68(3)
-	lwz	31, 72(3)
-	lwz	5, 76(3)
+	LOAD	1, 0(3)
+	LOAD	14, 1*SZ_LONG(3)
+	LOAD	15, 2*SZ_LONG(3)
+	LOAD	16, 3*SZ_LONG(3)
+	LOAD	17, 4*SZ_LONG(3)
+	LOAD	18, 5*SZ_LONG(3)
+	LOAD	19, 6*SZ_LONG(3)
+	LOAD	20, 7*SZ_LONG(3)
+	LOAD	21, 8*SZ_LONG(3)
+	LOAD	22, 9*SZ_LONG(3)
+	LOAD	23, 10*SZ_LONG(3)
+	LOAD	24, 11*SZ_LONG(3)
+	LOAD	25, 12*SZ_LONG(3)
+	LOAD	26, 13*SZ_LONG(3)
+	LOAD	27, 14*SZ_LONG(3)
+	LOAD	28, 15*SZ_LONG(3)
+	LOAD	29, 16*SZ_LONG(3)
+	LOAD	30, 17*SZ_LONG(3)
+	LOAD	31, 18*SZ_LONG(3)
+	LOAD	5, 19*SZ_LONG(3)
 	mtlr	5
-	lwz	5, 80(3)
+	LOAD	5, 20*SZ_LONG(3)
 	mtcr	5
 	mr.	3, 4
 	bne	1f
Signature · 1 line
1.8.5.3
#18 lore raw

Re: [RFC PATCH 11/23] Fix powerpc setjmp/longjmp 64bit issues

В Wed, 26 Feb 2014 10:31:10 -0800
Ram Pai <[email protected]> пишет:

Quoted 15 lines

From: Anton Blanchard <[email protected]>

Fix powerpc setjmp/longjmp 64bit issues

From: Anton Blanchard <[email protected]>

---
 grub-core/lib/powerpc/setjmp.S | 94 +++++++++++++++++++++++-------------------
 1 file changed, 52 insertions(+), 42 deletions(-)
grub-core/lib/powerpc/setjmp.S +0 -0
index 716b563..51fcae9 100644

grub-core/lib/powerpc/setjmp.S GRUB_MOD_LICENSE "GPLv3+" · line 28

Quoted 4 lines
grub-core/lib/powerpc/setjmp.S +1 -0
@@ -25,33 +25,43 @@ GRUB_MOD_LICENSE "GPLv3+"
 
 	.text
 
+#if defined( __powerpc64__ ) || defined( __powerpc64le__ )

Where is __powerpc64__ defined? Your previous patch adds only __powerpc64le__ and it does exist in current code as well?

author
#19 lore raw

Re: [RFC PATCH 11/23] Fix powerpc setjmp/longjmp 64bit issues

Quoted 19 lines · Andrey Borzenkov

В Wed, 26 Feb 2014 10:31:10 -0800
Ram Pai <[email protected]> пишет:

Quoted 16 lines

From: Anton Blanchard <[email protected]>

Fix powerpc setjmp/longjmp 64bit issues

From: Anton Blanchard <[email protected]>

---
 grub-core/lib/powerpc/setjmp.S | 94 +++++++++++++++++++++++-------------------
 1 file changed, 52 insertions(+), 42 deletions(-)
grub-core/lib/powerpc/setjmp.S +0 -0
index 716b563..51fcae9 100644
@@ -25,33 +25,43 @@ GRUB_MOD_LICENSE "GPLv3+"
 
Quoted 6 lines

grub-core/lib/powerpc/setjmp.S GRUB_MOD_LICENSE "GPLv3+" · line 28

Quoted 3 lines
grub-core/lib/powerpc/setjmp.S +1 -0
 	.text
 
+#if defined( __powerpc64__ ) || defined( __powerpc64le__ )

Where is __powerpc64__ defined? Your previous patch adds only __powerpc64le__ and it does exist in current code as well?

It is already defined even prior to this patch series. in this patch series i am just adding __powerpc64le__ .

Signature · 1 line
Ram Pai
#20 lore raw

Re: [RFC PATCH 11/23] Fix powerpc setjmp/longjmp 64bit issues

В Wed, 2 Apr 2014 10:06:05 -0700
Ram Pai <[email protected]> пишет:

Quoted 20 lines · Andrey Borzenkov
Quoted 19 lines

В Wed, 26 Feb 2014 10:31:10 -0800
Ram Pai <[email protected]> пишет:

Quoted 16 lines

From: Anton Blanchard <[email protected]>

Fix powerpc setjmp/longjmp 64bit issues

From: Anton Blanchard <[email protected]>

---
 grub-core/lib/powerpc/setjmp.S | 94 +++++++++++++++++++++++-------------------
 1 file changed, 52 insertions(+), 42 deletions(-)
grub-core/lib/powerpc/setjmp.S +0 -0
index 716b563..51fcae9 100644
@@ -25,33 +25,43 @@ GRUB_MOD_LICENSE "GPLv3+"
 
Quoted 8 lines
Quoted 6 lines

grub-core/lib/powerpc/setjmp.S GRUB_MOD_LICENSE "GPLv3+" · line 28

Quoted 3 lines
grub-core/lib/powerpc/setjmp.S +1 -0
 	.text
 
+#if defined( __powerpc64__ ) || defined( __powerpc64le__ )

Where is __powerpc64__ defined? Your previous patch adds only __powerpc64le__ and it does exist in current code as well?

It is already defined even prior to this patch series.

Where?

bor@opensuse:~/src/grub> grep -rw __powerpc64__ .
bor@opensuse:~/src/grub>

Quoted 3 lines

in this
patch series i am just adding __powerpc64le__ .

author
#21 lore raw

Re: [RFC PATCH 11/23] Fix powerpc setjmp/longjmp 64bit issues

Quoted 25 lines · Andrey Borzenkov

В Wed, 2 Apr 2014 10:06:05 -0700
Ram Pai <[email protected]> пишет:

Quoted 22 lines · Andrey Borzenkov
Quoted 21 lines

В Wed, 26 Feb 2014 10:31:10 -0800
Ram Pai <[email protected]> пишет:

Quoted 18 lines

From: Anton Blanchard <[email protected]>

Fix powerpc setjmp/longjmp 64bit issues

From: Anton Blanchard <[email protected]>

---
 grub-core/lib/powerpc/setjmp.S | 94 +++++++++++++++++++++++-------------------
 1 file changed, 52 insertions(+), 42 deletions(-)
grub-core/lib/powerpc/setjmp.S +0 -0
index 716b563..51fcae9 100644
@@ -25,33 +25,43 @@ GRUB_MOD_LICENSE "GPLv3+"
 
 	.text
 
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

grub-core/lib/powerpc/setjmp.S GRUB_MOD_LICENSE "GPLv3+" · line 28

Quoted 1 line
grub-core/lib/powerpc/setjmp.S +1 -0
+#if defined( __powerpc64__ ) || defined( __powerpc64le__ )

Where is __powerpc64__ defined? Your previous patch adds only __powerpc64le__ and it does exist in current code as well?

It is already defined even prior to this patch series.

Where?

just checked. Looks like it is defined automatically by the compiler automatically when -m64 is specified.

RP

#22 lore raw

Re: [RFC PATCH 11/23] Fix powerpc setjmp/longjmp 64bit issues

В Wed, 2 Apr 2014 10:48:34 -0700
Ram Pai <[email protected]> пишет:

Quoted 31 lines · Andrey Borzenkov
Quoted 30 lines

В Wed, 2 Apr 2014 10:06:05 -0700
Ram Pai <[email protected]> пишет:

Quoted 27 lines · Andrey Borzenkov
Quoted 25 lines

В Wed, 26 Feb 2014 10:31:10 -0800
Ram Pai <[email protected]> пишет:

Quoted 15 lines

From: Anton Blanchard <[email protected]>

Fix powerpc setjmp/longjmp 64bit issues

From: Anton Blanchard <[email protected]>

---
 grub-core/lib/powerpc/setjmp.S | 94 +++++++++++++++++++++++-------------------
 1 file changed, 52 insertions(+), 42 deletions(-)
grub-core/lib/powerpc/setjmp.S +0 -0
index 716b563..51fcae9 100644

grub-core/lib/powerpc/setjmp.S GRUB_MOD_LICENSE "GPLv3+" · line 28

Quoted 4 lines
grub-core/lib/powerpc/setjmp.S +1 -0
@@ -25,33 +25,43 @@ GRUB_MOD_LICENSE "GPLv3+"
 
 	.text
 
+#if defined( __powerpc64__ ) || defined( __powerpc64le__ )

Where is __powerpc64__ defined? Your previous patch adds only __powerpc64le__ and it does exist in current code as well?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

It is already defined even prior to this patch series.

Where?

just checked. Looks like it is defined automatically by the compiler automatically when -m64 is specified.

grub does not use -m64 on powerpc. Existing target is 32 bit.

author
#23 lore raw

Re: [RFC PATCH 11/23] Fix powerpc setjmp/longjmp 64bit issues

Quoted 36 lines · Andrey Borzenkov

В Wed, 2 Apr 2014 10:48:34 -0700
Ram Pai <[email protected]> пишет:

Quoted 33 lines · Andrey Borzenkov
Quoted 32 lines

В Wed, 2 Apr 2014 10:06:05 -0700
Ram Pai <[email protected]> пишет:

Quoted 28 lines · Andrey Borzenkov
Quoted 19 lines

В Wed, 26 Feb 2014 10:31:10 -0800
Ram Pai <[email protected]> пишет:

Quoted 16 lines

From: Anton Blanchard <[email protected]>

Fix powerpc setjmp/longjmp 64bit issues

From: Anton Blanchard <[email protected]>

---
 grub-core/lib/powerpc/setjmp.S | 94 +++++++++++++++++++++++-------------------
 1 file changed, 52 insertions(+), 42 deletions(-)
grub-core/lib/powerpc/setjmp.S +0 -0
index 716b563..51fcae9 100644
@@ -25,33 +25,43 @@ GRUB_MOD_LICENSE "GPLv3+"
 
Quoted 6 lines

grub-core/lib/powerpc/setjmp.S GRUB_MOD_LICENSE "GPLv3+" · line 28

Quoted 3 lines
grub-core/lib/powerpc/setjmp.S +1 -0
 	.text
 
+#if defined( __powerpc64__ ) || defined( __powerpc64le__ )

Where is __powerpc64__ defined? Your previous patch adds only __powerpc64le__ and it does exist in current code as well?

It is already defined even prior to this patch series.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Where?

just checked. Looks like it is defined automatically by the compiler automatically when -m64 is specified.

grub does not use -m64 on powerpc. Existing target is 32 bit.

Confirmed with our toolchain folks. the gcc compiler for LE targets assumes -m64 by default. -m32 is not supported for LE target.

However, it does feel a little kludgy to have __powerpc64__ defined by the compiler and __powerpc64le__ by my patches. Have to figure out a way to clean it up.

RP

author
#24 lore raw

RFC PATCH 12/23 Add powerpc64 ieee1275 trampoline

In reply to Ram Pai

From: Anton Blanchard <[email protected]>

Add a trampoline so a 64bit grub can call a 32 bit OF

From: Anton Blanchard <[email protected]>

---
 grub-core/Makefile.core.def              |   2 +
 grub-core/kern/powerpc/ieee1275/entry.S  | 150 +++++++++++++++++++++++++++++++
 include/grub/powerpc/ieee1275/ieee1275.h |   6 ++
 3 files changed, 158 insertions(+)
 create mode 100644 grub-core/kern/powerpc/ieee1275/entry.S
grub-core/Makefile.core.def +2 -0
index c6e70bb..0c80fe4 100644
@@ -256,9 +256,11 @@ kernel = {
 
   powerpc_ieee1275 = kern/powerpc/cache.S;
   powerpc_ieee1275 = kern/powerpc/dl.c;
+  powerpc_ieee1275 = kern/powerpc/ieee1275/entry.S;
 
   powerpc64le_ieee1275 = kern/powerpc/cache.S;
   powerpc64le_ieee1275 = kern/powerpc/dl.c;
+  powerpc64le_ieee1275 = kern/powerpc/ieee1275/entry.S;
 
   sparc64_ieee1275 = kern/sparc64/cache.S;
   sparc64_ieee1275 = kern/sparc64/dl.c;
grub-core/kern/powerpc/ieee1275/entry.S new file +150 -0

150 lines not on this page · raw message

include/grub/powerpc/ieee1275/ieee1275.h +6 -0
index 3c7683f..14bdc43 100644
@@ -25,4 +25,10 @@
 #define GRUB_IEEE1275_CELL_SIZEOF 4
 typedef grub_uint32_t grub_ieee1275_cell_t;
 
+#ifdef __powerpc64__
+int EXPORT_FUNC(ieee1275_call_entry_fn)(void *args, void *entry);
+#define	IEEE1275_CALL_ENTRY_FN(args)	\
+		ieee1275_call_entry_fn((args), grub_ieee1275_entry_fn)
+#endif
+
 #endif /* ! GRUB_IEEE1275_MACHINE_HEADER */
Signature · 1 line
1.8.5.3
author
#25 lore raw

RFC PATCH 13/23 Add 64bit support to powerpc startup code

In reply to Ram Pai

From: Anton Blanchard <[email protected]>

Add 64bit support to powerpc startup code

From: Anton Blanchard <[email protected]>

---
 grub-core/kern/powerpc/ieee1275/startup.S | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)
grub-core/kern/powerpc/ieee1275/startup.S +26 -4
index 21c884b..d93682e 100644
@@ -19,15 +19,26 @@
 
 #include <grub/symbol.h>
 #include <grub/offsets.h>
+#include <ppc-asm.h>
 
 .extern __bss_start
 .extern _end
 
 	.text
-	.align	2
-	.globl	start, _start
-start:
-_start:
+
+FUNC_START(_start)
+
+#if defined(_CALL_ELF) && _CALL_ELF == 2 /* Little endian */
+        .long 0x05009f42            /* bcl 20,31,$+4                      */
+        .long 0xa602487d            /* mflr r10                           */
+        .long 0x1c004a39            /* addi r10,r10,28                    */
+        .long 0xa600607d            /* mfmsr r11                          */
+        .long 0x01006b69            /* xori r11,r11,1                     */
+        .long 0xa6035a7d            /* mtsrr0 r10                         */
+        .long 0xa6037b7d            /* mtsrr1 r11                         */
+        .long 0x2400004c            /* rfid                               */
+#endif
+
 	li      2, 0
 	li      13, 0
 
@@ -61,7 +72,18 @@ _start:
 
 	/* Store r5 in grub_ieee1275_entry_fn.  */
 	lis	9, grub_ieee1275_entry_fn@ha
+
+#if defined( __powerpc64__ ) || defined ( __powerpc64le__ )
+	std	5, grub_ieee1275_entry_fn@l(9)
+	/* Set up the TOC */
+	bl	3f
+3:	mflr	9
+	addis	2,9,.TOC.-3b@ha
+	addi	2,2,.TOC.-3b@l
+#else
 	stw	5, grub_ieee1275_entry_fn@l(9)
+#endif
 
 	bl	grub_main
 1:	b	1b
+FUNC_END(_start)
Signature · 1 line
1.8.5.3
author
#26 lore raw

RFC PATCH 14/23 Add grub_dl_find_section_addr

In reply to Ram Pai

From: Anton Blanchard <[email protected]>

ppc64 needs to find the address of the toc and opd sections. Create grub_dl_find_section_addr to do this.

We also need grub_dl_find_section, so make it global.

From: Anton Blanchard <[email protected]>

---
 grub-core/kern/dl.c | 27 ++++++++++++++++++++++++++-
 include/grub/dl.h   |  2 ++
 2 files changed, 28 insertions(+), 1 deletion(-)
grub-core/kern/dl.c +26 -1
index 6850e04..de2d0ed 100644
@@ -191,6 +191,31 @@ grub_dl_get_section_addr (grub_dl_t mod, unsigned n)
   return 0;
 }
 
+void *grub_dl_find_section_addr (grub_dl_t mod, Elf_Ehdr *e, const char *name)
+{
+  Elf_Shdr *s;
+  const char *str;
+  unsigned i;
+  grub_dl_segment_t seg;
+
+  s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shstrndx * e->e_shentsize);
+  str = (char *) e + s->sh_offset;
+
+  for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
+       i < e->e_shnum;
+       i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
+    {
+      if (grub_strcmp (str + s->sh_name, name) == 0)
+	{
+	  for (seg = mod->segment; seg; seg = seg->next)
+	    if (seg->section == i)
+	      return seg->addr;
+	}
+    }
+
+  return 0;
+}
+
 /* Check if EHDR is a valid ELF header.  */
 static grub_err_t
 grub_dl_check_header (void *ehdr, grub_size_t size)
@@ -427,7 +452,7 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)
   return GRUB_ERR_NONE;
 }
 
-static Elf_Shdr *
+Elf_Shdr *
 grub_dl_find_section (Elf_Ehdr *e, const char *name)
 {
   Elf_Shdr *s;
include/grub/dl.h +2 -0
index 9562fa6..39c73a7 100644
@@ -250,6 +250,8 @@ grub_err_t grub_arch_dl_check_header (void *ehdr);
 grub_err_t
 grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
 			       Elf_Shdr *s, grub_dl_segment_t seg);
+Elf_Shdr * grub_dl_find_section (Elf_Ehdr *e, const char *name);
+void *grub_dl_find_section_addr (grub_dl_t mod, Elf_Ehdr *e, const char *name);
 #endif
 
 #if defined (_mips)
Signature · 1 line
1.8.5.3
author
#27 lore raw

RFC PATCH 15/23 Add ppc64 relocations

In reply to Ram Pai

From: Anton Blanchard <[email protected]>

Add ppc64 relocations

From: Anton Blanchard <[email protected]>

---
 grub-core/kern/powerpc/dl.c | 179 +++++++++++++++++++++++++++++++++++++++++---
 include/grub/elf.h          |   3 +
 2 files changed, 172 insertions(+), 10 deletions(-)
grub-core/kern/powerpc/dl.c +169 -10
index 7677e5a..2a3b022 100644
@@ -23,6 +23,20 @@
 #include <grub/err.h>
 #include <grub/i18n.h>
 
+#if defined( __powerpc64__ ) || defined( __powerpc64le__ )
+#define ELFCLASSXX ELFCLASS64
+#define ELFMACHINEXX EM_PPC64
+#else
+#define ELFCLASSXX ELFCLASS32
+#define ELFMACHINEXX EM_PPC32
+#endif
+
+#if defined( __powerpc64le__ )
+#define ELFDATA2XSB ELFDATA2LSB
+#else
+#define ELFDATA2XSB ELFDATA2MSB
+#endif
+
 /* Check if EHDR is a valid ELF header.  */
 grub_err_t
 grub_arch_dl_check_header (void *ehdr)
@@ -30,14 +44,77 @@ grub_arch_dl_check_header (void *ehdr)
   Elf_Ehdr *e = ehdr;
 
   /* Check the magic numbers.  */
-  if (e->e_ident[EI_CLASS] != ELFCLASS32
-      || e->e_ident[EI_DATA] != ELFDATA2MSB
-      || e->e_machine != EM_PPC)
+  if (e->e_ident[EI_CLASS] != ELFCLASSXX
+      || e->e_ident[EI_DATA] != ELFDATA2XSB
+      || e->e_machine != ELFMACHINEXX)
     return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
 
   return GRUB_ERR_NONE;
 }
 
+
+
+
+#if defined( __powerpc64le__ )
+struct trampoline
+{
+  grub_uint32_t std;
+  grub_uint32_t addis;
+  grub_uint32_t addi; 
+  grub_uint32_t mtctr;
+  grub_uint32_t bctr;
+};
+
+static const struct trampoline trampoline_template = 
+  {
+       0xf8410018,       /* std     r2,24(r1) */
+       0x3d800000,       /* addis   r12,0,0 */
+       0x398c0000,       /* addi    r12,r12,0 */
+       0x7d8903a6,       /* mtctr   r12 */
+       0x4e800420,       /* bctr */
+  };
+
+#define PPC_NOP 0x60000000
+#define	RESTORE_TOC 0xe8410018       /* ld      r2,24(r1) */
+
+#define STO_PPC64_LOCAL_BIT             5
+#define STO_PPC64_LOCAL_MASK            (7 << STO_PPC64_LOCAL_BIT)
+
+static inline unsigned int
+ppc64_decode_local_entry(unsigned int other)
+{
+  return ((1 << other) >> 2) << 2;
+}
+
+#define PPC64_LOCAL_ENTRY_OFFSET(other)                         \
+  ppc64_decode_local_entry (((other) & STO_PPC64_LOCAL_MASK)    \
+                            >> STO_PPC64_LOCAL_BIT)
+
+
+
+#elif defined( __powerpc64__ )
+
+#error "NOT SUPPORTED YET"
+
+static int grub_arch_dl_is_in_opd (grub_dl_t mod, void *ehdr, unsigned long addr)
+{
+  unsigned long start, end;
+  Elf_Shdr *s = grub_dl_find_section(ehdr, ".opd");
+
+  if (!s)
+	return 0;
+
+  start = (unsigned long)grub_dl_find_section_addr(mod, ehdr, ".opd");
+  end = start + s->sh_size;
+
+  if ((start <= addr) && (addr < end))
+    return 1;
+  else
+    return 0;
+}
+
+#else
+
 /* For low-endian reverse lis and addr_high as well as ori and addr_low. */
 struct trampoline
 {
@@ -55,8 +132,20 @@ static const struct trampoline trampoline_template =
     0x4e800420,
   };
 
+#endif
+
 #pragma GCC diagnostic ignored "-Wcast-align"
 
+static unsigned long grub_arch_dl_get_toc (grub_dl_t mod, void *ehdr)
+{
+  unsigned long i = (unsigned long)grub_dl_find_section_addr(mod, ehdr, ".toc");
+  if (!i)
+    return 0;
+
+  return i;
+}
+
+
 grub_err_t
 grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
 				 grub_size_t *got)
@@ -89,12 +178,15 @@ grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
   return GRUB_ERR_NONE;
 }
 
+#define PPC_LO(v) ((v) & 0xffff)
+#define PPC_HI(v) (((v) >> 16) & 0xffff)
+#define PPC_HA(v) PPC_HI ((v) + 0x8000)
+
 /* Relocate symbols.  */
 grub_err_t
 grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
 			       Elf_Shdr *s, grub_dl_segment_t seg)
 {
-#ifdef powerpc
   Elf_Rela *rel, *max;
 
   for (rel = (Elf_Rela *) ((char *) ehdr + s->sh_offset),
@@ -104,7 +196,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
     {
       Elf_Word *addr;
       Elf_Sym *sym;
-      grub_uint32_t value;
+      Elf_Addr value;
 
       if (seg->size < rel->r_offset)
 	return grub_error (GRUB_ERR_BAD_MODULE,
@@ -119,6 +211,76 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
       value = sym->st_value + rel->r_addend;
       switch (ELF_R_TYPE (rel->r_info))
 	{
+#ifdef __powerpc64le__
+	case GRUB_ELF_R_PPC_REL24:
+	  {
+	    struct trampoline *tptr = mod->trampptr;
+	    Elf_Sword delta;
+	    if (sym->st_shndx == SHN_UNDEF)
+	    {
+	      	grub_memcpy (tptr, &trampoline_template, sizeof (*tptr));
+
+		tptr->addis |= PPC_HA(value);
+		tptr->addi |= PPC_LO(value);
+
+	        mod->trampptr = tptr + 1;
+	        delta = (grub_uint8_t *) tptr - (grub_uint8_t *) addr;
+
+	        if (*(addr+1) != PPC_NOP)
+	               return grub_error (GRUB_ERR_BAD_MODULE,
+			     "Missing NOP after PPC_REL24 got %x", *(addr+1));
+	        *(addr+1) = RESTORE_TOC;
+	    } else
+	        delta = (grub_uint8_t *)value - (grub_uint8_t *) addr + 
+                     PPC64_LOCAL_ENTRY_OFFSET(sym->st_other);
+
+
+            if (delta << 6 >> 6 != delta)
+		      return grub_error (GRUB_ERR_BAD_MODULE,
+					 "relocation overflow");
+
+	    *(Elf_Word *) (addr) = (*addr & ~0x03fffffc) | (delta & 0x03fffffc);
+	  }
+	  break;
+
+	case GRUB_ELF_R_PPC64_ADDR64:
+	  *(Elf_Xword *) addr = value;
+	  break;
+
+	case GRUB_ELF_R_PPC64_TOC:
+	  *(Elf_Xword *) addr = grub_arch_dl_get_toc(mod, ehdr);
+	  break;
+
+	case GRUB_ELF_R_PPC64_TOC16_HA:
+          value -= grub_arch_dl_get_toc(mod, ehdr);
+          *(Elf_Half *) addr = PPC_HA(value);
+	  break;
+
+	case GRUB_ELF_R_PPC64_TOC16_LO:
+          value -= grub_arch_dl_get_toc(mod, ehdr);
+	  *(Elf_Half *) addr = PPC_LO(value);
+	  break;
+
+	case GRUB_ELF_R_PPC64_TOC16_LO_DS:
+	   value -= grub_arch_dl_get_toc(mod, ehdr);
+	   if (value & 3)
+	    return grub_error (GRUB_ERR_BAD_MODULE,
+			       "bad TOC16_LO_DS relocation");
+	
+	  *(Elf_Half *) addr = ((*(Elf_Half *) addr) & ~0xfffc) | (value & 0xfffc);
+	  break;
+
+	case GRUB_ELF_R_PPC64_REL16_HA:
+	  value -=  (unsigned long) addr;
+	  *(Elf_Half *) addr = PPC_HA(value);
+	  break;
+
+	case GRUB_ELF_R_PPC64_REL16_LO:
+	  value -=  (unsigned long) addr;
+	  *(Elf_Half *) addr = PPC_LO(value);
+	  break;
+#else
+
 	case GRUB_ELF_R_PPC_ADDR16_LO:
 	  *(Elf_Half *) addr = value;
 	  break;
@@ -156,6 +318,8 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
 	case GRUB_ELF_R_PPC_REL32:
 	  *addr = value - (Elf_Word) addr;
 	  break;
+#endif
+
 	default:
 	  return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
 			     N_("relocation 0x%x is not implemented yet"),
@@ -164,9 +328,4 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
     }
 
   return GRUB_ERR_NONE;
-#else
-  return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
-     N_("relocation is not implemented yet for module=%llx ehdr=%llx Elf_Shdr=%llx seg=%llx"), 
-     mod, ehdr, s, seg);
-#endif
 }
include/grub/elf.h +3 -0
index bee7583..224d164 100644
@@ -1998,6 +1998,9 @@ typedef Elf32_Addr Elf32_Conflict;
 #define GRUB_ELF_R_PPC_DIAB_RELSDA_HI	184	/* like EMB_RELSDA, but high 16 bit */
 #define GRUB_ELF_R_PPC_DIAB_RELSDA_HA	185	/* like EMB_RELSDA, adjusted high 16 */
 
+#define GRUB_ELF_R_PPC64_REL16_LO       250
+#define GRUB_ELF_R_PPC64_REL16_HA       252
+
 /* This is a phony reloc to handle any old fashioned TOC16 references
    that may still be in object files.  */
 #define GRUB_ELF_R_PPC_TOC16		255
Signature · 1 line
1.8.5.3
author
#28 lore raw

RFC PATCH 16/23 ppc64 doesn't need libgcc routines

In reply to Ram Pai

From: Anton Blanchard <[email protected]>

ppc64 doesn't need libgcc routines

From: Anton Blanchard <[email protected]>

---
 include/grub/libgcc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/grub/libgcc.h +1 -1
index fdc6611..69a95bc 100644
@@ -23,7 +23,7 @@
 #include <config-util.h>
 
 /* On x86 these functions aren't really needed. Save some space.  */
-#if !defined (__i386__) && !defined (__x86_64__)
+#if !defined (__i386__) && !defined (__x86_64__) && !defined (__powerpc64le__)
 # ifdef HAVE___ASHLDI3
 void EXPORT_FUNC (__ashldi3) (void);
 # endif
Signature · 1 line
1.8.5.3
author
#29 lore raw

RFC PATCH 17/23 Use FUNC_START/FUNC_END for powerpc function definitions

In reply to Ram Pai

From: Anton Blanchard <[email protected]>

Use FUNC_START/FUNC_END for powerpc function definitions

From: Anton Blanchard <[email protected]>

---
 grub-core/kern/powerpc/cache.S | 6 ++++--
 grub-core/lib/powerpc/setjmp.S | 8 +++++---
 2 files changed, 9 insertions(+), 5 deletions(-)
grub-core/kern/powerpc/cache.S +4 -2
index d85e68d..82f10f8 100644
@@ -17,10 +17,12 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <ppc-asm.h>
+
 	.text
 
 	.align 2
-	.globl grub_arch_sync_caches
-grub_arch_sync_caches:
+FUNC_START(grub_arch_sync_caches)
 #include "cache_flush.S"
 	blr
+FUNC_END(grub_arch_sync_caches)
grub-core/lib/powerpc/setjmp.S +5 -3
index 51fcae9..6fdd60e 100644
@@ -18,6 +18,7 @@
 
 #include <grub/symbol.h>
 #include <grub/dl.h>
+#include <ppc-asm.h>
 
 	.file	"setjmp.S"
 
@@ -38,7 +39,7 @@ GRUB_MOD_LICENSE "GPLv3+"
 /*
  * int grub_setjmp (grub_jmp_buf env)
  */
-FUNCTION(grub_setjmp)
+FUNC_START(grub_setjmp)
 	STORE	1, 0(3)
 	STORE	14, 1*SZ_LONG(3)
 	STORE	15, 2*SZ_LONG(3)
@@ -64,11 +65,12 @@ FUNCTION(grub_setjmp)
 	STORE	4, 20*SZ_LONG(3)
 	li	3, 0
 	blr
+FUNC_END(grub_setjmp)
 
 /*
  * int grub_longjmp (grub_jmp_buf env, int val)
  */
-FUNCTION(grub_longjmp)
+FUNC_START(grub_longjmp)
 	LOAD	1, 0(3)
 	LOAD	14, 1*SZ_LONG(3)
 	LOAD	15, 2*SZ_LONG(3)
@@ -96,4 +98,4 @@ FUNCTION(grub_longjmp)
 	bne	1f
 	li	3, 1
 1:	blr
-
+FUNC_END(grub_longjmp)
Signature · 1 line
1.8.5.3
author
#30 lore raw

RFC PATCH 18/23 .TOC. symbol is special in ppc64le

In reply to Ram Pai

.TOC. symbol is special in ppc64le . It maps to the address of the .toc section.

---
 grub-core/kern/dl.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)
grub-core/kern/dl.c +33 -1
index de2d0ed..ce2ff38 100644
@@ -343,6 +343,26 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
   return GRUB_ERR_NONE;
 }
 
+#ifdef __powerpc64le__
+static int
+grub_dl_find_section_index (Elf_Ehdr *e, const char *name)
+{ 
+  Elf_Shdr *s;
+  const char *str;
+  unsigned i;
+
+  s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shstrndx * e->e_shentsize);
+  str = (char *) e + s->sh_offset;
+
+  for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
+       i < e->e_shnum;
+       i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
+    if (grub_strcmp (str + s->sh_name, name) == 0)
+      return i;
+  return -1;
+}
+#endif
+
 static grub_err_t
 grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)
 {
@@ -392,7 +412,19 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)
 	  /* Resolve a global symbol.  */
 	  if (sym->st_name != 0 && sym->st_shndx == 0)
 	    {
-	      grub_symbol_t nsym = grub_dl_resolve_symbol (name);
+	      grub_symbol_t nsym;
+
+#ifdef __powerpc64le__
+              if (grub_strcmp(name, ".TOC.") == 0) {
+                int j = grub_dl_find_section_index (e, ".toc");
+                if (j < 0)
+                    return grub_error (GRUB_ERR_BAD_MODULE,
+                                   N_("section '.toc' not found"), name);
+                sym->st_value = (Elf_Addr) grub_dl_get_section_addr (mod, j);
+                break;
+              }
+#endif
+	      nsym = grub_dl_resolve_symbol (name);
 	      if (! nsym)
 		return grub_error (GRUB_ERR_BAD_MODULE,
 				   N_("symbol `%s' not found"), name);
Signature · 1 line
1.8.5.3
author
#31 lore raw

RFC PATCH 19/23 align .toc section on 4byte boundary.

In reply to Ram Pai

the .toc section in powerpc64le modules are sometimes
not aligned on a four byte boundary. This fails the module linker especially when processing R_PPC64_TOC16_LO_DS, since the addresses are expected to be aligned on 4byte boundary.

---
 grub-core/kern/dl.c | 5 +++++
 1 file changed, 5 insertions(+)
grub-core/kern/dl.c +5 -0
index ce2ff38..ee69c3c 100644
@@ -304,7 +304,12 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
 	    {
 	      void *addr;
 
+#ifdef __powerpc64le__
+	      ptr = (char *) ALIGN_UP ((grub_addr_t) ptr,
+                             (s->sh_addralign < 4 ? 4 : s->sh_addralign));
+#else
 	      ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, s->sh_addralign);
+#endif
 	      addr = ptr;
 	      ptr += s->sh_size;
 
Signature · 1 line
1.8.5.3
author
#32 lore raw

RFC PATCH 20/23 fix parameter to firmware calls

In reply to Ram Pai

all parameter to firmware calls should to be BigEndian and the results should be CPU endian.

---
 grub-core/disk/ieee1275/nand.c         |  41 +++++-----
 grub-core/disk/ieee1275/ofdisk.c       |  22 ++++--
 grub-core/kern/ieee1275/ieee1275.c     | 132 +++++++++++++++++++--------------
 grub-core/kern/ieee1275/openfw.c       |  19 ++---
 grub-core/lib/ieee1275/datetime.c      |  32 ++++----
 grub-core/net/drivers/ieee1275/ofnet.c |   6 +-
 include/grub/ieee1275/ieee1275.h       |   8 +-
 7 files changed, 146 insertions(+), 114 deletions(-)
grub-core/disk/ieee1275/nand.c +23 -18
index 576e9cc..1846c23 100644
@@ -102,32 +102,33 @@ grub_nand_open (const char *name, grub_disk_t disk)
   data->handle = dev_ihandle;
 
   INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 2);
-  args.method = (grub_ieee1275_cell_t) "block-size";
-  args.ihandle = dev_ihandle;
-  args.result = 1;
+  args.method = IEEE1275_ADDR("block-size");
+  args.ihandle = IEEE1275_VALUE(dev_ihandle);
+  args.result = IEEE1275_VALUE(1);
 
-  if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.result))
+  if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || IEEE1275_VALUE(args.result))
     {
       grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't get block size");
       goto fail;
     }
 
+  args.size1 = IEEE1275_VALUE(args.size1);
   data->block_size = (args.size1 >> GRUB_DISK_SECTOR_BITS);
 
   INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 3);
-  args.method = (grub_ieee1275_cell_t) "size";
-  args.ihandle = dev_ihandle;
-  args.result = 1;
+  args.method = IEEE1275_ADDR( "size");
+  args.ihandle = IEEE1275_VALUE(dev_ihandle);
+  args.result = IEEE1275_VALUE(1);
 
-  if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.result))
+  if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || IEEE1275_VALUE(args.result))
     {
       grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't get disk size");
       goto fail;
     }
 
-  disk->total_sectors = args.size1;
+  disk->total_sectors = IEEE1275_VALUE(args.size1);
   disk->total_sectors <<= 32;
-  disk->total_sectors += args.size2;
+  disk->total_sectors += IEEE1275_VALUE(args.size2);
   disk->total_sectors >>= GRUB_DISK_SECTOR_BITS;
 
   disk->id = dev_ihandle;
@@ -170,10 +171,10 @@ grub_nand_read (grub_disk_t disk, grub_disk_addr_t sector,
     } args;
 
   INIT_IEEE1275_COMMON (&args.common, "call-method", 6, 1);
-  args.method = (grub_ieee1275_cell_t) "pio-read";
-  args.ihandle = data->handle;
-  args.buf = (grub_ieee1275_cell_t) buf;
-  args.page = (grub_ieee1275_cell_t) ((grub_size_t) sector / data->block_size);
+  args.method = IEEE1275_ADDR("pio-read");
+  args.ihandle = IEEE1275_VALUE(data->handle);
+  args.buf =  buf;
+  args.page = (grub_size_t) sector / data->block_size;
 
   ofs = ((grub_size_t) sector % data->block_size) << GRUB_DISK_SECTOR_BITS;
   size <<= GRUB_DISK_SECTOR_BITS;
@@ -185,16 +186,20 @@ grub_nand_read (grub_disk_t disk, grub_disk_addr_t sector,
 
       len = (ofs + size > bsize) ? (bsize - ofs) : size;
 
-      args.len = (grub_ieee1275_cell_t) len;
-      args.ofs = (grub_ieee1275_cell_t) ofs;
-      args.result = 1;
+      args.len = IEEE1275_VALUE(len);
+      args.ofs = IEEE1275_VALUE(ofs);
+      args.result = IEEE1275_VALUE(1);
+      args.buf =  IEEE1275_ADDR(args.buf);
+      args.page =  IEEE1275_VALUE(args.page);
 
-      if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.result))
+      if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || IEEE1275_VALUE(args.result))
         return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx "
 						   "from `%s'"),
 			   (unsigned long long) sector,
 			   disk->name);
 
+      args.buf =  IEEE1275_ADDR(args.buf);
+      args.page =  IEEE1275_VALUE(args.page);
       ofs = 0;
       size -= len;
       args.buf += len;
grub-core/disk/ieee1275/ofdisk.c +14 -8
index d785d6a..72b36c5 100644
@@ -225,16 +225,19 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
     
       INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 3);
       args.method = IEEE1275_ADDR("vscsi-report-luns");
-      args.ihandle = ihandle;
-      args.table = 0;
-      args.nentries = 0;
+      args.ihandle = IEEE1275_VALUE(ihandle);
+      args.table = IEEE1275_ADDR(0);
+      args.nentries = IEEE1275_VALUE(0);
 
-      if (IEEE1275_CALL_ENTRY_FN (&args) == -1 || args.catch_result)
+      if (IEEE1275_CALL_ENTRY_FN (&args) == -1 || IEEE1275_VALUE(args.catch_result))
 	{
 	  grub_ieee1275_close (ihandle);
 	  return;
 	}
 
+      args.table = IEEE1275_ADDR(args.table);
+      args.nentries = IEEE1275_VALUE(args.nentries);
+
       buf = grub_malloc (grub_strlen (alias->path) + 32);
       if (!buf)
 	return;
@@ -245,6 +248,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
 	  grub_uint64_t *ptr;
 
 	  ptr = *(grub_uint64_t **) ((grub_addr_t)args.table + 4 + 8 * i);
+          ptr = (grub_uint64_t *) (grub_addr_t) IEEE1275_ADDR(ptr);
 	  while (*ptr)
 	    {
 	      grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr++);
@@ -614,18 +618,20 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size)
 
   INIT_IEEE1275_COMMON (&args_ieee1275.common, "call-method", 2, 2);
   args_ieee1275.method = IEEE1275_ADDR("block-size");
-  args_ieee1275.ihandle = last_ihandle;
-  args_ieee1275.result = 1;
+  args_ieee1275.ihandle = IEEE1275_VALUE(last_ihandle);
+  args_ieee1275.result = IEEE1275_VALUE(1);
 
   *block_size = GRUB_DISK_SECTOR_SIZE;
 
-  if ((IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1) || (args_ieee1275.result))
+  if ((IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1) || IEEE1275_VALUE(args_ieee1275.result))
     grub_dprintf ("disk", "can't get block size\n");
-  else
+  else {
+    args_ieee1275.size1 = IEEE1275_VALUE(args_ieee1275.size1);
     if (args_ieee1275.size1
         && !(args_ieee1275.size1 & (args_ieee1275.size1 - 1))
         && args_ieee1275.size1 >= 512 && args_ieee1275.size1 <= 16384)
       *block_size = args_ieee1275.size1;
+  }
 
   return 0;
 }
grub-core/kern/ieee1275/ieee1275.c +76 -56

342 lines not on this page · raw message

grub-core/kern/ieee1275/openfw.c +10 -9
index a8bbc71..ced8e3f 100644
@@ -286,20 +286,20 @@ grub_ieee1275_map (grub_addr_t phys, grub_addr_t virt, grub_size_t size,
 #endif
 			1);
   args.method = IEEE1275_ADDR("map");
-  args.ihandle = grub_ieee1275_mmu;
+  args.ihandle = IEEE1275_VALUE(grub_ieee1275_mmu);
 #ifdef __sparc__
   args.phys_high = 0;
 #endif
-  args.phys_low = phys;
-  args.virt = virt;
-  args.size = size;
-  args.mode = mode; /* Format is WIMG0PP.  */
-  args.catch_result = (grub_ieee1275_cell_t) -1;
+  args.phys_low = IEEE1275_ADDR(phys);
+  args.virt = IEEE1275_ADDR(virt);
+  args.size = IEEE1275_VALUE(size);
+  args.mode = IEEE1275_VALUE(mode); /* Format is WIMG0PP.  */
+  args.catch_result = IEEE1275_VALUE((grub_ieee1275_cell_t) -1);
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
     return -1;
 
-  return args.catch_result;
+  return IEEE1275_VALUE(args.catch_result);
 }
 
 grub_err_t
@@ -545,10 +545,12 @@ grub_ieee1275_canonicalise_devname (const char *path)
       INIT_IEEE1275_COMMON (&args.common, "canon", 3, 1);
       args.path = IEEE1275_ADDR(path);
       args.buf = IEEE1275_ADDR(buf);
-      args.inlen = (grub_ieee1275_cell_t) (bufsize - 1);
+      args.inlen = IEEE1275_VALUE(bufsize - 1);
 
       if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
 	return 0;
+
+      args.outlen = IEEE1275_VALUE(args.outlen);
       if (args.outlen > bufsize - 1)
 	{
 	  bufsize = args.outlen + 2;
@@ -560,4 +562,3 @@ grub_ieee1275_canonicalise_devname (const char *path)
   grub_free (buf);
   return NULL;
 }
-
grub-core/lib/ieee1275/datetime.c +16 -16
index fa0d3b6..7ee1ae2 100644
@@ -83,22 +83,22 @@ grub_get_datetime (struct grub_datetime *datetime)
     return grub_error (GRUB_ERR_IO, "couldn't open RTC");
 
   INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 7);
-  args.device = (grub_ieee1275_cell_t) ihandle;
+  args.device = IEEE1275_VALUE((grub_ieee1275_cell_t) ihandle);
   args.method = IEEE1275_ADDR("get-time");
 
   status = IEEE1275_CALL_ENTRY_FN (&args);
 
   grub_ieee1275_close (ihandle);
 
-  if (status == -1 || args.catch_result)
+  if (status == -1 || IEEE1275_VALUE(args.catch_result))
     return grub_error (GRUB_ERR_IO, "get-time failed");
 
-  datetime->year = args.year;
-  datetime->month = args.month;
-  datetime->day = args.day;
-  datetime->hour = args.hour;
-  datetime->minute = args.minute;
-  datetime->second = args.second;
+  datetime->year = IEEE1275_VALUE(args.year);
+  datetime->month = IEEE1275_VALUE(args.month);
+  datetime->day = IEEE1275_VALUE(args.day);
+  datetime->hour = IEEE1275_VALUE(args.hour);
+  datetime->minute = IEEE1275_VALUE(args.minute);
+  datetime->second = IEEE1275_VALUE(args.second);
 
   return GRUB_ERR_NONE;
 }
@@ -135,21 +135,21 @@ grub_set_datetime (struct grub_datetime *datetime)
     return grub_error (GRUB_ERR_IO, "couldn't open RTC");
 
   INIT_IEEE1275_COMMON (&args.common, "call-method", 8, 1);
-  args.device = (grub_ieee1275_cell_t) ihandle;
+  args.device = IEEE1275_VALUE(ihandle);
   args.method = IEEE1275_ADDR("set-time");
 
-  args.year = datetime->year;
-  args.month = datetime->month;
-  args.day = datetime->day;
-  args.hour = datetime->hour;
-  args.minute = datetime->minute;
-  args.second = datetime->second;
+  args.year = IEEE1275_VALUE(datetime->year);
+  args.month = IEEE1275_VALUE(datetime->month);
+  args.day = IEEE1275_VALUE(datetime->day);
+  args.hour = IEEE1275_VALUE(datetime->hour);
+  args.minute = IEEE1275_VALUE(datetime->minute);
+  args.second = IEEE1275_VALUE(datetime->second);
 
   status = IEEE1275_CALL_ENTRY_FN (&args);
 
   grub_ieee1275_close (ihandle);
 
-  if (status == -1 || args.catch_result)
+  if (status == -1 || IEEE1275_VALUE(args.catch_result))
     return grub_error (GRUB_ERR_IO, "set-time failed");
 
   return GRUB_ERR_NONE;
grub-core/net/drivers/ieee1275/ofnet.c +3 -3
index 07c8446..01dfe85 100644
@@ -385,17 +385,17 @@ search_net_devices (struct grub_ieee1275_devalias *alias)
       }
       args;
       INIT_IEEE1275_COMMON (&args.common, "interpret", 2, 2);
-      args.len = card->txbufsize;
+      args.len = IEEE1275_VALUE(card->txbufsize);
       args.method = IEEE1275_ADDR("alloc-mem");
 
       if (IEEE1275_CALL_ENTRY_FN (&args) == -1
-	  || args.catch)
+	  || IEEE1275_VALUE(args.catch))
 	{
 	  card->txbuf = 0;
 	  grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
 	}
       else
-	card->txbuf = (void *) (grub_addr_t) args.result;
+	card->txbuf = (void *) (grub_addr_t) IEEE1275_VALUE(args.result);
     }
   else
     card->txbuf = grub_zalloc (card->txbufsize);
include/grub/ieee1275/ieee1275.h +4 -4
index 2e5270c..be0c235 100644
@@ -49,12 +49,12 @@ struct grub_ieee1275_common_hdr
   grub_ieee1275_cell_t nr_outs;
 };
 
-#define IEEE1275_ADDR(x)         (grub_uint32_t)(grub_addr_t)(x)
-
+#define IEEE1275_ADDR(x)         (grub_uint32_t)grub_cpu_to_be32((grub_addr_t)(x))
+#define IEEE1275_VALUE(x)         (grub_uint32_t)grub_cpu_to_be32(x)
 #define INIT_IEEE1275_COMMON(p, xname, xins, xouts) \
   (p)->name = (grub_ieee1275_cell_t) IEEE1275_ADDR(xname); \
-  (p)->nr_ins = (grub_ieee1275_cell_t) xins; \
-  (p)->nr_outs = (grub_ieee1275_cell_t) xouts
+  (p)->nr_ins = (grub_ieee1275_cell_t) IEEE1275_VALUE(xins); \
+  (p)->nr_outs = (grub_ieee1275_cell_t) IEEE1275_VALUE(xouts)
 
 typedef grub_uint32_t grub_ieee1275_ihandle_t;
 typedef grub_uint32_t grub_ieee1275_phandle_t;
Signature · 1 line
1.8.5.3
#33 lore raw

Re: [RFC PATCH 20/23] fix parameter to firmware calls

В Wed, 26 Feb 2014 10:31:19 -0800
Ram Pai <[email protected]> пишет:

include/grub/ieee1275/ieee1275.h struct grub_ieee1275_common_hdr · line 53

Quoted 4 lines
include/grub/ieee1275/ieee1275.h +2 -2
-#define IEEE1275_ADDR(x)         (grub_uint32_t)(grub_addr_t)(x)
-
+#define IEEE1275_ADDR(x)         (grub_uint32_t)grub_cpu_to_be32((grub_addr_t)(x))
+#define IEEE1275_VALUE(x)         (grub_uint32_t)grub_cpu_to_be32(x)

Same question - what about sparc64, is it safe to truncate values there?

author
#34 lore raw

Re: [RFC PATCH 20/23] fix parameter to firmware calls

Quoted 9 lines · Andrey Borzenkov

В Wed, 26 Feb 2014 10:31:19 -0800
Ram Pai <[email protected]> пишет:

include/grub/ieee1275/ieee1275.h struct grub_ieee1275_common_hdr · line 53

Quoted 4 lines
include/grub/ieee1275/ieee1275.h +2 -2
-#define IEEE1275_ADDR(x)         (grub_uint32_t)(grub_addr_t)(x)
-
+#define IEEE1275_ADDR(x)         (grub_uint32_t)grub_cpu_to_be32((grub_addr_t)(x))
+#define IEEE1275_VALUE(x)         (grub_uint32_t)grub_cpu_to_be32(x)

Same question - what about sparc64, is it safe to truncate values there?

dont know anything about sparc64. Probably not.

These macros are used only for the powerpc specific code AFAICT. I will audit and confirm.

Signature · 1 line
Ram Pai
#35 lore raw

Re: [RFC PATCH 20/23] fix parameter to firmware calls

В Wed, 2 Apr 2014 10:08:32 -0700
Ram Pai <[email protected]> пишет:

Quoted 11 lines · Andrey Borzenkov
Quoted 9 lines

В Wed, 26 Feb 2014 10:31:19 -0800
Ram Pai <[email protected]> пишет:

include/grub/ieee1275/ieee1275.h struct grub_ieee1275_common_hdr · line 53

Quoted 4 lines
include/grub/ieee1275/ieee1275.h +2 -2
-#define IEEE1275_ADDR(x)         (grub_uint32_t)(grub_addr_t)(x)
-
+#define IEEE1275_ADDR(x)         (grub_uint32_t)grub_cpu_to_be32((grub_addr_t)(x))
+#define IEEE1275_VALUE(x)         (grub_uint32_t)grub_cpu_to_be32(x)

Same question - what about sparc64, is it safe to truncate values there?

Quoted 3 lines

dont know anything about sparc64. Probably not.

These macros are used only for the powerpc specific code AFAICT.

Files under grub-core/*/ieee1275 are used for ieee1275 platforms, which include sparc64 (and actually i385 as well, so you need to check how it affects these too)

GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ]

Quoted 3 lines

I will audit and confirm.

author
#36 lore raw

RFC PATCH 21/23 powerpc64 is not necessarily BigEndian anymore! :)

In reply to Ram Pai

From: Anton Blanchard <[email protected]>

powerpc64 is not necessarily BigEndian anymore! :)

---
 include/grub/powerpc/types.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
include/grub/powerpc/types.h +7 -3
index 7a2fc6b..ab138d4 100644
@@ -19,7 +19,7 @@
 #ifndef GRUB_TYPES_CPU_HEADER
 #define GRUB_TYPES_CPU_HEADER	1
 
-#ifdef __powerpc64le__
+#ifdef __powerpc64__
 /* The size of void *.  */
 #define GRUB_TARGET_SIZEOF_VOID_P	8
 
@@ -33,8 +33,12 @@
 #define GRUB_TARGET_SIZEOF_LONG		4
 #endif
 
-/* powerpc is big-endian.  */
-#define GRUB_TARGET_WORDS_BIGENDIAN	1
+#ifdef __powerpc64le__
+#undef GRUB_TARGET_WORDS_BIGENDIAN
+#else
+#define GRUB_TARGET_WORDS_BIGENDIAN     1
+#endif
+
 
 
 #endif /* ! GRUB_TYPES_CPU_HEADER */
Signature · 1 line
1.8.5.3
#37 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

В Wed, 26 Feb 2014 10:31:20 -0800
Ram Pai <[email protected]> пишет:

Quoted 24 lines

From: Anton Blanchard <[email protected]>

powerpc64 is not necessarily BigEndian anymore! :)

---
 include/grub/powerpc/types.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
include/grub/powerpc/types.h +1 -1
index 7a2fc6b..ab138d4 100644
@@ -19,7 +19,7 @@
 #ifndef GRUB_TYPES_CPU_HEADER
 #define GRUB_TYPES_CPU_HEADER	1
 
-#ifdef __powerpc64le__
+#ifdef __powerpc64__
 /* The size of void *.  */
 #define GRUB_TARGET_SIZEOF_VOID_P	8
 
@@ -33,8 +33,12 @@
 #define GRUB_TARGET_SIZEOF_LONG		4

include/grub/powerpc/types.h line 41

Quoted 10 lines
include/grub/powerpc/types.h +6 -2
 #endif
 
-/* powerpc is big-endian.  */
-#define GRUB_TARGET_WORDS_BIGENDIAN	1
+#ifdef __powerpc64le__
+#undef GRUB_TARGET_WORDS_BIGENDIAN
+#else
+#define GRUB_TARGET_WORDS_BIGENDIAN     1
+#endif
+

For the sake of bisectability this really should be moved earlier; otherwise at least patch "fix parameter to firmware calls" would be wrong.

Quoted 3 lines
include/grub/powerpc/types.h +0 -0
 #endif /* ! GRUB_TYPES_CPU_HEADER */
#38 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 6 lines

For the sake of bisectability this really should be moved earlier; otherwise at least patch "fix parameter to firmware calls" would be wrong.

Even bigger problem is whether we want to run in LE mode at all. From what I understand (correct if I'm wrong) firmware calls remain big-endian and you need to switch back and forth between LE and BE when doing firmware calls. Byteswapping for the purpose of firmware calls is to be avoided as bugs are easy to slip through (in fact the byte-swapping isn't complete in proposed patches.
(correct me if I'm wrong) these new patches cover a subset of already supported machines and don't add any user-visible feature and no new kernel type (LE kernel can be loaded from BE GRUB). Cross-compiling to BE from LE is easy (TARGET_CFLAGS=-EL).
So it looks like this patch series adds a new high-maintenance-cost port covering only already supported machines and already supportred features.

author
#39 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 10 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 6 lines

For the sake of bisectability this really should be moved earlier; otherwise at least patch "fix parameter to firmware calls" would be wrong.

Even bigger problem is whether we want to run in LE mode at all. From what I understand (correct if I'm wrong) firmware calls remain big-endian and you need to switch back and forth between LE and BE when doing firmware calls.

Yes. firmware runs in 32bit BE mode. And there is a constant switch from 64bit LE to 32bit BE and vice-versa for each firmware call.

Quoted 4 lines

doing firmware calls. Byteswapping for the purpose of firmware calls is to be avoided as bugs are easy to slip through (in fact the byte-swapping isn't complete in proposed patches.
(correct me if I'm wrong)

Is that true? maybe you are right. I might have missed something. However please hint me what i have missed. I will look into some other arch code that support the same ieee platform.

Quoted 4 lines

these new patches cover a subset of already
supported machines and don't add any user-visible feature and no new kernel type (LE kernel can be loaded from BE GRUB). Cross-compiling to BE from LE is easy (TARGET_CFLAGS=-EL).

Well. that is the issue. Various distros have varied support for cross-compilation (multi-arch support). If the distro does not have 32bit BE libraries natively installed (out-of-the-box), they wont be able to generate a 32bit BE grub loader. These set of patches overcomes the deficiency by generating a working native executable on LE systems.

Quoted 2 lines

So it looks like this patch series adds a new high-maintenance-cost port covering only already supported machines and already supportred features.

It does add maintainence; I agree. But than it does overcome some deficiences aswell.

Thanks for your comments. And sorry for the delay. I had not seen this email, since i was not on copy. I will watch the mailing list regularly. RP

Quoted 8 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 1 line
Ram Pai
#40 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

В Thu, 3 Apr 2014 10:33:36 -0700
Ram Pai <[email protected]> пишет:

Quoted 15 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 10 lines
Quoted 6 lines

For the sake of bisectability this really should be moved earlier; otherwise at least patch "fix parameter to firmware calls" would be wrong.

Even bigger problem is whether we want to run in LE mode at all. From what I understand (correct if I'm wrong) firmware calls remain big-endian and you need to switch back and forth between LE and BE when doing firmware calls.

Yes. firmware runs in 32bit BE mode. And there is a constant switch from 64bit LE to 32bit BE and vice-versa for each firmware call.

Quoted 15 lines
Quoted 4 lines

doing firmware calls. Byteswapping for the purpose of firmware calls is to be avoided as bugs are easy to slip through (in fact the byte-swapping isn't complete in proposed patches.
(correct me if I'm wrong)

Is that true? maybe you are right. I might have missed something. However please hint me what i have missed. I will look into some other arch code that support the same ieee platform.

Quoted 4 lines

these new patches cover a subset of already
supported machines and don't add any user-visible feature and no new kernel type (LE kernel can be loaded from BE GRUB). Cross-compiling to BE from LE is easy (TARGET_CFLAGS=-EL).

Hmm ... gcc docs mention this only for MIPS, not for PowerPC; for PowerPC it says -mbig.

Quoted 4 lines

Well. that is the issue. Various distros have varied support for cross-compilation (multi-arch support). If the distro does not have 32bit BE libraries natively installed (out-of-the-box), they wont be able to generate a 32bit BE grub loader.

We speak only about target code that runs at boot time. This code does not use any library. It only needs compiler support. GRUB does not support anything besides gcc and recently some clang support was added. Do you have real life example of distribution which does not support -mbig gcc option to produce big-endian *code*?

It is perfectly legal to have different architectures for host and target. So you will have little-endian 64 bit host tools and big-endan 32 bit target. If this works for you this of course is much better solution (at the end it requires just a single line in configure.ac).

Quoted 10 lines

These set of patches
overcomes the deficiency by generating a working native executable on LE systems.

Quoted 2 lines

So it looks like this patch series adds a new high-maintenance-cost port covering only already supported machines and already supportred features.

It does add maintainence; I agree. But than it does overcome some deficiences aswell.

Do you mean there are some problems with big-endian code at boot time? Could you give more details?

Quoted 18 lines

Thanks for your comments. And sorry for the delay. I had not seen this email, since i was not on copy. I will watch the mailing list regularly. RP

Quoted 8 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

author
#41 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 37 lines · Andrey Borzenkov

В Thu, 3 Apr 2014 10:33:36 -0700
Ram Pai <[email protected]> пишет:

Quoted 15 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 10 lines
Quoted 6 lines

For the sake of bisectability this really should be moved earlier; otherwise at least patch "fix parameter to firmware calls" would be wrong.

Even bigger problem is whether we want to run in LE mode at all. From what I understand (correct if I'm wrong) firmware calls remain big-endian and you need to switch back and forth between LE and BE when doing firmware calls.

Yes. firmware runs in 32bit BE mode. And there is a constant switch from 64bit LE to 32bit BE and vice-versa for each firmware call.

Quoted 15 lines
Quoted 4 lines

doing firmware calls. Byteswapping for the purpose of firmware calls is to be avoided as bugs are easy to slip through (in fact the byte-swapping isn't complete in proposed patches.
(correct me if I'm wrong)

Is that true? maybe you are right. I might have missed something. However please hint me what i have missed. I will look into some other arch code that support the same ieee platform.

Quoted 4 lines

these new patches cover a subset of already
supported machines and don't add any user-visible feature and no new kernel type (LE kernel can be loaded from BE GRUB). Cross-compiling to BE from LE is easy (TARGET_CFLAGS=-EL).

Hmm ... gcc docs mention this only for MIPS, not for PowerPC; for PowerPC it says -mbig.

Quoted 7 lines
Quoted 4 lines

Well. that is the issue. Various distros have varied support for cross-compilation (multi-arch support). If the distro does not have 32bit BE libraries natively installed (out-of-the-box), they wont be able to generate a 32bit BE grub loader.

We speak only about target code that runs at boot time. This code does not use any library.

I am not a compiler/toolchain expert. But dont we need all the necessary tools and libraries in /lib/<arch>-<dist>-linux/ directory for cross compilation; even to generate static executables?

Quoted 4 lines

It only needs compiler support. GRUB does not
support anything besides gcc and recently some clang support was added. Do you have real life example of distribution which does not support -mbig gcc option to produce big-endian *code*?

This is ideally what I want too. But it is not possible **out-of-the-box** on any distro for power arch. I am told that debian has a new multi-arch support added which makes this work out-of-the-box, but it is still in early stages to work seemlessly **out-of-the-box**. I may be wrong.

Quoted 13 lines

It is perfectly legal to have different architectures for host and target. So you will have little-endian 64 bit host tools and big-endan 32 bit target. If this works for you this of course is much better solution (at the end it requires just a single line in configure.ac).

Quoted 7 lines

These set of patches
overcomes the deficiency by generating a working native executable on LE systems.

Quoted 2 lines

So it looks like this patch series adds a new high-maintenance-cost port covering only already supported machines and already supportred features.

Quoted 6 lines
Quoted 3 lines

It does add maintainence; I agree. But than it does overcome some deficiences aswell.

Do you mean there are some problems with big-endian code at boot time? Could you give more details?

No there is absolutely no problem with big endian code at boot time. I am talking about the challenges faced in cross compiling, if the necessary multiarch/multilib support is not natively(out-of-the-box) available on the distro.

RP

#42 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

В Thu, 3 Apr 2014 11:37:05 -0700
Ram Pai <[email protected]> пишет:

Quoted 55 lines · Andrey Borzenkov
Quoted 37 lines

В Thu, 3 Apr 2014 10:33:36 -0700
Ram Pai <[email protected]> пишет:

Quoted 15 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 10 lines
Quoted 6 lines

For the sake of bisectability this really should be moved earlier; otherwise at least patch "fix parameter to firmware calls" would be wrong.

Even bigger problem is whether we want to run in LE mode at all. From what I understand (correct if I'm wrong) firmware calls remain big-endian and you need to switch back and forth between LE and BE when doing firmware calls.

Yes. firmware runs in 32bit BE mode. And there is a constant switch from 64bit LE to 32bit BE and vice-versa for each firmware call.

Quoted 15 lines
Quoted 4 lines

doing firmware calls. Byteswapping for the purpose of firmware calls is to be avoided as bugs are easy to slip through (in fact the byte-swapping isn't complete in proposed patches.
(correct me if I'm wrong)

Is that true? maybe you are right. I might have missed something. However please hint me what i have missed. I will look into some other arch code that support the same ieee platform.

Quoted 4 lines

these new patches cover a subset of already
supported machines and don't add any user-visible feature and no new kernel type (LE kernel can be loaded from BE GRUB). Cross-compiling to BE from LE is easy (TARGET_CFLAGS=-EL).

Hmm ... gcc docs mention this only for MIPS, not for PowerPC; for PowerPC it says -mbig.

Quoted 7 lines
Quoted 4 lines

Well. that is the issue. Various distros have varied support for cross-compilation (multi-arch support). If the distro does not have 32bit BE libraries natively installed (out-of-the-box), they wont be able to generate a 32bit BE grub loader.

We speak only about target code that runs at boot time. This code does not use any library.

I am not a compiler/toolchain expert. But dont we need all the necessary tools and libraries in /lib/<arch>-<dist>-linux/ directory for cross compilation; even to generate static executables?

Quoted 4 lines

It only needs compiler support. GRUB does not
support anything besides gcc and recently some clang support was added. Do you have real life example of distribution which does not support -mbig gcc option to produce big-endian *code*?

Quoted 6 lines

This is ideally what I want too. But it is not possible **out-of-the-box** on any distro for power arch. I am told that debian has a new multi-arch support added which makes this work out-of-the-box, but it is still in early stages to work seemlessly **out-of-the-box**. I may be wrong.

If distribution is capable of building Linux kernel, it should be capable of compiling 32 bit big-endian code. Linux startup code on PowerPC is built as 32 bit big-endian:

BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                 -fno-strict-aliasing -Os -msoft-float -pipe \
                 -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
                 -isystem $(shell $(CROSS32CC) -print-file-name=include) \
                 -mbig-endian
Quoted 28 lines
Quoted 13 lines

It is perfectly legal to have different architectures for host and target. So you will have little-endian 64 bit host tools and big-endan 32 bit target. If this works for you this of course is much better solution (at the end it requires just a single line in configure.ac).

Quoted 7 lines

These set of patches
overcomes the deficiency by generating a working native executable on LE systems.

Quoted 2 lines

So it looks like this patch series adds a new high-maintenance-cost port covering only already supported machines and already supportred features.

Quoted 6 lines
Quoted 3 lines

It does add maintainence; I agree. But than it does overcome some deficiences aswell.

Do you mean there are some problems with big-endian code at boot time? Could you give more details?

No there is absolutely no problem with big endian code at boot time. I am talking about the challenges faced in cross compiling, if the necessary multiarch/multilib support is not natively(out-of-the-box) available on the distro.

RP

author
#43 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 69 lines · Andrey Borzenkov

В Thu, 3 Apr 2014 11:37:05 -0700
Ram Pai <[email protected]> пишет:

Quoted 55 lines · Andrey Borzenkov
Quoted 37 lines

В Thu, 3 Apr 2014 10:33:36 -0700
Ram Pai <[email protected]> пишет:

Quoted 15 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 10 lines
Quoted 6 lines

For the sake of bisectability this really should be moved earlier; otherwise at least patch "fix parameter to firmware calls" would be wrong.

Even bigger problem is whether we want to run in LE mode at all. From what I understand (correct if I'm wrong) firmware calls remain big-endian and you need to switch back and forth between LE and BE when doing firmware calls.

Yes. firmware runs in 32bit BE mode. And there is a constant switch from 64bit LE to 32bit BE and vice-versa for each firmware call.

Quoted 15 lines
Quoted 4 lines

doing firmware calls. Byteswapping for the purpose of firmware calls is to be avoided as bugs are easy to slip through (in fact the byte-swapping isn't complete in proposed patches.
(correct me if I'm wrong)

Is that true? maybe you are right. I might have missed something. However please hint me what i have missed. I will look into some other arch code that support the same ieee platform.

Quoted 4 lines

these new patches cover a subset of already
supported machines and don't add any user-visible feature and no new kernel type (LE kernel can be loaded from BE GRUB). Cross-compiling to BE from LE is easy (TARGET_CFLAGS=-EL).

Hmm ... gcc docs mention this only for MIPS, not for PowerPC; for PowerPC it says -mbig.

Quoted 7 lines
Quoted 4 lines

Well. that is the issue. Various distros have varied support for cross-compilation (multi-arch support). If the distro does not have 32bit BE libraries natively installed (out-of-the-box), they wont be able to generate a 32bit BE grub loader.

We speak only about target code that runs at boot time. This code does not use any library.

I am not a compiler/toolchain expert. But dont we need all the necessary tools and libraries in /lib/<arch>-<dist>-linux/ directory for cross compilation; even to generate static executables?

Quoted 4 lines

It only needs compiler support. GRUB does not
support anything besides gcc and recently some clang support was added. Do you have real life example of distribution which does not support -mbig gcc option to produce big-endian *code*?

Quoted 6 lines

This is ideally what I want too. But it is not possible **out-of-the-box** on any distro for power arch. I am told that debian has a new multi-arch support added which makes this work out-of-the-box, but it is still in early stages to work seemlessly **out-of-the-box**. I may be wrong.

If distribution is capable of building Linux kernel, it should be capable of compiling 32 bit big-endian code. Linux startup code on PowerPC is built as 32 bit big-endian:

Quoted 5 lines
BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                 -fno-strict-aliasing -Os -msoft-float -pipe \
                 -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
                 -isystem $(shell $(CROSS32CC) -print-file-name=include) \
                 -mbig-endian

But that is different though. Yes it is possible to cross compile for any target on any arch. But the key is that the environment needs to be setup to do so.

We are talking about generating crosscompiled grub boot loader by an uninitiated/not-so-expert adminstrator. If the distribution makes it easy for that administrator to be able to cross-compile, than life is easy. But that is not generally the case though. The administrator has to scramble around to find the right cross-compilation setup installed on her system to achieve the end result.

RP

#44 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 7 lines · Ram Pai
Quoted 5 lines
Quoted 5 lines
BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                 -fno-strict-aliasing -Os -msoft-float -pipe \
                 -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
                 -isystem $(shell $(CROSS32CC) -print-file-name=include) \
                 -mbig-endian

But that is different though.

How so? It's exactly the same thing: compilation of standalone BE using LE compiler.
Andrey found a very good argument. And if distro can't compile Linux, it's surely broken.
Also powerpc64le is relatively new platform as far as distrros are concerned. I think if big distros show good example, other minor will follow, resulting in more comfortable environment rather than locking ourselves into uncomfortable environments.

Quoted 6 lines

Yes it is possible to cross compile for
any target on any arch. But the key is that the environment needs to be setup to do so.

We are talking about generating crosscompiled grub boot loader by an uninitiated/not-so-expert adminstrator.

It probably amounts to adding -mbig-endian to TARGET_* and using right --target. Both of which can be automated in configure.ac rather than maintaining yet another port.

Quoted 5 lines

If the distribution makes it
easy for that administrator to be able to cross-compile, than life is easy. But that is not generally the case though. The administrator has to scramble around to find the right cross-compilation setup installed on her system to achieve the end result.

author
#45 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 8 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 7 lines · Ram Pai
Quoted 5 lines
Quoted 5 lines
BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                 -fno-strict-aliasing -Os -msoft-float -pipe \
                 -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
                 -isystem $(shell $(CROSS32CC) -print-file-name=include) \
                 -mbig-endian

But that is different though.

Quoted 8 lines

How so? It's exactly the same thing: compilation of standalone BE using LE compiler.
Andrey found a very good argument. And if distro can't compile Linux, it's surely broken.
Also powerpc64le is relatively new platform as far as distrros are concerned. I think if big distros show good example, other minor will follow, resulting in more comfortable environment rather than locking ourselves into uncomfortable environments.

Two things:

a) the cross-compilation on 64bit LE to 32bit-BE target has to be working and supported.
b) distros need to enable (a).

regarding (a) -- is not true currently and i am told that its not in their plans in
the near future.

regarding (b) -- can't speak for all the major distros. But none have it currently.

Quoted 9 lines
Quoted 6 lines

Yes it is possible to cross compile for
any target on any arch. But the key is that the environment needs to be setup to do so.

We are talking about generating crosscompiled grub boot loader by an uninitiated/not-so-expert adminstrator.

It probably amounts to adding -mbig-endian to TARGET_* and using right --target. Both of which can be automated in configure.ac rather than maintaining yet another port.

Yes, if (a) and (b) line up.

RP

#46 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

In reply to Ram Pai

В Thu, 3 Apr 2014 12:26:57 -0700
Ram Pai <[email protected]> пишет:

Quoted 36 lines
Quoted 29 lines
Quoted 18 lines
Quoted 8 lines
Quoted 5 lines

Well. that is the issue. Various distros have varied support for cross-compilation (multi-arch support). If the distro does not have 32bit BE libraries natively installed (out-of-the-box), they wont be able to generate a 32bit BE grub loader.

We speak only about target code that runs at boot time. This code does not use any library.

I am not a compiler/toolchain expert. But dont we need all the necessary tools and libraries in /lib/<arch>-<dist>-linux/ directory for cross compilation; even to generate static executables?

Quoted 4 lines

It only needs compiler support. GRUB does not
support anything besides gcc and recently some clang support was added. Do you have real life example of distribution which does not support -mbig gcc option to produce big-endian *code*?

Quoted 6 lines

This is ideally what I want too. But it is not possible **out-of-the-box** on any distro for power arch. I am told that debian has a new multi-arch support added which makes this work out-of-the-box, but it is still in early stages to work seemlessly **out-of-the-box**. I may be wrong.

If distribution is capable of building Linux kernel, it should be capable of compiling 32 bit big-endian code. Linux startup code on PowerPC is built as 32 bit big-endian:

Quoted 5 lines
BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                 -fno-strict-aliasing -Os -msoft-float -pipe \
                 -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
                 -isystem $(shell $(CROSS32CC) -print-file-name=include) \
                 -mbig-endian
Quoted 8 lines

But that is different though. Yes it is possible to cross compile for any target on any arch. But the key is that the environment needs to be setup to do so.

We are talking about generating crosscompiled grub boot loader by an uninitiated/not-so-expert adminstrator. If the distribution makes it easy for that administrator to be able to cross-compile, than life is easy. But that is not generally the case though.

E-h-h ... could you be more specific? You need exactly the same tool set to compile 32 bit big-endian grub as to compile Linux kernel. So it follows that generally it is impossible to compile Linux kernel on distributions for ppc64le. Is it what you mean?

Quoted 4 lines

The administrator has
to scramble around to find the right cross-compilation setup installed on her system to achieve the end result.

I try to understand what exactly is required beyond what is needed to compile Linux kernel? I do not consider need to install a couple of RPMs as high burden.

Here is what grub2 on SUSE needs:

%ifarch x86_64 ppc64

BuildRequires:  gcc-32bit
BuildRequires:  glibc-32bit
BuildRequires:  glibc-devel-32bit
%else
BuildRequires:  gcc
BuildRequires:  glibc-devel

%ifarch s390x
BuildRequires: glibc-static
%endif
%endif

See https://build.opensuse.org/package/show/Base:System/grub2 for details. It simply forces -m32 -big-endian for powerpc. It also includes brute-force patche to work around libgcc issue that probably may be done differently, but otherwise it is amazingly small change.

author
#47 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 48 lines · Andrey Borzenkov

В Thu, 3 Apr 2014 12:26:57 -0700
Ram Pai <[email protected]> пишет:

Quoted 36 lines
Quoted 29 lines
Quoted 18 lines
Quoted 8 lines
Quoted 5 lines

Well. that is the issue. Various distros have varied support for cross-compilation (multi-arch support). If the distro does not have 32bit BE libraries natively installed (out-of-the-box), they wont be able to generate a 32bit BE grub loader.

We speak only about target code that runs at boot time. This code does not use any library.

I am not a compiler/toolchain expert. But dont we need all the necessary tools and libraries in /lib/<arch>-<dist>-linux/ directory for cross compilation; even to generate static executables?

Quoted 4 lines

It only needs compiler support. GRUB does not
support anything besides gcc and recently some clang support was added. Do you have real life example of distribution which does not support -mbig gcc option to produce big-endian *code*?

Quoted 6 lines

This is ideally what I want too. But it is not possible **out-of-the-box** on any distro for power arch. I am told that debian has a new multi-arch support added which makes this work out-of-the-box, but it is still in early stages to work seemlessly **out-of-the-box**. I may be wrong.

If distribution is capable of building Linux kernel, it should be capable of compiling 32 bit big-endian code. Linux startup code on PowerPC is built as 32 bit big-endian:

Quoted 5 lines
BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                 -fno-strict-aliasing -Os -msoft-float -pipe \
                 -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
                 -isystem $(shell $(CROSS32CC) -print-file-name=include) \
                 -mbig-endian
Quoted 8 lines

But that is different though. Yes it is possible to cross compile for any target on any arch. But the key is that the environment needs to be setup to do so.

We are talking about generating crosscompiled grub boot loader by an uninitiated/not-so-expert adminstrator. If the distribution makes it easy for that administrator to be able to cross-compile, than life is easy. But that is not generally the case though.

Quoted 4 lines

E-h-h ... could you be more specific? You need exactly the same tool set to compile 32 bit big-endian grub as to compile Linux kernel. So it follows that generally it is impossible to compile Linux kernel on distributions for ppc64le. Is it what you mean?

It is not possible to generate a ppc64be kernel on a ppc64le distro. Toolchain does not support it. Vice-versa is possible.

Quoted 24 lines
Quoted 5 lines

The administrator has
to scramble around to find the right cross-compilation setup installed on her system to achieve the end result.

I try to understand what exactly is required beyond what is needed to compile Linux kernel? I do not consider need to install a couple of RPMs as high burden.

Here is what grub2 on SUSE needs:

%ifarch x86_64 ppc64

BuildRequires:  gcc-32bit
BuildRequires:  glibc-32bit
BuildRequires:  glibc-devel-32bit
%else
BuildRequires:  gcc
BuildRequires:  glibc-devel

%ifarch s390x
BuildRequires: glibc-static
%endif
%endif

Quoted 4 lines

See https://build.opensuse.org/package/show/Base:System/grub2 for details. It simply forces -m32 -big-endian for powerpc. It also includes brute-force patche to work around libgcc issue that probably may be done differently, but otherwise it is amazingly small change.

They generate a 32bit BE grub binary on a LE system? No. I dont think so. Because the cross-compile tool chain is not enabled do so.

Signature · 1 line
Ram Pai
#48 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 7 lines · Ram Pai
Quoted 5 lines · Andrey Borzenkov

В Thu, 3 Apr 2014 12:26:57 -0700
Ram Pai <[email protected]> пишет:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Well. that is the issue. Various distros have varied support

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

cross-compilation (multi-arch support). If the distro does not have 32bit BE libraries natively installed (out-of-the-box),

they

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

wont be able to generate a 32bit BE grub loader.

We speak only about target code that runs at boot time. This

code does

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

not use any library.

I am not a compiler/toolchain expert. But dont we need all the

necessary

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

tools and libraries in /lib/<arch>-<dist>-linux/ directory for

cross

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

compilation; even to generate static executables?

Quoted 2 lines

It only needs compiler support. GRUB does not support anything besides gcc and recently some clang support

was added.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Do you have real life example of distribution which does not

support

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 1 line

-mbig gcc option to produce big-endian *code*?

This is ideally what I want too. But it is not possible **out-of-the-box** on any distro for power arch. I am told that debian has a new multi-arch support added which makes this work out-of-the-box, but it is still in early stages to work seemlessly **out-of-the-box**. I may be wrong.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

If distribution is capable of building Linux kernel, it should be capable of compiling 32 bit big-endian code. Linux startup code on PowerPC is built as 32 bit big-endian:

BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                 -fno-strict-aliasing -Os -msoft-float -pipe \
                 -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
                 -isystem $(shell $(CROSS32CC)

-print-file-name=include) \

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

-mbig-endian

But that is different though. Yes it is possible to cross compile for any target on any arch. But the key is that the environment needs to

be

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

setup to do so.

We are talking about generating crosscompiled grub boot loader by an uninitiated/not-so-expert adminstrator. If the distribution makes it easy for that administrator to be able to cross-compile, than life is easy. But that is not generally the case though.

Quoted 9 lines
Quoted 4 lines

E-h-h ... could you be more specific? You need exactly the same tool set to compile 32 bit big-endian grub as to compile Linux kernel. So it follows that generally it is impossible to compile Linux kernel on distributions for ppc64le. Is it what you mean?

It is not possible to generate a ppc64be kernel on a ppc64le distro. Toolchain does not support it. Vice-versa is possible.

No. Ppc64le kernel has some BE code. If you can compile ppc64le kernel you can compile ppc32be GRUB

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

The administrator

has

Quoted 38 lines
Quoted 22 lines
Quoted 3 lines

to scramble around to find the right cross-compilation setup installed on her system to achieve the end result.

I try to understand what exactly is required beyond what is needed to compile Linux kernel? I do not consider need to install a couple of RPMs as high burden.

Here is what grub2 on SUSE needs:

%ifarch x86_64 ppc64

BuildRequires:  gcc-32bit
BuildRequires:  glibc-32bit
BuildRequires:  glibc-devel-32bit
%else
BuildRequires:  gcc
BuildRequires:  glibc-devel

%ifarch s390x
BuildRequires: glibc-static
%endif
%endif

Quoted 4 lines

See https://build.opensuse.org/package/show/Base:System/grub2 for details. It simply forces -m32 -big-endian for powerpc. It also includes brute-force patche to work around libgcc issue that probably may be done differently, but otherwise it is amazingly small change.

They generate a 32bit BE grub binary on a LE system? No. I dont think so. Because the cross-compile tool chain is not enabled do so.

--
Ram Pai

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#49 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

In reply to Ram Pai

В Thu, 3 Apr 2014 13:32:22 -0700
Ram Pai <[email protected]> пишет:

Quoted 4 lines

They generate a 32bit BE grub binary on a LE system? No. I dont think so. Because the cross-compile tool chain is not enabled do so.

bor@opensuse:/tmp/binaries> file usr/bin/grub2-mkimage
usr/bin/grub2-mkimage: ELF 64-bit LSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.0.0, BuildID[sha1]=4a9b7759e1c41a2b2de9f4d33bc179186bf04f8f, stripped bor@opensuse:/tmp/binaries> file usr/lib/grub2/powerpc-ieee1275/kernel.exec
usr/lib/grub2/powerpc-ieee1275/kernel.exec: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, not stripped
bor@opensuse:/tmp/binaries>

author
#50 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 8 lines · Andrey Borzenkov

В Thu, 3 Apr 2014 13:32:22 -0700
Ram Pai <[email protected]> пишет:

Quoted 4 lines

They generate a 32bit BE grub binary on a LE system? No. I dont think so. Because the cross-compile tool chain is not enabled do so.

Quoted 5 lines

bor@opensuse:/tmp/binaries> file usr/bin/grub2-mkimage
usr/bin/grub2-mkimage: ELF 64-bit LSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.0.0, BuildID[sha1]=4a9b7759e1c41a2b2de9f4d33bc179186bf04f8f, stripped bor@opensuse:/tmp/binaries> file usr/lib/grub2/powerpc-ieee1275/kernel.exec
usr/lib/grub2/powerpc-ieee1275/kernel.exec: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, not stripped
bor@opensuse:/tmp/binaries>

I know Dinar had attempted and abondoned the work, because it did not work for him.

As of now that thing is not there anymore...if you look at openSUSE:Factory:PowerPC/grub2 RP

#51 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

В Fri, 4 Apr 2014 10:47:35 -0700
Ram Pai <[email protected]> пишет:

Quoted 15 lines · Andrey Borzenkov
Quoted 8 lines

В Thu, 3 Apr 2014 13:32:22 -0700
Ram Pai <[email protected]> пишет:

Quoted 4 lines

They generate a 32bit BE grub binary on a LE system? No. I dont think so. Because the cross-compile tool chain is not enabled do so.

Quoted 5 lines

bor@opensuse:/tmp/binaries> file usr/bin/grub2-mkimage
usr/bin/grub2-mkimage: ELF 64-bit LSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.0.0, BuildID[sha1]=4a9b7759e1c41a2b2de9f4d33bc179186bf04f8f, stripped bor@opensuse:/tmp/binaries> file usr/lib/grub2/powerpc-ieee1275/kernel.exec
usr/lib/grub2/powerpc-ieee1275/kernel.exec: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, not stripped
bor@opensuse:/tmp/binaries>

Quoted 3 lines

I know Dinar had attempted and abondoned the work, because it did not work for him.

As of now that thing is not there anymore...if you look at openSUSE:Factory:PowerPC/grub2

What do you mean? openSUSE:Factory:PowerPC/grub2 does not exist because openSUSE:Factory:PowerPC links to openSUSE:Factory and pulls everything not explicitly defined from there. And openSUSE:Factory itself gets updates from Base:System.

Cc'ing to clear confusion :)

Fri Jan 31 14:42:26 UTC 2014 - [email protected]

- Enable grub2 for PowerPC LE (ppc64le)
- Add ppc64le to exclusive arches
- Don't require gcc-32bit (PowerLE don't have 32bit toolchain)

- added patches:
* grub2-powerpc-libgcc.patch
Provide 32bit libgcc functions for PowerLE

* grub2-ppc64le-core-bigendian.patch
Build grub kernel and images as BE on ppc64le (BL is BE there)

* grub2-ppc64le-platform.patch
Enable ppc64le platform

#52 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 20 lines · Andrey Borzenkov

В Fri, 4 Apr 2014 10:47:35 -0700
Ram Pai <[email protected]> пишет:

Quoted 17 lines · Andrey Borzenkov
Quoted 8 lines

В Thu, 3 Apr 2014 13:32:22 -0700
Ram Pai <[email protected]> пишет:

Quoted 4 lines

They generate a 32bit BE grub binary on a LE system? No. I dont think so. Because the cross-compile tool chain is not enabled do so.

Quoted 5 lines

bor@opensuse:/tmp/binaries> file usr/bin/grub2-mkimage
usr/bin/grub2-mkimage: ELF 64-bit LSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.0.0, BuildID[sha1]=4a9b7759e1c41a2b2de9f4d33bc179186bf04f8f, stripped bor@opensuse:/tmp/binaries> file usr/lib/grub2/powerpc-ieee1275/kernel.exec
usr/lib/grub2/powerpc-ieee1275/kernel.exec: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, not stripped
bor@opensuse:/tmp/binaries>

I know Dinar had attempted and abondoned the work, because it did not work for him.

Quoted 8 lines
Quoted 1 line

As of now that thing is not there anymore...if you look at openSUSE:Factory:PowerPC/grub2

What do you mean? openSUSE:Factory:PowerPC/grub2 does not exist because openSUSE:Factory:PowerPC links to openSUSE:Factory and pulls everything not explicitly defined from there. And openSUSE:Factory itself gets updates from Base:System.

Cc'ing to clear confusion :)

Right, my mistake. I recall a message message with 64bit LE patches. But seems that came from somewhere else.

Long story short. With 32Bit BE stage one I had several issues like accessing btrfs and booting from media. I gave up on my hack, and now use proposed patches (64Bit LE).

I'll submit it to Base:System.

Have fun,
Dinar

Quoted 18 lines

Fri Jan 31 14:42:26 UTC 2014 - [email protected]

- Enable grub2 for PowerPC LE (ppc64le)
- Add ppc64le to exclusive arches
- Don't require gcc-32bit (PowerLE don't have 32bit toolchain)

- added patches:
* grub2-powerpc-libgcc.patch
Provide 32bit libgcc functions for PowerLE

* grub2-ppc64le-core-bigendian.patch
Build grub kernel and images as BE on ppc64le (BL is BE there)

* grub2-ppc64le-platform.patch
Enable ppc64le platform

#53 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

В Fri, 04 Apr 2014 20:24:58 +0200
Dinar Valeev <[email protected]> пишет:

Quoted 8 lines

Right, my mistake. I recall a message message with 64bit LE patches. But seems that came from somewhere else.

Long story short. With 32Bit BE stage one I had several issues like accessing btrfs and booting from media. I gave up on my hack, and now use proposed patches (64Bit LE).

Well, then this is the real bug that has to be fixed. btrfs driver is supposed to be endian-clean.

Did you try to disable SUSE btrfs patch to verify? There is at least one suspicious place

+ tree = grub_le_to_cpu64(data->sblock.root_tree);
+ err = get_fs_root(data, tree, grub_cpu_to_le64(GRUB_BTRFS_FS_TREE_OBJECTID),
+ 0, &fs_root);

get_fs_root expects "tree" in on-disk format, not in CPU format.

+get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree,
+ grub_uint64_t objectid, grub_uint64_t offset,
+ grub_uint64_t *fs_root)
...

+ err = lower_bound(data, &key_in, &key_out, tree,
+ &elemaddr, &elemsize, &desc, 0);

and lower_bound converts fourth argument again

lower_bound (struct grub_btrfs_data *data,
const struct grub_btrfs_key *key_in, struct grub_btrfs_key *key_out, grub_uint64_t root
...
grub_disk_addr_t addr = grub_le_to_cpu64 (root);

Quoted 2 lines

I'll submit it to Base:System.

#54 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 32 lines · Andrey Borzenkov

В Fri, 04 Apr 2014 20:24:58 +0200
Dinar Valeev <[email protected]> пишет:

Quoted 8 lines

Right, my mistake. I recall a message message with 64bit LE patches. But seems that came from somewhere else.

Long story short. With 32Bit BE stage one I had several issues like accessing btrfs and booting from media. I gave up on my hack, and now use proposed patches (64Bit LE).

Well, then this is the real bug that has to be fixed. btrfs driver is supposed to be endian-clean.

Did you try to disable SUSE btrfs patch to verify? There is at least one suspicious place

(quoted diff) +3 -0
+  tree = grub_le_to_cpu64(data->sblock.root_tree);
+  err = get_fs_root(data, tree, grub_cpu_to_le64(GRUB_BTRFS_FS_TREE_OBJECTID),
+                    0, &fs_root);

get_fs_root expects "tree" in on-disk format, not in CPU format.

(quoted diff) +5 -0
+get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree,
+            grub_uint64_t objectid, grub_uint64_t offset,
+            grub_uint64_t *fs_root)
...
 
+  err = lower_bound(data, &key_in, &key_out, tree,
+                    &elemaddr, &elemsize, &desc, 0);
Quoted 8 lines

and lower_bound converts fourth argument again

lower_bound (struct grub_btrfs_data *data,
const struct grub_btrfs_key *key_in, struct grub_btrfs_key *key_out, grub_uint64_t root
...
grub_disk_addr_t addr = grub_le_to_cpu64 (root);

Huh... I can give it a try, if time permits.

Quoted 5 lines
Quoted 4 lines

I'll submit it to Base:System.

author
#55 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 35 lines · Dinar Valeev
Quoted 34 lines · Andrey Borzenkov

В Fri, 04 Apr 2014 20:24:58 +0200
Dinar Valeev <[email protected]> пишет:

Quoted 8 lines

Right, my mistake. I recall a message message with 64bit LE patches. But seems that came from somewhere else.

Long story short. With 32Bit BE stage one I had several issues like accessing btrfs and booting from media. I gave up on my hack, and now use proposed patches (64Bit LE).

Well, then this is the real bug that has to be fixed. btrfs driver is supposed to be endian-clean.

Did you try to disable SUSE btrfs patch to verify? There is at least one suspicious place

(quoted diff) +3 -0
+  tree = grub_le_to_cpu64(data->sblock.root_tree);
+  err = get_fs_root(data, tree, grub_cpu_to_le64(GRUB_BTRFS_FS_TREE_OBJECTID),
+                    0, &fs_root);

get_fs_root expects "tree" in on-disk format, not in CPU format.

(quoted diff) +5 -0
+get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree,
+            grub_uint64_t objectid, grub_uint64_t offset,
+            grub_uint64_t *fs_root)
...
 
+  err = lower_bound(data, &key_in, &key_out, tree,
+                    &elemaddr, &elemsize, &desc, 0);

and lower_bound converts fourth argument again

Quoted 7 lines
Quoted 6 lines

lower_bound (struct grub_btrfs_data *data,
const struct grub_btrfs_key *key_in, struct grub_btrfs_key *key_out, grub_uint64_t root
...
grub_disk_addr_t addr = grub_le_to_cpu64 (root);

Huh... I can give it a try, if time permits.

If this works; assuming all the libgcc calls have been replaced appropriately with native code, there is no strong reason; that I can think off, to do 64bit LE grub. May the best solution win.

However in the long run, it does constrain grub bootloader from using any libgcc calls, thus impeding easy extensibility in the future for this architecture.

RP

A message that is not in the archive (sent off-list or not yet received): CAEaD8JN9SkqU9+BkU2MYub=aC3Wb143nMPgRWjVbFvgit90yBQ@mail.gmail.com

#57 lore raw

Fwd: Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

---------- Forwarded message ----------
From: "Vladimir 'phcoder' Serbinenko" <[email protected]>
Date: 5 Apr 2014 01:45
Subject: Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)
To: "Ram Pai" <[email protected]>
Cc:

Quoted 8 lines · Ram Pai
Quoted 6 lines · Dinar Valeev
Quoted 5 lines · Andrey Borzenkov

В Fri, 04 Apr 2014 20:24:58 +0200
Dinar Valeev <[email protected]> пишет:

Quoted 2 lines

Right, my mistake. I recall a message message with 64bit LE

patches. But

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

seems that came from somewhere else.

Long story short. With 32Bit BE stage one I had several issues like accessing btrfs and booting from media. I gave up on my hack, and

now

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

use proposed patches (64Bit LE).

Well, then this is the real bug that has to be fixed. btrfs driver is supposed to be endian-clean.

Did you try to disable SUSE btrfs patch to verify? There is at least

one

Quoted 4 lines
Quoted 4 lines

Review

Quoted 4 lines

suspicious place

(quoted diff) +2 -0
+  tree = grub_le_to_cpu64(data->sblock.root_tree);
+  err = get_fs_root(data, tree,

grub_cpu_to_le64(GRUB_BTRFS_FS_TREE_OBJECTID),

Quoted 22 lines
Quoted 14 lines
Quoted 14 lines

+ 0, &fs_root);

get_fs_root expects "tree" in on-disk format, not in CPU format.

(quoted diff) +5 -0
+get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree,
+            grub_uint64_t objectid, grub_uint64_t offset,
+            grub_uint64_t *fs_root)
...
 
+  err = lower_bound(data, &key_in, &key_out, tree,
+                    &elemaddr, &elemsize, &desc, 0);

and lower_bound converts fourth argument again

Quoted 7 lines
Quoted 6 lines

lower_bound (struct grub_btrfs_data *data,
const struct grub_btrfs_key *key_in, struct grub_btrfs_key *key_out, grub_uint64_t root
...
grub_disk_addr_t addr = grub_le_to_cpu64 (root);

Huh... I can give it a try, if time permits.

Quoted 8 lines

If this works; assuming all the libgcc calls have been replaced appropriately with native code, there is no strong reason; that I can think off, to do 64bit LE grub. May the best solution win.

However in the long run, it does constrain grub bootloader from using any libgcc calls, thus impeding easy extensibility in the future for this architecture.

There are other reasons to replace libgcc as well. Main one is that libgcc may be compiled with options that use instructions unavailable at runtime. It already happened with libgcc using fpu for divisions. Adding libgcc functions as needed is already needed so maintaining increase ia small.

Quoted 2 lines

RP

#58 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

In reply to Dinar Valeev

В Fri, 04 Apr 2014 20:24:58 +0200
Dinar Valeev <[email protected]> пишет:

Quoted 30 lines · Andrey Borzenkov
Quoted 20 lines

В Fri, 4 Apr 2014 10:47:35 -0700
Ram Pai <[email protected]> пишет:

Quoted 17 lines · Andrey Borzenkov
Quoted 8 lines

В Thu, 3 Apr 2014 13:32:22 -0700
Ram Pai <[email protected]> пишет:

Quoted 4 lines

They generate a 32bit BE grub binary on a LE system? No. I dont think so. Because the cross-compile tool chain is not enabled do so.

Quoted 5 lines

bor@opensuse:/tmp/binaries> file usr/bin/grub2-mkimage
usr/bin/grub2-mkimage: ELF 64-bit LSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.0.0, BuildID[sha1]=4a9b7759e1c41a2b2de9f4d33bc179186bf04f8f, stripped bor@opensuse:/tmp/binaries> file usr/lib/grub2/powerpc-ieee1275/kernel.exec
usr/lib/grub2/powerpc-ieee1275/kernel.exec: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, not stripped
bor@opensuse:/tmp/binaries>

I know Dinar had attempted and abondoned the work, because it did not work for him.

Quoted 8 lines
Quoted 1 line

As of now that thing is not there anymore...if you look at openSUSE:Factory:PowerPC/grub2

What do you mean? openSUSE:Factory:PowerPC/grub2 does not exist because openSUSE:Factory:PowerPC links to openSUSE:Factory and pulls everything not explicitly defined from there. And openSUSE:Factory itself gets updates from Base:System.

Cc'ing to clear confusion :)

Quoted 9 lines

Right, my mistake. I recall a message message with 64bit LE patches. But seems that came from somewhere else.

Long story short. With 32Bit BE stage one I had several issues like accessing btrfs and booting from media. I gave up on my hack, and now use proposed patches (64Bit LE).

I'll submit it to Base:System.

It does not look like it has anything to do with these patches. I cannot access btrfs on PPC BE as well - using packages from Factory ppc and ppc64. It sounds like there is missing endian conversion somewhere in btrfs code and using LE platform simply masks it off.

I can access all other filesystems I tried which makes me believe it is btrfs issue.

#59 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

В Sat, 27 Sep 2014 09:42:04 +0400
Andrei Borzenkov <[email protected]> пишет:

Quoted 43 lines

В Fri, 04 Apr 2014 20:24:58 +0200
Dinar Valeev <[email protected]> пишет:

Quoted 30 lines · Andrey Borzenkov
Quoted 20 lines

В Fri, 4 Apr 2014 10:47:35 -0700
Ram Pai <[email protected]> пишет:

Quoted 17 lines · Andrey Borzenkov
Quoted 8 lines

В Thu, 3 Apr 2014 13:32:22 -0700
Ram Pai <[email protected]> пишет:

Quoted 4 lines

They generate a 32bit BE grub binary on a LE system? No. I dont think so. Because the cross-compile tool chain is not enabled do so.

Quoted 5 lines

bor@opensuse:/tmp/binaries> file usr/bin/grub2-mkimage
usr/bin/grub2-mkimage: ELF 64-bit LSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.0.0, BuildID[sha1]=4a9b7759e1c41a2b2de9f4d33bc179186bf04f8f, stripped bor@opensuse:/tmp/binaries> file usr/lib/grub2/powerpc-ieee1275/kernel.exec
usr/lib/grub2/powerpc-ieee1275/kernel.exec: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, not stripped
bor@opensuse:/tmp/binaries>

I know Dinar had attempted and abondoned the work, because it did not work for him.

Quoted 8 lines
Quoted 1 line

As of now that thing is not there anymore...if you look at openSUSE:Factory:PowerPC/grub2

What do you mean? openSUSE:Factory:PowerPC/grub2 does not exist because openSUSE:Factory:PowerPC links to openSUSE:Factory and pulls everything not explicitly defined from there. And openSUSE:Factory itself gets updates from Base:System.

Cc'ing to clear confusion :)

Quoted 9 lines

Right, my mistake. I recall a message message with 64bit LE patches. But seems that came from somewhere else.

Long story short. With 32Bit BE stage one I had several issues like accessing btrfs and booting from media. I gave up on my hack, and now use proposed patches (64Bit LE).

I'll submit it to Base:System.

Quoted 7 lines

It does not look like it has anything to do with these patches. I cannot access btrfs on PPC BE as well - using packages from Factory ppc and ppc64. It sounds like there is missing endian conversion somewhere in btrfs code and using LE platform simply masks it off.

I can access all other filesystems I tried which makes me believe it is btrfs issue.

And this was even fixed in GIT at the same time this discussion was active :) I added patch to our RPM.

#60 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

In reply to Andrey Borzenkov
Quoted 71 lines · Andrey Borzenkov

В Thu, 3 Apr 2014 12:26:57 -0700
Ram Pai <[email protected]> пишет:

Quoted 36 lines
Quoted 29 lines
Quoted 18 lines
Quoted 8 lines
Quoted 5 lines

Well. that is the issue. Various distros have varied support for cross-compilation (multi-arch support). If the distro does not have 32bit BE libraries natively installed (out-of-the-box), they wont be able to generate a 32bit BE grub loader.

We speak only about target code that runs at boot time. This code does not use any library.

I am not a compiler/toolchain expert. But dont we need all the necessary tools and libraries in /lib/<arch>-<dist>-linux/ directory for cross compilation; even to generate static executables?

Quoted 4 lines

It only needs compiler support. GRUB does not
support anything besides gcc and recently some clang support was added. Do you have real life example of distribution which does not support -mbig gcc option to produce big-endian *code*?

Quoted 6 lines

This is ideally what I want too. But it is not possible **out-of-the-box** on any distro for power arch. I am told that debian has a new multi-arch support added which makes this work out-of-the-box, but it is still in early stages to work seemlessly **out-of-the-box**. I may be wrong.

If distribution is capable of building Linux kernel, it should be capable of compiling 32 bit big-endian code. Linux startup code on PowerPC is built as 32 bit big-endian:

Quoted 5 lines
BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                 -fno-strict-aliasing -Os -msoft-float -pipe \
                 -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
                 -isystem $(shell $(CROSS32CC) -print-file-name=include) \
                 -mbig-endian
Quoted 8 lines

But that is different though. Yes it is possible to cross compile for any target on any arch. But the key is that the environment needs to be setup to do so.

We are talking about generating crosscompiled grub boot loader by an uninitiated/not-so-expert adminstrator. If the distribution makes it easy for that administrator to be able to cross-compile, than life is easy. But that is not generally the case though.

E-h-h ... could you be more specific? You need exactly the same tool set to compile 32 bit big-endian grub as to compile Linux kernel. So it follows that generally it is impossible to compile Linux kernel on distributions for ppc64le. Is it what you mean?

Quoted 4 lines

The administrator has
to scramble around to find the right cross-compilation setup installed on her system to achieve the end result.

I try to understand what exactly is required beyond what is needed to compile Linux kernel? I do not consider need to install a couple of RPMs as high burden.

Here is what grub2 on SUSE needs:

%ifarch x86_64 ppc64

BuildRequires:  gcc-32bit
BuildRequires:  glibc-32bit
BuildRequires:  glibc-devel-32bit
%else
BuildRequires:  gcc
BuildRequires:  glibc-devel
Quoted 6 lines

%ifarch s390x
BuildRequires: glibc-static
%endif
%endif

See https://build.opensuse.org/package/show/Base:System/grub2

I see you have some outdated patches like btrfs ones, you shouldn't need them now (didn't really look in them).
As for eliminating libgcc dependency I created branch phcoder/no-libgcc. For ppc only ucmpdi2 was needed actually.

Quoted 5 lines

for
details. It simply forces -m32 -big-endian for powerpc. It also includes brute-force patche to work around libgcc issue that probably may be done differently, but otherwise it is amazingly small change.

#61 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

В Fri, 04 Apr 2014 08:37:20 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]> пишет:

Quoted 1 line

As for eliminating libgcc dependency I created branch phcoder/no-libgcc.

I'm afraid it results in too much churn that will be unmanageable

module-cmos.o test -f 'lib/ieee1275/cmos.c' || echo '../../grub-core/'lib/ieee1275/cmos.c

[  140s] ../../grub-core/lib/relocator.c:655:2: error: implicit declaration of function 'memset' [-Werror=implicit-function-declaration]
[  140s]   memset (counter, 0, (1 + (1 << DIGITSORT_BITS)) * sizeof (counter[0]));
[  140s]   ^
[  140s] ../../grub-core/lib/relocator.c:655:2: error: nested extern declaration of 'memset' [-Werror=nested-externs]

It is impossible to include compiler-rt.h from misc.h due to circular dependencies and it is near to impossible to find all places where compiler-rt.h has to be included (at least I do not have an idea).

Someone will need to build test it for sparc, mips, arm (two flavors) and powerpc (three flavors).

Quoted 1 line

For ppc only ucmpdi2 was needed actually.

#62 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 5 lines · Andrey Borzenkov

В Fri, 04 Apr 2014 08:37:20 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]> пишет:

Quoted 1 line

As for eliminating libgcc dependency I created branch phcoder/no-libgcc.

Quoted 8 lines

I'm afraid it results in too much churn that will be unmanageable

module-cmos.o test -f 'lib/ieee1275/cmos.c' || echo '../../grub-core/'lib/ieee1275/cmos.c

[  140s] ../../grub-core/lib/relocator.c:655:2: error: implicit declaration of function 'memset' [-Werror=implicit-function-declaration]
[  140s]   memset (counter, 0, (1 + (1 << DIGITSORT_BITS)) * sizeof (counter[0]));
[  140s]   ^
[  140s] ../../grub-core/lib/relocator.c:655:2: error: nested extern declaration of 'memset' [-Werror=nested-externs]

memset in GRUB code is a bug. I fixed the instances I've found and added #define's to posix wrapping

Quoted 4 lines

It is impossible to include compiler-rt.h from misc.h due to circular dependencies and it is near to impossible to find all places where compiler-rt.h has to be included (at least I do not have an idea).

compiler-rt.,h shouldn't be included anywhere. The idea is that it contains only functions used by compiler and never used by GRUB code.

Quoted 2 lines

Someone will need to build test it for sparc, mips, arm (two flavors) and powerpc (three flavors).

I did all of this (I have a script).
A problem is that restgpr and [al]sh[lr]di3 weren't used by any platform. Some other gcc versions probably use them. I'll need to figure out on which platforms.
restgpr is definitely ppc-only.
[al]sh[lr]di3 I think was for arm.

Quoted 10 lines
Quoted 2 lines

For ppc only ucmpdi2 was needed actually.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#63 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

В Sat, 05 Apr 2014 17:45:30 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]> пишет:

Quoted 2 lines

A problem is that restgpr and [al]sh[lr]di3 weren't used by any platform.

What do you mean? They are used, but resolved from -lgcc for all current platforms. Where it breaks is ppc64le where libgcc for BE does not normally exist. And without -lgcc we get

[  152s] kern/powerpc/kernel_exec-dl.o: In function `grub_arch_dl_relocate_symbols':
[  152s] /home/abuild/rpmbuild/BUILD/grub-2.02~beta2/build/grub-core/../../grub-core/kern/powerpc/dl.c:167: undefined reference to `_restgpr_21_x'
[  152s] disk/ieee1275/kernel_exec-ofdisk.o: In function `grub_ofdisk_close':
[  152s] /home/abuild/rpmbuild/BUILD/grub-2.02~beta2/build/grub-core/../../grub-core/disk/ieee1275/ofdisk.c:448: undefined reference to `_restgpr_29_x'

...

Quoted 2 lines

Some other gcc versions probably use them. I'll need to figure
out on which platforms.

Just set TARGET_LDFLAGS_STATIC_LIBGCC= and TARGET_LIBGCC= and try to compile. If you intend to replace libgcc by internal implementation, those flags are not needed anyway.

Quoted 14 lines

restgpr is definitely ppc-only.
[al]sh[lr]di3 I think was for arm.

Quoted 10 lines
Quoted 2 lines

For ppc only ucmpdi2 was needed actually.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#64 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

Quoted 10 lines · Andrey Borzenkov

В Sat, 05 Apr 2014 17:45:30 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]> пишет:

Quoted 2 lines

A problem is that restgpr and [al]sh[lr]di3 weren't used by any platform.

What do you mean? They are used, but resolved from -lgcc for all current platforms. Where it breaks is ppc64le where libgcc for BE does not normally exist. And without -lgcc we get

Quoted 7 lines
[  152s] kern/powerpc/kernel_exec-dl.o: In function `grub_arch_dl_relocate_symbols':
[  152s] /home/abuild/rpmbuild/BUILD/grub-2.02~beta2/build/grub-core/../../grub-core/kern/powerpc/dl.c:167: undefined reference to `_restgpr_21_x'
[  152s] disk/ieee1275/kernel_exec-ofdisk.o: In function `grub_ofdisk_close':
[  152s] /home/abuild/rpmbuild/BUILD/grub-2.02~beta2/build/grub-core/../../grub-core/disk/ieee1275/ofdisk.c:448: undefined reference to `_restgpr_29_x'

...

Not on my system. I use GCC 4.7.2. What version do you get this with?

Quoted 29 lines
Quoted 2 lines

Some other gcc versions probably use them. I'll need to figure
out on which platforms.

Just set TARGET_LDFLAGS_STATIC_LIBGCC= and TARGET_LIBGCC= and try to compile. If you intend to replace libgcc by internal implementation, those flags are not needed anyway.

Quoted 14 lines

restgpr is definitely ppc-only.
[al]sh[lr]di3 I think was for arm.

Quoted 10 lines
Quoted 2 lines

For ppc only ucmpdi2 was needed actually.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#65 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

В Sat, 05 Apr 2014 20:29:24 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]> пишет:

Quoted 11 lines · Andrey Borzenkov
Quoted 10 lines

В Sat, 05 Apr 2014 17:45:30 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]> пишет:

Quoted 2 lines

A problem is that restgpr and [al]sh[lr]di3 weren't used by any platform.

What do you mean? They are used, but resolved from -lgcc for all current platforms. Where it breaks is ppc64le where libgcc for BE does not normally exist. And without -lgcc we get

Quoted 8 lines
Quoted 7 lines
[  152s] kern/powerpc/kernel_exec-dl.o: In function `grub_arch_dl_relocate_symbols':
[  152s] /home/abuild/rpmbuild/BUILD/grub-2.02~beta2/build/grub-core/../../grub-core/kern/powerpc/dl.c:167: undefined reference to `_restgpr_21_x'
[  152s] disk/ieee1275/kernel_exec-ofdisk.o: In function `grub_ofdisk_close':
[  152s] /home/abuild/rpmbuild/BUILD/grub-2.02~beta2/build/grub-core/../../grub-core/disk/ieee1275/ofdisk.c:448: undefined reference to `_restgpr_29_x'

...

Not on my system. I use GCC 4.7.2. What version do you get this with?

GCC 4.8

Quoted 31 lines
Quoted 29 lines
Quoted 2 lines

Some other gcc versions probably use them. I'll need to figure
out on which platforms.

Just set TARGET_LDFLAGS_STATIC_LIBGCC= and TARGET_LIBGCC= and try to compile. If you intend to replace libgcc by internal implementation, those flags are not needed anyway.

Quoted 14 lines

restgpr is definitely ppc-only.
[al]sh[lr]di3 I think was for arm.

Quoted 10 lines
Quoted 2 lines

For ppc only ucmpdi2 was needed actually.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

author
#66 lore raw

Re: [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :)

In reply to Andrey Borzenkov
Quoted 29 lines · Andrey Borzenkov

В Wed, 26 Feb 2014 10:31:20 -0800
Ram Pai <[email protected]> пишет:

Quoted 26 lines

From: Anton Blanchard <[email protected]>

powerpc64 is not necessarily BigEndian anymore! :)

---
 include/grub/powerpc/types.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
include/grub/powerpc/types.h +1 -1
index 7a2fc6b..ab138d4 100644
@@ -19,7 +19,7 @@
 #ifndef GRUB_TYPES_CPU_HEADER
 #define GRUB_TYPES_CPU_HEADER	1
 
-#ifdef __powerpc64le__
+#ifdef __powerpc64__
 /* The size of void *.  */
 #define GRUB_TARGET_SIZEOF_VOID_P	8
 
@@ -33,8 +33,12 @@
 #define GRUB_TARGET_SIZEOF_LONG		4
 #endif
 
Quoted 12 lines

include/grub/powerpc/types.h line 41

Quoted 8 lines
include/grub/powerpc/types.h +6 -2
-/* powerpc is big-endian.  */
-#define GRUB_TARGET_WORDS_BIGENDIAN	1
+#ifdef __powerpc64le__
+#undef GRUB_TARGET_WORDS_BIGENDIAN
+#else
+#define GRUB_TARGET_WORDS_BIGENDIAN     1
+#endif
+

For the sake of bisectability this really should be moved earlier; otherwise at least patch "fix parameter to firmware calls" would be wrong.

Yes. will do.

Thanks for your time and valuable comments!
RP

author
#67 lore raw

RFC PATCH 22/23 fix segfaults if initrd

In reply to Ram Pai

grub segfaults if initrd is specified before specifying
the kernel. The problem is the initrd module sees that kernel is not specified and takes the fail path. In the fail path it checks if anything has be malloc'ed. Unfortunately the variable that it looks to check for is a uninitialized stack variable. The stack variable can incorrectly indicate something is malloced, which leads the module to free some unallocated memory. This patch fixes the problem by initializing the stack variable.

---
 grub-core/loader/powerpc/ieee1275/linux.c | 4 ++++
 1 file changed, 4 insertions(+)
grub-core/loader/powerpc/ieee1275/linux.c +4 -0
index 3d6a61e..7f85eab 100644
@@ -335,6 +335,10 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
   grub_addr_t addr;
   struct grub_linux_initrd_context initrd_ctx;
 
+  // initialize, otherwise the fail path will try to 
+  // free up data and segfault
+  initrd_ctx.components = NULL; 
+
   if (argc == 0)
     {
       grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
Signature · 1 line
1.8.5.3
author
#68 lore raw

RFC PATCH 23/23 Optional: Power7 VSX instructions workaround.

In reply to Ram Pai

Power7 cannot handle VSX instructions correctly. It segfaults. This patch is applicable only for power7 systems.

---
 grub-core/fs/fshelp.c   | 10 ++++++++++
 grub-core/kern/term.c   | 11 +++++++++++
 grub-core/normal/term.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)
grub-core/fs/fshelp.c +10 -0
index 42bd542..bd610df 100644
@@ -207,12 +207,22 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
 		       read_symlink_func read_symlink,
 		       enum grub_fshelp_filetype expecttype)
 {
+#ifdef __powerpc64le__
+   // workaround for a problem on power7 in LE.
+  struct grub_fshelp_find_file_ctx ctx;
+    ctx.path = path;
+    ctx.rootnode = rootnode;
+    ctx.foundtype = GRUB_FSHELP_DIR;
+    ctx.symlinknest = 0;
+#else 
   struct grub_fshelp_find_file_ctx ctx = {
     .path = path,
     .rootnode = rootnode,
     .foundtype = GRUB_FSHELP_DIR,
     .symlinknest = 0
   };
+#endif 
+
   grub_err_t err;
 
   if (!path || path[0] != '/')
grub-core/kern/term.c +11 -0
index 07720ee..4ff3886 100644
@@ -40,6 +40,16 @@ static void
 grub_putcode_dumb (grub_uint32_t code,
 		   struct grub_term_output *term)
 {
+#ifdef __powerpc64le__
+  // this hack is needed for powerpc64le on power7 cpu only
+  // segfaults on VSX instructions generated by the compiler
+  struct grub_unicode_glyph c;
+      c.base = code;
+      c.variant = 0;
+      c.attributes = 0;
+      c.ncomb = 0;
+      c.estimated_width = 1;
+#else
   struct grub_unicode_glyph c =
     {
       .base = code,
@@ -48,6 +58,7 @@ grub_putcode_dumb (grub_uint32_t code,
       .ncomb = 0,
       .estimated_width = 1
     };
+#endif
 
   if (code == '\t' && term->getxy)
     {
grub-core/normal/term.c +42 -0

102 lines not on this page · raw message

Signature · 1 line
1.8.5.3