From d2986cb6d05cd2ed7f7e613b69c64b1625c76a43 Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Fri, 21 Feb 2020 14:26:56 -0600 Subject: [PATCH] system/boot: More cleanup and shuffling * arm efi additions * cleanup some cpu headers which were oddly split between efi and bios_ia32 * Move calculate_cpu_conversion_factor over to arch_timer since it is timerish, and x86 only * Drop some duplicated code from efi start. Move hpet init code into efi timer/hpet code Change-Id: Ia4264a5690ba8c09417b06788febc4f572f111ce Reviewed-on: https://review.haiku-os.org/c/haiku/+/2259 Reviewed-by: Alex von Gluck IV Reviewed-by: Adrien Destugues --- headers/private/kernel/arch/arm/arch_kernel.h | 2 + .../kernel/arch/arm/arch_kernel_args.h | 17 +++-- .../private/kernel/boot/arch/x86/arch_cpu.h | 1 - src/system/boot/platform/bios_ia32/cpu.cpp | 2 +- src/system/boot/platform/bios_ia32/cpu.h | 12 ++++ src/system/boot/platform/bios_ia32/start.cpp | 1 + .../platform/efi/arch/x86_64/arch_timer.cpp | 8 ++- src/system/boot/platform/efi/cpu.cpp | 5 +- src/system/boot/platform/efi/cpu.h | 12 ++++ src/system/boot/platform/efi/start.cpp | 8 +-- src/system/ldscripts/arm/boot_loader_efi.ld | 66 +++++++++++++++++++ 11 files changed, 115 insertions(+), 19 deletions(-) create mode 100644 src/system/boot/platform/bios_ia32/cpu.h create mode 100644 src/system/boot/platform/efi/cpu.h create mode 100644 src/system/ldscripts/arm/boot_loader_efi.ld diff --git a/headers/private/kernel/arch/arm/arch_kernel.h b/headers/private/kernel/arch/arm/arch_kernel.h index e4fa45b959..29706219ad 100644 --- a/headers/private/kernel/arch/arm/arch_kernel.h +++ b/headers/private/kernel/arch/arm/arch_kernel.h @@ -8,6 +8,8 @@ #include // memory layout +#define KERNEL_LOAD_BASE 0x80000000 + #define KERNEL_BASE 0x80000000 #define KERNEL_SIZE 0x80000000 #define KERNEL_TOP (KERNEL_BASE + (KERNEL_SIZE - 1)) diff --git a/headers/private/kernel/arch/arm/arch_kernel_args.h b/headers/private/kernel/arch/arm/arch_kernel_args.h index 206fe4276b..e19183db9b 100644 --- a/headers/private/kernel/arch/arm/arch_kernel_args.h +++ b/headers/private/kernel/arch/arm/arch_kernel_args.h @@ -9,6 +9,12 @@ # error This file is included from only #endif + +#include + + +#define _PACKED __attribute__((packed)) + // kernel args typedef struct { int cpu_type; @@ -18,9 +24,12 @@ typedef struct { int machine; // platform specific machine type // architecture specific - uint32 phys_pgdir; - uint32 vir_pgdir; - uint32 next_pagetable; -} arch_kernel_args; + uint32 phys_pgdir; + uint32 vir_pgdir; + uint32 next_pagetable; + + // needed for UEFI, otherwise kernel acpi support can't find ACPI root + FixedWidthPointer acpi_root; +} _PACKED arch_kernel_args; #endif /* KERNEL_ARCH_ARM_KERNEL_ARGS_H */ diff --git a/headers/private/kernel/boot/arch/x86/arch_cpu.h b/headers/private/kernel/boot/arch/x86/arch_cpu.h index 771f11a6d1..9c697ce3b5 100644 --- a/headers/private/kernel/boot/arch/x86/arch_cpu.h +++ b/headers/private/kernel/boot/arch/x86/arch_cpu.h @@ -13,7 +13,6 @@ extern "C" { #endif -extern void cpu_init(void); void calculate_cpu_conversion_factor(uint8 channel); diff --git a/src/system/boot/platform/bios_ia32/cpu.cpp b/src/system/boot/platform/bios_ia32/cpu.cpp index 2d9e00f11e..2d177f7bf7 100644 --- a/src/system/boot/platform/bios_ia32/cpu.cpp +++ b/src/system/boot/platform/bios_ia32/cpu.cpp @@ -59,7 +59,7 @@ check_cpu_features() // #pragma mark - -extern "C" void +void cpu_init() { if (check_cpu_features() != B_OK) diff --git a/src/system/boot/platform/bios_ia32/cpu.h b/src/system/boot/platform/bios_ia32/cpu.h new file mode 100644 index 0000000000..00091d65ec --- /dev/null +++ b/src/system/boot/platform/bios_ia32/cpu.h @@ -0,0 +1,12 @@ +/* + * Copyright 2019-2020, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _BIOS_IA32_CPU_H +#define _BIOS_IA32_CPU_H + + +void cpu_init(void); + + +#endif /* _BIOS_IA32_CPU_H */ diff --git a/src/system/boot/platform/bios_ia32/start.cpp b/src/system/boot/platform/bios_ia32/start.cpp index 5c788750f8..f3ddb7cf52 100644 --- a/src/system/boot/platform/bios_ia32/start.cpp +++ b/src/system/boot/platform/bios_ia32/start.cpp @@ -19,6 +19,7 @@ #include "apm.h" #include "bios.h" #include "console.h" +#include "cpu.h" #include "debug.h" #include "hpet.h" #include "interrupts.h" diff --git a/src/system/boot/platform/efi/arch/x86_64/arch_timer.cpp b/src/system/boot/platform/efi/arch/x86_64/arch_timer.cpp index a5485fcfbc..430f9aabef 100644 --- a/src/system/boot/platform/efi/arch/x86_64/arch_timer.cpp +++ b/src/system/boot/platform/efi/arch/x86_64/arch_timer.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -40,13 +41,15 @@ hpet_init(void) TRACE(("hpet_init: Looking for HPET...\n")); acpi_hpet *hpet = (acpi_hpet *)acpi_find_table(ACPI_HPET_SIGNATURE); + // Clear hpet kernel args to known invalid state; + gKernelArgs.arch_args.hpet_phys = 0; + gKernelArgs.arch_args.hpet = NULL; + if (hpet == NULL) { // No HPET table in the RSDT. // Since there are no other methods for finding it, // assume we don't have one. TRACE(("hpet_init: HPET not found.\n")); - gKernelArgs.arch_args.hpet_phys = 0; - gKernelArgs.arch_args.hpet = NULL; return; } @@ -60,5 +63,6 @@ hpet_init(void) void arch_timer_init(void) { + calculate_cpu_conversion_factor(2); hpet_init(); } diff --git a/src/system/boot/platform/efi/cpu.cpp b/src/system/boot/platform/efi/cpu.cpp index 5093cfe322..88a3fc5758 100644 --- a/src/system/boot/platform/efi/cpu.cpp +++ b/src/system/boot/platform/efi/cpu.cpp @@ -8,14 +8,11 @@ #include #include #include -#include -extern "C" void +void cpu_init() { - calculate_cpu_conversion_factor(2); - gKernelArgs.num_cpus = 1; // this will eventually be corrected later on } diff --git a/src/system/boot/platform/efi/cpu.h b/src/system/boot/platform/efi/cpu.h new file mode 100644 index 0000000000..b8e39313d1 --- /dev/null +++ b/src/system/boot/platform/efi/cpu.h @@ -0,0 +1,12 @@ +/* + * Copyright 2019-2020, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _EFI_CPU_H +#define _EFI_CPU_H + + +void cpu_init(void); + + +#endif /* _EFI_CPU_H */ diff --git a/src/system/boot/platform/efi/start.cpp b/src/system/boot/platform/efi/start.cpp index 586fee8610..ac4b48d4d5 100644 --- a/src/system/boot/platform/efi/start.cpp +++ b/src/system/boot/platform/efi/start.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -23,6 +22,7 @@ #include "arch_start.h" #include "acpi.h" #include "console.h" +#include "cpu.h" #include "efi_platform.h" #include "mmu.h" #include "quirks.h" @@ -195,12 +195,6 @@ efi_main(efi_handle image, efi_system_table *systemTable) // disable apm in case we ever load a 32-bit kernel... gKernelArgs.platform_args.apm.version = 0; - gKernelArgs.num_cpus = 1; - #if defined(__x86_64__) || defined(__x86__) - gKernelArgs.arch_args.hpet_phys = 0; - gKernelArgs.arch_args.hpet = NULL; - #endif - cpu_init(); acpi_init(); timer_init(); diff --git a/src/system/ldscripts/arm/boot_loader_efi.ld b/src/system/ldscripts/arm/boot_loader_efi.ld new file mode 100644 index 0000000000..6851c1f821 --- /dev/null +++ b/src/system/ldscripts/arm/boot_loader_efi.ld @@ -0,0 +1,66 @@ +OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") +OUTPUT_ARCH(arm) +ENTRY(_start) +SECTIONS +{ + .text 0x0 : { + _text = .; + *(.text.head) + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + *(.srodata) + *(.rodata*) + . = ALIGN(16); + } + _etext = .; + _text_size = . - _text; + .dynamic : { *(.dynamic) } + .data : + { + __ctor_list = .; + *(.ctors) + __ctor_end = .; + _data = .; + *(.sdata) + *(.data) + *(.data1) + *(.data.*) + *(.got.plt) + *(.got) + + /* the EFI loader doesn't seem to like a .bss section, so we stick + it all into .data: */ + . = ALIGN(16); + _bss = .; + *(.sbss) + *(.scommon) + *(.dynbss) + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN(16); + _bss_end = .; + } + + .rel.dyn : { *(.rel.dyn) } + .rel.plt : { *(.rel.plt) } + .rel.got : { *(.rel.got) } + .rel.data : { *(.rel.data) *(.rel.data*) } + _edata = .; + _data_size = . - _etext; + + . = ALIGN(4096); + .dynsym : { *(.dynsym) } + . = ALIGN(4096); + .dynstr : { *(.dynstr) } + . = ALIGN(4096); + .note.gnu.build-id : { *(.note.gnu.build-id) } + /DISCARD/ : + { + *(.rel.reloc) + *(.eh_frame) + *(.note.GNU-stack) + } + .comment 0 : { *(.comment) } +}