dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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