nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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