All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Serbinenko <phcoder@gmail.com>
To: grub-devel@gnu.org
Cc: Vladimir Serbinenko <phcoder@gmail.com>
Subject: [PATCH v11 10/14] Enable (u)divdi3 and (u)moddi3 for mips
Date: Tue, 15 Apr 2025 10:35:44 +0000	[thread overview]
Message-ID: <20250415103710.116109-11-phcoder@gmail.com> (raw)
In-Reply-To: <20250415103710.116109-1-phcoder@gmail.com>

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 <phcoder@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

  parent reply	other threads:[~2025-04-15 10:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-15 10:35 [PATCH v11 00/14] Upgrade libgcrypt to 1.11 Vladimir Serbinenko
2025-04-15 10:35 ` [PATCH v11 01/14] Import libgcrypt 1.11 Vladimir Serbinenko
2025-04-15 10:35 ` [PATCH v11 02/14] Import b64dec from gpg-error Vladimir Serbinenko
2025-04-15 10:35 ` [PATCH v11 03/14] b64dec: Adjust for compilation in GRUB environment Vladimir Serbinenko
2025-04-15 10:35 ` [PATCH v11 04/14] Adjust import script, definitions and API users for libgcrypt 1.11 Vladimir Serbinenko
2025-04-15 10:35 ` [PATCH v11 05/14] Add DSA and RSA SEXP tests Vladimir Serbinenko
2025-04-15 10:35 ` [PATCH v11 06/14] keccak: Disable acceleration with SSE asm Vladimir Serbinenko
2025-04-15 10:35 ` [PATCH v11 07/14] libgcrypt: Fix coverity warnings Vladimir Serbinenko
2025-04-15 10:35 ` [PATCH v11 08/14] Remove now unneeded gcrypt compilation flag Vladimir Serbinenko
2025-04-15 10:35 ` [PATCH v11 09/14] Implement __aeabi_uldivmod Vladimir Serbinenko
2025-04-15 10:35 ` Vladimir Serbinenko [this message]
2025-04-15 10:35 ` [PATCH v11 11/14] gcry: Ignore sign-compare warnings Vladimir Serbinenko
2025-04-15 10:35 ` [PATCH v11 12/14] libgcrypt: Import blake family of hashes Vladimir Serbinenko
2025-04-15 10:35 ` [PATCH v11 13/14] import_gcry: Make compatible with python 3.4 Vladimir Serbinenko
2025-04-15 10:35 ` [PATCH v11 14/14] import_gcry: Fix pylint warnings Vladimir Serbinenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250415103710.116109-11-phcoder@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.