Skip to contentSkip to conversation

riscv64: Support riscv_align relocations

PATCH New Vladimir Serbinenko 1 participant 8 messages Sep 11, 2024 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/8 riscv64: Support riscv_align relocations

They are purely for optimization, so no need to do anything.

---
 grub-core/kern/riscv/dl.c | 1 +
 util/grub-mkimagexx.c     | 2 ++
 2 files changed, 3 insertions(+)
grub-core/kern/riscv/dl.c +1 -0
index 896653bb4..c47db6959 100644
@@ -329,6 +329,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
 	  break;
 
 	case R_RISCV_RELAX:
+	case R_RISCV_ALIGN:
 	  break;
 	default:
 	  {
util/grub-mkimagexx.c +2 -0
index e50b29533..f9158edda 100644
@@ -1477,6 +1477,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd,
 		     }
 		     break;
 		   case R_RISCV_RELAX:
+		   case R_RISCV_ALIGN:
 		     break;
 		   default:
 		     grub_util_error (_("relocation 0x%x is not implemented yet"),
@@ -1891,6 +1892,7 @@ translate_relocation_pe (struct translate_context *ctx,
 	  }
 	  break;
 	case R_RISCV_RELAX:
+	case R_RISCV_ALIGN:
 	  break;
 	default:
 	  grub_util_error (_("relocation 0x%x is not implemented yet"),
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw

PATCH 2/8 compiler-rt: Add __multi3

It's necessary for clang sparc64 support

---
 grub-core/kern/compiler-rt.c | 58 ++++++++++++++++++++++++++++++++++++
 include/grub/compiler-rt.h   |  7 +++++
 2 files changed, 65 insertions(+)
grub-core/kern/compiler-rt.c +58 -0
index eda689a0c..2902ed03d 100644
@@ -452,3 +452,61 @@ __clzdi2 (grub_uint64_t val)
     }
 }
 #endif
+
+#if defined(__sparc__) && defined(__clang__)
+/* Copied from multi3.c which is under MIT license.  */
+typedef          long long di_int;
+typedef unsigned long long du_int;
+
+typedef union
+{
+    grub_clang_ti_int all;
+    struct
+    {
+#ifndef GRUB_CPU_WORDS_BIGENDIAN
+        du_int low;
+        di_int high;
+#else
+        di_int high;
+        du_int low;
+#endif /* _YUGA_LITTLE_ENDIAN */
+    }s;
+} twords;
+
+static
+grub_clang_ti_int
+__mulddi3(du_int a, du_int b)
+{
+    twords r;
+    const int bits_in_dword_2 = (int)(sizeof(di_int) * 8) / 2;
+    const du_int lower_mask = (du_int)~0 >> bits_in_dword_2;
+    r.s.low = (a & lower_mask) * (b & lower_mask);
+    du_int t = r.s.low >> bits_in_dword_2;
+    r.s.low &= lower_mask;
+    t += (a >> bits_in_dword_2) * (b & lower_mask);
+    r.s.low += (t & lower_mask) << bits_in_dword_2;
+    r.s.high = t >> bits_in_dword_2;
+    t = r.s.low >> bits_in_dword_2;
+    r.s.low &= lower_mask;
+    t += (b >> bits_in_dword_2) * (a & lower_mask);
+    r.s.low += (t & lower_mask) << bits_in_dword_2;
+    r.s.high += t >> bits_in_dword_2;
+    r.s.high += (a >> bits_in_dword_2) * (b >> bits_in_dword_2);
+    return r.all;
+}
+
+/* Returns: a * b */
+
+grub_clang_ti_int
+__multi3(grub_clang_ti_int a, grub_clang_ti_int b)
+{
+    twords x;
+    x.all = a;
+    twords y;
+    y.all = b;
+    twords r;
+    r.all = __mulddi3(x.s.low, y.s.low);
+    r.s.high += x.s.high * y.s.low + x.s.low * y.s.high;
+    return r.all;
+}
+#endif
include/grub/compiler-rt.h +7 -0
index 17828b322..3637db47e 100644
@@ -209,5 +209,12 @@ void EXPORT_FUNC (___chkstk_ms) (void);
 void EXPORT_FUNC (__chkstk_ms) (void);
 #endif
 
+#if defined(__sparc__) && defined(__clang__)
+/* Copied from multi3.c which is under MIT license.  */
+typedef int      grub_clang_ti_int __attribute__ ((mode (TI)));
+
+grub_clang_ti_int EXPORT_FUNC(__multi3) (grub_clang_ti_int a, grub_clang_ti_int b);
+#endif
+
 #endif
 
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#2 lore raw

