From patchwork Tue Feb 12 10:30:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 158146 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3669222jaa; Tue, 12 Feb 2019 02:37:06 -0800 (PST) X-Google-Smtp-Source: AHgI3IY8IeskIpmC4vfhQnL2JBM4xbkLVOusUqeSgB0irNirR/0K0PEeB8p1GPlSo0qrTBAvhKOb X-Received: by 2002:a81:2fcc:: with SMTP id v195mr2155009ywv.419.1549967826786; Tue, 12 Feb 2019 02:37:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967826; cv=none; d=google.com; s=arc-20160816; b=J3vTdVYjJOtp6matKvyJRFV6ANMvmK0FrZjqZvUwO/PzXCppHFhXptZ9GIJFEYePGq 8ksj1v/4NeOGf+23xypJJd1TdSDkpiUs1R+2dWIFKjOiDpN/CH4+TnnDpJ5Bk9r2NaU4 w9DlHgsMZSLJ0E4DUm1+ZLuEAmiT5SR8oQbBolZzpbi/2niE7Edk8VxYUgeYEfXW9ERC 0Cy/N/xDJj+FTDWyI6BCNUegbCaODMNcZnXzcxccfGLz501xk8aYCEm0b+H44TMi8U8Y VROsdnjWWajpYUp0TdgXARbq9yLW7chTZd+gcRn7fIQFXk0vHzFPYRvWYrFey6FNx+tI /DRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=ruQ1U4HkED8ZAW2stun9RQwaXz7MtxVzx13pPN1SDls=; b=0nCFNKrjNflYUyh/m6UmuEDk/Fj0JtqKk2TbkgntZQmK39JNQI4cFrTA8HYbqs3cEK s4u4sIevfjGJA9p4AL7hRxYtyIAiM68SkxGyia1OOtkg49PodDdiUR9xQSNWK+jZkDDT eZzkiW3zNlTsNq9JxEhgLMuDrckKjI+EdbCfij5vhhy4OPInR6CQWPhwxvP/RJqPso3b lcV9K4cMkgQ1GAcjfpEzw4E49/K4EMILX8t/5YBnfOzOwiAPjCvkDsQKB+NDpbdFN6xg jd/9M7f0DgPm33oaHXR0watFZXqhj2rMmeraiwQALm8SgE29fQ5XeUpl6Tagn1T+zRGq DfYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 185si3731582ybq.202.2019.02.12.02.37.06 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Feb 2019 02:37:06 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:36998 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVR4-0004LJ-3z for patch@linaro.org; Tue, 12 Feb 2019 05:37:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVML-0000w5-BC for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtVMC-00049G-2U for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:13 -0500 Received: from mx2.suse.de ([195.135.220.15]:51824 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtVM9-0002um-Tr for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:03 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 98EFCAF9A; Tue, 12 Feb 2019 10:31:11 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v6 01/11] efi: Rename armxx to arch Date: Tue, 12 Feb 2019 11:30:58 +0100 Message-Id: <20190212103108.56963-2-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190212103108.56963-1-agraf@suse.de> References: <20190212103108.56963-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng , Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" Some architectures want to boot Linux as plain UEFI binary. Today that really only encompasses ARM and AArch64, but going forward more architectures may adopt that model. So rename our internal API accordingly. Signed-off-by: Alexander Graf Acked-by: Leif Lindholm Reviewed-by: Alistair Francis Reviewed-by: Bin Meng Tested-by: Bin Meng Reviewed-by: Daniel Kiper --- v3 -> v4: - Rebase --- grub-core/loader/arm64/linux.c | 10 +++++----- grub-core/loader/arm64/xen_boot.c | 6 +++--- include/grub/arm/linux.h | 2 +- include/grub/arm64/linux.h | 2 +- include/grub/efi/efi.h | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c index 7c6d8daa1..ef3e9f944 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c @@ -49,7 +49,7 @@ static grub_addr_t initrd_start; static grub_addr_t initrd_end; grub_err_t -grub_armxx_efi_linux_check_image (struct linux_armxx_kernel_header * lh) +grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh) { if (lh->magic != GRUB_LINUX_ARMXX_MAGIC_SIGNATURE) return grub_error(GRUB_ERR_BAD_OS, "invalid magic number"); @@ -110,7 +110,7 @@ failure: } grub_err_t -grub_armxx_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) +grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) { grub_efi_memory_mapped_device_path_t *mempath; grub_efi_handle_t image_handle; @@ -173,7 +173,7 @@ grub_linux_boot (void) if (finalize_params_linux () != GRUB_ERR_NONE) return grub_errno; - return (grub_armxx_efi_linux_boot_image((grub_addr_t)kernel_addr, + return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr, kernel_size, linux_args)); } @@ -287,7 +287,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) { grub_file_t file = 0; - struct linux_armxx_kernel_header lh; + struct linux_arch_kernel_header lh; grub_err_t err; grub_dl_ref (my_mod); @@ -307,7 +307,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, &lh, sizeof (lh)) < (long) sizeof (lh)) return grub_errno; - if (grub_armxx_efi_linux_check_image (&lh) != GRUB_ERR_NONE) + if (grub_arch_efi_linux_check_image (&lh) != GRUB_ERR_NONE) goto fail; grub_loader_unset(); diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c index a742868a4..22cc25ecc 100644 --- a/grub-core/loader/arm64/xen_boot.c +++ b/grub-core/loader/arm64/xen_boot.c @@ -265,7 +265,7 @@ xen_boot (void) if (err) return err; - return grub_armxx_efi_linux_boot_image (xen_hypervisor->start, + return grub_arch_efi_linux_boot_image (xen_hypervisor->start, xen_hypervisor->size, xen_hypervisor->cmdline); } @@ -469,8 +469,8 @@ grub_cmd_xen_hypervisor (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, &sh, sizeof (sh)) != (long) sizeof (sh)) goto fail; - if (grub_armxx_efi_linux_check_image - ((struct linux_armxx_kernel_header *) &sh) != GRUB_ERR_NONE) + if (grub_arch_efi_linux_check_image + ((struct linux_arch_kernel_header *) &sh) != GRUB_ERR_NONE) goto fail; grub_file_seek (file, 0); diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h index d0b24d474..2e98a6689 100644 --- a/include/grub/arm/linux.h +++ b/include/grub/arm/linux.h @@ -36,7 +36,7 @@ struct linux_arm_kernel_header { #if defined(__arm__) # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE -# define linux_armxx_kernel_header linux_arm_kernel_header +# define linux_arch_kernel_header linux_arm_kernel_header #endif #if defined GRUB_MACHINE_UBOOT diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h index 8655067e0..4269adc6d 100644 --- a/include/grub/arm64/linux.h +++ b/include/grub/arm64/linux.h @@ -38,7 +38,7 @@ struct linux_arm64_kernel_header #if defined(__aarch64__) # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE -# define linux_armxx_kernel_header linux_arm64_kernel_header +# define linux_arch_kernel_header linux_arm64_kernel_header #endif #endif /* ! GRUB_ARM64_LINUX_HEADER */ diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index 2c6648d46..ec44aef7e 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -94,8 +94,8 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *); #include -grub_err_t grub_armxx_efi_linux_check_image(struct linux_armxx_kernel_header *lh); -grub_err_t grub_armxx_efi_linux_boot_image(grub_addr_t addr, grub_size_t size, +grub_err_t grub_arch_efi_linux_check_image(struct linux_arch_kernel_header *lh); +grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size, char *args); #endif From patchwork Tue Feb 12 10:30:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 158144 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3667663jaa; Tue, 12 Feb 2019 02:35:30 -0800 (PST) X-Google-Smtp-Source: AHgI3Iax6AgkDf/kRsJfwamm+fr0a2IvWT70vLIAjB1W4pSAkqaSRhMXEWWTN607SSHGyouPHqvg X-Received: by 2002:a25:1257:: with SMTP id 84mr2219526ybs.257.1549967730414; Tue, 12 Feb 2019 02:35:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967730; cv=none; d=google.com; s=arc-20160816; b=ZB2oGOBEQ/1kuZDQZtdSp25eJMikE9EKSAUGJCguwkIOJzNELY+47FIw8uzS0bHNYI 4gcws2jRQWSfU/hre0JbQ2BZl5QPWrUfIjDPwPUPxT/vTwNpVgIZjFymK8nDctgw+YLV BxXFl22ht/iX7oybwZBUkBuIgd+WXnupk67iR2+L8EzwWECKWrwoAVJb1IieyfqPaszC wOcpE16FAR2Ps0MDYpTgX3SkrCBsGVIjy2inxozc6sTJMpUh2uxo2Eh0bRplo4t5LwjL plz01HcHM7uoxvGiTr4WS1szqCLSZehcgjYsYv3MinUFbG0lCI9jhwzFFbIKM9ycRJ2a H1uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=IhtDnf8qO48UEv9vD/jfXK3BLm9qYScsx3mhEmC9Atw=; b=klEJpzpwUpA/nkXR1mrdM7UDk8ua2KmhG87TKMWjTPRNmA2pJoiQBwA+SP5TdPnAD/ 1SPIX0JrTSNrIHEIZtTyyYZV3e9bvyDk5S72sEObLxvLFid2Jy12hVpazPgtja7jedHv AuqhTFy40YxgomCw/O/jyQVAXThq8yCDAWfDxCVGcp65DlTomwDRYWLqYxhcDHcBQ3Bg vznVo3lLw5jeVyKF9lFvzo5W2c0iECsWYkiLoKJCTP/amI/MJNz7a+4LGInPhxWMaOKE Iq6HEPzj7+X9ShlV+J1ZKAMAFdEujZeZs0tv6uCz97AHjn25JosF1khOAFAaVQK0YMMm ap4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l198si7304456ybl.131.2019.02.12.02.35.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Feb 2019 02:35:30 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:36984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVPV-0003Cv-TU for patch@linaro.org; Tue, 12 Feb 2019 05:35:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVMJ-0000uG-5V for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtVMB-000493-Vo for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:10 -0500 Received: from mx2.suse.de ([195.135.220.15]:51780 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtVM8-0002uH-3E for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:01 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 98FE0B116; Tue, 12 Feb 2019 10:31:11 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v6 02/11] PE: Add RISC-V definitions Date: Tue, 12 Feb 2019 11:30:59 +0100 Message-Id: <20190212103108.56963-3-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190212103108.56963-1-agraf@suse.de> References: <20190212103108.56963-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng , Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" The PE format defines magic numbers as well as relocation identifiers for RISC-V. Add them to our include file, so we can make use of them. Signed-off-by: Alexander Graf Reviewed-by: Leif Lindholm Reviewed-by: Alistair Francis Reviewed-by: Bin Meng Tested-by: Bin Meng Reviewed-by: Daniel Kiper --- include/grub/efi/pe32.h | 5 +++++ 1 file changed, 5 insertions(+) -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h index 207b0382e..0ed8781f0 100644 --- a/include/grub/efi/pe32.h +++ b/include/grub/efi/pe32.h @@ -77,6 +77,8 @@ struct grub_pe32_coff_header #define GRUB_PE32_MACHINE_X86_64 0x8664 #define GRUB_PE32_MACHINE_ARMTHUMB_MIXED 0x01c2 #define GRUB_PE32_MACHINE_ARM64 0xAA64 +#define GRUB_PE32_MACHINE_RISCV32 0x5032 +#define GRUB_PE32_MACHINE_RISCV64 0x5064 #define GRUB_PE32_RELOCS_STRIPPED 0x0001 #define GRUB_PE32_EXECUTABLE_IMAGE 0x0002 @@ -288,9 +290,12 @@ struct grub_pe32_fixup_block #define GRUB_PE32_REL_BASED_HIGHADJ 4 #define GRUB_PE32_REL_BASED_MIPS_JMPADDR 5 #define GRUB_PE32_REL_BASED_ARM_MOV32A 5 +#define GRUB_PE32_REL_BASED_RISCV_HI20 5 #define GRUB_PE32_REL_BASED_SECTION 6 #define GRUB_PE32_REL_BASED_REL 7 #define GRUB_PE32_REL_BASED_ARM_MOV32T 7 +#define GRUB_PE32_REL_BASED_RISCV_LOW12I 7 +#define GRUB_PE32_REL_BASED_RISCV_LOW12S 8 #define GRUB_PE32_REL_BASED_IA64_IMM64 9 #define GRUB_PE32_REL_BASED_DIR64 10 #define GRUB_PE32_REL_BASED_HIGH3ADJ 11 From patchwork Tue Feb 12 10:31:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 158136 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3664145jaa; Tue, 12 Feb 2019 02:32:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IbZoEQMt3+63N72mDhcy1hI/Qrf/M2jhJTSMeG1aXAKQc9d2WRg1YaC2ksBfwJvALXd7nMz X-Received: by 2002:a25:800c:: with SMTP id m12mr2146908ybk.93.1549967521678; Tue, 12 Feb 2019 02:32:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967521; cv=none; d=google.com; s=arc-20160816; b=Mf5E7oWPwScuTUFYRU0Ipjl4UFcaJUDzzasnufID6q7olXHRSDM2msZjJ4CITsnHGX DRNdFDkvfS6bTN49F/yHcpV8OAmsPLPJAceRZfqvKJICGst5RFSFf+p9Ns5wW/YCXwX5 EmhZF3ddEaDZoHy72CEH9ldgXY9/l6LVWPEN5ic+TXJzej/nX4ZQhhNjKTBiI2idZq5I ctV/2p0JKY+Xmm9veZqejvfMhTUyyXTmcUuIAAxJn3ChjD4HTGT1KeZwLEZDMZ9s7htv CHOV89fAqMoVExSOX9uv6UKDnnA78SAeIy12choPVhSg2Kf4Ob+igaDfpNE3lMIZNyQi kVAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=5U77O9UrQDr6IjfFUdD7jMt35uw3hzr4s0C8J8gxEwU=; b=t1tTn7m6UEGtfPflkFxQzAyLsEuPSeppORxIWR6RpL3QWchwilALjEibn//l0Eluek oSWjRHd7cVLpkb3Xhq4R/37HZZJhU3XlibHU4D4sqtFm6lz+ccKgnmOsK4weNi8Tnue6 DIJV2QtMQN+UJfR7Gcx9C8iDQVFYZEaGZS81hqwpSCP5mP58u8A27RhxPGrRh4Uvg7/1 cgDwZoVCTxN67yZnjHMwq3MsoOl4jOifPAMm4VpU+Eh1yskwq0e2rpdEh16fn9ZBJG3I eJaMQVoGfcX2COpw+1K24q7dFjZWQJehoEKMt6GavHzYThfnJQQn9z4ueIFTUoqNGdBY V0Gw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g186si7140413ybg.276.2019.02.12.02.32.01 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Feb 2019 02:32:01 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:36922 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVM9-0000mM-8x for patch@linaro.org; Tue, 12 Feb 2019 05:32:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVM3-0000m3-3V for grub-devel@gnu.org; Tue, 12 Feb 2019 05:31:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtVM0-0003jX-Vv for grub-devel@gnu.org; Tue, 12 Feb 2019 05:31:54 -0500 Received: from mx2.suse.de ([195.135.220.15]:51796 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtVLr-0002uT-Bj for grub-devel@gnu.org; Tue, 12 Feb 2019 05:31:47 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 98A81AF27; Tue, 12 Feb 2019 10:31:11 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v6 03/11] elf.h: Add RISC-V definitions Date: Tue, 12 Feb 2019 11:31:00 +0100 Message-Id: <20190212103108.56963-4-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190212103108.56963-1-agraf@suse.de> References: <20190212103108.56963-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng , Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" The RISC-V ABI document outlines ELF header structure and relocation information. Pull the respective magic numbers into our elf header so we can make use of them. Signed-off-by: Alexander Graf Reviewed-by: Alistair Francis Reviewed-by: Bin Meng Tested-by: Bin Meng Reviewed-by: Daniel Kiper --- include/grub/elf.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/include/grub/elf.h b/include/grub/elf.h index c8492f9dc..c478933ee 100644 --- a/include/grub/elf.h +++ b/include/grub/elf.h @@ -247,6 +247,7 @@ typedef struct #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ #define EM_NUM 95 #define EM_AARCH64 183 /* ARM 64-bit architecture */ +#define EM_RISCV 243 /* RISC-V */ /* If it is necessary to assign new unofficial EM_* values, please pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the @@ -2473,6 +2474,63 @@ typedef Elf32_Addr Elf32_Conflict; #define R_X86_64_NUM 24 +/* RISC-V relocations */ +#define R_RISCV_NONE 0 +#define R_RISCV_32 1 +#define R_RISCV_64 2 +#define R_RISCV_RELATIVE 3 +#define R_RISCV_COPY 4 +#define R_RISCV_JUMP_SLOT 5 +#define R_RISCV_TLS_DTPMOD32 6 +#define R_RISCV_TLS_DTPMOD64 7 +#define R_RISCV_TLS_DTPREL32 8 +#define R_RISCV_TLS_DTPREL64 9 +#define R_RISCV_TLS_TPREL32 10 +#define R_RISCV_TLS_TPREL64 11 + +#define R_RISCV_BRANCH 16 +#define R_RISCV_JAL 17 +#define R_RISCV_CALL 18 +#define R_RISCV_CALL_PLT 19 +#define R_RISCV_GOT_HI20 20 +#define R_RISCV_TLS_GOT_HI20 21 +#define R_RISCV_TLS_GD_HI20 22 +#define R_RISCV_PCREL_HI20 23 +#define R_RISCV_PCREL_LO12_I 24 +#define R_RISCV_PCREL_LO12_S 25 +#define R_RISCV_HI20 26 +#define R_RISCV_LO12_I 27 +#define R_RISCV_LO12_S 28 +#define R_RISCV_TPREL_HI20 29 +#define R_RISCV_TPREL_LO12_I 30 +#define R_RISCV_TPREL_LO12_S 31 +#define R_RISCV_TPREL_ADD 32 +#define R_RISCV_ADD8 33 +#define R_RISCV_ADD16 34 +#define R_RISCV_ADD32 35 +#define R_RISCV_ADD64 36 +#define R_RISCV_SUB8 37 +#define R_RISCV_SUB16 38 +#define R_RISCV_SUB32 39 +#define R_RISCV_SUB64 40 +#define R_RISCV_GNU_VTINHERIT 41 +#define R_RISCV_GNU_VTENTRY 42 +#define R_RISCV_ALIGN 43 +#define R_RISCV_RVC_BRANCH 44 +#define R_RISCV_RVC_JUMP 45 +#define R_RISCV_LUI 46 +#define R_RISCV_GPREL_I 47 +#define R_RISCV_GPREL_S 48 +#define R_RISCV_TPREL_I 49 +#define R_RISCV_TPREL_S 50 +#define R_RISCV_RELAX 51 +#define R_RISCV_SUB6 52 +#define R_RISCV_SET6 53 +#define R_RISCV_SET8 54 +#define R_RISCV_SET16 55 +#define R_RISCV_SET32 56 +#define R_RISCV_32_PCREL 57 + #ifdef GRUB_TARGET_WORDSIZE #if GRUB_TARGET_WORDSIZE == 32 From patchwork Tue Feb 12 10:31:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 158145 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3668855jaa; Tue, 12 Feb 2019 02:36:41 -0800 (PST) X-Google-Smtp-Source: AHgI3IYPHZeZ/tIUjaFd2XCVL4YoKLf23EnAifmfoSO3REiaxbnFIsHKWjb7twK5eGrLm5S7W2Ju X-Received: by 2002:a0d:e607:: with SMTP id p7mr2156037ywe.329.1549967801285; Tue, 12 Feb 2019 02:36:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967801; cv=none; d=google.com; s=arc-20160816; b=f1cTE3RYY9Uq9lojFPjh6QCvkvhFM0AZgkQyhhNEwOaUddBxUP7b7+r3yj6n/OEXPR YGUF3jlSCjacj5LRt6STa/Hvv6pyVwf8kCx2yd3Li00vx+jM1+UiXuAW0383mDGy9IxK roRwpu/QUt1nMw+HaDx25GG4goGpXwwelZZrZQ5D6vad4wVT7q8lsJyyEYbClI3obRWf EwDZk7eAAb8KHLP9AT7fJbsUpl86rQn7xJY8T1uMlszHzjI2dO9oVp0j2afhot1MvdI9 PsCCZJZm3eeTr2oc5QCnrOQfng7sl0nAORLSizT4e2yGJ6Ab/qjE30lo3KMfK8tc+BU1 6pLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=TTRgXmHwvJ6JpfAy/O4PRb77Vr7iMfme++lWJBpdzWw=; b=njL3RTMH8Oo+qCXh0YlaxW1CEGZAtX/iPsiqs4M09v+5RO77vtCqVsWhNGGh4y5w+i MZG8pnXbzTuslTJxQTYGtFuBY3prLltJ4ID5k4FTY1Mr3JX7rr9FLEiXA/jC8gZN7EoL kL4SB6JcD/VDnk+VvYONkfbGK1NQj3h0vUfai2jUrol19O/LL+Rst65L200crxRD5xOu zYBymmcPIp8/WSozOYgS+dILZbGkyC1kXPKo8L+/2SaJ5RJ/I4kgH+4Jg6TCJvPZKVVb VV1YsPP/ImZpZM4dYZUKjLbtYvdKp2IoUJ0VNtrmeAA3OHOzoODTKT6D1uDzCpK+CrDk 270A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h5si7417951ywa.260.2019.02.12.02.36.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Feb 2019 02:36:41 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:36990 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVQe-0003zz-KQ for patch@linaro.org; Tue, 12 Feb 2019 05:36:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVML-0000vm-0g for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtVMB-00048n-UZ for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:11 -0500 Received: from mx2.suse.de ([195.135.220.15]:51846 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtVM8-0002ut-1I for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:02 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 98AB8AF45; Tue, 12 Feb 2019 10:31:11 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v6 04/11] RISC-V: Add setjmp implementation Date: Tue, 12 Feb 2019 11:31:01 +0100 Message-Id: <20190212103108.56963-5-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190212103108.56963-1-agraf@suse.de> References: <20190212103108.56963-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng , Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" This patch adds a 32/64 capable setjmp implementation for RISC-V. Signed-off-by: Alexander Graf Reviewed-by: Alistair Francis Reviewed-by: Bin Meng Tested-by: Bin Meng Reviewed-by: Daniel Kiper --- v3 -> v4: - Change copyright from 2013 to 2018 v4 -> v5: - Add blank lines before and after license tag --- grub-core/lib/riscv/setjmp.S | 84 +++++++++++++++++++++++++++++++++++++++++++ include/grub/riscv32/setjmp.h | 27 ++++++++++++++ include/grub/riscv64/setjmp.h | 27 ++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 grub-core/lib/riscv/setjmp.S create mode 100644 include/grub/riscv32/setjmp.h create mode 100644 include/grub/riscv64/setjmp.h -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/lib/riscv/setjmp.S b/grub-core/lib/riscv/setjmp.S new file mode 100644 index 000000000..b48ef29ea --- /dev/null +++ b/grub-core/lib/riscv/setjmp.S @@ -0,0 +1,84 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include + + .file "setjmp.S" + +GRUB_MOD_LICENSE "GPLv3+" + + .text + +#if __riscv_xlen == 64 +#define STORE_IDX(reg, idx) sd reg, (idx*8)(a0) +#define LOAD_IDX(reg, idx) ld reg, (idx*8)(a0) +#else +#define STORE_IDX(reg, idx) sw reg, (idx*4)(a0) +#define LOAD_IDX(reg, idx) lw reg, (idx*4)(a0) +#endif + +/* + * int grub_setjmp (grub_jmp_buf env) + */ +FUNCTION(grub_setjmp) + /* Preserve all callee-saved registers and the SP */ + STORE_IDX(s0, 0) + STORE_IDX(s1, 1) + STORE_IDX(s2, 2) + STORE_IDX(s3, 3) + STORE_IDX(s4, 4) + STORE_IDX(s5, 5) + STORE_IDX(s6, 6) + STORE_IDX(s7, 7) + STORE_IDX(s8, 8) + STORE_IDX(s9, 9) + STORE_IDX(s10, 10) + STORE_IDX(s11, 11) + STORE_IDX(ra, 12) + STORE_IDX(sp, 13) + li a0, 0 + ret + +/* + * int grub_longjmp (grub_jmp_buf env, int val) + */ +FUNCTION(grub_longjmp) + LOAD_IDX(s0, 0) + LOAD_IDX(s1, 1) + LOAD_IDX(s2, 2) + LOAD_IDX(s3, 3) + LOAD_IDX(s4, 4) + LOAD_IDX(s5, 5) + LOAD_IDX(s6, 6) + LOAD_IDX(s7, 7) + LOAD_IDX(s8, 8) + LOAD_IDX(s9, 9) + LOAD_IDX(s10, 10) + LOAD_IDX(s11, 11) + LOAD_IDX(ra, 12) + LOAD_IDX(sp, 13) + + /* Move the return value in place, but return 1 if passed 0. */ + beq a1, zero, longjmp_1 + mv a0, a1 + ret + + longjmp_1: + li a0, 1 + ret diff --git a/include/grub/riscv32/setjmp.h b/include/grub/riscv32/setjmp.h new file mode 100644 index 000000000..5a2123846 --- /dev/null +++ b/include/grub/riscv32/setjmp.h @@ -0,0 +1,27 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_SETJMP_CPU_HEADER +#define GRUB_SETJMP_CPU_HEADER 1 + +typedef unsigned long long grub_jmp_buf[14]; + +int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE; +void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn)); + +#endif /* ! GRUB_SETJMP_CPU_HEADER */ diff --git a/include/grub/riscv64/setjmp.h b/include/grub/riscv64/setjmp.h new file mode 100644 index 000000000..5a2123846 --- /dev/null +++ b/include/grub/riscv64/setjmp.h @@ -0,0 +1,27 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_SETJMP_CPU_HEADER +#define GRUB_SETJMP_CPU_HEADER 1 + +typedef unsigned long long grub_jmp_buf[14]; + +int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE; +void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn)); + +#endif /* ! GRUB_SETJMP_CPU_HEADER */ From patchwork Tue Feb 12 10:31:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 158138 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3664550jaa; Tue, 12 Feb 2019 02:32:27 -0800 (PST) X-Google-Smtp-Source: AHgI3IbucDp7C5sAxXeNuUKKj36qThkkRxjlqak5dT3DzlPRfLyS1rvhyXwp0GIXxOuaP9EmAOU0 X-Received: by 2002:a25:9a89:: with SMTP id s9mr2262876ybo.358.1549967547199; Tue, 12 Feb 2019 02:32:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967547; cv=none; d=google.com; s=arc-20160816; b=Gw4afkLeqGIit4WcQ9mFEELlybkSbAqSrt1V9sg2n8F8YmllRit4GdESyvBqPp40Kc jpyu9ct4647aq+2aJ+FlxzdvQDXIG6WlO7SxnZOs3II2bdlHAEsTgJOt6kmtW16f/aGL ook6hsp9Ea3IE/GgwrkyOfCWLnosJtenU6l97P13y5YY5Yq0l8fSRti+c9LyPwiu3xVy 1r4auR/0rPD02PMfy2AZxHKIppR+nr6yM1nOp4EF2idsREkOfvd13RYCQQSzroTSVzAj kcT1VB/H4fwc/w2a3lLw27lyAZiLqWve7gqLvKrvLhRH9K2qDRouVzy4tDDOtt9UVde4 8ByQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=yiyLE3sUdgk/ezPOFSJ9xRJsA761h2aAR9ujjChh61g=; b=HBMn7vXjII6Ra3D8ZM9Nym7+GaR72t2IS9muI5mAnIIMRm3Q7ESIOtMFVqTcfKVlnU xy9oWxjM9A/PlygGiPrj0lzaRsGV2U892HJo4uN1g1MVZJo7G2Ix43cXy9HfLSVB2Kt6 HtRAKXjSmC65AmRVe6XzpVJiHrCfRh4Sv15Q6q8/xF/OYp7dsuvmAldxpD9zj0rsGD1Y H/4OWX+ORxRNFLAkk0vFzpWs4W/UiIIzDygBbDzAlXEM1GTHplN5c8A40Dg1TbZOIK0H iarSftma9hpDz6smc1DHgha9H4tQYKPh2CvctLjN02FaI3E9WaLCRD8Wdvo16d2TnxgG WCEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v130si7265525ybv.143.2019.02.12.02.32.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Feb 2019 02:32:27 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:36926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVMY-0000v9-Iu for patch@linaro.org; Tue, 12 Feb 2019 05:32:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37249) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVMH-0000tb-Qe for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtVME-0004EQ-Q8 for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:08 -0500 Received: from mx2.suse.de ([195.135.220.15]:52044 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtVMC-00042j-IU for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:04 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 09DC7B14C; Tue, 12 Feb 2019 10:31:12 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v6 05/11] RISC-V: Add early startup code Date: Tue, 12 Feb 2019 11:31:02 +0100 Message-Id: <20190212103108.56963-6-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190212103108.56963-1-agraf@suse.de> References: <20190212103108.56963-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng , Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" On entry, we need to save the system table pointer as well as our image handle. Add an early startup file that saves them and then brings us into our main function. Signed-off-by: Alexander Graf Reviewed-by: Alistair Francis Reviewed-by: Bin Meng Tested-by: Bin Meng Reviewed-by: Daniel Kiper --- v3 -> v4: - Change copyright from 2013 to 2018 v4 -> v5: - Remove blank line at EOF --- grub-core/kern/riscv/efi/startup.S | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 grub-core/kern/riscv/efi/startup.S -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/kern/riscv/efi/startup.S b/grub-core/kern/riscv/efi/startup.S new file mode 100644 index 000000000..f2a7b2b1e --- /dev/null +++ b/grub-core/kern/riscv/efi/startup.S @@ -0,0 +1,48 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include + +#if __riscv_xlen == 64 +#define sl sd +#define ll ld +#else +#define sl sw +#define ll lw +#endif + + + .file "startup.S" + .text +FUNCTION(_start) + /* + * EFI_SYSTEM_TABLE and EFI_HANDLE are passed in a1/a0. + */ + + ll a2, efi_image_handle_val + sl a0, 0(a2) + ll a2, efi_system_table_val + sl a1, 0(a2) + ll a2, grub_main_val + jr a2 +grub_main_val: + .quad EXT_C(grub_main) +efi_system_table_val: + .quad EXT_C(grub_efi_system_table) +efi_image_handle_val: + .quad EXT_C(grub_efi_image_handle) From patchwork Tue Feb 12 10:31:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 158147 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3670002jaa; Tue, 12 Feb 2019 02:37:56 -0800 (PST) X-Google-Smtp-Source: AHgI3IZF78AIbh09PnZZnTKnPi04i1t+NOwLSNoMhZyyyEdoiTHOVJr7YjJgwh8qgB+VQKHrbbgV X-Received: by 2002:a25:1182:: with SMTP id 124mr2190594ybr.307.1549967876347; Tue, 12 Feb 2019 02:37:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967876; cv=none; d=google.com; s=arc-20160816; b=tq8u2gk0eYgJPjm+q7pN6AUOEJCIkMMKfIweNZO4WZtPqpuXZp7UgsOYJDs7F32ElS V+yKWfWcpHxav9oASY+HRvy1PquIpVhmHpDuz6OH0w+Q7osNBBvSRgH6Odd1cHe0EMTx /1euT8GZ35mfyEoqnDV7BWG/tTPvVGM2EiCOIOfEg/3K5sWEUpEg4VOSy/jqkvtSaXWv ieQKG3uOh7OZKqYJbWmaOc2hJdwQioi5wfzcXNg1+Ud+vOKLAJWVDuk0DbwMtQxKa/t4 ecH0EvvtR3i+rz/qITu9Pmu7RehfbuQdgM3+9srUt2DNSRoAIhCKyUSNbUy8ZH0Vzm5t fQHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=Nv/Vy9eILNn8B/Q08M7RfkWGv9+yb9lSMlQigAXovro=; b=WcMAGG8ugeUAvp+4pp3JVqpE8l228dDTblQgDvC/QFSDAdQMhbAfIGgoFUqSsSNHii iylt6MsNrXoXfGGRFN3lbZWeolWaONnWO/DjsxBVkl53KihCqHQ00wybCeEbqLDcUXAz 4oqla+uwyzVaf29y1Zf4INVoZ3NetAEu/ajVmIhPdwwffcKAgd8PonMKDAl9g1JhcmBj MnZcHyctG60ysI9KSjD7d/eKqcYr9fTjJIVZlE4SQqwL3k7nfv+RZdwaobOVMqY1Wvna OAG8CbtGdny8LnhBb91/ni9VTwdzYCnvShgl3ysenvD6a+EyFaHsomGvPQoNmecTcXXF iDoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v204si7441899ybb.69.2019.02.12.02.37.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Feb 2019 02:37:56 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:37002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVRr-0004xZ-Nu for patch@linaro.org; Tue, 12 Feb 2019 05:37:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVMN-0000ym-FR for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtVML-0004Qt-Cm for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:15 -0500 Received: from mx2.suse.de ([195.135.220.15]:52048 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtVMI-00045f-TE for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:11 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1A34EB39B; Tue, 12 Feb 2019 10:31:12 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v6 06/11] RISC-V: Add Linux load logic Date: Tue, 12 Feb 2019 11:31:03 +0100 Message-Id: <20190212103108.56963-7-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190212103108.56963-1-agraf@suse.de> References: <20190212103108.56963-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng , Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" We currently only support to run grub on RISC-V as UEFI payload. Ideally, we also only want to support running Linux underneath as UEFI payload. Prepare that with some Linux boot stub code. Once the arm64 target is generalized, we can hook into that one and gain boot functionality. Signed-off-by: Alexander Graf --- v1 -> v2: - adapt to new grub_open_file() API - adapt to new grub_create_loader_cmdline() API v3 -> v4: - Change copyright from 2013 to 2018 - Coding style fixes v4 -> v5: - Use GRUB_EFI_LINUX_FDT_EXTRA_SPACE - Fix whitespace - s/failure/fail v5 -> v6: - remove most linux logic --- grub-core/loader/riscv/linux.c | 59 ++++++++++++++++++++++++++++++++++++++++++ include/grub/riscv32/linux.h | 41 +++++++++++++++++++++++++++++ include/grub/riscv64/linux.h | 43 ++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 grub-core/loader/riscv/linux.c create mode 100644 include/grub/riscv32/linux.h create mode 100644 include/grub/riscv64/linux.h -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel Reviewed-by: Alistair Francis Reviewed-by: Daniel Kiper diff --git a/grub-core/loader/riscv/linux.c b/grub-core/loader/riscv/linux.c new file mode 100644 index 000000000..d17c488e1 --- /dev/null +++ b/grub-core/loader/riscv/linux.c @@ -0,0 +1,59 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +static grub_err_t +grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char *argv[] __attribute__ ((unused))) +{ + grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); + + return grub_errno; +} + +static grub_err_t +grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char *argv[] __attribute__ ((unused))) +{ + grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); + + return grub_errno; +} + +static grub_command_t cmd_linux, cmd_initrd; + +GRUB_MOD_INIT (linux) +{ + cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, + N_("Load Linux.")); + cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, + N_("Load initrd.")); +} + +GRUB_MOD_FINI (linux) +{ + grub_unregister_command (cmd_linux); + grub_unregister_command (cmd_initrd); +} diff --git a/include/grub/riscv32/linux.h b/include/grub/riscv32/linux.h new file mode 100644 index 000000000..b8ed39407 --- /dev/null +++ b/include/grub/riscv32/linux.h @@ -0,0 +1,41 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_RISCV32_LINUX_HEADER +#define GRUB_RISCV32_LINUX_HEADER 1 + +#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ + +/* From linux/Documentation/riscv/booting.txt */ +struct linux_riscv_kernel_header +{ + grub_uint32_t code0; /* Executable code */ + grub_uint32_t code1; /* Executable code */ + grub_uint64_t text_offset; /* Image load offset */ + grub_uint64_t res0; /* reserved */ + grub_uint64_t res1; /* reserved */ + grub_uint64_t res2; /* reserved */ + grub_uint64_t res3; /* reserved */ + grub_uint64_t res4; /* reserved */ + grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ + grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ +}; + +# define linux_arch_kernel_header linux_riscv_kernel_header + +#endif /* ! GRUB_RISCV32_LINUX_HEADER */ diff --git a/include/grub/riscv64/linux.h b/include/grub/riscv64/linux.h new file mode 100644 index 000000000..29140e45e --- /dev/null +++ b/include/grub/riscv64/linux.h @@ -0,0 +1,43 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_RISCV64_LINUX_HEADER +#define GRUB_RISCV64_LINUX_HEADER 1 + +#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ + +#define GRUB_EFI_PE_MAGIC 0x5A4D + +/* From linux/Documentation/riscv/booting.txt */ +struct linux_riscv_kernel_header +{ + grub_uint32_t code0; /* Executable code */ + grub_uint32_t code1; /* Executable code */ + grub_uint64_t text_offset; /* Image load offset */ + grub_uint64_t res0; /* reserved */ + grub_uint64_t res1; /* reserved */ + grub_uint64_t res2; /* reserved */ + grub_uint64_t res3; /* reserved */ + grub_uint64_t res4; /* reserved */ + grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ + grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ +}; + +# define linux_arch_kernel_header linux_riscv_kernel_header + +#endif /* ! GRUB_RISCV64_LINUX_HEADER */ From patchwork Tue Feb 12 10:31:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 158143 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3667403jaa; Tue, 12 Feb 2019 02:35:18 -0800 (PST) X-Google-Smtp-Source: AHgI3Iba5l5hwgG8q5qZ6nSOfLA9AOcuifgTaNb1pfG3ANcD4Qm9t5uB4Fq6h9S4Wwx7htLMbG+m X-Received: by 2002:a25:6642:: with SMTP id z2mr2212163ybm.302.1549967718714; Tue, 12 Feb 2019 02:35:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967718; cv=none; d=google.com; s=arc-20160816; b=QefKPTSR0eFcb7XTg9JK8wvHFVEJCihEMVzQcTqzUAfVekFcN60ADYj6MIqkuVZpdy 8ZHjrzqyo5pkTNCT7BeEvleZ3j7d50Au0lTAzGzUg/NpXoG04IkbAMa6JniWk0tkrvSw m6KjCJx7sbfN0jwLzDmdFclQMY/hiuRyTpt6LTCp7BOtcZqj4REn/QaOotkpxarIyCGB pHyfBsvaUniwJABencyLX11C8jjkoBQXcNdLAD+anIxlmVPFGMtS2UvqtPd1Xn8Yz+w4 XI/NGtfTrtsUPX9WyCf9qIm3Rc39tUhbwuZHFkdZqNdr+FcRwwb7wU0Uat4bcdHWqQKV 5rbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=ZB6AyXg3uTnFwzHBIsg8mNAMgNGD1t70yyoh/wc9Hs0=; b=082vae6w7X3QvL9iec/iUfBXxlrS08qkfKlWSUQFFSFsv+/KW440/iXoavTUgAmovJ TZxFBpowR+nhLlkW1xYlqdWsPy5YtZywTgFUwDBF1+DYgO3+14y2Wj+zorZKXYE1hhrO usVJIiPrmvtISP5/O/7fA9KKxETmmFmUBWWi8k6n6xdOKZ3vLFQTPiNBgtmA2QnXUo8l fvdCA1WVr5TSc4Kf6AteYX+gpyZ5C6XYf9+jEjoxS5Nv17nvG2Wivj7bjcdw5BOtCChJ tdA8sbSjwUWdYE6JrvOPgkKzFf7GP+v8E6HxO+AuPZV1OsNpE5Rt0JRYyrA+5ktskSUV rCpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 133si7905308ybd.490.2019.02.12.02.35.18 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Feb 2019 02:35:18 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:36954 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVPK-00030G-5g for patch@linaro.org; Tue, 12 Feb 2019 05:35:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVMP-00010U-R1 for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtVML-0004Qn-AU for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:17 -0500 Received: from mx2.suse.de ([195.135.220.15]:52068 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtVMI-00049O-R7 for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:11 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1B0BFB3B1; Tue, 12 Feb 2019 10:31:12 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v6 07/11] RISC-V: Add awareness for RISC-V reloations Date: Tue, 12 Feb 2019 11:31:04 +0100 Message-Id: <20190212103108.56963-8-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190212103108.56963-1-agraf@suse.de> References: <20190212103108.56963-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng , Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" This patch adds awareness of RISC-V relocations throughout the grub tools as well as dynamic linkage and elf->PE relocation conversion support. Signed-off-by: Alexander Graf --- v2 -> v3: - Fix riscv32 target v3 -> v4: - Change copyright from 2013 to 2018 - Add spec reference v4 -> v5: - Add spec link to mkimagexx.c - Remove curly braces --- grub-core/kern/dl.c | 6 +- grub-core/kern/riscv/dl.c | 340 ++++++++++++++++++++++++++++++++++++++++++++ include/grub/dl.h | 6 +- util/grub-mkimagexx.c | 259 +++++++++++++++++++++++++++++++++ util/grub-module-verifier.c | 56 ++++++++ 5 files changed, 662 insertions(+), 5 deletions(-) create mode 100644 grub-core/kern/riscv/dl.c -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel Reviewed-by: Alistair Francis Reviewed-by: Daniel Kiper diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index f8d58f029..48eb5e7b6 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -225,7 +225,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) unsigned i; const Elf_Shdr *s; grub_size_t tsize = 0, talign = 1; -#if !defined (__i386__) && !defined (__x86_64__) +#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) grub_size_t tramp; grub_size_t got; grub_err_t err; @@ -241,7 +241,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) talign = s->sh_addralign; } -#if !defined (__i386__) && !defined (__x86_64__) +#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) err = grub_arch_dl_get_tramp_got_size (e, &tramp, &got); if (err) return err; @@ -304,7 +304,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) mod->segment = seg; } } -#if !defined (__i386__) && !defined (__x86_64__) +#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, GRUB_ARCH_DL_TRAMP_ALIGN); mod->tramp = ptr; mod->trampptr = ptr; diff --git a/grub-core/kern/riscv/dl.c b/grub-core/kern/riscv/dl.c new file mode 100644 index 000000000..6fb8385ef --- /dev/null +++ b/grub-core/kern/riscv/dl.c @@ -0,0 +1,340 @@ +/* dl.c - arch-dependent part of loadable module support */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +/* + * Instructions and instruction encoding are documented in the RISC-V + * specification. This file is based on version 2.2: + * + * https://github.com/riscv/riscv-isa-manual/blob/master/release/riscv-spec-v2.2.pdf + */ +#define LDR 0x58000050 +#define BR 0xd61f0200 + +/* + * Check if EHDR is a valid ELF header. + */ +grub_err_t +grub_arch_dl_check_header (void *ehdr) +{ + Elf_Ehdr *e = ehdr; + + /* Check the magic numbers. */ + if (e->e_ident[EI_DATA] != ELFDATA2LSB || e->e_machine != EM_RISCV) + return grub_error (GRUB_ERR_BAD_OS, + N_("invalid arch-dependent ELF magic")); + + return GRUB_ERR_NONE; +} + +#pragma GCC diagnostic ignored "-Wcast-align" + +/* Relocate symbols. */ +grub_err_t +grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, + Elf_Shdr *s, grub_dl_segment_t seg) +{ + Elf_Rel *rel, *max; + + for (rel = (Elf_Rel *) ((char *) ehdr + s->sh_offset), + max = (Elf_Rel *) ((char *) rel + s->sh_size); + rel < max; + rel = (Elf_Rel *) ((char *) rel + s->sh_entsize)) + { + Elf_Sym *sym; + void *place; + grub_size_t sym_addr; + + if (rel->r_offset >= seg->size) + return grub_error (GRUB_ERR_BAD_MODULE, + "reloc offset is out of the segment"); + + sym = (Elf_Sym *) ((char *) mod->symtab + + mod->symsize * ELF_R_SYM (rel->r_info)); + + sym_addr = sym->st_value; + if (s->sh_type == SHT_RELA) + sym_addr += ((Elf_Rela *) rel)->r_addend; + + place = (void *) ((grub_addr_t) seg->addr + rel->r_offset); + + switch (ELF_R_TYPE (rel->r_info)) + { + case R_RISCV_32: + { + grub_uint32_t *abs_place = place; + + grub_dprintf ("dl", " reloc_abs32 %p => 0x%016llx\n", + place, (unsigned long long) sym_addr); + + *abs_place = (grub_uint32_t) sym_addr; + } + break; + case R_RISCV_64: + { + grub_size_t *abs_place = place; + + grub_dprintf ("dl", " reloc_abs64 %p => 0x%016llx\n", + place, (unsigned long long) sym_addr); + + *abs_place = (grub_size_t) sym_addr; + } + break; + + case R_RISCV_ADD8: + { + grub_uint8_t *abs_place = place; + + *abs_place += (grub_uint8_t) sym_addr; + } + break; + case R_RISCV_ADD16: + { + grub_uint16_t *abs_place = place; + + *abs_place += (grub_uint16_t) sym_addr; + } + break; + case R_RISCV_ADD32: + { + grub_uint32_t *abs_place = place; + + *abs_place += (grub_uint32_t) sym_addr; + } + break; + case R_RISCV_ADD64: + { + grub_size_t *abs_place = place; + + *abs_place += (grub_size_t) sym_addr; + } + break; + + case R_RISCV_SUB8: + { + grub_uint8_t *abs_place = place; + + *abs_place -= (grub_uint8_t) sym_addr; + } + break; + case R_RISCV_SUB16: + { + grub_uint16_t *abs_place = place; + + *abs_place -= (grub_uint16_t) sym_addr; + } + break; + case R_RISCV_SUB32: + { + grub_uint32_t *abs_place = place; + + *abs_place -= (grub_uint32_t) sym_addr; + } + break; + case R_RISCV_SUB64: + { + grub_size_t *abs_place = place; + + *abs_place -= (grub_size_t) sym_addr; + } + break; + + case R_RISCV_BRANCH: + { + grub_uint32_t *abs_place = place; + grub_ssize_t off = sym_addr - (grub_addr_t) place; + grub_uint32_t imm12 = (off & 0x1000) << (31 - 12); + grub_uint32_t imm11 = (off & 0x800) >> (11 - 7); + grub_uint32_t imm10_5 = (off & 0x7e0) << (30 - 10); + grub_uint32_t imm4_1 = (off & 0x1e) << (11 - 4); + *abs_place = (*abs_place & 0x1fff07f) + | imm12 | imm11 | imm10_5 | imm4_1; + } + break; + + case R_RISCV_JAL: + { + grub_uint32_t *abs_place = place; + grub_ssize_t off = sym_addr - (grub_addr_t) place; + grub_uint32_t imm20 = (off & 0x100000) << (31 - 20); + grub_uint32_t imm19_12 = (off & 0xff000); + grub_uint32_t imm11 = (off & 0x800) << (20 - 11); + grub_uint32_t imm10_1 = (off & 0x7fe) << (30 - 10); + *abs_place = (*abs_place & 0xfff) + | imm20 | imm19_12 | imm11 | imm10_1; + } + break; + + case R_RISCV_CALL: + { + grub_uint32_t *abs_place = place; + grub_ssize_t off = sym_addr - (grub_addr_t) place; + grub_uint32_t hi20, lo12; + + if (off != (grub_int32_t) off) + return grub_error (GRUB_ERR_BAD_MODULE, "relocation overflow"); + + hi20 = (off + 0x800) & 0xfffff000; + lo12 = (off - hi20) & 0xfff; + abs_place[0] = (abs_place[0] & 0xfff) | hi20; + abs_place[1] = (abs_place[1] & 0xfffff) | (lo12 << 20); + } + break; + + case R_RISCV_RVC_BRANCH: + { + grub_uint16_t *abs_place = place; + grub_ssize_t off = sym_addr - (grub_addr_t) place; + grub_uint16_t imm8 = (off & 0x100) << (12 - 8); + grub_uint16_t imm7_6 = (off & 0xc0) >> (6 - 5); + grub_uint16_t imm5 = (off & 0x20) >> (5 - 2); + grub_uint16_t imm4_3 = (off & 0x18) << (12 - 5); + grub_uint16_t imm2_1 = (off & 0x6) << (12 - 10); + *abs_place = (*abs_place & 0xe383) + | imm8 | imm7_6 | imm5 | imm4_3 | imm2_1; + } + break; + + case R_RISCV_RVC_JUMP: + { + grub_uint16_t *abs_place = place; + grub_ssize_t off = sym_addr - (grub_addr_t) place; + grub_uint16_t imm11 = (off & 0x800) << (12 - 11); + grub_uint16_t imm10 = (off & 0x400) >> (10 - 8); + grub_uint16_t imm9_8 = (off & 0x300) << (12 - 11); + grub_uint16_t imm7 = (off & 0x80) >> (7 - 6); + grub_uint16_t imm6 = (off & 0x40) << (12 - 11); + grub_uint16_t imm5 = (off & 0x20) >> (5 - 2); + grub_uint16_t imm4 = (off & 0x10) << (12 - 5); + grub_uint16_t imm3_1 = (off & 0xe) << (12 - 10); + *abs_place = ((*abs_place & 0xe003) + | imm11 | imm10 | imm9_8 | imm7 | imm6 + | imm5 | imm4 | imm3_1); + } + break; + + case R_RISCV_PCREL_HI20: + { + grub_uint32_t *abs_place = place; + grub_ssize_t off = sym_addr - (grub_addr_t) place; + grub_int32_t hi20; + + if (off != (grub_int32_t)off) + return grub_error (GRUB_ERR_BAD_MODULE, "relocation overflow"); + + hi20 = (off + 0x800) & 0xfffff000; + *abs_place = (*abs_place & 0xfff) | hi20; + } + break; + + case R_RISCV_PCREL_LO12_I: + case R_RISCV_PCREL_LO12_S: + { + grub_uint32_t *t32 = place; + Elf_Rela *rel2; + /* Search backwards for matching HI20 reloc. */ + for (rel2 = (Elf_Rela *) ((char *) rel - s->sh_entsize); + (unsigned long)rel2 >= ((unsigned long)ehdr + s->sh_offset); + rel2 = (Elf_Rela *) ((char *) rel2 - s->sh_entsize)) + { + Elf_Addr rel2_info; + Elf_Addr rel2_offset; + Elf_Addr rel2_sym_addr; + Elf_Addr rel2_loc; + grub_ssize_t rel2_off; + grub_ssize_t off; + Elf_Sym *sym2; + + rel2_offset = rel2->r_offset; + rel2_info = rel2->r_info; + rel2_loc = (grub_addr_t) seg->addr + rel2_offset; + + if (ELF_R_TYPE (rel2_info) == R_RISCV_PCREL_HI20 + && rel2_loc == sym_addr) + { + sym2 = (Elf_Sym *) ((char *) mod->symtab + + mod->symsize * ELF_R_SYM (rel2->r_info)); + rel2_sym_addr = sym2->st_value; + if (s->sh_type == SHT_RELA) + rel2_sym_addr += ((Elf_Rela *) rel2)->r_addend; + + rel2_off = rel2_sym_addr - rel2_loc; + off = rel2_off - ((rel2_off + 0x800) & 0xfffff000); + + if (ELF_R_TYPE (rel->r_info) == R_RISCV_PCREL_LO12_I) + *t32 = (*t32 & 0xfffff) | (off & 0xfff) << 20; + else + { + grub_uint32_t imm11_5 = (off & 0xfe0) << (31 - 11); + grub_uint32_t imm4_0 = (off & 0x1f) << (11 - 4); + *t32 = (*t32 & 0x1fff07f) | imm11_5 | imm4_0; + } + break; + } + } + if ((unsigned long)rel2 < ((unsigned long)ehdr + s->sh_offset)) + return grub_error (GRUB_ERR_BAD_MODULE, "cannot find matching HI20 relocation"); + } + break; + + case R_RISCV_HI20: + { + grub_uint32_t *abs_place = place; + *abs_place = (*abs_place & 0xfff) | + (((grub_int32_t) sym_addr + 0x800) & 0xfffff000); + } + break; + + case R_RISCV_LO12_I: + { + grub_uint32_t *abs_place = place; + grub_int32_t lo12 = (grub_int32_t) sym_addr - + (((grub_int32_t) sym_addr + 0x800) & 0xfffff000); + *abs_place = (*abs_place & 0xfffff) | ((lo12 & 0xfff) << 20); + } + break; + + case R_RISCV_LO12_S: + { + grub_uint32_t *abs_place = place; + grub_int32_t lo12 = (grub_int32_t) sym_addr - + (((grub_int32_t) sym_addr + 0x800) & 0xfffff000); + grub_uint32_t imm11_5 = (lo12 & 0xfe0) << (31 - 11); + grub_uint32_t imm4_0 = (lo12 & 0x1f) << (11 - 4); + *abs_place = (*abs_place & 0x1fff07f) | imm11_5 | imm4_0; + } + break; + + case R_RISCV_RELAX: + break; + default: + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + N_("relocation 0x%x is not implemented yet"), + ELF_R_TYPE (rel->r_info)); + } + } + + return GRUB_ERR_NONE; +} diff --git a/include/grub/dl.h b/include/grub/dl.h index fee27a14c..f03c03561 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -292,12 +292,14 @@ grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, grub_size_t *got); #endif -#if defined (__powerpc__) || defined (__mips__) || defined (__arm__) +#if defined (__powerpc__) || defined (__mips__) || defined (__arm__) || \ + (defined(__riscv) && (__riscv_xlen == 32)) #define GRUB_ARCH_DL_TRAMP_ALIGN 4 #define GRUB_ARCH_DL_GOT_ALIGN 4 #endif -#if defined (__aarch64__) || defined (__sparc__) +#if defined (__aarch64__) || defined (__sparc__) || \ + (defined(__riscv) && (__riscv_xlen == 64)) #define GRUB_ARCH_DL_TRAMP_ALIGN 8 #define GRUB_ARCH_DL_GOT_ALIGN 8 #endif diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index e94a721b4..c04f17d4e 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -1226,6 +1226,196 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, break; } #endif /* MKIMAGE_ELF32 */ + case EM_RISCV: + { + grub_uint64_t *t64 = (grub_uint64_t *) target; + grub_uint32_t *t32 = (grub_uint32_t *) target; + grub_uint16_t *t16 = (grub_uint16_t *) target; + grub_uint8_t *t8 = (grub_uint8_t *) target; + grub_int64_t off = (long)sym_addr - target_section_addr - offset + - image_target->vaddr_offset; + + /* + * Instructions and instruction encoding are documented in the RISC-V + * specification. This file is based on version 2.2: + * + * https://github.com/riscv/riscv-isa-manual/blob/master/release/riscv-spec-v2.2.pdf + */ + + sym_addr += addend; + + switch (ELF_R_TYPE (info)) + { + case R_RISCV_ADD8: + *t8 = *t8 + sym_addr; + break; + case R_RISCV_ADD16: + *t16 = grub_host_to_target16 (grub_target_to_host16 (*t16) + sym_addr); + break; + case R_RISCV_32: + case R_RISCV_ADD32: + *t32 = grub_host_to_target32 (grub_target_to_host32 (*t32) + sym_addr); + break; + case R_RISCV_64: + case R_RISCV_ADD64: + *t64 = grub_host_to_target64 (grub_target_to_host64 (*t64) + sym_addr); + break; + + case R_RISCV_SUB8: + *t8 = sym_addr - *t8; + break; + case R_RISCV_SUB16: + *t16 = grub_host_to_target16 (grub_target_to_host16 (*t16) - sym_addr); + break; + case R_RISCV_SUB32: + *t32 = grub_host_to_target32 (grub_target_to_host32 (*t32) - sym_addr); + break; + case R_RISCV_SUB64: + *t64 = grub_host_to_target64 (grub_target_to_host64 (*t64) - sym_addr); + break; + case R_RISCV_BRANCH: + { + grub_uint32_t imm12 = (off & 0x1000) << (31 - 12); + grub_uint32_t imm11 = (off & 0x800) >> (11 - 7); + grub_uint32_t imm10_5 = (off & 0x7e0) << (30 - 10); + grub_uint32_t imm4_1 = (off & 0x1e) << (11 - 4); + *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0x1fff07f) + | imm12 | imm11 | imm10_5 | imm4_1); + } + break; + case R_RISCV_JAL: + { + grub_uint32_t imm20 = (off & 0x100000) << (31 - 20); + grub_uint32_t imm19_12 = (off & 0xff000); + grub_uint32_t imm11 = (off & 0x800) << (20 - 11); + grub_uint32_t imm10_1 = (off & 0x7fe) << (30 - 10); + *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0xfff) + | imm20 | imm19_12 | imm11 | imm10_1); + } + break; + case R_RISCV_CALL: + { + grub_uint32_t hi20, lo12; + + if (off != (grub_int32_t)off) + grub_util_error ("target %lx not reachable from pc=%lx", (long)sym_addr, (long)target); + + hi20 = (off + 0x800) & 0xfffff000; + lo12 = (off - hi20) & 0xfff; + t32[0] = grub_host_to_target32 ((grub_target_to_host32 (t32[0]) & 0xfff) | hi20); + t32[1] = grub_host_to_target32 ((grub_target_to_host32 (t32[1]) & 0xfffff) | (lo12 << 20)); + } + break; + case R_RISCV_RVC_BRANCH: + { + grub_uint16_t imm8 = (off & 0x100) << (12 - 8); + grub_uint16_t imm7_6 = (off & 0xc0) >> (6 - 5); + grub_uint16_t imm5 = (off & 0x20) >> (5 - 2); + grub_uint16_t imm4_3 = (off & 0x18) << (12 - 5); + grub_uint16_t imm2_1 = (off & 0x6) << (12 - 10); + *t16 = grub_host_to_target16 ((grub_target_to_host16 (*t16) & 0xe383) + | imm8 | imm7_6 | imm5 | imm4_3 | imm2_1); + } + break; + case R_RISCV_RVC_JUMP: + { + grub_uint16_t imm11 = (off & 0x800) << (12 - 11); + grub_uint16_t imm10 = (off & 0x400) >> (10 - 8); + grub_uint16_t imm9_8 = (off & 0x300) << (12 - 11); + grub_uint16_t imm7 = (off & 0x80) >> (7 - 6); + grub_uint16_t imm6 = (off & 0x40) << (12 - 11); + grub_uint16_t imm5 = (off & 0x20) >> (5 - 2); + grub_uint16_t imm4 = (off & 0x10) << (12 - 5); + grub_uint16_t imm3_1 = (off & 0xe) << (12 - 10); + *t16 = grub_host_to_target16 ((grub_target_to_host16 (*t16) & 0xe003) + | imm11 | imm10 | imm9_8 | imm7 | imm6 + | imm5 | imm4 | imm3_1); + } + break; + case R_RISCV_PCREL_HI20: + { + grub_int32_t hi20; + + if (off != (grub_int32_t)off) + grub_util_error ("target %lx not reachable from pc=%lx", (long)sym_addr, (long)target); + + hi20 = (off + 0x800) & 0xfffff000; + *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0xfff) | hi20); + } + break; + case R_RISCV_PCREL_LO12_I: + case R_RISCV_PCREL_LO12_S: + { + Elf_Rela *rel2; + Elf_Word k; + /* Search backwards for matching HI20 reloc. */ + for (k = j, rel2 = (Elf_Rela *) ((char *) r - r_size); + k > 0; + k--, rel2 = (Elf_Rela *) ((char *) rel2 - r_size)) + { + Elf_Addr rel2_info; + Elf_Addr rel2_offset; + Elf_Addr rel2_sym_addr; + Elf_Addr rel2_addend; + Elf_Addr rel2_loc; + grub_int64_t rel2_off; + + rel2_offset = grub_target_to_host (rel2->r_offset); + rel2_info = grub_target_to_host (rel2->r_info); + rel2_loc = target_section_addr + rel2_offset + image_target->vaddr_offset; + + if (ELF_R_TYPE (rel2_info) == R_RISCV_PCREL_HI20 + && rel2_loc == sym_addr) + { + rel2_sym_addr = SUFFIX (get_symbol_address) + (e, smd->symtab, ELF_R_SYM (rel2_info), + image_target); + rel2_addend = (s->sh_type == grub_target_to_host32 (SHT_RELA)) ? + grub_target_to_host (rel2->r_addend) : 0; + rel2_off = rel2_sym_addr + rel2_addend - rel2_loc; + off = rel2_off - ((rel2_off + 0x800) & 0xfffff000); + + if (ELF_R_TYPE (info) == R_RISCV_PCREL_LO12_I) + *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0xfffff) | (off & 0xfff) << 20); + else + { + grub_uint32_t imm11_5 = (off & 0xfe0) << (31 - 11); + grub_uint32_t imm4_0 = (off & 0x1f) << (11 - 4); + *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0x1fff07f) | imm11_5 | imm4_0); + } + break; + } + } + if (k == 0) + grub_util_error ("cannot find matching HI20 relocation"); + } + break; + case R_RISCV_HI20: + *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0xfff) | (((grub_int32_t) sym_addr + 0x800) & 0xfffff000)); + break; + case R_RISCV_LO12_I: + { + grub_int32_t lo12 = (grub_int32_t) sym_addr - (((grub_int32_t) sym_addr + 0x800) & 0xfffff000); + *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0xfffff) | ((lo12 & 0xfff) << 20)); + } + break; + case R_RISCV_LO12_S: + { + grub_int32_t lo12 = (grub_int32_t) sym_addr - (((grub_int32_t) sym_addr + 0x800) & 0xfffff000); + grub_uint32_t imm11_5 = (lo12 & 0xfe0) << (31 - 11); + grub_uint32_t imm4_0 = (lo12 & 0x1f) << (11 - 4); + *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0x1fff07f) | imm11_5 | imm4_0); + } + break; + case R_RISCV_RELAX: + break; + default: + grub_util_error (_("relocation 0x%x is not implemented yet"), + (unsigned int) ELF_R_TYPE (info)); + break; + } + break; + } default: grub_util_error ("unknown architecture type %d", image_target->elf_target); @@ -1510,6 +1700,75 @@ translate_relocation_pe (struct translate_context *ctx, } break; #endif /* defined(MKIMAGE_ELF32) */ + case EM_RISCV: + switch (ELF_R_TYPE (info)) + { + case R_RISCV_32: + { + ctx->current_address + = add_fixup_entry (&ctx->lst, + GRUB_PE32_REL_BASED_HIGHLOW, + addr, 0, ctx->current_address, + image_target); + } + break; + case R_RISCV_64: + { + ctx->current_address + = add_fixup_entry (&ctx->lst, + GRUB_PE32_REL_BASED_DIR64, + addr, 0, ctx->current_address, + image_target); + } + break; + /* Relative relocations do not require fixup entries. */ + case R_RISCV_BRANCH: + case R_RISCV_JAL: + case R_RISCV_CALL: + case R_RISCV_PCREL_HI20: + case R_RISCV_PCREL_LO12_I: + case R_RISCV_PCREL_LO12_S: + case R_RISCV_RVC_BRANCH: + case R_RISCV_RVC_JUMP: + case R_RISCV_ADD32: + case R_RISCV_SUB32: + grub_util_info (" %s: not adding fixup: 0x%08x : 0x%08x", __FUNCTION__, (unsigned int) addr, (unsigned int) ctx->current_address); + break; + case R_RISCV_HI20: + { + ctx->current_address + = add_fixup_entry (&ctx->lst, + GRUB_PE32_REL_BASED_RISCV_HI20, + addr, 0, ctx->current_address, + image_target); + } + break; + case R_RISCV_LO12_I: + { + ctx->current_address + = add_fixup_entry (&ctx->lst, + GRUB_PE32_REL_BASED_RISCV_LOW12I, + addr, 0, ctx->current_address, + image_target); + } + break; + case R_RISCV_LO12_S: + { + ctx->current_address + = add_fixup_entry (&ctx->lst, + GRUB_PE32_REL_BASED_RISCV_LOW12S, + addr, 0, ctx->current_address, + image_target); + } + break; + case R_RISCV_RELAX: + break; + default: + grub_util_error (_("relocation 0x%x is not implemented yet"), + (unsigned int) ELF_R_TYPE (info)); + break; + } + break; default: grub_util_error ("unknown machine type 0x%x", image_target->elf_target); } diff --git a/util/grub-module-verifier.c b/util/grub-module-verifier.c index 979999cb9..60e4d2c06 100644 --- a/util/grub-module-verifier.c +++ b/util/grub-module-verifier.c @@ -117,6 +117,62 @@ struct grub_module_verifier_arch archs[] = { R_AARCH64_LDST64_ABS_LO12_NC, R_AARCH64_PREL32, -1 + } }, + { "riscv32", 4, 0, EM_RISCV, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){ + R_RISCV_32, + R_RISCV_64, + R_RISCV_ADD8, + R_RISCV_ADD16, + R_RISCV_ADD32, + R_RISCV_ADD64, + R_RISCV_SUB8, + R_RISCV_SUB16, + R_RISCV_SUB32, + R_RISCV_SUB64, + R_RISCV_ALIGN, + R_RISCV_BRANCH, + R_RISCV_CALL, + R_RISCV_CALL_PLT, + R_RISCV_GOT_HI20, + R_RISCV_HI20, + R_RISCV_JAL, + R_RISCV_LO12_I, + R_RISCV_LO12_S, + R_RISCV_PCREL_HI20, + R_RISCV_PCREL_LO12_I, + R_RISCV_PCREL_LO12_S, + R_RISCV_RELAX, + R_RISCV_RVC_BRANCH, + R_RISCV_RVC_JUMP, + -1 + } }, + { "riscv64", 8, 0, EM_RISCV, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){ + R_RISCV_32, + R_RISCV_64, + R_RISCV_ADD8, + R_RISCV_ADD16, + R_RISCV_ADD32, + R_RISCV_ADD64, + R_RISCV_SUB8, + R_RISCV_SUB16, + R_RISCV_SUB32, + R_RISCV_SUB64, + R_RISCV_ALIGN, + R_RISCV_BRANCH, + R_RISCV_CALL, + R_RISCV_CALL_PLT, + R_RISCV_GOT_HI20, + R_RISCV_HI20, + R_RISCV_JAL, + R_RISCV_LO12_I, + R_RISCV_LO12_S, + R_RISCV_PCREL_HI20, + R_RISCV_PCREL_LO12_I, + R_RISCV_PCREL_LO12_S, + R_RISCV_RELAX, + R_RISCV_RVC_BRANCH, + R_RISCV_RVC_JUMP, + -1 } }, }; From patchwork Tue Feb 12 10:31:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 158139 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3664576jaa; Tue, 12 Feb 2019 02:32:29 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ/5k+8FARyeNadjxN+aEc11sOpotfyIsPtmc1qQtcrSvBTXr2OaxBEJn+A97KNuasjdPc4 X-Received: by 2002:a25:ac2:: with SMTP id 185mr2177223ybk.349.1549967549213; Tue, 12 Feb 2019 02:32:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967549; cv=none; d=google.com; s=arc-20160816; b=gVv0+Cn6Y37/Vl851wxaj9C02W9p4uNCybqvJwdd7/eF2tcBzpgv0Dcbs0wVmvAGQX 7VAE8INUbApn5FlR4itqaeGWAeZfoOIOKRIVADoEPwlgRWp5eI8OAN2ZjJMOImUM2THJ 3rHa2XXLUN8On8VdrnM7F9F0Znc/HksdgVuCk0NwDRrsFerjXE7YYz+ERJVnYagesLsR Kei6jnKiNxScan8/W4JrpsYmdmPfJ+DTctaV1npj3gKYxBc9BMyc6PvhYl/Yy4A3/zYI bOgljq/+FQnoRCsp5Ib92t/mseaYf+0qiGUFewPUMFlFtgJ68Bre+fl0I2HI9RqzVNf7 o5yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=UkijJKmrBBIqhw64unGeMrPPbUoWglhBQ/8wye0UoMI=; b=KAaRFyrvKl8OgPjMQCVJQI+5sLlNrraTnknS8xDFq3tDRhHOR8OgoDu/EEvuMbDC6D uf44Ei/z/rWJUn10w65e/wwafl1b3fF5Th+x+KfZ0wctfxIyIB/FsXgZOHrwckcE41/Z fmwiY9iHFj1CmIBTM6lfzZnHV4Nf3n05ZR4Zuqqi9WRUAMq7i1CkbsQ9oF1WMl2I+AqN P3I8v5s87n5agCxTRxVY5RRxZmQNOg0PHxCHW9b09NTfe7Bn+rFJzgXYFmcYlreesPdB 7q3pFDSSH434T90qs/R3NQIIrzzB/H6d+VzFn//v5e/0ReTtFipTw0ASOtTn47gIjY/8 jrtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k64si7646339ywc.240.2019.02.12.02.32.29 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Feb 2019 02:32:29 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:36928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVMa-0000wJ-JL for patch@linaro.org; Tue, 12 Feb 2019 05:32:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVMH-0000ta-QX for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtVMC-0004BY-OM for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:08 -0500 Received: from mx2.suse.de ([195.135.220.15]:52038 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtVMC-0003kH-37 for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:04 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E9CFBB121; Tue, 12 Feb 2019 10:31:11 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v6 08/11] RISC-V: Add auxiliary files Date: Tue, 12 Feb 2019 11:31:05 +0100 Message-Id: <20190212103108.56963-9-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190212103108.56963-1-agraf@suse.de> References: <20190212103108.56963-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng , Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" To support a new architecture we need to provide a few helper functions for memory, cache, timer, etc support. This patch adds the remainders of those. Some bits are still disabled, as I couldn't guarantee that we're always running on models / in modes where the respective hardware is available. Signed-off-by: Alexander Graf --- v2 -> v3: - Fix riscv32 target v3 -> v4: - Change copyright from 2013 to 2018 - Fix coding style - Resurrect time reading code - Add fence.i for icache flush v4 -> v5: - Mark grub_arch_sync_dma_caches args as unused - Whitespace fix --- grub-core/kern/riscv/cache.c | 63 +++++++++++++++++++++++++++++++ grub-core/kern/riscv/cache_flush.S | 44 ++++++++++++++++++++++ grub-core/kern/riscv/efi/init.c | 76 ++++++++++++++++++++++++++++++++++++++ include/grub/riscv32/efi/memory.h | 6 +++ include/grub/riscv32/time.h | 28 ++++++++++++++ include/grub/riscv32/types.h | 34 +++++++++++++++++ include/grub/riscv64/efi/memory.h | 6 +++ include/grub/riscv64/time.h | 28 ++++++++++++++ include/grub/riscv64/types.h | 34 +++++++++++++++++ 9 files changed, 319 insertions(+) create mode 100644 grub-core/kern/riscv/cache.c create mode 100644 grub-core/kern/riscv/cache_flush.S create mode 100644 grub-core/kern/riscv/efi/init.c create mode 100644 include/grub/riscv32/efi/memory.h create mode 100644 include/grub/riscv32/time.h create mode 100644 include/grub/riscv32/types.h create mode 100644 include/grub/riscv64/efi/memory.h create mode 100644 include/grub/riscv64/time.h create mode 100644 include/grub/riscv64/types.h -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/kern/riscv/cache.c b/grub-core/kern/riscv/cache.c new file mode 100644 index 000000000..47777a033 --- /dev/null +++ b/grub-core/kern/riscv/cache.c @@ -0,0 +1,63 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include + +static grub_int64_t dlinesz; +static grub_int64_t ilinesz; + +/* Prototypes for asm functions. */ +void grub_arch_clean_dcache_range (grub_addr_t beg, grub_addr_t end, + grub_size_t line_size); +void grub_arch_invalidate_icache_range (grub_addr_t beg, grub_addr_t end, + grub_size_t line_size); + +static void +probe_caches (void) +{ + /* TODO */ + dlinesz = 32; + ilinesz = 32; +} + +void +grub_arch_sync_caches (void *address, grub_size_t len) +{ + grub_size_t start, end, max_align; + + if (dlinesz == 0) + probe_caches(); + if (dlinesz == 0) + grub_fatal ("Unknown cache line size!"); + + max_align = dlinesz > ilinesz ? dlinesz : ilinesz; + + start = ALIGN_DOWN ((grub_size_t) address, max_align); + end = ALIGN_UP ((grub_size_t) address + len, max_align); + + grub_arch_clean_dcache_range (start, end, dlinesz); + grub_arch_invalidate_icache_range (start, end, ilinesz); +} + +void +grub_arch_sync_dma_caches (volatile void *address __attribute__((unused)), + grub_size_t len __attribute__((unused))) +{ + /* DMA incoherent devices not supported yet */ +} diff --git a/grub-core/kern/riscv/cache_flush.S b/grub-core/kern/riscv/cache_flush.S new file mode 100644 index 000000000..41de6e411 --- /dev/null +++ b/grub-core/kern/riscv/cache_flush.S @@ -0,0 +1,44 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include + + .file "cache_flush.S" + .text + +/* + * Simple cache maintenance functions + */ + +/* + * a0 - *beg (inclusive) + * a1 - *end (exclusive) + * a2 - line size +*/ +FUNCTION(grub_arch_clean_dcache_range) + /* TODO */ + ret + +/* + * a0 - *beg (inclusive) + * a1 - *end (exclusive) + * a2 - line size + */ +FUNCTION(grub_arch_invalidate_icache_range) + fence.i + ret diff --git a/grub-core/kern/riscv/efi/init.c b/grub-core/kern/riscv/efi/init.c new file mode 100644 index 000000000..dd446ffd1 --- /dev/null +++ b/grub-core/kern/riscv/efi/init.c @@ -0,0 +1,76 @@ +/* init.c - initialize a riscv-based EFI system */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include + +static grub_uint64_t timer_frequency_in_khz; + +static grub_uint64_t +grub_efi_get_time_ms (void) +{ + grub_uint64_t tmr; + +#if __riscv_xlen == 64 + asm volatile ("rdcycle %0" : "=r" (tmr)); +#else + grub_uint32_t lo, hi, tmp; + asm volatile ( + "1:\n" + "rdcycleh %0\n" + "rdcycle %1\n" + "rdcycleh %2\n" + "bne %0, %2, 1b" + : "=&r" (hi), "=&r" (lo), "=&r" (tmp)); + tmr = ((u64)hi << 32) | lo; +#endif + + return tmr / timer_frequency_in_khz; +} + +void +grub_machine_init (void) +{ + grub_uint64_t time_before, time_after; + + grub_efi_init (); + + /* Calculate timer frequency */ + timer_frequency_in_khz = 1; + time_before = grub_efi_get_time_ms(); + grub_efi_stall(1000); + time_after = grub_efi_get_time_ms(); + timer_frequency_in_khz = time_after - time_before; + + grub_install_get_time_ms (grub_efi_get_time_ms); +} + +void +grub_machine_fini (int flags) +{ + if (!(flags & GRUB_LOADER_FLAG_NORETURN)) + return; + + grub_efi_fini (); +} diff --git a/include/grub/riscv32/efi/memory.h b/include/grub/riscv32/efi/memory.h new file mode 100644 index 000000000..e61c474ff --- /dev/null +++ b/include/grub/riscv32/efi/memory.h @@ -0,0 +1,6 @@ +#ifndef GRUB_MEMORY_CPU_HEADER +#include + +#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffUL + +#endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/riscv32/time.h b/include/grub/riscv32/time.h new file mode 100644 index 000000000..20abd648b --- /dev/null +++ b/include/grub/riscv32/time.h @@ -0,0 +1,28 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inline void +grub_cpu_idle (void) +{ + /* TODO */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */ diff --git a/include/grub/riscv32/types.h b/include/grub/riscv32/types.h new file mode 100644 index 000000000..fac57a752 --- /dev/null +++ b/include/grub/riscv32/types.h @@ -0,0 +1,34 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_TYPES_CPU_HEADER +#define GRUB_TYPES_CPU_HEADER 1 + +/* The size of void *. */ +#define GRUB_TARGET_SIZEOF_VOID_P 4 + +/* The size of long. */ +#define GRUB_TARGET_SIZEOF_LONG 4 + +/* currently only support little-endian. */ +#undef GRUB_TARGET_WORDS_BIGENDIAN + +/* Unaligned accesses can be very slow, so avoid them */ +#undef GRUB_HAVE_UNALIGNED_ACCESS + +#endif /* ! GRUB_TYPES_CPU_HEADER */ diff --git a/include/grub/riscv64/efi/memory.h b/include/grub/riscv64/efi/memory.h new file mode 100644 index 000000000..c6cb32417 --- /dev/null +++ b/include/grub/riscv64/efi/memory.h @@ -0,0 +1,6 @@ +#ifndef GRUB_MEMORY_CPU_HEADER +#include + +#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL + +#endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/riscv64/time.h b/include/grub/riscv64/time.h new file mode 100644 index 000000000..20abd648b --- /dev/null +++ b/include/grub/riscv64/time.h @@ -0,0 +1,28 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inline void +grub_cpu_idle (void) +{ + /* TODO */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */ diff --git a/include/grub/riscv64/types.h b/include/grub/riscv64/types.h new file mode 100644 index 000000000..c6bcad470 --- /dev/null +++ b/include/grub/riscv64/types.h @@ -0,0 +1,34 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_TYPES_CPU_HEADER +#define GRUB_TYPES_CPU_HEADER 1 + +/* The size of void *. */ +#define GRUB_TARGET_SIZEOF_VOID_P 8 + +/* The size of long. */ +#define GRUB_TARGET_SIZEOF_LONG 8 + +/* currently only support little-endian. */ +#undef GRUB_TARGET_WORDS_BIGENDIAN + +/* Unaligned accesses can be very slow, so avoid them */ +#undef GRUB_HAVE_UNALIGNED_ACCESS + +#endif /* ! GRUB_TYPES_CPU_HEADER */ From patchwork Tue Feb 12 10:31:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 158142 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3665951jaa; Tue, 12 Feb 2019 02:33:53 -0800 (PST) X-Google-Smtp-Source: AHgI3IZpf9JknkJHo672o9E1soq2v8yyJbNwulpgE6KyLnJiWFEYga+0j+QvzbMY1oTy0fzasXPG X-Received: by 2002:a81:a68e:: with SMTP id d136mr2189788ywh.214.1549967633797; Tue, 12 Feb 2019 02:33:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967633; cv=none; d=google.com; s=arc-20160816; b=iYqI6APo6KwHhLN+9jszDOBaag3LOGn/sE0zAMrl2uhutuAInH/nU37tdWjWkJv6w8 5MS73PSd03RfzcpHxKHHXB9NpPMhC1YuFeexrtZTxXLmbci555Hgegn5ooGdwZP2iSZ3 NIvI8zsruPMzGcQ4IcZC0+LgIxUF0MwSF/CbIlW+q8srIL72rtXvOEwOE61ZRdYYMiWc RVflR/oRtfJOWQXGeCpO4o62co7et5W4ZWKDbIwCBSF8uNXR4GIcpjhJMUKD3PrOvLbW xUuXKwwVbm1Gcv3AmGZX6Zyn5XggcZbHG+HJ/8eIbOxhyCgEgBRM440/ouSwc2uD97xh hjkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=nytzG3hUgOFCE7zE30Hr1gRhEyiv7oSPUiFNEnOYc8Q=; b=yROeE7RJCuppREJ3eLKQ8Ksz7PGx/hMj+1wTgecZBHfvfRNJk9zUtW5aKYDneUS/gr qQ75s51/QGL5Ui4g2Aut/VrIY3LKjIcY4zG8jpKYr1NUMHvwoatXrbVLlJXSW35OGkyn V2m90ZFI7JL9ohykfkPqA1ziXgLXR0uXRiXuNU3u2lH6Rv3J6aAa8cUHFqh6wy68uMfT 1fsxY5+hlRG+0Uv+E1o2IUvraJmLKxWv0xl4mZuu34t+3FkfPSvklQLUO6iG9703oLss QQezvB9xeOykf0QEnwYuaRaq650AE3JGJorhb4eWK1oohcBsc/h9MwDXsI3QaQk3Kl9C FwIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a13si591262ybe.315.2019.02.12.02.33.53 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Feb 2019 02:33:53 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:36936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVNx-0001y3-8Z for patch@linaro.org; Tue, 12 Feb 2019 05:33:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVML-0000w7-BV for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtVMJ-0004Mi-9V for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:13 -0500 Received: from mx2.suse.de ([195.135.220.15]:52046 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtVMH-00045e-4Y for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:10 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0EFF7B25D; Tue, 12 Feb 2019 10:31:12 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v6 09/11] RISC-V: Add libgcc helpers for clz Date: Tue, 12 Feb 2019 11:31:06 +0100 Message-Id: <20190212103108.56963-10-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190212103108.56963-1-agraf@suse.de> References: <20190212103108.56963-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng , Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" Gcc may decide it wants to call helper functions to execute clz. Provide them in our own copy of libgcc. Signed-off-by: Alexander Graf --- grub-core/kern/compiler-rt.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/grub/compiler-rt.h | 7 +++++++ 2 files changed, 49 insertions(+) -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/kern/compiler-rt.c b/grub-core/kern/compiler-rt.c index 5cfcb3907..404902119 100644 --- a/grub-core/kern/compiler-rt.c +++ b/grub-core/kern/compiler-rt.c @@ -417,3 +417,45 @@ __aeabi_llsl (grub_uint64_t u, int b) __attribute__ ((alias ("__ashldi3"))); #endif + +#ifdef __riscv + +/* Based on libgcc from gcc suite. */ +int +__clzsi2 (grub_uint32_t val) +{ + int i = 32; + int j = 16; + int temp; + + for (; j; j >>= 1) + { + if ((temp = val) >> j) + { + if (j == 1) + { + return (i - 2); + } + else + { + i -= j; + val = temp; + } + } + } + return (i - val); +} + +int +__clzdi2 (grub_uint64_t val) +{ + if (val >> 32) + { + return __clzsi2 (val >> 32); + } + else + { + return __clzsi2 (val) + 32; + } +} +#endif diff --git a/include/grub/compiler-rt.h b/include/grub/compiler-rt.h index dc73649a5..2cc69e239 100644 --- a/include/grub/compiler-rt.h +++ b/include/grub/compiler-rt.h @@ -108,6 +108,13 @@ EXPORT_FUNC (__aeabi_llsr) (grub_uint64_t u, int b); #endif +#ifdef __riscv +int +EXPORT_FUNC (__clzsi2) (grub_uint32_t val); + +int +EXPORT_FUNC (__clzdi2) (grub_uint64_t val); +#endif #if defined (__powerpc__) From patchwork Tue Feb 12 10:31:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 158140 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3665337jaa; Tue, 12 Feb 2019 02:33:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IbYz8DUGTWSKlzLtW2RpB969qknUFImrWHGdJxwjTtlCUC8klLSt7YiYc6FJm1+0OOKZr2M X-Received: by 2002:a81:840a:: with SMTP id u10mr2219575ywf.292.1549967593721; Tue, 12 Feb 2019 02:33:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967593; cv=none; d=google.com; s=arc-20160816; b=a5bc/PfRAbR4brTn6MiXqMNOjMp8F+BQQ3GSXcHc8+EEAn/9VCylX3VjqWN7t335tr PsBJ/ErPlqRQ3tLXqnXscen6wHn1WpckTl9YYafpkgR/AzThg4v6ytOvTApXOAYAEdF4 vYUPXEg11Gp0m1u0ZkoK6ZqrpqYxlb3Yy71X4bU/GLTwX99i99q4ah2a/RfVPwgLTcdR r1BOPjbjc4c8rmCBMq4xEsEkiWXepOYnJ22vT9ryE8wQtzQkgCi8ftIUTXjZ6aAJKZE7 P0blQMNK0lM/iSgShZnfZ6pi0qePSWS1kKk78wPHhnh1CczM+51gscQ1NC/czY3obioI i3mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=+5p//gYUk0E/DemMpWJKfk5Y4/Nx00KJq5v6dRRqPVc=; b=camkfpQgCJbQHZ0U5dwccfG1D32+ftC2aACRPoFXK6mh3d7BrWEz1rspl6mEdUoV02 I/dYdjfI71uTbUipK9PtS6znpY8CyomxBwj9uohE2Nu3MOSaq+Svzs0nLyUG0DFmTTB0 KWIb+iu2RlV416L3JFuIYYwjFcL2qlGpyEWMsw1WFVF98A7cmJYCc+bgalt2/lBXW1E+ m6zd+RNhNJB/03D+nBs8xUzjW9DCimpZPfgvfMe8HOXXquUDssemRAUA55CmyaQouszl rmXZ6AzawqYBT2gA1RuRFqm7AVkfka+G9bHHDpJG0AC2jqlgMeMyXJF/H/e/x40bNJAp R/4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p81si2896964ywp.149.2019.02.12.02.33.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Feb 2019 02:33:13 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:36930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVNJ-0001Ts-6N for patch@linaro.org; Tue, 12 Feb 2019 05:33:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37180) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVME-0000sC-Ra for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtVMA-00045S-52 for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:06 -0500 Received: from mx2.suse.de ([195.135.220.15]:52040 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtVM4-0003kI-S7 for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:00 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 00367B12F; Tue, 12 Feb 2019 10:31:11 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v6 10/11] RISC-V: Add to build system Date: Tue, 12 Feb 2019 11:31:07 +0100 Message-Id: <20190212103108.56963-11-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190212103108.56963-1-agraf@suse.de> References: <20190212103108.56963-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng , Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" 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 Reviewed-by: Alistair Francis Reviewed-by: Bin Meng Tested-by: Bin Meng --- v2 -> v3: - Fix riscv32 target --- configure.ac | 28 ++++++++++++++++++++++++++-- gentpl.py | 11 +++++++---- grub-core/Makefile.am | 12 ++++++++++++ grub-core/Makefile.core.def | 29 +++++++++++++++++++++++++++++ grub-core/commands/file.c | 14 +++++++++++++- grub-core/kern/compiler-rt.c | 6 ++++-- grub-core/kern/efi/mm.c | 2 +- grub-core/kern/emu/cache.c | 6 ++++++ grub-core/kern/emu/cache_s.S | 1 + grub-core/kern/emu/lite.c | 2 ++ grub-core/lib/efi/halt.c | 3 ++- grub-core/lib/setjmp.S | 2 ++ include/grub/compiler-rt.h | 12 ++++++++---- include/grub/efi/api.h | 3 ++- include/grub/efi/efi.h | 2 +- include/grub/misc.h | 3 ++- include/grub/util/install.h | 2 ++ util/grub-install-common.c | 2 ++ util/grub-install.c | 28 ++++++++++++++++++++++++++++ util/grub-mknetdir.c | 4 +++- util/grub-mkrescue.c | 16 +++++++++++++++- util/mkimage.c | 32 ++++++++++++++++++++++++++++++++ 22 files changed, 200 insertions(+), 20 deletions(-) -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel Reviewed-by: Daniel Kiper diff --git a/configure.ac b/configure.ac index 81a19afd5..e36195266 100644 --- a/configure.ac +++ b/configure.ac @@ -104,6 +104,12 @@ case "$target_cpu" in aarch64*) target_cpu=arm64 ;; + riscv32*) + target_cpu=riscv32 + ;; + riscv64*) + target_cpu=riscv64 + ;; esac # Specify the platform (such as firmware). @@ -127,6 +133,8 @@ if test "x$with_platform" = x; then ia64-*) platform=efi ;; arm-*) platform=uboot ;; arm64-*) platform=efi ;; + riscv32-*) platform=efi ;; + riscv64-*) platform=efi ;; *) AC_MSG_WARN([unsupported CPU: "$target_cpu" - only building utilities]) platform=none @@ -175,6 +183,8 @@ case "$target_cpu"-"$platform" in arm-coreboot) ;; arm-efi) ;; arm64-efi) ;; + riscv32-efi) ;; + riscv64-efi) ;; *-emu) ;; *-none) ;; *) 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([[]], [[]])], [grub_cv_target_cc_soft_float="-mgeneral-regs-only"], []) 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 CFLAGS="$TARGET_CFLAGS -mno-inline-float-divide -mno-inline-sqrt -Werror" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], @@ -1143,7 +1163,7 @@ AC_SUBST(TARGET_LDFLAGS_OLDMAGIC) 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 AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [ 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 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" 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_arm64], [test x$target_cpu = xarm64 ]) 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_LINUX], [test x$host_kernel = xlinux]) diff --git a/gentpl.py b/gentpl.py index e8439484a..387588c05 100644 --- a/gentpl.py +++ b/gentpl.py @@ -32,7 +32,7 @@ GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "mips_loongson", "sparc64_ieee1275", "powerpc_ieee1275", "mips_arc", "ia64_efi", "mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi", - "arm_coreboot"] + "arm_coreboot", "riscv32_efi", "riscv64_efi" ] GROUPS = {} @@ -47,9 +47,12 @@ GROUPS["sparc64"] = [ "sparc64_ieee1275" ] GROUPS["powerpc"] = [ "powerpc_ieee1275" ] GROUPS["arm"] = [ "arm_uboot", "arm_efi", "arm_coreboot" ] GROUPS["arm64"] = [ "arm64_efi" ] +GROUPS["riscv32"] = [ "riscv32_efi" ] +GROUPS["riscv64"] = [ "riscv64_efi" ] # 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["uboot"] = [ "arm_uboot" ] GROUPS["xen"] = [ "i386_xen", "x86_64_xen" ] @@ -76,11 +79,11 @@ GROUPS["terminfomodule"] = GRUB_PLATFORMS[:]; for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i) # 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 # 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[:] for i in GROUPS["softdiv"]: GROUPS["no_softdiv"].remove(i) diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index df8dbe2fb..3ea8e7ff4 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -284,6 +284,18 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h 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 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index e16fb06ba..2346bd291 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -65,6 +65,12 @@ kernel = { 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'; + 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_BASE_LDOPT),0x9000'; i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)'; @@ -114,6 +120,8 @@ kernel = { arm_coreboot_startup = kern/arm/startup.S; arm_efi_startup = kern/arm/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/corecmd.c; @@ -246,6 +254,12 @@ kernel = { arm64_efi = kern/arm64/efi/init.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/mmap.c; i386_pc = term/i386/pc/console.c; @@ -317,6 +331,14 @@ kernel = { arm64 = kern/arm64/dl.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 = kern/emu/cache_s.S; emu = kern/emu/hostdisk.c; @@ -792,6 +814,8 @@ module = { enable = arm64_efi; enable = arm_uboot; enable = arm_coreboot; + enable = riscv32_efi; + enable = riscv64_efi; }; module = { @@ -1649,6 +1673,7 @@ module = { extra_dist = lib/ia64/longjmp.S; extra_dist = lib/arm/setjmp.S; extra_dist = lib/arm64/setjmp.S; + extra_dist = lib/riscv/setjmp.S; }; module = { @@ -1750,6 +1775,8 @@ module = { arm_efi = loader/arm64/linux.c; arm_uboot = loader/arm/linux.c; arm64 = loader/arm64/linux.c; + riscv32 = loader/riscv/linux.c; + riscv64 = loader/riscv/linux.c; common = loader/linux.c; common = lib/cmdline.c; enable = noemu; @@ -1844,6 +1871,8 @@ module = { enable = ia64_efi; enable = arm_efi; enable = arm64_efi; + enable = riscv32_efi; + enable = riscv64_efi; enable = mips; }; diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c index 4f81aa1f9..2574e6685 100644 --- a/grub-core/commands/file.c +++ b/grub-core/commands/file.c @@ -90,6 +90,10 @@ static const struct grub_arg_option options[] = { N_("Check if FILE is ARM64 EFI file"), 0, 0}, {"is-arm-efi", 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, N_("Check if FILE is hiberfil.sys in hibernated state"), 0, 0}, {"is-x86_64-xnu", 0, 0, @@ -130,6 +134,7 @@ enum IS_IA_EFI, IS_ARM64_EFI, IS_ARM_EFI, + IS_RISCV_EFI, IS_HIBERNATED, IS_XNU64, IS_XNU32, @@ -571,6 +576,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) case IS_IA_EFI: case IS_ARM64_EFI: case IS_ARM_EFI: + case IS_RISCV_EFI: { char signature[4]; grub_uint32_t pe_offset; @@ -616,7 +622,13 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) && coff_head.machine != grub_cpu_to_le16_compile_time (GRUB_PE32_MACHINE_ARMTHUMB_MIXED)) 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; if (grub_file_read (file, &o64, sizeof (o64)) != sizeof (o64)) diff --git a/grub-core/kern/compiler-rt.c b/grub-core/kern/compiler-rt.c index 404902119..aaed3f25d 100644 --- a/grub-core/kern/compiler-rt.c +++ b/grub-core/kern/compiler-rt.c @@ -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. */ grub_uint64_t @@ -343,7 +344,8 @@ __ucmpdi2 (grub_uint64_t a, grub_uint64_t b) #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. */ grub_uint32_t diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index 42ad7c570..a29af9fa5 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -634,7 +634,7 @@ grub_efi_mm_init (void) 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); } -#if defined (__aarch64__) || defined (__arm__) +#if defined (__aarch64__) || defined (__arm__) || defined (__riscv) grub_err_t grub_efi_get_ram_base(grub_addr_t *base_addr) { diff --git a/grub-core/kern/emu/cache.c b/grub-core/kern/emu/cache.c index 6f89e871a..113682cc4 100644 --- a/grub-core/kern/emu/cache.c +++ b/grub-core/kern/emu/cache.c @@ -25,5 +25,11 @@ grub_arch_sync_caches (void *address, grub_size_t len) return _flush_cache (address, len, 0); } +#elif defined(__riscv) +void +grub_arch_sync_caches (void *address, grub_size_t len) +{ +} + #endif diff --git a/grub-core/kern/emu/cache_s.S b/grub-core/kern/emu/cache_s.S index 76cf7560d..e27b865f9 100644 --- a/grub-core/kern/emu/cache_s.S +++ b/grub-core/kern/emu/cache_s.S @@ -9,6 +9,7 @@ #elif defined(__powerpc__) #include "../powerpc/cache.S" #elif defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || defined(__mips__) +#elif defined(__riscv) #else #error "No target cpu type is defined" #endif diff --git a/grub-core/kern/emu/lite.c b/grub-core/kern/emu/lite.c index b2fc93d7f..b327d4e41 100644 --- a/grub-core/kern/emu/lite.c +++ b/grub-core/kern/emu/lite.c @@ -24,6 +24,8 @@ #elif defined(__aarch64__) #include "../arm64/dl_helper.c" #include "../arm64/dl.c" +#elif defined(__riscv) +#include "../riscv/dl.c" #else #error "No target cpu type is defined" #endif diff --git a/grub-core/lib/efi/halt.c b/grub-core/lib/efi/halt.c index e9441c844..5859f0498 100644 --- a/grub-core/lib/efi/halt.c +++ b/grub-core/lib/efi/halt.c @@ -29,7 +29,8 @@ void grub_halt (void) { 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 (); #endif efi_call_4 (grub_efi_system_table->runtime_services->reset_system, diff --git a/grub-core/lib/setjmp.S b/grub-core/lib/setjmp.S index f6e4905e2..aa297ab0a 100644 --- a/grub-core/lib/setjmp.S +++ b/grub-core/lib/setjmp.S @@ -15,6 +15,8 @@ #include "./arm/setjmp.S" #elif defined(__aarch64__) #include "./arm64/setjmp.S" +#elif defined(__riscv) +#include "./riscv/setjmp.S" #else #error "Unknown target cpu type" #endif diff --git a/include/grub/compiler-rt.h b/include/grub/compiler-rt.h index 2cc69e239..e6a25c6ea 100644 --- a/include/grub/compiler-rt.h +++ b/include/grub/compiler-rt.h @@ -53,13 +53,15 @@ EXPORT_FUNC (__umoddi3) (grub_uint64_t a, grub_uint64_t b); #endif -#if defined (__sparc__) || defined (__powerpc__) || defined (__mips__) || defined (__arm__) +#if defined (__sparc__) || defined (__powerpc__) || defined (__mips__) || \ + defined (__arm__) || defined(__riscv) unsigned EXPORT_FUNC (__ctzdi2) (grub_uint64_t x); #define NEED_CTZDI2 1 #endif -#if defined (__mips__) || defined (__arm__) +#if defined (__mips__) || defined (__arm__) || \ + (defined(__riscv) && (__riscv_xlen == 32)) unsigned EXPORT_FUNC (__ctzsi2) (grub_uint32_t x); #define NEED_CTZSI2 1 @@ -157,7 +159,8 @@ void EXPORT_FUNC (_savegpr_31) (void); #endif -#if defined (__powerpc__) || defined(__mips__) || defined (__arm__) +#if defined (__powerpc__) || defined(__mips__) || defined (__arm__) || \ + (defined(__riscv) && (__riscv_xlen == 32)) int 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); #endif -#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__) || defined (__arm__) +#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__) || \ + defined (__arm__) || defined(__riscv) grub_uint32_t EXPORT_FUNC(__bswapsi2) (grub_uint32_t u); diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h index c7c9f0e1d..addcbfa8f 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h @@ -1686,7 +1686,8 @@ struct grub_efi_block_io typedef struct grub_efi_block_io grub_efi_block_io_t; #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_1(func, a) func(a) diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index ec44aef7e..e90e00dc4 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -90,7 +90,7 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, char **device, char **path); -#if defined(__arm__) || defined(__aarch64__) +#if defined(__arm__) || defined(__aarch64__) || defined(__riscv) void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *); #include diff --git a/include/grub/misc.h b/include/grub/misc.h index 372f009e8..ee48eb7a7 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -340,7 +340,8 @@ grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, grub_uint64_t *r); /* 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 #else #define GRUB_DIVISION_IN_SOFTWARE 0 diff --git a/include/grub/util/install.h b/include/grub/util/install.h index af2bf65d7..b1a00154f 100644 --- a/include/grub/util/install.h +++ b/include/grub/util/install.h @@ -103,6 +103,8 @@ enum grub_install_plat GRUB_INSTALL_PLATFORM_I386_XEN_PVH, GRUB_INSTALL_PLATFORM_ARM64_EFI, GRUB_INSTALL_PLATFORM_ARM_COREBOOT, + GRUB_INSTALL_PLATFORM_RISCV32_EFI, + GRUB_INSTALL_PLATFORM_RISCV64_EFI, GRUB_INSTALL_PLATFORM_MAX }; diff --git a/util/grub-install-common.c b/util/grub-install-common.c index 1b1cb43b4..0a7d68b9b 100644 --- a/util/grub-install-common.c +++ b/util/grub-install-common.c @@ -729,6 +729,8 @@ static struct [GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64", "efi" }, [GRUB_INSTALL_PLATFORM_ARM_UBOOT] = { "arm", "uboot" }, [GRUB_INSTALL_PLATFORM_ARM_COREBOOT] = { "arm", "coreboot" }, + [GRUB_INSTALL_PLATFORM_RISCV32_EFI] = { "riscv32", "efi" }, + [GRUB_INSTALL_PLATFORM_RISCV64_EFI] = { "riscv64", "efi" }, }; char * diff --git a/util/grub-install.c b/util/grub-install.c index 4a0a66168..c6c3da331 100644 --- a/util/grub-install.c +++ b/util/grub-install.c @@ -477,6 +477,8 @@ have_bootdev (enum grub_install_plat pl) case GRUB_INSTALL_PLATFORM_IA64_EFI: case GRUB_INSTALL_PLATFORM_ARM_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_SPARC64_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_ARM_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_I386_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_ARM_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_I386_IEEE1275: 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_ARM_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: is_efi = 1; break; @@ -1111,6 +1119,12 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_ARM64_EFI: efi_file = "BOOTAA64.EFI"; break; + case GRUB_INSTALL_PLATFORM_RISCV32_EFI: + efi_file = "BOOTRISCV32.EFI"; + break; + case GRUB_INSTALL_PLATFORM_RISCV64_EFI: + efi_file = "BOOTRISCV64.EFI"; + break; default: grub_util_error ("%s", _("You've found a bug")); break; @@ -1138,6 +1152,12 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_ARM64_EFI: efi_file = "grubaa64.efi"; break; + case GRUB_INSTALL_PLATFORM_RISCV32_EFI: + efi_file = "grubriscv32.efi"; + break; + case GRUB_INSTALL_PLATFORM_RISCV64_EFI: + efi_file = "grubriscv64.efi"; + break; default: efi_file = "grub.efi"; break; @@ -1440,6 +1460,8 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_X86_64_EFI: case GRUB_INSTALL_PLATFORM_ARM_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: g = grub_util_guess_efi_drive (*curdev); break; @@ -1533,6 +1555,8 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_X86_64_EFI: case GRUB_INSTALL_PLATFORM_ARM_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: core_name = "core.efi"; snprintf (mkimage_target, sizeof (mkimage_target), @@ -1636,6 +1660,8 @@ main (int argc, char *argv[]) break; case GRUB_INSTALL_PLATFORM_ARM_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_MIPSEL_QEMU_MIPS: case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS: @@ -1871,6 +1897,8 @@ main (int argc, char *argv[]) /* FALLTHROUGH */ case GRUB_INSTALL_PLATFORM_ARM_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: { char *dst = grub_util_path_concat (2, efidir, efi_file); diff --git a/util/grub-mknetdir.c b/util/grub-mknetdir.c index 82073d5cc..602574d52 100644 --- a/util/grub-mknetdir.c +++ b/util/grub-mknetdir.c @@ -107,7 +107,9 @@ static const struct [GRUB_INSTALL_PLATFORM_X86_64_EFI] = { "x86_64-efi", "efinet", ".efi" }, [GRUB_INSTALL_PLATFORM_IA64_EFI] = { "ia64-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 diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c index 9545945d8..21e5ce4e4 100644 --- a/util/grub-mkrescue.c +++ b/util/grub-mkrescue.c @@ -538,6 +538,8 @@ main (int argc, char *argv[]) || source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI] || source_dirs[GRUB_INSTALL_PLATFORM_ARM_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]) system_area = SYS_AREA_COMMON; 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_IA64_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_efi = grub_util_path_concat (2, efidir, "efi"); @@ -770,6 +774,16 @@ main (int argc, char *argv[]) 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]) { imgname = grub_util_path_concat (2, efidir_efi_boot, "boot.efi"); diff --git a/util/mkimage.c b/util/mkimage.c index cf1a47c94..37d6249f1 100644 --- a/util/mkimage.c +++ b/util/mkimage.c @@ -622,6 +622,38 @@ static const struct grub_install_image_target_desc image_targets[] = .pe_target = GRUB_PE32_MACHINE_ARM64, .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 From patchwork Tue Feb 12 10:31:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 158141 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3665900jaa; Tue, 12 Feb 2019 02:33:50 -0800 (PST) X-Google-Smtp-Source: AHgI3Ial7YW+8GSDDveMHDBZ2p1qrCKsHh1SgGDyxAiDdLaZMUXkXUxfvEB0vlkj6PXEiiDMk09J X-Received: by 2002:a25:bf92:: with SMTP id l18mr2231300ybk.501.1549967630053; Tue, 12 Feb 2019 02:33:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967630; cv=none; d=google.com; s=arc-20160816; b=WX0cHagt9+kNCKd2/mJ3mT9H14jqqS0m4OsHBi5CpFtDo3kyFT738ddleh3BL9EHTe lFKXbyv/ZLLFVlZCM+wyTUetmGSCmHNqPGO48Qn3dWXu90rVuhB2ZHEUWyzf56ngTyZd ylTSGQ22S+A2yWuYjwG0eRxShdGXCTDWv4TcRtKhw4wGNfsRE95UHB3q226NX7fRqXpm +QJ+9BnFVpAG4Lv7D3zahEb932uR91QT0HLY8P5pt8hVop25kPM6rNaJhEiheD2dTo7N zAbiuzpJvMD0zsNhbWUHAo/DWK6shFO/qo53lU5WQmn85aU1DaVRsdDmo6LCnCSJEP4D 6pkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=J9ZMc+68zJWTAcnXsRm/dtl7UIgvX4CIJ6Td0OzV/eM=; b=GypBUmEb5KXj6Nt5szhCj1ZnPo7SPyFVWiInUUE0MRJ7YEeMrbjvZT6PFRjJZJktG5 nvuXwbnjtzwKeab8SoQwJylu9Uuh9YRMhn4kZHaLMudgS6LTgWndN6UihLxlnMOS0Mbt 7emtwnGChulD9321DyoozUWIi76r14+OLsa33UOWgKp1PkxXF7Lv3Uknj3zRVyoPSB9g 2Xd9KPTVku9jiokYm+pVQxKMrVUn/Hv7jySf2giOIdVp/r5GWG9T/jiBj0nzaWWzamzB PdHLBcSOF65NW2ZJ99srKts/LATrmrEFu6RvywzWL8YK/YYACJ7Cu+Gk9fVz7aYZaBc9 nyCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b83si6990540yba.304.2019.02.12.02.33.49 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Feb 2019 02:33:50 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:36934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVNt-0001ut-2C for patch@linaro.org; Tue, 12 Feb 2019 05:33:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVMG-0000tY-U8 for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtVMC-0004B2-Fl for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:08 -0500 Received: from mx2.suse.de ([195.135.220.15]:52042 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtVMB-00042i-UQ for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:04 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0EA79B151; Tue, 12 Feb 2019 10:31:12 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v6 11/11] fdt: Treat device tree file type like ACPI Date: Tue, 12 Feb 2019 11:31:08 +0100 Message-Id: <20190212103108.56963-12-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190212103108.56963-1-agraf@suse.de> References: <20190212103108.56963-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng , Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" We now have signature check logic in grub which allows us to treat files differently depending on their file type. Treat a loaded device tree like an overlayed ACPI table. Both describe hardware, so I suppose their threat level is the same. Signed-off-by: Alexander Graf Reviewed-by: Daniel Kiper --- v3 -> v4: - Rebase onto current git master --- grub-core/commands/efi/shim_lock.c | 1 + include/grub/file.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel Reviewed-by: Alistair Francis diff --git a/grub-core/commands/efi/shim_lock.c b/grub-core/commands/efi/shim_lock.c index 01246b0fc..83568cb2b 100644 --- a/grub-core/commands/efi/shim_lock.c +++ b/grub-core/commands/efi/shim_lock.c @@ -81,6 +81,7 @@ shim_lock_init (grub_file_t io, enum grub_file_type type, /* Fall through. */ case GRUB_FILE_TYPE_ACPI_TABLE: + case GRUB_FILE_TYPE_DEVICE_TREE_IMAGE: *flags = GRUB_VERIFY_FLAGS_DEFER_AUTH; return GRUB_ERR_NONE; diff --git a/include/grub/file.h b/include/grub/file.h index cbbd29465..31567483c 100644 --- a/include/grub/file.h +++ b/include/grub/file.h @@ -74,8 +74,6 @@ enum grub_file_type GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE, - GRUB_FILE_TYPE_DEVICE_TREE_IMAGE, - /* File holding signature. */ GRUB_FILE_TYPE_SIGNATURE, /* File holding public key to verify signature once. */ @@ -100,6 +98,8 @@ enum grub_file_type GRUB_FILE_TYPE_FILE_ID, /* File holding ACPI table. */ GRUB_FILE_TYPE_ACPI_TABLE, + /* File holding Device Tree. */ + GRUB_FILE_TYPE_DEVICE_TREE_IMAGE, /* File we intend show to user. */ GRUB_FILE_TYPE_CAT, GRUB_FILE_TYPE_HEXCAT,