Some mips compilers insert 64-bit division into the
code compiled from libgcrypt source and possibly others.
Rather than fighting it, simply provide the functions in
question.

Signed-off-by: Vladimir Serbinenko <phco...@gmail.com>
---
 gentpl.py                    | 2 +-
 grub-core/kern/compiler-rt.c | 6 +++++-
 grub-core/kern/misc.c        | 2 +-
 include/grub/compiler-rt.h   | 6 +++++-
 include/grub/misc.h          | 2 +-
 5 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/gentpl.py b/gentpl.py
index d8c6965d8..ed1287f34 100644
--- a/gentpl.py
+++ b/gentpl.py
@@ -84,7 +84,7 @@ GROUPS["fdt"] = [ "arm64_efi", "arm_uboot", "arm_efi", 
"loongarch64_efi", "riscv
 
 # Needs software helpers for division
 # Must match GRUB_DIVISION_IN_SOFTWARE in misc.h
-GROUPS["softdiv"] = GROUPS["arm"] + ["ia64_efi"] + GROUPS["riscv32"]
+GROUPS["softdiv"] = GROUPS["arm"] + ["ia64_efi"] + GROUPS["riscv32"] + 
GROUPS["mips"]
 GROUPS["no_softdiv"]   = GRUB_PLATFORMS[:]
 for i in GROUPS["softdiv"]: GROUPS["no_softdiv"].remove(i)
 
diff --git a/grub-core/kern/compiler-rt.c b/grub-core/kern/compiler-rt.c
index eda689a0c..a7caec999 100644
--- a/grub-core/kern/compiler-rt.c
+++ b/grub-core/kern/compiler-rt.c
@@ -52,7 +52,7 @@ __bzero (void *s, grub_size_t n)
 
 #endif
 
-#if GRUB_DIVISION_IN_SOFTWARE
+#if GRUB_DIVISION_IN_SOFTWARE && !defined(__mips__)
 
 grub_uint32_t
 __udivsi3 (grub_uint32_t a, grub_uint32_t b)
@@ -82,6 +82,10 @@ __modsi3 (grub_int32_t a, grub_int32_t b)
   return ret;
 }
 
+#endif
+
+#if GRUB_DIVISION_IN_SOFTWARE
+
 grub_uint64_t
 __udivdi3 (grub_uint64_t a, grub_uint64_t b)
 {
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index 2b7922393..26d36929a 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -627,7 +627,7 @@ grub_divmod64 (grub_uint64_t n, grub_uint64_t d, 
grub_uint64_t *r)
      Using that code would just make us use software division routines, calling
      ourselves indirectly and hence getting infinite recursion.
   */
-#if !GRUB_DIVISION_IN_SOFTWARE
+#if !GRUB_DIVISION_IN_SOFTWARE || defined(__mips__)
   /* Skip the slow computation if 32-bit arithmetic is possible.  */
   if (n < 0xffffffff && d < 0xffffffff)
     {
diff --git a/include/grub/compiler-rt.h b/include/grub/compiler-rt.h
index 43fd8f4d7..1ee2927be 100644
--- a/include/grub/compiler-rt.h
+++ b/include/grub/compiler-rt.h
@@ -25,7 +25,7 @@
 #include <grub/symbol.h>
 #include <grub/misc.h>
 
-#if defined(GRUB_DIVISION_IN_SOFTWARE) && GRUB_DIVISION_IN_SOFTWARE
+#if defined(GRUB_DIVISION_IN_SOFTWARE) && GRUB_DIVISION_IN_SOFTWARE && 
!defined(__mips__)
 
 grub_uint32_t
 EXPORT_FUNC (__udivsi3) (grub_uint32_t a, grub_uint32_t b);
@@ -39,6 +39,10 @@ EXPORT_FUNC (__divsi3) (grub_int32_t a, grub_int32_t b);
 grub_int32_t
 EXPORT_FUNC (__modsi3) (grub_int32_t a, grub_int32_t b);
 
+#endif
+
+#if (defined(GRUB_DIVISION_IN_SOFTWARE) && GRUB_DIVISION_IN_SOFTWARE)
+
 grub_int64_t
 EXPORT_FUNC (__divdi3) (grub_int64_t a, grub_int64_t b);
 
diff --git a/include/grub/misc.h b/include/grub/misc.h
index e087e7b3e..c8f192224 100644
--- a/include/grub/misc.h
+++ b/include/grub/misc.h
@@ -436,7 +436,7 @@ extern void EXPORT_FUNC(grub_cli_set_auth_needed) (void);
 
 /* Must match softdiv group in gentpl.py.  */
 #if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__ia64__) || \
-    (defined(__riscv) && (__riscv_xlen == 32)))
+    (defined(__riscv) && (__riscv_xlen == 32))) || defined(__mips__)
 #define GRUB_DIVISION_IN_SOFTWARE 1
 #else
 #define GRUB_DIVISION_IN_SOFTWARE 0
-- 
2.49.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to