PATCH 3/8 Support clang integrated-as sparc64

In reply to Vladimir Serbinenko
---
 asm-tests/sparc64.S                        | 2 +-
 grub-core/boot/sparc64/ieee1275/boot.S     | 3 +++
 grub-core/boot/sparc64/ieee1275/diskboot.S | 3 +++
 grub-core/kern/sparc64/ieee1275/crt0.S     | 2 +-
 4 files changed, 8 insertions(+), 2 deletions(-)
asm-tests/sparc64.S +1 -1
index 03c5fe02a..56bd9cda8 100644
@@ -3,7 +3,7 @@
 	/* A small list of examples of what clang doesn't support.  */
 	clr	%o0
 	lduw	[%o4 + 4], %o4
-	and     %o6, ~0xff, %o6
+	and     %o6, 0xffffffffffffff00, %o6
 	stw	%o5, [%o3]
 	bne,pt	%icc, 1b
 	 nop
grub-core/boot/sparc64/ieee1275/boot.S +3 -0
index ff8a79d3b..9a67bc609 100644
@@ -93,7 +93,10 @@ prom_exit_name:		.asciz "exit"
 grub_name:		.asciz "GRUB "
 #ifdef CDBOOT
 prom_close_name:	.asciz "close"
+			.byte 0
+			.byte 0
 #endif
+			.byte 0
 
 #define GRUB_NAME_LEN	5
 
grub-core/boot/sparc64/ieee1275/diskboot.S +3 -0
index 35e02c1b6..0c8deb11f 100644
@@ -43,6 +43,9 @@ notification_step:		.asciz "."
 notification_done:		.asciz "\r\n"
 #define NOTIFICATION_DONE_LEN	2
 
+	.byte 0
+	.byte 0
+
 	.align	4
 
 	/* %o2: message string
grub-core/kern/sparc64/ieee1275/crt0.S +1 -1
index 03b916f05..92bac2142 100644
@@ -56,7 +56,7 @@ codestart:
 	sethi	%hi(GRUB_KERNEL_MACHINE_STACK_SIZE), %o5
 	or	%o5, %lo(GRUB_KERNEL_MACHINE_STACK_SIZE), %o5
 	add     %o3, %o5, %o6
-	and     %o6, ~0xff, %o6
+	and     %o6, 0xffffffffffffff00, %o6
 	sub     %o6, 2047, %o6
 	
 	sub	%o2, 4, %o2
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#3 lore raw

PATCH 4/8 powerpc-ieee1275: Fix warnings and alignment

In reply to Vladimir Serbinenko
---
 grub-core/kern/ieee1275/init.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
grub-core/kern/ieee1275/init.c +10 -9
index dfbd0b899..e3abd51a8 100644
@@ -789,7 +789,10 @@ grub_ieee1275_ibm_cas (void)
 {
   int rc;
   grub_ieee1275_ihandle_t root;
-  grub_uint8_t ibm_arch_platform_support[8];
+  union {
+    grub_uint8_t u8[8];
+    grub_uint32_t u32[2];
+  } ibm_arch_platform_support;
   grub_ssize_t actual;
   grub_uint8_t xive_support = 0;
   grub_uint8_t mmu_support = 0;
@@ -807,23 +810,23 @@ grub_ieee1275_ibm_cas (void)
 
   grub_ieee1275_get_integer_property (grub_ieee1275_chosen,
                                       "ibm,arch-vec-5-platform-support",
-                                      (grub_uint32_t *) ibm_arch_platform_support,
+                                      ibm_arch_platform_support.u32,
                                       sizeof (ibm_arch_platform_support),
                                       &actual);
 
-  for (i = 0; i < prop_len; i++)
+  for (i = 0; i < prop_len; i += 2)
     {
-      switch (ibm_arch_platform_support[i])
+      switch (ibm_arch_platform_support.u8[i])
         {
           case XIVE_INDEX:
-            if (ibm_arch_platform_support[i + 1] & MAX_SUPPORTED)
+            if (ibm_arch_platform_support.u8[i + 1] & MAX_SUPPORTED)
               xive_support = XIVE_ENABLED;
             else
               xive_support = 0;
             break;
 
           case MMU_INDEX:
-            if (ibm_arch_platform_support[i + 1] & MAX_SUPPORTED)
+            if (ibm_arch_platform_support.u8[i + 1] & MAX_SUPPORTED)
               mmu_support = RADIX_ENABLED;
             else
               mmu_support = HASH_ENABLED;
@@ -831,7 +834,7 @@ grub_ieee1275_ibm_cas (void)
 
           case RADIX_GTSE_INDEX:
             if (mmu_support == RADIX_ENABLED)
-              radix_gtse_support = ibm_arch_platform_support[i + 1] & RADIX_GTSE_ENABLED;
+              radix_gtse_support = ibm_arch_platform_support.u8[i + 1] & RADIX_GTSE_ENABLED;
             else
               radix_gtse_support = 0;
             break;
@@ -840,8 +843,6 @@ grub_ieee1275_ibm_cas (void)
             /* Ignoring the other indexes of ibm,arch-vec-5-platform-support. */
             break;
         }
