[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 04/05] Enable multiboot2 support on arm64-efi target
From: |
Chris Plant |
Subject: |
[PATCH 04/05] Enable multiboot2 support on arm64-efi target |
Date: |
Wed, 28 Oct 2020 19:50:37 +0000 |
User-agent: |
Evolution 3.36.4-2 |
Enable ARM64/aarch64 support in multiboot2 loader
Signed-off-by: Chris Plant <chris@monkeyircd.org>
---
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 <http://www.gnu.org/licenses/>;.
+ */
+
+#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