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

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