RISC-V: Add to build system

This patch adds support for RISC-V to the grub build system. With this
patch, I can successfully build grub on RISC-V as a UEFI application.

Signed-off-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Alexander Graf 2019-02-12 11:31:07 +01:00 committed by Vincent Batts
parent 1edef90cf9
commit 09d8eedbba
22 changed files with 201 additions and 21 deletions

View file

@ -104,6 +104,12 @@ case "$target_cpu" in
aarch64*) aarch64*)
target_cpu=arm64 target_cpu=arm64
;; ;;
riscv32*)
target_cpu=riscv32
;;
riscv64*)
target_cpu=riscv64
;;
esac esac
# Specify the platform (such as firmware). # Specify the platform (such as firmware).
@ -127,6 +133,8 @@ if test "x$with_platform" = x; then
ia64-*) platform=efi ;; ia64-*) platform=efi ;;
arm-*) platform=uboot ;; arm-*) platform=uboot ;;
arm64-*) platform=efi ;; arm64-*) platform=efi ;;
riscv32-*) platform=efi ;;
riscv64-*) platform=efi ;;
*) *)
AC_MSG_WARN([unsupported CPU: "$target_cpu" - only building utilities]) AC_MSG_WARN([unsupported CPU: "$target_cpu" - only building utilities])
platform=none platform=none
@ -175,6 +183,8 @@ case "$target_cpu"-"$platform" in
arm-coreboot) ;; arm-coreboot) ;;
arm-efi) ;; arm-efi) ;;
arm64-efi) ;; arm64-efi) ;;
riscv32-efi) ;;
riscv64-efi) ;;
*-emu) ;; *-emu) ;;
*-none) ;; *-none) ;;
*) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;; *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
@ -828,6 +838,16 @@ if test x"$platform" != xemu ; then
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
[grub_cv_target_cc_soft_float="-mgeneral-regs-only"], []) [grub_cv_target_cc_soft_float="-mgeneral-regs-only"], [])
fi fi
if test "x$target_cpu" = xriscv32; then
CFLAGS="$TARGET_CFLAGS -march=rv32imac -mabi=ilp32 -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
[grub_cv_target_cc_soft_float="-march=rv32imac -mabi=ilp32"], [])
fi
if test "x$target_cpu" = xriscv64; then
CFLAGS="$TARGET_CFLAGS -march=rv64imac -mabi=lp64 -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
[grub_cv_target_cc_soft_float="-march=rv64imac -mabi=lp64"], [])
fi
if test "x$target_cpu" = xia64; then if test "x$target_cpu" = xia64; then
CFLAGS="$TARGET_CFLAGS -mno-inline-float-divide -mno-inline-sqrt -Werror" CFLAGS="$TARGET_CFLAGS -mno-inline-float-divide -mno-inline-sqrt -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
@ -1143,7 +1163,7 @@ AC_SUBST(TARGET_LDFLAGS_OLDMAGIC)
LDFLAGS="$TARGET_LDFLAGS" LDFLAGS="$TARGET_LDFLAGS"
if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; then if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
# Use large model to support 4G memory # Use large model to support 4G memory
AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [ AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
CFLAGS="$TARGET_CFLAGS -mcmodel=large" CFLAGS="$TARGET_CFLAGS -mcmodel=large"
@ -1153,7 +1173,7 @@ if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; then
]) ])
if test "x$grub_cv_cc_mcmodel" = xyes; then if test "x$grub_cv_cc_mcmodel" = xyes; then
TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large" TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
elif test "$target_cpu" = sparc64; then elif test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64; then
TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany" TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
fi fi
fi fi
@ -1916,6 +1936,10 @@ AM_CONDITIONAL([COND_arm_coreboot], [test x$target_cpu = xarm -a x$platform = xc
AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a x$platform = xefi]) AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a x$platform = xefi])
AM_CONDITIONAL([COND_arm64], [test x$target_cpu = xarm64 ]) AM_CONDITIONAL([COND_arm64], [test x$target_cpu = xarm64 ])
AM_CONDITIONAL([COND_arm64_efi], [test x$target_cpu = xarm64 -a x$platform = xefi]) AM_CONDITIONAL([COND_arm64_efi], [test x$target_cpu = xarm64 -a x$platform = xefi])
AM_CONDITIONAL([COND_riscv32], [test x$target_cpu = xriscv32 ])
AM_CONDITIONAL([COND_riscv64], [test x$target_cpu = xriscv64 ])
AM_CONDITIONAL([COND_riscv32_efi], [test x$target_cpu = xriscv32 -a x$platform = xefi])
AM_CONDITIONAL([COND_riscv64_efi], [test x$target_cpu = xriscv64 -a x$platform = xefi])
AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd]) AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd])
AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux]) AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux])