-      /* Skipping the property value. */
-      i++;
     }
 
   struct cas_vector vector =
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#4 lore raw

PATCH 5/8 efi/linux: Silence warning

In reply to Vladimir Serbinenko
---
 grub-core/loader/efi/linux.c | 1 +
 1 file changed, 1 insertion(+)
grub-core/loader/efi/linux.c +1 -0
index bfbd95aee..bcb39c40a 100644
@@ -55,6 +55,7 @@ static bool initrd_use_loadfile2 = false;
 static grub_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID;
 static grub_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
 
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
 static initrd_media_device_path_t initrd_lf2_device_path = {
   {
     {
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#5 lore raw

PATCH 6/8 btrfs: Add an explicit GRUB_PACKED

In reply to Vladimir Serbinenko

Otherwise clang on arm complains

---
 grub-core/fs/btrfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/fs/btrfs.c +1 -1
index ba0c58352..0b06bc824 100644
@@ -222,7 +222,7 @@ struct grub_btrfs_extent_data
       grub_uint64_t compressed_size;
       grub_uint64_t offset;
       grub_uint64_t filled;
-    };
+    } GRUB_PACKED;
   };
 } GRUB_PACKED;
 
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#6 lore raw

PATCH 7/8 Enable __clzsi2/__clzdi2 on arm

In reply to Vladimir Serbinenko

It's emitted by clang

---
 grub-core/kern/compiler-rt.c | 4 +---
 include/grub/compiler-rt.h   | 5 +----
 2 files changed, 2 insertions(+), 7 deletions(-)
grub-core/kern/compiler-rt.c +1 -3
index 2902ed03d..17ae435c1 100644
@@ -410,7 +410,7 @@ __aeabi_llsl (grub_uint64_t u, int b)
 
 #endif
 
-#if defined(__mips__) || defined(__riscv) || defined(__sparc__)
+#if defined(__mips__) || defined(__riscv) || defined(__sparc__) || defined(__arm__)
 /* Based on libgcc from gcc suite. */
 int
 __clzsi2 (grub_uint32_t val)
@@ -436,9 +436,7 @@ __clzsi2 (grub_uint32_t val)
     }
   return (i - val);
 }
-#endif
 
-#if defined(__mips__) || defined(__riscv) || defined(__sparc__)
 int
 __clzdi2 (grub_uint64_t val)
 {
include/grub/compiler-rt.h +1 -4
index 3637db47e..26016088e 100644
@@ -110,12 +110,9 @@ EXPORT_FUNC (__aeabi_llsr) (grub_uint64_t u, int b);
 
 #endif
 
-#if defined(__mips__) || defined(__riscv) || defined(__sparc__)
+#if defined(__mips__) || defined(__riscv) || defined(__sparc__) || defined(__arm__)
 int
 EXPORT_FUNC (__clzsi2) (grub_uint32_t val);
-#endif
-
-#if defined(__mips__) || defined(__riscv) || defined(__sparc__)
 int
 EXPORT_FUNC (__clzdi2) (grub_uint64_t val);
 #endif
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#7 lore raw

PATCH 8/8 configure: Try -msoft-float -mfloat-abi=soft on arm

In reply to Vladimir Serbinenko
---
 configure.ac | 5 +++++
 1 file changed, 5 insertions(+)
configure.ac +5 -0
index d4a14bf93..2bca8814b 100644
@@ -941,6 +941,11 @@ if test x"$platform" != xemu ; then
        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
 		         [grub_cv_target_cc_soft_float="-m4-nofpu"], [])
     fi
+    if test "x$target_cpu" = xarm; then
+       CFLAGS="$TARGET_CFLAGS -msoft-float -mfloat-abi=soft -Werror"
+       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+		         [grub_cv_target_cc_soft_float="-msoft-float -mfloat-abi=soft"], [])
+    fi
     for cand in "-msoft-float -Xclang -msoft-float -Xclang -no-implicit-float" \
 		"-Xclang -msoft-float -Xclang -no-implicit-float" \
 		"-Xclang -msoft-float" "-msoft-float"; do
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel