diff --git a/headers/private/kernel/arch/x86/arch_cpu.h b/headers/private/kernel/arch/x86/arch_cpu.h index 155c88d9d2..dbb6cb1e5c 100644 --- a/headers/private/kernel/arch/x86/arch_cpu.h +++ b/headers/private/kernel/arch/x86/arch_cpu.h @@ -18,6 +18,7 @@ #include #include +#include #include #ifdef __x86_64__ @@ -497,115 +498,6 @@ struct intel_microcode_extended_signature { }; -#define nop() __asm__ ("nop"::) - -#define x86_read_cr0() ({ \ - size_t _v; \ - __asm__("mov %%cr0,%0" : "=r" (_v)); \ - _v; \ -}) - -#define x86_write_cr0(value) \ - __asm__("mov %0,%%cr0" : : "r" (value)) - -#define x86_read_cr2() ({ \ - size_t _v; \ - __asm__("mov %%cr2,%0" : "=r" (_v)); \ - _v; \ -}) - -#define x86_read_cr3() ({ \ - size_t _v; \ - __asm__("mov %%cr3,%0" : "=r" (_v)); \ - _v; \ -}) - -#define x86_write_cr3(value) \ - __asm__("mov %0,%%cr3" : : "r" (value)) - -#define x86_read_cr4() ({ \ - size_t _v; \ - __asm__("mov %%cr4,%0" : "=r" (_v)); \ - _v; \ -}) - -#define x86_write_cr4(value) \ - __asm__("mov %0,%%cr4" : : "r" (value)) - -#define x86_read_dr3() ({ \ - size_t _v; \ - __asm__("mov %%dr3,%0" : "=r" (_v)); \ - _v; \ -}) - -#define x86_write_dr3(value) \ - __asm__("mov %0,%%dr3" : : "r" (value)) - -#define invalidate_TLB(va) \ - __asm__("invlpg (%0)" : : "r" (va)) - -#define wbinvd() \ - __asm__ volatile ("wbinvd" : : : "memory") - -#define set_ac() \ - __asm__ volatile (ASM_STAC : : : "memory") - -#define clear_ac() \ - __asm__ volatile (ASM_CLAC : : : "memory") - -#define xgetbv(reg) ({ \ - uint32 low, high; \ - __asm__ volatile ("xgetbv" : "=a" (low), "=d" (high), "c" (reg)); \ - (low | (uint64)high << 32); \ -}) - -#define xsetbv(reg, value) { \ - uint32 low = value; uint32 high = value >> 32; \ - __asm__ volatile ("xsetbv" : : "a" (low), "d" (high), "c" (reg)); } - -#define out8(value,port) \ - __asm__ ("outb %%al,%%dx" : : "a" (value), "d" (port)) - -#define out16(value,port) \ - __asm__ ("outw %%ax,%%dx" : : "a" (value), "d" (port)) - -#define out32(value,port) \ - __asm__ ("outl %%eax,%%dx" : : "a" (value), "d" (port)) - -#define in8(port) ({ \ - uint8 _v; \ - __asm__ volatile ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); \ - _v; \ -}) - -#define in16(port) ({ \ - uint16 _v; \ - __asm__ volatile ("inw %%dx,%%ax":"=a" (_v) : "d" (port)); \ - _v; \ -}) - -#define in32(port) ({ \ - uint32 _v; \ - __asm__ volatile ("inl %%dx,%%eax":"=a" (_v) : "d" (port)); \ - _v; \ -}) - -#define out8_p(value,port) \ - __asm__ ("outb %%al,%%dx\n" \ - "\tjmp 1f\n" \ - "1:\tjmp 1f\n" \ - "1:" : : "a" (value), "d" (port)) - -#define in8_p(port) ({ \ - uint8 _v; \ - __asm__ volatile ("inb %%dx,%%al\n" \ - "\tjmp 1f\n" \ - "1:\tjmp 1f\n" \ - "1:" : "=a" (_v) : "d" (port)); \ - _v; \ -}) - - extern void (*gCpuIdleFunc)(void); diff --git a/headers/private/kernel/arch/x86/arch_cpuasm.h b/headers/private/kernel/arch/x86/arch_cpuasm.h new file mode 100644 index 0000000000..878c2d6b8b --- /dev/null +++ b/headers/private/kernel/arch/x86/arch_cpuasm.h @@ -0,0 +1,123 @@ +/* + * Copyright 2018, Jérôme Duval, jerome.duval@gmail.com. + * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2012, Alex Smith, alex@alex-smith.me.uk. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ +#ifndef _KERNEL_ARCH_x86_CPUASM_H +#define _KERNEL_ARCH_x86_CPUASM_H + + +#define nop() __asm__ ("nop"::) + +#define x86_read_cr0() ({ \ + size_t _v; \ + __asm__("mov %%cr0,%0" : "=r" (_v)); \ + _v; \ +}) + +#define x86_write_cr0(value) \ + __asm__("mov %0,%%cr0" : : "r" (value)) + +#define x86_read_cr2() ({ \ + size_t _v; \ + __asm__("mov %%cr2,%0" : "=r" (_v)); \ + _v; \ +}) + +#define x86_read_cr3() ({ \ + size_t _v; \ + __asm__("mov %%cr3,%0" : "=r" (_v)); \ + _v; \ +}) + +#define x86_write_cr3(value) \ + __asm__("mov %0,%%cr3" : : "r" (value)) + +#define x86_read_cr4() ({ \ + size_t _v; \ + __asm__("mov %%cr4,%0" : "=r" (_v)); \ + _v; \ +}) + +#define x86_write_cr4(value) \ + __asm__("mov %0,%%cr4" : : "r" (value)) + +#define x86_read_dr3() ({ \ + size_t _v; \ + __asm__("mov %%dr3,%0" : "=r" (_v)); \ + _v; \ +}) + +#define x86_write_dr3(value) \ + __asm__("mov %0,%%dr3" : : "r" (value)) + +#define invalidate_TLB(va) \ + __asm__("invlpg (%0)" : : "r" (va)) + +#define wbinvd() \ + __asm__ volatile ("wbinvd" : : : "memory") + +#define set_ac() \ + __asm__ volatile (ASM_STAC : : : "memory") + +#define clear_ac() \ + __asm__ volatile (ASM_CLAC : : : "memory") + +#define xgetbv(reg) ({ \ + uint32 low, high; \ + __asm__ volatile ("xgetbv" : "=a" (low), "=d" (high), "c" (reg)); \ + (low | (uint64)high << 32); \ +}) + +#define xsetbv(reg, value) { \ + uint32 low = value; uint32 high = value >> 32; \ + __asm__ volatile ("xsetbv" : : "a" (low), "d" (high), "c" (reg)); } + +#define out8(value,port) \ + __asm__ ("outb %%al,%%dx" : : "a" (value), "d" (port)) + +#define out16(value,port) \ + __asm__ ("outw %%ax,%%dx" : : "a" (value), "d" (port)) + +#define out32(value,port) \ + __asm__ ("outl %%eax,%%dx" : : "a" (value), "d" (port)) + +#define in8(port) ({ \ + uint8 _v; \ + __asm__ volatile ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); \ + _v; \ +}) + +#define in16(port) ({ \ + uint16 _v; \ + __asm__ volatile ("inw %%dx,%%ax":"=a" (_v) : "d" (port)); \ + _v; \ +}) + +#define in32(port) ({ \ + uint32 _v; \ + __asm__ volatile ("inl %%dx,%%eax":"=a" (_v) : "d" (port)); \ + _v; \ +}) + +#define out8_p(value,port) \ + __asm__ ("outb %%al,%%dx\n" \ + "\tjmp 1f\n" \ + "1:\tjmp 1f\n" \ + "1:" : : "a" (value), "d" (port)) + +#define in8_p(port) ({ \ + uint8 _v; \ + __asm__ volatile ("inb %%dx,%%al\n" \ + "\tjmp 1f\n" \ + "1:\tjmp 1f\n" \ + "1:" : "=a" (_v) : "d" (port)); \ + _v; \ +}) + + +#endif /* _KERNEL_ARCH_x86_CPUASM_H */ diff --git a/headers/private/kernel/boot/arch/arm/arch_cpu.h b/headers/private/kernel/boot/arch/arm/arch_cpu.h new file mode 100644 index 0000000000..bf89986fac --- /dev/null +++ b/headers/private/kernel/boot/arch/arm/arch_cpu.h @@ -0,0 +1,25 @@ +/* + * Copyright 2013-2020 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef EFI_BOOT_PLATFORM_EFI_ARCH_CPU_H +#define EFI_BOOT_PLATFORM_EFI_ARCH_CPU_H + + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +status_t boot_arch_cpu_init(void); +void arch_ucode_load(BootVolume& volume); + +#ifdef __cplusplus +} +#endif + + +#endif /* EFI_BOOT_PLATFORM_EFI_ARCH_CPU_H */ diff --git a/headers/private/kernel/boot/arch/x86/arch_cpu.h b/headers/private/kernel/boot/arch/x86/arch_cpu.h index 59608e3e25..d9dd1303e4 100644 --- a/headers/private/kernel/boot/arch/x86/arch_cpu.h +++ b/headers/private/kernel/boot/arch/x86/arch_cpu.h @@ -7,6 +7,9 @@ #include +#include + +#include "../../../arch/x86/arch_cpuasm.h" #ifdef __cplusplus @@ -15,15 +18,13 @@ extern "C" { void calculate_cpu_conversion_factor(uint8 channel); +status_t boot_arch_cpu_init(void); +void arch_ucode_load(BootVolume& volume); #ifdef __cplusplus } #endif -#include - -void ucode_load(BootVolume& volume); - #endif /* BOOT_ARCH_CPU_H */ diff --git a/src/system/boot/arch/arm/arch_cpu.cpp b/src/system/boot/arch/arm/arch_cpu.cpp index fdd6d07297..11f8548655 100644 --- a/src/system/boot/arch/arm/arch_cpu.cpp +++ b/src/system/boot/arch/arm/arch_cpu.cpp @@ -1,13 +1,11 @@ /* - * Copyright 2012, Haiku, Inc. + * Copyright 2012-2020, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Ithamar R. Adema */ -#include "cpu.h" - #include #include #include @@ -16,9 +14,9 @@ #include #include #include -#include #include + #define TRACE_CPU #ifdef TRACE_CPU # define TRACE(x) dprintf x @@ -26,6 +24,7 @@ # define TRACE(x) ; #endif + /*! Detect ARM core version and features. Please note the fact that ARM7 and ARMv7 are two different things ;) ARMx is a specific ARM CPU core instance, while ARMvX refers to the @@ -82,8 +81,8 @@ check_cpu_features() break; } - // TODO actually check for VFP support, and maybe there is a better place - // to do this. + // We could check for VFP/NEON support here, but for the moment we only + // really target ARM CPU's with VFP/NEON built-in (cortex-a7+) if (arch >= ARCH_ARM_v7) { // Enable VFP/NEON. We HAVE to do this before the trace call below, @@ -109,20 +108,6 @@ check_cpu_features() } -extern "C" void -arch_cpu_memory_read_barrier(void) -{ - asm volatile ("" : : : "memory"); -} - - -extern "C" void -arch_cpu_memory_write_barrier(void) -{ - asm volatile ("" : : : "memory"); -} - - extern "C" status_t boot_arch_cpu_init(void) { @@ -132,13 +117,17 @@ boot_arch_cpu_init(void) return err; } - gKernelArgs.num_cpus = 1; - // this will eventually be corrected later on - return B_OK; } +extern "C" void +arch_ucode_load(BootVolume& volume) +{ + // NOP on arm currently +} + + extern "C" bigtime_t system_time() { diff --git a/src/system/boot/arch/arm/arch_cpu.h b/src/system/boot/arch/arm/arch_cpu.h deleted file mode 100644 index f904cf2e01..0000000000 --- a/src/system/boot/arch/arm/arch_cpu.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. - * Distributed under the terms of the MIT License. - */ -#ifndef CPU_H -#define CPU_H - - -#include - - -#ifdef __cplusplus -extern "C" { -#endif - -extern void arch_cpu_memory_read_barrier(void); -extern void arch_cpu_memory_write_barrier(void); -extern status_t boot_arch_cpu_init(void); -extern void cpu_init(void); - -#ifdef __cplusplus -} -#endif - -#endif /* CPU_H */ diff --git a/src/system/boot/arch/x86/Jamfile b/src/system/boot/arch/x86/Jamfile index 448a50b4be..1a4f30cbcf 100644 --- a/src/system/boot/arch/x86/Jamfile +++ b/src/system/boot/arch/x86/Jamfile @@ -28,7 +28,7 @@ for platform in [ MultiBootSubDirSetup bios_ia32 efi pxe_ia32 ] { $(kernelArchSpecificSources) $(kernelLibArchSpecificSources) $(librootOsArchSources) - cpu.cpp + arch_cpu.cpp : -std=c++11 # additional flags ; diff --git a/src/system/boot/arch/x86/cpu.cpp b/src/system/boot/arch/x86/arch_cpu.cpp similarity index 98% rename from src/system/boot/arch/x86/cpu.cpp rename to src/system/boot/arch/x86/arch_cpu.cpp index 664baec29b..f24bac34dc 100644 --- a/src/system/boot/arch/x86/cpu.cpp +++ b/src/system/boot/arch/x86/arch_cpu.cpp @@ -387,3 +387,18 @@ spin(bigtime_t microseconds) while ((system_time() - time) < microseconds) asm volatile ("pause;"); } + + +extern "C" status_t +boot_arch_cpu_init() +{ + // Nothing really to init on x86 + return B_OK; +} + + +extern "C" void +arch_ucode_load(BootVolume& volume) +{ + ucode_load(volume); +} diff --git a/src/system/boot/platform/bios_ia32/cpu.cpp b/src/system/boot/platform/bios_ia32/cpu.cpp index 93a782ffbb..9ac3c7fe98 100644 --- a/src/system/boot/platform/bios_ia32/cpu.cpp +++ b/src/system/boot/platform/bios_ia32/cpu.cpp @@ -75,5 +75,5 @@ cpu_init() extern "C" void platform_load_ucode(BootVolume& volume) { - ucode_load(volume); + arch_ucode_load(volume); } diff --git a/src/system/boot/platform/efi/Jamfile b/src/system/boot/platform/efi/Jamfile index b7d62e366d..671d3e52a6 100644 --- a/src/system/boot/platform/efi/Jamfile +++ b/src/system/boot/platform/efi/Jamfile @@ -3,7 +3,7 @@ SubDir HAIKU_TOP src system boot platform efi ; UsePrivateHeaders [ FDirName kernel boot ] ; UsePrivateHeaders [ FDirName kernel platform ] ; UsePrivateHeaders [ FDirName kernel boot platform efi ] ; -UsePrivateHeaders [ FDirName kernel arch $(TARGET_KERNEL_ARCH) ] ; +UsePrivateHeaders [ FDirName kernel boot arch $(TARGET_KERNEL_ARCH) ] ; SubDirHdrs $(HAIKU_TOP) src add-ons kernel partitioning_systems gpt ; @@ -17,6 +17,7 @@ SubDirHdrs $(HAIKU_TOP) src add-ons kernel partitioning_systems gpt ; local platform_src = start.cpp console.cpp + cpu.cpp video.cpp debug.cpp mmu.cpp @@ -25,7 +26,6 @@ local platform_src = timer.cpp menu.cpp devices.cpp - cpu.cpp quirks.cpp smp.cpp serial.cpp diff --git a/src/system/boot/platform/efi/arch/arm/arch_timer.cpp b/src/system/boot/platform/efi/arch/arm/arch_timer.cpp index 0f9f76a535..2debfcf8f6 100644 --- a/src/system/boot/platform/efi/arch/arm/arch_timer.cpp +++ b/src/system/boot/platform/efi/arch/arm/arch_timer.cpp @@ -1,5 +1,5 @@ /* - * Copyright, 2019, Haiku, Inc. All rights reserved. + * Copyright, 2019-2020, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -11,7 +11,6 @@ #include -#include #include #include #include diff --git a/src/system/boot/platform/efi/cpu.cpp b/src/system/boot/platform/efi/cpu.cpp index aab6ad0102..3e07994a3e 100644 --- a/src/system/boot/platform/efi/cpu.cpp +++ b/src/system/boot/platform/efi/cpu.cpp @@ -8,10 +8,10 @@ #include #include #include +#include #include -#ifdef __x86_64__ -# include -#endif + +#include void @@ -19,13 +19,13 @@ cpu_init() { gKernelArgs.num_cpus = 1; // this will eventually be corrected later on + + boot_arch_cpu_init(); } extern "C" void platform_load_ucode(BootVolume& volume) { -#ifdef __x86_64__ - ucode_load(volume); -#endif + arch_ucode_load(volume); }