From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kXrT2-00052t-Ju for mharc-grub-devel@gnu.org; Wed, 28 Oct 2020 15:50:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXrT1-00051n-FG for Grub-devel@gnu.org; Wed, 28 Oct 2020 15:50:43 -0400 Received: from shcp25.hosting.zen.net.uk ([82.71.204.30]:60882) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXrSz-0003z3-3g for Grub-devel@gnu.org; Wed, 28 Oct 2020 15:50:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=monkeyircd.org; s=default; h=Content-Transfer-Encoding:MIME-Version: Content-Type:References:In-Reply-To:Date:Cc:To:Reply-To:From:Subject: Message-ID:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SJx+EMmr2uJnNwNrm5PlZ0JJ3E0ZtnkgnfkFVhxo/8Q=; b=JTTyuVyV2cLsGk5twEMYQWh3NZ H9NsAVqsEPijbtLLbLtFekjaD9aodE4nsJKYY+/6nnSfflAYA1AIoWy40HwZUnf7YHiocGJso2qGP WQjxNEEkYVrmsHduBGY/lkWBuukFrd6QVnGwGMOK5AWofJM/2RWXlHKPDa/N4gxLn1Ov2yxmNLivB nqs88RpKuJ9yx2mhDeoihE09crli+Fcp7EROdJqu0W8G80r/zhfVyC8Zu/iGADuMFqDnGYKMXu2UE d3e8Q78G7xkrsYj0eDJtYmylgoStn4FbWy6wTaw5kl6ORavlCLkkCU3Yy5lf2CTEpaFoiNFkJb+gz +UgPq66g==; Received: from [82.69.123.44] (port=45070 helo=zoidberg.local.monkeyircd.org) by shcp25.hosting.zen.net.uk with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kXrSw-002iaB-E6; Wed, 28 Oct 2020 19:50:40 +0000 Message-ID: Subject: [PATCH 04/05] Enable multiboot2 support on arm64-efi target From: Chris Plant Reply-To: chris@monkeyircd.org To: Grub-devel@gnu.org Cc: chris@monkeyircd.org Date: Wed, 28 Oct 2020 19:50:37 +0000 In-Reply-To: <4b23bf36d0a833ff038709ae7c443647976dcd8c.camel@monkeyircd.org> References: <4b23bf36d0a833ff038709ae7c443647976dcd8c.camel@monkeyircd.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.4-2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - shcp25.hosting.zen.net.uk X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - monkeyircd.org X-Get-Message-Sender-Via: shcp25.hosting.zen.net.uk: authenticated_id: chris@monkeyircd.org X-Authenticated-Sender: shcp25.hosting.zen.net.uk: chris@monkeyircd.org Received-SPF: pass client-ip=82.71.204.30; envelope-from=chris@monkeyircd.org; helo=shcp25.hosting.zen.net.uk X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/28 15:45:20 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Oct 2020 19:50:43 -0000 Enable ARM64/aarch64 support in multiboot2 loader Signed-off-by: Chris Plant --- grub-core/loader/multiboot.c | 2 +- grub-core/loader/multiboot_elfxx.c | 2 +- grub-core/loader/multiboot_mbi2.c | 34 +++++++++++++++--- include/grub/arm64/multiboot.h | 56 ++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 include/grub/arm64/multiboot.h diff --git a/grub-core/loader/multiboot.c b/grub- core/loader/multiboot.c index facb13f3d..e88a4a7f7 100644 --- a/grub-core/loader/multiboot.c +++ b/grub-core/loader/multiboot.c @@ -127,7 +127,7 @@ GRUB_MULTIBOOT (set_video_mode) (void) } #ifdef GRUB_MACHINE_EFI -#ifdef __x86_64__ +#if defined (__x86_64__) || defined (__arch64__) #define grub_relocator_efi_boot grub_relocator64_efi_bo ot #define grub_relocator_efi_state grub_relocator64_efi_state #endif diff --git a/grub-core/loader/multiboot_elfxx.c b/grub- core/loader/multiboot_elfxx.c index f2318e0d1..851b09164 100644 --- a/grub-core/loader/multiboot_elfxx.c +++ b/grub-core/loader/multiboot_elfxx.c @@ -205,7 +205,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) if (i == ehdr->e_phnum) return grub_error (GRUB_ERR_BAD_OS, "entry point isn't in a segment"); -#if defined (__i386__) || defined (__x86_64__) +#if defined (__i386__) || defined (__x86_64__) || defined (__aarch64__) #elif defined (__mips) GRUB_MULTIBOOT (payload_eip) |= 0x80000000; diff --git a/grub-core/loader/multiboot_mbi2.c b/grub- core/loader/multiboot_mbi2.c index 9a943d7bd..6ca195a87 100644 --- a/grub-core/loader/multiboot_mbi2.c +++ b/grub-core/loader/multiboot_mbi2.c @@ -186,6 +186,7 @@ grub_multiboot2_load (grub_file_t file, const char *filename) case MULTIBOOT_TAG_TYPE_EFI32_IH: case MULTIBOOT_TAG_TYPE_EFI64_IH: case MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR: + case MULTIBOOT_TAG_TYPE_ELF64_SECTIONS: break; default: @@ -445,8 +446,13 @@ grub_multiboot2_get_mbi_size (void) + ALIGN_UP (sizeof (struct multiboot_tag_basic_meminfo), MULTIBOOT_TAG_ALIGN) + ALIGN_UP (sizeof (struct multiboot_tag_bootdev), MULTIBOOT_TAG_ALIGN) +#if defined (__i386__) || defined (__x86_64__) || defined (__mips) + /* This tag doesn't align correct for aarch64/arm64 */ + ALIGN_UP (sizeof (struct multiboot_tag_elf_sections), MULTIBOOT_TAG_ALIGN) - + ALIGN_UP (elf_sec_entsize * elf_sec_num, MULTIBOOT_TAG_ALIGN) + + ALIGN_UP (elf_sec_entsize * elf_sec_num, MULTIBOOT_TAG_ALIGN) +#endif + + ALIGN_UP (sizeof (struct multiboot_tag_elf64_sections), MULTIBOOT_TAG_ALIGN) + + ALIGN_UP (elf_sec_entsize * elf_sec_num, MULTIBOOT_TAG_ALIGN) + ALIGN_UP ((sizeof (struct multiboot_tag_mmap) + grub_multiboot2_get_mmap_count () * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN) @@ -721,7 +727,7 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) return err; ptrorig = get_virtual_current_address (ch); -#if defined (__i386__) || defined (__x86_64__) +#if defined (__i386__) || defined (__x86_64__) || defined (__aarch64__) *target = get_physical_target_address (ch); #elif defined (__mips) *target = get_physical_target_address (ch) | 0x80000000; @@ -815,7 +821,8 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) / sizeof (grub_properly_aligned_t); } - { +#if defined (__i386__) || defined (__x86_64__) || defined (__mips) + { struct multiboot_tag_elf_sections *tag = (struct multiboot_tag_elf_sections *) ptrorig; tag->type = MULTIBOOT_TAG_TYPE_ELF_SECTIONS; @@ -828,6 +835,23 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) / sizeof (grub_properly_aligned_t); } +#endif + + { + struct multiboot_tag_elf64_sections *tag + = (struct multiboot_tag_elf64_sections *) ptrorig; + tag->type = MULTIBOOT_TAG_TYPE_ELF64_SECTIONS; + tag->size = sizeof (struct multiboot_tag_elf64_sections) + + elf_sec_entsize * elf_sec_num; + grub_memcpy (tag->sections, elf_sections, elf_sec_entsize * elf_sec_num); + tag->num = elf_sec_num; + tag->entsize = elf_sec_entsize; + tag->shndx = elf_sec_shstrndx; + grub_memset (&(tag->reserved), 0, sizeof(multiboot_uint32_t)); + ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) + / sizeof (grub_properly_aligned_t); + } + if (!keep_bs) { @@ -882,7 +906,7 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) } } -#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__) +#if defined (GRUB_MACHINE_EFI) && (defined (__x86_64__) || defined(__aarch64__)) { struct multiboot_tag_efi64 *tag = (struct multiboot_tag_efi64 *) ptrorig; tag->type = MULTIBOOT_TAG_TYPE_EFI64; @@ -981,7 +1005,7 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) } #endif -#ifdef __x86_64__ +#if defined ( __x86_64__) || defined (__aarch64__) { struct multiboot_tag_efi64_ih *tag = (struct multiboot_tag_efi64_ih *) ptrorig; tag->type = MULTIBOOT_TAG_TYPE_EFI64_IH; diff --git a/include/grub/arm64/multiboot.h b/include/grub/arm64/multiboot.h new file mode 100644 index 000000000..427dca07f --- /dev/null +++ b/include/grub/arm64/multiboot.h @@ -0,0 +1,56 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2003,2004,2007,2008,2009 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_MULTIBOOT_CPU_HEADER +#define GRUB_MULTIBOOT_CPU_HEADER 1 + +#define MULTIBOOT2_INITIAL_STATE { .w[0] = MULTIBOOT2_BOOTLOADER_MAGIC, \ + .w[2] = 0, \ + .w[3] = 0, \ + .pc_reg = 8 \ +} +#define MULTIBOOT_INITIAL_STATE { .w[0] = MULTIBOOT_BOOTLOADER_MAGIC, \ + .w[2] = 0, \ + .w[3] = 0, \ + .pc_reg = 8 \ + } +#define MULTIBOOT_ENTRY_REGISTER w[8] +#define MULTIBOOT_MBI_REGISTER w[1] +#define MULTIBOOT2_ARCHITECTURE_CURRENT MULTIBOOT2_ARCHITECTURE_AARCH64 + +#ifdef GRUB_MACHINE_EFI + +#define MULTIBOOT_EFI_INITIAL_STATE { .w[0] = MULTIBOOT_BOOTLOADER_MAGIC, \ + .w[2] = 0, \ + .w[3] = 0, \ + .pc_reg = 8 \ + } +#define MULTIBOOT2_EFI_INITIAL_STATE { .w[0] = MULTIBOOT2_BOOTLOADER_MAGIC, \ + .w[2] = 0, \ + .w[3] = 0, \ + .pc_reg = 8 \ + } +#define MULTIBOOT_EFI_ENTRY_REGISTER w[8] +#define MULTIBOOT_EFI_MBI_REGISTER w[1] + +#endif /* GRUB_MACHINE_EFI */ + +#define MULTIBOOT_ELF32_MACHINE EM_AARCH64 +#define MULTIBOOT_ELF64_MACHINE EM_AARCH64 + +#endif /* ! GRUB_MULTIBOOT_CPU_HEADER */ -- 2.28.0