View file

@ -32,7 +32,7 @@ GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
"mips_loongson", "sparc64_ieee1275", "mips_loongson", "sparc64_ieee1275",
"powerpc_ieee1275", "mips_arc", "ia64_efi", "powerpc_ieee1275", "mips_arc", "ia64_efi",
"mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi", "mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi",
"arm_coreboot"] "arm_coreboot", "riscv32_efi", "riscv64_efi" ]
GROUPS = {} GROUPS = {}
@ -47,9 +47,12 @@ GROUPS["sparc64"] = [ "sparc64_ieee1275" ]
GROUPS["powerpc"] = [ "powerpc_ieee1275" ] GROUPS["powerpc"] = [ "powerpc_ieee1275" ]
GROUPS["arm"] = [ "arm_uboot", "arm_efi", "arm_coreboot" ] GROUPS["arm"] = [ "arm_uboot", "arm_efi", "arm_coreboot" ]
GROUPS["arm64"] = [ "arm64_efi" ] GROUPS["arm64"] = [ "arm64_efi" ]
GROUPS["riscv32"] = [ "riscv32_efi" ]
GROUPS["riscv64"] = [ "riscv64_efi" ]
# Groups based on firmware # Groups based on firmware
GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi" ] GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi",
"riscv32_efi", "riscv64_efi" ]
GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ] GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ]
GROUPS["uboot"] = [ "arm_uboot" ] GROUPS["uboot"] = [ "arm_uboot" ]
GROUPS["xen"] = [ "i386_xen", "x86_64_xen" ] GROUPS["xen"] = [ "i386_xen", "x86_64_xen" ]
@ -76,11 +79,11 @@ GROUPS["terminfomodule"] = GRUB_PLATFORMS[:];
for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i) for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i)
# Flattened Device Trees (FDT) # Flattened Device Trees (FDT)
GROUPS["fdt"] = [ "arm64_efi", "arm_uboot", "arm_efi" ] GROUPS["fdt"] = [ "arm64_efi", "arm_uboot", "arm_efi", "riscv32_efi", "riscv64_efi" ]
# Needs software helpers for division # Needs software helpers for division
# Must match GRUB_DIVISION_IN_SOFTWARE in misc.h # Must match GRUB_DIVISION_IN_SOFTWARE in misc.h
GROUPS["softdiv"] = GROUPS["arm"] + ["ia64_efi"] GROUPS["softdiv"] = GROUPS["arm"] + ["ia64_efi"] + GROUPS["riscv32"]
GROUPS["no_softdiv"] = GRUB_PLATFORMS[:] GROUPS["no_softdiv"] = GRUB_PLATFORMS[:]
for i in GROUPS["softdiv"]: GROUPS["no_softdiv"].remove(i) for i in GROUPS["softdiv"]: GROUPS["no_softdiv"].remove(i)

View file

@ -285,6 +285,18 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif endif
if COND_riscv32_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_riscv64_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_emu if COND_emu
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h

View file

@ -65,6 +65,12 @@ kernel = {
arm64_efi_ldflags = '-Wl,-r,-d'; arm64_efi_ldflags = '-Wl,-r,-d';
arm64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame'; arm64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame';
riscv32_efi_ldflags = '-Wl,-r,-d';
riscv32_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame';
riscv64_efi_ldflags = '-Wl,-r,-d';
riscv64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame';
i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x9000'; i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x9000';
i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)'; i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)';
@ -114,6 +120,8 @@ kernel = {
arm_coreboot_startup = kern/arm/startup.S; arm_coreboot_startup = kern/arm/startup.S;
arm_efi_startup = kern/arm/efi/startup.S; arm_efi_startup = kern/arm/efi/startup.S;
arm64_efi_startup = kern/arm64/efi/startup.S; arm64_efi_startup = kern/arm64/efi/startup.S;
riscv32_efi_startup = kern/riscv/efi/startup.S;
riscv64_efi_startup = kern/riscv/efi/startup.S;
common = kern/command.c; common = kern/command.c;
common = kern/corecmd.c; common = kern/corecmd.c;
@ -248,6 +256,12 @@ kernel = {
arm64_efi = kern/arm64/efi/init.c; arm64_efi = kern/arm64/efi/init.c;
arm64_efi = kern/efi/fdt.c; arm64_efi = kern/efi/fdt.c;
riscv32_efi = kern/riscv/efi/init.c;
riscv32_efi = kern/efi/fdt.c;
riscv64_efi = kern/riscv/efi/init.c;
riscv64_efi = kern/efi/fdt.c;
i386_pc = kern/i386/pc/init.c; i386_pc = kern/i386/pc/init.c;
i386_pc = kern/i386/pc/mmap.c; i386_pc = kern/i386/pc/mmap.c;
i386_pc = kern/i386/pc/tpm.c; i386_pc = kern/i386/pc/tpm.c;
@ -320,6 +334,14 @@ kernel = {
arm64 = kern/arm64/dl.c; arm64 = kern/arm64/dl.c;
arm64 = kern/arm64/dl_helper.c; arm64 = kern/arm64/dl_helper.c;
riscv32 = kern/riscv/cache.c;
riscv32 = kern/riscv/cache_flush.S;
riscv32 = kern/riscv/dl.c;
riscv64 = kern/riscv/cache.c;
riscv64 = kern/riscv/cache_flush.S;
riscv64 = kern/riscv/dl.c;
emu = disk/host.c; emu = disk/host.c;
emu = kern/emu/cache_s.S; emu = kern/emu/cache_s.S;
emu = kern/emu/hostdisk.c; emu = kern/emu/hostdisk.c;
@ -795,6 +817,8 @@ module = {
enable = arm64_efi; enable = arm64_efi;
enable = arm_uboot; enable = arm_uboot;
enable = arm_coreboot; enable = arm_coreboot;
enable = riscv32_efi;
enable = riscv64_efi;
}; };
module = { module = {
@ -1703,6 +1727,7 @@ module = {
extra_dist = lib/ia64/longjmp.S; extra_dist = lib/ia64/longjmp.S;
extra_dist = lib/arm/setjmp.S; extra_dist = lib/arm/setjmp.S;
extra_dist = lib/arm64/setjmp.S; extra_dist = lib/arm64/setjmp.S;
extra_dist = lib/riscv/setjmp.S;
}; };
module = { module = {
@ -1804,6 +1829,8 @@ module = {
arm_efi = loader/arm64/linux.c; arm_efi = loader/arm64/linux.c;
arm_uboot = loader/arm/linux.c; arm_uboot = loader/arm/linux.c;
arm64 = loader/arm64/linux.c; arm64 = loader/arm64/linux.c;
riscv32 = loader/riscv/linux.c;
riscv64 = loader/riscv/linux.c;
common = loader/linux.c; common = loader/linux.c;
common = lib/cmdline.c; common = lib/cmdline.c;
enable = noemu; enable = noemu;
@ -1906,6 +1933,8 @@ module = {
enable = ia64_efi; enable = ia64_efi;
enable = arm_efi; enable = arm_efi;
enable = arm64_efi; enable = arm64_efi;
enable = riscv32_efi;
enable = riscv64_efi;
enable = mips; enable = mips;
}; };

View file

@ -90,6 +90,10 @@ static const struct grub_arg_option options[] = {
N_("Check if FILE is ARM64 EFI file"), 0, 0}, N_("Check if FILE is ARM64 EFI file"), 0, 0},
{"is-arm-efi", 0, 0, {"is-arm-efi", 0, 0,
N_("Check if FILE is ARM EFI file"), 0, 0}, N_("Check if FILE is ARM EFI file"), 0, 0},
{"is-riscv32-efi", 0, 0,
N_("Check if FILE is RISC-V 32bit EFI file"), 0, 0},
{"is-riscv64-efi", 0, 0,
N_("Check if FILE is RISC-V 64bit EFI file"), 0, 0},
{"is-hibernated-hiberfil", 0, 0, {"is-hibernated-hiberfil", 0, 0,
N_("Check if FILE is hiberfil.sys in hibernated state"), 0, 0}, N_("Check if FILE is hiberfil.sys in hibernated state"), 0, 0},
{"is-x86_64-xnu", 0, 0, {"is-x86_64-xnu", 0, 0,
@ -130,6 +134,7 @@ enum
IS_IA_EFI, IS_IA_EFI,
IS_ARM64_EFI, IS_ARM64_EFI,
IS_ARM_EFI, IS_ARM_EFI,
IS_RISCV_EFI,
IS_HIBERNATED, IS_HIBERNATED,
IS_XNU64, IS_XNU64,
IS_XNU32, IS_XNU32,
@ -571,6 +576,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
case IS_IA_EFI: case IS_IA_EFI:
case IS_ARM64_EFI: case IS_ARM64_EFI:
case IS_ARM_EFI: case IS_ARM_EFI:
case IS_RISCV_EFI:
{ {
char signature[4]; char signature[4];
grub_uint32_t pe_offset; grub_uint32_t pe_offset;
@ -616,7 +622,13 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
&& coff_head.machine != && coff_head.machine !=
grub_cpu_to_le16_compile_time (GRUB_PE32_MACHINE_ARMTHUMB_MIXED)) grub_cpu_to_le16_compile_time (GRUB_PE32_MACHINE_ARMTHUMB_MIXED))
break; break;
if (type == IS_IA_EFI || type == IS_64_EFI || type == IS_ARM64_EFI) if (type == IS_RISCV_EFI
&& coff_head.machine !=
grub_cpu_to_le16_compile_time (GRUB_PE32_MACHINE_RISCV64))
/* TODO: Determine bitness dynamically */
break;
if (type == IS_IA_EFI || type == IS_64_EFI || type == IS_ARM64_EFI ||
type == IS_RISCV_EFI)
{ {
struct grub_pe64_optional_header o64; struct grub_pe64_optional_header o64;
if (grub_file_read (file, &o64, sizeof (o64)) != sizeof (o64)) if (grub_file_read (file, &o64, sizeof (o64)) != sizeof (o64))

View file

@ -237,7 +237,8 @@ union component64
}; };
}; };
#if defined (__powerpc__) || defined (__arm__) || defined(__mips__) #if defined (__powerpc__) || defined (__arm__) || defined(__mips__) || \
(defined(__riscv) && (__riscv_xlen == 32))
/* Based on libgcc2.c from gcc suite. */ /* Based on libgcc2.c from gcc suite. */
grub_uint64_t grub_uint64_t
@ -343,7 +344,8 @@ __ucmpdi2 (grub_uint64_t a, grub_uint64_t b)
#endif #endif
#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__) || defined(__arm__) #if defined (__powerpc__) || defined(__mips__) || defined(__sparc__) || \
defined(__arm__) || defined(__riscv)
/* Based on libgcc2.c from gcc suite. */ /* Based on libgcc2.c from gcc suite. */
grub_uint32_t grub_uint32_t

View file

@ -666,7 +666,7 @@ grub_efi_mm_init (void)
2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
} }
#if defined (__aarch64__) || defined (__arm__) #if defined (__aarch64__) || defined (__arm__) || defined (__riscv)
grub_err_t grub_err_t
grub_efi_get_ram_base(grub_addr_t *base_addr) grub_efi_get_ram_base(grub_addr_t *base_addr)
{ {

View file

@ -25,5 +25,11 @@ grub_arch_sync_caches (void *address, grub_size_t len)
return _flush_cache (address, len, 0); return _flush_cache (address, len, 0);
} }
#elif defined(__riscv)
void
grub_arch_sync_caches (void *address, grub_size_t len)
{
}
#endif #endif

View file

@ -8,7 +8,8 @@
#include "../sparc64/cache.S" #include "../sparc64/cache.S"
#elif defined(__powerpc__) #elif defined(__powerpc__)
#include "../powerpc/cache.S" #include "../powerpc/cache.S"
#elif defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || defined(__mips__) #elif defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \
defined(__mips__) || defined(__riscv)
#else #else
#error "No target cpu type is defined" #error "No target cpu type is defined"
#endif #endif

View file

@ -24,6 +24,8 @@
#elif defined(__aarch64__) #elif defined(__aarch64__)
#include "../arm64/dl_helper.c" #include "../arm64/dl_helper.c"
#include "../arm64/dl.c" #include "../arm64/dl.c"
#elif defined(__riscv)
#include "../riscv/dl.c"
#else #else
#error "No target cpu type is defined" #error "No target cpu type is defined"
#endif #endif

View file

@ -29,7 +29,8 @@ void
grub_halt (void) grub_halt (void)
{ {
grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
#if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__) #if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__) && \
!defined(__riscv)
grub_acpi_halt (); grub_acpi_halt ();
#endif #endif
efi_call_4 (grub_efi_system_table->runtime_services->reset_system, efi_call_4 (grub_efi_system_table->runtime_services->reset_system,

View file

@ -15,6 +15,8 @@
#include "./arm/setjmp.S" #include "./arm/setjmp.S"
#elif defined(__aarch64__) #elif defined(__aarch64__)
#include "./arm64/setjmp.S" #include "./arm64/setjmp.S"
#elif defined(__riscv)
#include "./riscv/setjmp.S"
#else #else
#error "Unknown target cpu type" #error "Unknown target cpu type"
#endif #endif

View file

@ -53,13 +53,15 @@ EXPORT_FUNC (__umoddi3) (grub_uint64_t a, grub_uint64_t b);
#endif #endif
#if defined (__sparc__) || defined (__powerpc__) || defined (__mips__) || defined (__arm__) #if defined (__sparc__) || defined (__powerpc__) || defined (__mips__) || \
defined (__arm__) || defined(__riscv)
unsigned unsigned
EXPORT_FUNC (__ctzdi2) (grub_uint64_t x); EXPORT_FUNC (__ctzdi2) (grub_uint64_t x);
#define NEED_CTZDI2 1 #define NEED_CTZDI2 1
#endif #endif
#if defined (__mips__) || defined (__arm__) #if defined (__mips__) || defined (__arm__) || \
(defined(__riscv) && (__riscv_xlen == 32))
unsigned unsigned
EXPORT_FUNC (__ctzsi2) (grub_uint32_t x); EXPORT_FUNC (__ctzsi2) (grub_uint32_t x);
#define NEED_CTZSI2 1 #define NEED_CTZSI2 1
@ -157,7 +159,8 @@ void EXPORT_FUNC (_savegpr_31) (void);
#endif #endif
#if defined (__powerpc__) || defined(__mips__) || defined (__arm__) #if defined (__powerpc__) || defined(__mips__) || defined (__arm__) || \
(defined(__riscv) && (__riscv_xlen == 32))
int int
EXPORT_FUNC(__ucmpdi2) (grub_uint64_t a, grub_uint64_t b); EXPORT_FUNC(__ucmpdi2) (grub_uint64_t a, grub_uint64_t b);
@ -172,7 +175,8 @@ grub_uint64_t
EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b); EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b);
#endif #endif
#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__) || defined (__arm__) #if defined (__powerpc__) || defined(__mips__) || defined(__sparc__) || \
defined (__arm__) || defined(__riscv)
grub_uint32_t grub_uint32_t
EXPORT_FUNC(__bswapsi2) (grub_uint32_t u); EXPORT_FUNC(__bswapsi2) (grub_uint32_t u);

View file

@ -1691,7 +1691,8 @@ struct grub_efi_block_io
typedef struct grub_efi_block_io grub_efi_block_io_t; typedef struct grub_efi_block_io grub_efi_block_io_t;
#if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \ #if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \
|| defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \
|| defined(__riscv)
#define efi_call_0(func) func() #define efi_call_0(func) func()
#define efi_call_1(func, a) func(a) #define efi_call_1(func, a) func(a)

View file

@ -92,7 +92,7 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd,
char **device, char **device,
char **path); char **path);
#if defined(__arm__) || defined(__aarch64__) #if defined(__arm__) || defined(__aarch64__) || defined(__riscv)
void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);
grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *); grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);
#include <grub/cpu/linux.h> #include <grub/cpu/linux.h>

View file

@ -340,7 +340,8 @@ grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
grub_uint64_t *r); grub_uint64_t *r);
/* Must match softdiv group in gentpl.py. */ /* Must match softdiv group in gentpl.py. */
#if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__ia64__)) #if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__ia64__) || \
(defined(__riscv) && (__riscv_xlen == 32)))
#define GRUB_DIVISION_IN_SOFTWARE 1 #define GRUB_DIVISION_IN_SOFTWARE 1
#else #else
#define GRUB_DIVISION_IN_SOFTWARE 0 #define GRUB_DIVISION_IN_SOFTWARE 0

View file

@ -103,6 +103,8 @@ enum grub_install_plat
GRUB_INSTALL_PLATFORM_I386_XEN_PVH, GRUB_INSTALL_PLATFORM_I386_XEN_PVH,
GRUB_INSTALL_PLATFORM_ARM64_EFI, GRUB_INSTALL_PLATFORM_ARM64_EFI,
GRUB_INSTALL_PLATFORM_ARM_COREBOOT, GRUB_INSTALL_PLATFORM_ARM_COREBOOT,
GRUB_INSTALL_PLATFORM_RISCV32_EFI,
GRUB_INSTALL_PLATFORM_RISCV64_EFI,
GRUB_INSTALL_PLATFORM_MAX GRUB_INSTALL_PLATFORM_MAX
}; };

