Blame SOURCES/0142-Files-reorganization-and-include-some-libgcc-fuction.patch

d41074
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
a85e8e
From: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
a85e8e
Date: Wed, 13 Aug 2014 19:00:19 +0000
d41074
Subject: [PATCH] Files reorganization and include some libgcc fuctions
a85e8e
a85e8e
As we avoid libgcc dependency for powerpc64el, we moved some functions
a85e8e
to other files and add the necessary ones.
a85e8e
a85e8e
* Makefile.core.def: Include compiler-rt.S.
a85e8e
* misc.c: Add the necessary libgcc functions.
a85e8e
* compiler-rt.S: New file.
a85e8e
* libgcc.h: Move some content from here ...
a85e8e
* compiler.h: ... to here.
a85e8e
a85e8e
Also-By: Brent Baude <bbaude@redhat.com>
a85e8e
Also-By: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
a85e8e
---
a85e8e
 grub-core/Makefile.core.def          |   1 +
a85e8e
 grub-core/kern/misc.c                | 107 ++++++++++++++++++++++++++++
a85e8e
 include/grub/compiler.h              |  61 ++++++++++++++++
a85e8e
 include/grub/libgcc.h                |  67 ------------------
d41074
 grub-core/kern/powerpc/compiler-rt.S | 130 +++++++++++++++++++++++++++++++++++
a85e8e
 5 files changed, 299 insertions(+), 67 deletions(-)
a85e8e
 create mode 100644 grub-core/kern/powerpc/compiler-rt.S
a85e8e
a85e8e
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
d41074
index 7bf1c8a5880..9ff9ae5a311 100644
a85e8e
--- a/grub-core/Makefile.core.def
a85e8e
+++ b/grub-core/Makefile.core.def
a85e8e
@@ -252,6 +252,7 @@ kernel = {
a85e8e
 
a85e8e
   powerpc_ieee1275 = kern/powerpc/cache.S;
a85e8e
   powerpc_ieee1275 = kern/powerpc/dl.c;
a85e8e
+  powerpc_ieee1275 = kern/powerpc/compiler-rt.S;
a85e8e
 
a85e8e
   sparc64_ieee1275 = kern/sparc64/cache.S;
a85e8e
   sparc64_ieee1275 = kern/sparc64/dl.c;
a85e8e
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
d41074
index a56cfe78994..a3e5056db3f 100644
a85e8e
--- a/grub-core/kern/misc.c
a85e8e
+++ b/grub-core/kern/misc.c
a85e8e
@@ -1345,3 +1345,110 @@ grub_real_boot_time (const char *file,
a85e8e
   grub_error_pop ();
a85e8e
 }
a85e8e
 #endif
a85e8e
+
a85e8e
+#if defined (NO_LIBGCC)
a85e8e
+
a85e8e
+/* Based on libgcc2.c from gcc suite.  */
a85e8e
+int
a85e8e
+__ucmpdi2 (grub_uint64_t a, grub_uint64_t b)
a85e8e
+{
a85e8e
+  union component64 ac, bc;
a85e8e
+  ac.full = a;
a85e8e
+  bc.full = b;
a85e8e
+
a85e8e
+  if (ac.high < bc.high)
a85e8e
+    return 0;
a85e8e
+  else if (ac.high > bc.high)
a85e8e
+    return 2;
a85e8e
+
a85e8e
+  if (ac.low < bc.low)
a85e8e
+    return 0;
a85e8e
+  else if (ac.low > bc.low)
a85e8e
+    return 2;
a85e8e
+  return 1;
a85e8e
+}
a85e8e
+
a85e8e
+
a85e8e
+/* Based on libgcc2.c from gcc suite.  */
a85e8e
+grub_uint64_t
a85e8e
+__lshrdi3 (grub_uint64_t u, int b)
a85e8e
+{
a85e8e
+  if (b == 0)
a85e8e
+    return u;
a85e8e
+
a85e8e
+  const union component64 uu = {.full = u};
a85e8e
+  const int bm = 32 - b;
a85e8e
+  union component64 w;
a85e8e
+
a85e8e
+  if (bm <= 0)
a85e8e
+    {
a85e8e
+      w.high = 0;
a85e8e
+      w.low = (grub_uint32_t) uu.high >> -bm;
a85e8e
+    }
a85e8e
+  else
a85e8e
+    {
a85e8e
+      const grub_uint32_t carries = (grub_uint32_t) uu.high << bm;
a85e8e
+
a85e8e
+      w.high = (grub_uint32_t) uu.high >> b;
a85e8e
+      w.low = ((grub_uint32_t) uu.low >> b) | carries;
a85e8e
+    }
a85e8e
+
a85e8e
+  return w.full;
a85e8e
+}
a85e8e
+
a85e8e
+/* Based on libgcc2.c from gcc suite.  */
a85e8e
+grub_uint64_t
a85e8e
+__ashrdi3 (grub_uint64_t u, int b)
a85e8e
+{
a85e8e
+  if (b == 0)
a85e8e
+    return u;
a85e8e
+
a85e8e
+  const union component64 uu = {.full = u};
a85e8e
+  const int bm = 32 - b;
a85e8e
+  union component64 w;
a85e8e
+
a85e8e
+  if (bm <= 0)
a85e8e
+    {
a85e8e
+      /* w.high = 1..1 or 0..0 */
a85e8e
+      w.high = uu.high >> (32 - 1);
a85e8e
+      w.low = uu.high >> -bm;
a85e8e
+    }
a85e8e
+  else
a85e8e
+    {
a85e8e
+      const grub_uint32_t carries = (grub_uint32_t) uu.high << bm;
a85e8e
+
a85e8e
+      w.high = uu.high >> b;
a85e8e
+      w.low = ((grub_uint32_t) uu.low >> b) | carries;
a85e8e
+    }
a85e8e
+
a85e8e
+  return w.full;
a85e8e
+}
a85e8e
+
a85e8e
+/* Based on libgcc2.c from gcc suite.  */
a85e8e
+grub_uint64_t
a85e8e
+__ashldi3 (grub_uint64_t u, int b)
a85e8e
+{
a85e8e
+  if (b == 0)
a85e8e
+    return u;
a85e8e
+
a85e8e
+  const union component64 uu = {.full = u};
a85e8e
+  const int bm = 32 - b;
a85e8e
+  union component64 w;
a85e8e
+
a85e8e
+  if (bm <= 0)
a85e8e
+    {
a85e8e
+      w.low = 0;
a85e8e
+      w.high = (grub_uint32_t) uu.low << -bm;
a85e8e
+    }
a85e8e
+  else
a85e8e
+    {
a85e8e
+      const grub_uint32_t carries = (grub_uint32_t) uu.low >> bm;
a85e8e
+
a85e8e
+      w.low = (grub_uint32_t) uu.low << b;
a85e8e
+      w.high = ((grub_uint32_t) uu.high << b) | carries;
a85e8e
+    }
a85e8e
+
a85e8e
+  return w.full;
a85e8e
+}
a85e8e
+
a85e8e
+#endif
a85e8e
diff --git a/include/grub/compiler.h b/include/grub/compiler.h
d41074
index c9e1d7a73dc..a9a684ccba6 100644
a85e8e
--- a/include/grub/compiler.h
a85e8e
+++ b/include/grub/compiler.h
a85e8e
@@ -48,4 +48,65 @@
a85e8e
 #  define WARN_UNUSED_RESULT
a85e8e
 #endif
a85e8e
 
a85e8e
+#include "types.h"
a85e8e
+
a85e8e
+union component64
a85e8e
+{
a85e8e
+  grub_uint64_t full;
a85e8e
+  struct
a85e8e
+  {
a85e8e
+#ifdef GRUB_CPU_WORDS_BIGENDIAN
a85e8e
+    grub_uint32_t high;
a85e8e
+    grub_uint32_t low;
a85e8e
+#else
a85e8e
+    grub_uint32_t low;
a85e8e
+    grub_uint32_t high;
a85e8e
+#endif
a85e8e
+  };
a85e8e
+};
a85e8e
+
a85e8e
+#if defined (__powerpc__)
a85e8e
+grub_uint64_t EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b);
a85e8e
+grub_uint64_t EXPORT_FUNC (__ashrdi3) (grub_uint64_t u, int b);
a85e8e
+grub_uint64_t EXPORT_FUNC (__ashldi3) (grub_uint64_t u, int b);
a85e8e
+int EXPORT_FUNC(__ucmpdi2) (grub_uint64_t a, grub_uint64_t b);
a85e8e
+void EXPORT_FUNC (_restgpr_14_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_15_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_16_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_17_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_18_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_19_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_20_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_21_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_22_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_23_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_24_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_25_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_26_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_27_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_28_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_29_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_30_x) (void);
a85e8e
+void EXPORT_FUNC (_restgpr_31_x) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_14) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_15) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_16) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_17) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_18) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_19) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_20) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_21) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_22) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_23) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_24) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_25) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_26) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_27) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_28) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_29) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_30) (void);
a85e8e
+void EXPORT_FUNC (_savegpr_31) (void);
a85e8e
+
a85e8e
+#endif
a85e8e
+
a85e8e
 #endif /* ! GRUB_COMPILER_HEADER */
a85e8e
diff --git a/include/grub/libgcc.h b/include/grub/libgcc.h
d41074
index 8e93b6792d9..5bdb8fb5cb9 100644
a85e8e
--- a/include/grub/libgcc.h
a85e8e
+++ b/include/grub/libgcc.h
a85e8e
@@ -16,73 +16,6 @@
a85e8e
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
a85e8e
  */
a85e8e
 
a85e8e
-/* We need to include config-util.h.in for HAVE_*.  */
a85e8e
-#ifndef __STDC_VERSION__
a85e8e
-#define __STDC_VERSION__ 0
a85e8e
-#endif
a85e8e
-#include <config-util.h>
a85e8e
-
a85e8e
-/* On x86 these functions aren't really needed. Save some space.  */
a85e8e
-#if !defined (__i386__) && !defined (__x86_64__)
a85e8e
-# ifdef HAVE___ASHLDI3
a85e8e
-void EXPORT_FUNC (__ashldi3) (void);
a85e8e
-# endif
a85e8e
-# ifdef HAVE___ASHRDI3
a85e8e
-void EXPORT_FUNC (__ashrdi3) (void);
a85e8e
-# endif
a85e8e
-# ifdef HAVE___LSHRDI3
a85e8e
-void EXPORT_FUNC (__lshrdi3) (void);
a85e8e
-# endif
a85e8e
-# ifdef HAVE___UCMPDI2
a85e8e
-void EXPORT_FUNC (__ucmpdi2) (void);
a85e8e
-# endif
a85e8e
-# ifdef HAVE___BSWAPSI2
a85e8e
-void EXPORT_FUNC (__bswapsi2) (void);
a85e8e
-# endif
a85e8e
-# ifdef HAVE___BSWAPDI2
a85e8e
-void EXPORT_FUNC (__bswapdi2) (void);
a85e8e
-# endif
a85e8e
-#endif
a85e8e
-
a85e8e
-#ifdef HAVE__RESTGPR_14_X
a85e8e
-void EXPORT_FUNC (_restgpr_14_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_15_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_16_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_17_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_18_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_19_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_20_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_21_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_22_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_23_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_24_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_25_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_26_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_27_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_28_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_29_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_30_x) (void);
a85e8e
-void EXPORT_FUNC (_restgpr_31_x) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_14) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_15) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_16) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_17) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_18) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_19) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_20) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_21) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_22) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_23) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_24) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_25) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_26) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_27) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_28) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_29) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_30) (void);
a85e8e
-void EXPORT_FUNC (_savegpr_31) (void);
a85e8e
-#endif
a85e8e
-
a85e8e
 #if defined (__arm__)
a85e8e
 void EXPORT_FUNC (__aeabi_lasr) (void);
a85e8e
 void EXPORT_FUNC (__aeabi_llsl) (void);
d41074
diff --git a/grub-core/kern/powerpc/compiler-rt.S b/grub-core/kern/powerpc/compiler-rt.S
d41074
new file mode 100644
d41074
index 00000000000..63e3a0d4e89
d41074
--- /dev/null
d41074
+++ b/grub-core/kern/powerpc/compiler-rt.S
d41074
@@ -0,0 +1,130 @@
d41074
+/*
d41074
+ * Special support for eabi and SVR4
d41074
+ *
d41074
+ *   Copyright (C) 1995-2014 Free Software Foundation, Inc.
d41074
+ *   Written By Michael Meissner
d41074
+ *   64-bit support written by David Edelsohn
d41074
+ *
d41074
+ * This file is free software; you can redistribute it and/or modify it
d41074
+ * under the terms of the GNU General Public License as published by the
d41074
+ * Free Software Foundation; either version 3, or (at your option) any
d41074
+ * later version.
d41074
+ *
d41074
+ * This file is distributed in the hope that it will be useful, but
d41074
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
d41074
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
d41074
+ * General Public License for more details.
d41074
+ *
d41074
+ * Under Section 7 of GPL version 3, you are granted additional
d41074
+ * permissions described in the GCC Runtime Library Exception, version
d41074
+ * 3.1, as published by the Free Software Foundation.
d41074
+ *
d41074
+ * You should have received a copy of the GNU General Public License and
d41074
+ * a copy of the GCC Runtime Library Exception along with this program;
d41074
+ * see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
d41074
+ * <http://www.gnu.org/licenses/>.
d41074
+ */
d41074
+
d41074
+/* Do any initializations needed for the eabi environment */
d41074
+
d41074
+#include <grub/symbol.h>
d41074
+#include <grub/dl.h>
d41074
+
d41074
+	.section ".text"
d41074
+
d41074
+#define CFI_RESTORE(reg)		.cfi_restore reg
d41074
+#define CFI_OFFSET(reg, off)		.cfi_offset reg, off
d41074
+#define CFI_DEF_CFA_REGISTER(reg)	.cfi_def_cfa_register reg
d41074
+#define CFI_STARTPROC			.cfi_startproc
d41074
+#define CFI_ENDPROC			.cfi_endproc
d41074
+
d41074
+/* Routines for restoring integer registers, called by the compiler.  */
d41074
+/* Called with r11 pointing to the stack header word of the caller of the */
d41074
+/* function, just beyond the end of the integer restore area.  */
d41074
+
d41074
+CFI_STARTPROC
d41074
+CFI_DEF_CFA_REGISTER (11)
d41074
+CFI_OFFSET (65, 4)
d41074
+CFI_OFFSET (14, -72)
d41074
+CFI_OFFSET (15, -68)
d41074
+CFI_OFFSET (16, -64)
d41074
+CFI_OFFSET (17, -60)
d41074
+CFI_OFFSET (18, -56)
d41074
+CFI_OFFSET (19, -52)
d41074
+CFI_OFFSET (20, -48)
d41074
+CFI_OFFSET (21, -44)
d41074
+CFI_OFFSET (22, -40)
d41074
+CFI_OFFSET (23, -36)
d41074
+CFI_OFFSET (24, -32)
d41074
+CFI_OFFSET (25, -28)
d41074
+CFI_OFFSET (26, -24)
d41074
+CFI_OFFSET (27, -20)
d41074
+CFI_OFFSET (28, -16)
d41074
+CFI_OFFSET (29, -12)
d41074
+CFI_OFFSET (30, -8)
d41074
+CFI_OFFSET (31, -4)
d41074
+FUNCTION(_restgpr_14_x)	lwz	14,-72(11)	/* restore gp registers */
d41074
+CFI_RESTORE (14)
d41074
+FUNCTION(_restgpr_15_x)	lwz	15,-68(11)
d41074
+CFI_RESTORE (15)
d41074
+FUNCTION(_restgpr_16_x)	lwz	16,-64(11)
d41074
+CFI_RESTORE (16)
d41074
+FUNCTION(_restgpr_17_x)	lwz	17,-60(11)
d41074
+CFI_RESTORE (17)
d41074
+FUNCTION(_restgpr_18_x)	lwz	18,-56(11)
d41074
+CFI_RESTORE (18)
d41074
+FUNCTION(_restgpr_19_x)	lwz	19,-52(11)
d41074
+CFI_RESTORE (19)
d41074
+FUNCTION(_restgpr_20_x)	lwz	20,-48(11)
d41074
+CFI_RESTORE (20)
d41074
+FUNCTION(_restgpr_21_x)	lwz	21,-44(11)
d41074
+CFI_RESTORE (21)
d41074
+FUNCTION(_restgpr_22_x)	lwz	22,-40(11)
d41074
+CFI_RESTORE (22)
d41074
+FUNCTION(_restgpr_23_x)	lwz	23,-36(11)
d41074
+CFI_RESTORE (23)
d41074
+FUNCTION(_restgpr_24_x)	lwz	24,-32(11)
d41074
+CFI_RESTORE (24)
d41074
+FUNCTION(_restgpr_25_x)	lwz	25,-28(11)
d41074
+CFI_RESTORE (25)
d41074
+FUNCTION(_restgpr_26_x)	lwz	26,-24(11)
d41074
+CFI_RESTORE (26)
d41074
+FUNCTION(_restgpr_27_x)	lwz	27,-20(11)
d41074
+CFI_RESTORE (27)
d41074
+FUNCTION(_restgpr_28_x)	lwz	28,-16(11)
d41074
+CFI_RESTORE (28)
d41074
+FUNCTION(_restgpr_29_x)	lwz	29,-12(11)
d41074
+CFI_RESTORE (29)
d41074
+FUNCTION(_restgpr_30_x)	lwz	30,-8(11)
d41074
+CFI_RESTORE (30)
d41074
+FUNCTION(_restgpr_31_x)	lwz	0,4(11)
d41074
+				lwz	31,-4(11)
d41074
+CFI_RESTORE (31)
d41074
+				mtlr	0
d41074
+CFI_RESTORE (65)
d41074
+				mr	1,11
d41074
+CFI_DEF_CFA_REGISTER (1)
d41074
+				blr
d41074
+CFI_ENDPROC
d41074
+
d41074
+CFI_STARTPROC
d41074
+FUNCTION(_savegpr_14)	stw	14,-72(11)	/* save gp registers */
d41074
+FUNCTION(_savegpr_15)	stw	15,-68(11)
d41074
+FUNCTION(_savegpr_16)	stw	16,-64(11)
d41074
+FUNCTION(_savegpr_17)	stw	17,-60(11)
d41074
+FUNCTION(_savegpr_18)	stw	18,-56(11)
d41074
+FUNCTION(_savegpr_19)	stw	19,-52(11)
d41074
+FUNCTION(_savegpr_20)	stw	20,-48(11)
d41074
+FUNCTION(_savegpr_21)	stw	21,-44(11)
d41074
+FUNCTION(_savegpr_22)	stw	22,-40(11)
d41074
+FUNCTION(_savegpr_23)	stw	23,-36(11)
d41074
+FUNCTION(_savegpr_24)	stw	24,-32(11)
d41074
+FUNCTION(_savegpr_25)	stw	25,-28(11)
d41074
+FUNCTION(_savegpr_26)	stw	26,-24(11)
d41074
+FUNCTION(_savegpr_27)	stw	27,-20(11)
d41074
+FUNCTION(_savegpr_28)	stw	28,-16(11)
d41074
+FUNCTION(_savegpr_29)	stw	29,-12(11)
d41074
+FUNCTION(_savegpr_30)	stw	30,-8(11)
d41074
+FUNCTION(_savegpr_31)	stw	31,-4(11)
d41074
+			blr
d41074
+CFI_ENDPROC