From 01cb3ed58ea5928566201e43bf8291ad36503463 Mon Sep 17 00:00:00 2001 From: David Karoly Date: Mon, 27 Dec 2021 20:03:32 +0100 Subject: [PATCH] boot/efi: add stubs for x86 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8d3dfa7cc07679a8b024df24f7cddb3a5bcec02c Reviewed-on: https://review.haiku-os.org/c/haiku/+/4747 Tested-by: Commit checker robot Reviewed-by: Jérôme Duval --- src/system/boot/platform/efi/arch/x86/Jamfile | 31 ++++++ .../boot/platform/efi/arch/x86/arch_mmu.cpp | 11 ++ .../boot/platform/efi/arch/x86/arch_smp.cpp | 38 +++++++ .../boot/platform/efi/arch/x86/arch_start.cpp | 25 +++++ .../boot/platform/efi/arch/x86/arch_timer.cpp | 13 +++ .../platform/efi/arch/x86/relocation_func.cpp | 101 ++++++++++++++++++ 6 files changed, 219 insertions(+) create mode 100644 src/system/boot/platform/efi/arch/x86/Jamfile create mode 100644 src/system/boot/platform/efi/arch/x86/arch_mmu.cpp create mode 100644 src/system/boot/platform/efi/arch/x86/arch_smp.cpp create mode 100644 src/system/boot/platform/efi/arch/x86/arch_start.cpp create mode 100644 src/system/boot/platform/efi/arch/x86/arch_timer.cpp create mode 100644 src/system/boot/platform/efi/arch/x86/relocation_func.cpp diff --git a/src/system/boot/platform/efi/arch/x86/Jamfile b/src/system/boot/platform/efi/arch/x86/Jamfile new file mode 100644 index 0000000000..1f89c03b26 --- /dev/null +++ b/src/system/boot/platform/efi/arch/x86/Jamfile @@ -0,0 +1,31 @@ +SubDir HAIKU_TOP src system boot platform efi arch x86 ; + +SubDirHdrs $(HAIKU_TOP) src system boot platform efi ; + +UsePrivateHeaders [ FDirName kernel platform ] ; +UsePrivateHeaders [ FDirName kernel boot platform efi ] ; + +local platform ; +for platform in [ MultiBootSubDirSetup efi ] { + on $(platform) { + { + local defines = _BOOT_MODE _BOOT_PLATFORM_EFI ; + defines = [ FDefines $(defines) ] ; + SubDirCcFlags $(defines) ; + SubDirC++Flags $(defines) -fno-rtti ; + } + + local arch_src = + crt0-efi-$(TARGET_ARCH).S + relocation_func.cpp + arch_mmu.cpp + arch_smp.cpp + arch_start.cpp + arch_timer.cpp + ; + + BootMergeObject boot_platform_efi_x86.o : + $(arch_src) + ; + } +} diff --git a/src/system/boot/platform/efi/arch/x86/arch_mmu.cpp b/src/system/boot/platform/efi/arch/x86/arch_mmu.cpp new file mode 100644 index 0000000000..0e6396943a --- /dev/null +++ b/src/system/boot/platform/efi/arch/x86/arch_mmu.cpp @@ -0,0 +1,11 @@ +/* + * Copyright 2021 Haiku, Inc. All rights reserved. + * Released under the terms of the MIT License. + */ + + +void +arch_mmu_init(void) +{ + +} diff --git a/src/system/boot/platform/efi/arch/x86/arch_smp.cpp b/src/system/boot/platform/efi/arch/x86/arch_smp.cpp new file mode 100644 index 0000000000..73c5797ad0 --- /dev/null +++ b/src/system/boot/platform/efi/arch/x86/arch_smp.cpp @@ -0,0 +1,38 @@ +/* + * Copyright 2021 Haiku, Inc. All rights reserved. + * Released under the terms of the MIT License. + */ + + +#include "arch_smp.h" + + +int +arch_smp_get_current_cpu(void) +{ + return 0; +} + + +void +arch_smp_init_other_cpus(void) +{ +} + + +void +arch_smp_boot_other_cpus(uint32 pml4, uint64 kernel_entry) +{ +} + + +void +arch_smp_add_safemode_menus(Menu *menu) +{ +} + + +void +arch_smp_init(void) +{ +} diff --git a/src/system/boot/platform/efi/arch/x86/arch_start.cpp b/src/system/boot/platform/efi/arch/x86/arch_start.cpp new file mode 100644 index 0000000000..9766878d6c --- /dev/null +++ b/src/system/boot/platform/efi/arch/x86/arch_start.cpp @@ -0,0 +1,25 @@ +/* + * Copyright 2021 Haiku, Inc. All rights reserved. + * Released under the terms of the MIT License. + */ + + +#include +#include + +#include "mmu.h" + + +void +arch_convert_kernel_args(void) +{ + fix_address(gKernelArgs.ucode_data); + fix_address(gKernelArgs.arch_args.apic); + fix_address(gKernelArgs.arch_args.hpet); +} + + +void +arch_start_kernel(addr_t kernelEntry) +{ +} diff --git a/src/system/boot/platform/efi/arch/x86/arch_timer.cpp b/src/system/boot/platform/efi/arch/x86/arch_timer.cpp new file mode 100644 index 0000000000..a59a2fb52f --- /dev/null +++ b/src/system/boot/platform/efi/arch/x86/arch_timer.cpp @@ -0,0 +1,13 @@ +/* + * Copyright 2021 Haiku, Inc. All rights reserved. + * Released under the terms of the MIT License. + */ + + +#include "arch_timer.h" + + +void +arch_timer_init(void) +{ +} diff --git a/src/system/boot/platform/efi/arch/x86/relocation_func.cpp b/src/system/boot/platform/efi/arch/x86/relocation_func.cpp new file mode 100644 index 0000000000..7514f8a2c2 --- /dev/null +++ b/src/system/boot/platform/efi/arch/x86/relocation_func.cpp @@ -0,0 +1,101 @@ +/* reloc_ia32.c - position independent x86 ELF shared object relocator + Copyright (C) 1999 Hewlett-Packard Co. + Contributed by David Mosberger . + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + * Neither the name of Hewlett-Packard Co. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. +*/ + +#include +#include + +#include + + +extern "C" efi_status _relocate (long ldbase, Elf32_Dyn *dyn, + efi_handle image __attribute__((__unused__)), + efi_system_table *systab __attribute__((__unused__))) +{ + long relsz = 0, relent = 0; + Elf32_Rel *rel = 0; + unsigned long *addr; + int i; + + for (i = 0; dyn[i].d_tag != DT_NULL; ++i) { + switch (dyn[i].d_tag) { + case DT_REL: + rel = (Elf32_Rel*) + ((unsigned long)dyn[i].d_un.d_ptr + + ldbase); + break; + + case DT_RELSZ: + relsz = dyn[i].d_un.d_val; + break; + + case DT_RELENT: + relent = dyn[i].d_un.d_val; + break; + + case DT_RELA: + break; + + default: + break; + } + } + + if (!rel && relent == 0) + return EFI_SUCCESS; + + if (!rel || relent == 0) + return EFI_LOAD_ERROR; + + while (relsz > 0) { + /* apply the relocs */ + switch (ELF32_R_TYPE (rel->r_info)) { + case R_386_NONE: + break; + + case R_386_RELATIVE: + addr = (unsigned long *) + (ldbase + rel->r_offset); + *addr += ldbase; + break; + + default: + break; + } + rel = (Elf32_Rel*) ((char *) rel + relent); + relsz -= relent; + } + + return EFI_SUCCESS; +}