View file

@ -729,6 +729,8 @@ static struct
[GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64", "efi" }, [GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64", "efi" },
[GRUB_INSTALL_PLATFORM_ARM_UBOOT] = { "arm", "uboot" }, [GRUB_INSTALL_PLATFORM_ARM_UBOOT] = { "arm", "uboot" },
[GRUB_INSTALL_PLATFORM_ARM_COREBOOT] = { "arm", "coreboot" }, [GRUB_INSTALL_PLATFORM_ARM_COREBOOT] = { "arm", "coreboot" },
[GRUB_INSTALL_PLATFORM_RISCV32_EFI] = { "riscv32", "efi" },
[GRUB_INSTALL_PLATFORM_RISCV64_EFI] = { "riscv64", "efi" },
}; };
char * char *

View file

@ -477,6 +477,8 @@ have_bootdev (enum grub_install_plat pl)
case GRUB_INSTALL_PLATFORM_IA64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI:
case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI:
case GRUB_INSTALL_PLATFORM_ARM64_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI:
case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
case GRUB_INSTALL_PLATFORM_I386_IEEE1275: case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275: case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275: case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
@ -900,6 +902,8 @@ main (int argc, char *argv[])
case GRUB_INSTALL_PLATFORM_X86_64_EFI: case GRUB_INSTALL_PLATFORM_X86_64_EFI:
case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI:
case GRUB_INSTALL_PLATFORM_ARM64_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI:
case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
case GRUB_INSTALL_PLATFORM_IA64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI:
case GRUB_INSTALL_PLATFORM_I386_IEEE1275: case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275: case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
@ -945,6 +949,8 @@ main (int argc, char *argv[])
case GRUB_INSTALL_PLATFORM_X86_64_EFI: case GRUB_INSTALL_PLATFORM_X86_64_EFI:
case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI:
case GRUB_INSTALL_PLATFORM_ARM64_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI:
case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
case GRUB_INSTALL_PLATFORM_IA64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI:
case GRUB_INSTALL_PLATFORM_I386_IEEE1275: case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
case GRUB_INSTALL_PLATFORM_ARM_UBOOT: case GRUB_INSTALL_PLATFORM_ARM_UBOOT:
@ -998,6 +1004,8 @@ main (int argc, char *argv[])
case GRUB_INSTALL_PLATFORM_X86_64_EFI: case GRUB_INSTALL_PLATFORM_X86_64_EFI:
case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI:
case GRUB_INSTALL_PLATFORM_ARM64_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI:
case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
case GRUB_INSTALL_PLATFORM_IA64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI:
is_efi = 1; is_efi = 1;
break; break;
@ -1111,6 +1119,12 @@ main (int argc, char *argv[])
case GRUB_INSTALL_PLATFORM_ARM64_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI:
efi_file = "BOOTAA64.EFI"; efi_file = "BOOTAA64.EFI";
break; break;
case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
efi_file = "BOOTRISCV32.EFI";
break;
case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
efi_file = "BOOTRISCV64.EFI";
break;
default: default:
grub_util_error ("%s", _("You've found a bug")); grub_util_error ("%s", _("You've found a bug"));
break; break;
@ -1138,6 +1152,12 @@ main (int argc, char *argv[])
case GRUB_INSTALL_PLATFORM_ARM64_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI:
efi_file = "grubaa64.efi"; efi_file = "grubaa64.efi";
break; break;
case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
efi_file = "grubriscv32.efi";
break;
case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
efi_file = "grubriscv64.efi";
break;
default: default:
efi_file = "grub.efi"; efi_file = "grub.efi";
break; break;
@ -1440,6 +1460,8 @@ main (int argc, char *argv[])
case GRUB_INSTALL_PLATFORM_X86_64_EFI: case GRUB_INSTALL_PLATFORM_X86_64_EFI:
case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI:
case GRUB_INSTALL_PLATFORM_ARM64_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI:
case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
case GRUB_INSTALL_PLATFORM_IA64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI:
g = grub_util_guess_efi_drive (*curdev); g = grub_util_guess_efi_drive (*curdev);
break; break;
@ -1533,6 +1555,8 @@ main (int argc, char *argv[])
case GRUB_INSTALL_PLATFORM_X86_64_EFI: case GRUB_INSTALL_PLATFORM_X86_64_EFI:
case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI:
case GRUB_INSTALL_PLATFORM_ARM64_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI:
case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
case GRUB_INSTALL_PLATFORM_IA64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI:
core_name = "core.efi"; core_name = "core.efi";
snprintf (mkimage_target, sizeof (mkimage_target), snprintf (mkimage_target, sizeof (mkimage_target),
@ -1636,6 +1660,8 @@ main (int argc, char *argv[])
break; break;
case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI:
case GRUB_INSTALL_PLATFORM_ARM64_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI:
case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
case GRUB_INSTALL_PLATFORM_IA64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI:
case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS: case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS:
case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS: case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS:
@ -1871,6 +1897,8 @@ main (int argc, char *argv[])
/* FALLTHROUGH */ /* FALLTHROUGH */
case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI:
case GRUB_INSTALL_PLATFORM_ARM64_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI:
case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
case GRUB_INSTALL_PLATFORM_IA64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI:
{ {
char *dst = grub_util_path_concat (2, efidir, efi_file); char *dst = grub_util_path_concat (2, efidir, efi_file);

View file

@ -107,7 +107,9 @@ static const struct
[GRUB_INSTALL_PLATFORM_X86_64_EFI] = { "x86_64-efi", "efinet", ".efi" }, [GRUB_INSTALL_PLATFORM_X86_64_EFI] = { "x86_64-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_IA64_EFI] = { "ia64-efi", "efinet", ".efi" }, [GRUB_INSTALL_PLATFORM_IA64_EFI] = { "ia64-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_ARM_EFI] = { "arm-efi", "efinet", ".efi" }, [GRUB_INSTALL_PLATFORM_ARM_EFI] = { "arm-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64-efi", "efinet", ".efi" } [GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_RISCV32_EFI] = { "riscv32-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_RISCV64_EFI] = { "riscv64-efi", "efinet", ".efi" },
}; };
static void static void

View file

@ -538,6 +538,8 @@ main (int argc, char *argv[])
|| source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI] || source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI] || source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI] || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_RISCV32_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI]) || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
system_area = SYS_AREA_COMMON; system_area = SYS_AREA_COMMON;
else if (source_dirs[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275]) else if (source_dirs[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275])
@ -735,7 +737,9 @@ main (int argc, char *argv[])
|| source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI] || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI] || source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI] || source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI]) || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_RISCV32_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI])
{ {
char *efidir = grub_util_make_temporary_dir (); char *efidir = grub_util_make_temporary_dir ();
char *efidir_efi = grub_util_path_concat (2, efidir, "efi"); char *efidir_efi = grub_util_path_concat (2, efidir, "efi");
@ -770,6 +774,16 @@ main (int argc, char *argv[])
imgname); imgname);
free (imgname); free (imgname);
imgname = grub_util_path_concat (2, efidir_efi_boot, "bootriscv32.efi");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_RISCV32_EFI, "riscv32-efi",
imgname);
free (imgname);
imgname = grub_util_path_concat (2, efidir_efi_boot, "bootriscv64.efi");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_RISCV64_EFI, "riscv64-efi",
imgname);
free (imgname);
if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]) if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI])
{ {
imgname = grub_util_path_concat (2, efidir_efi_boot, "boot.efi"); imgname = grub_util_path_concat (2, efidir_efi_boot, "boot.efi");

View file

@ -622,6 +622,38 @@ static const struct grub_install_image_target_desc image_targets[] =
.pe_target = GRUB_PE32_MACHINE_ARM64, .pe_target = GRUB_PE32_MACHINE_ARM64,
.elf_target = EM_AARCH64, .elf_target = EM_AARCH64,
}, },
{
.dirname = "riscv32-efi",
.names = { "riscv32-efi", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_EFI,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_PE32_SECTION_ALIGNMENT,
.vaddr_offset = EFI32_HEADER_SIZE,
.pe_target = GRUB_PE32_MACHINE_RISCV32,
.elf_target = EM_RISCV,
},
{
.dirname = "riscv64-efi",
.names = { "riscv64-efi", NULL },
.voidp_sizeof = 8,
.bigendian = 0,
.id = IMAGE_EFI,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_PE32_SECTION_ALIGNMENT,
.vaddr_offset = EFI64_HEADER_SIZE,
.pe_target = GRUB_PE32_MACHINE_RISCV64,
.elf_target = EM_RISCV,
},
}; };
#include <grub/lib/LzmaEnc.h> #include <grub/lib/LzmaEnc.h>