efi: Refactor CPU code to be arch-specific
* Migrate some platform agnostic architecture code into boot/arch from efi/arch. This helps to avoid conflicts between kernel and boot sources as well. * Conflicts between arch_cpu in efi and kernel code means bootcode really should *never* directly use kernel arch headers. (other platforms don't, which is why they don't have this same issue) * We carefully thread any needed kernel headers (namely assembly helper macros) into the bootloader headers without mixing in the whole conflicting kernel/arch headers. * ARM now properly get its cpu init code called, and we progress further into the EFI bootloader. Change-Id: If67ec9758b5ce68563ebd9eb45d5196401911c67 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2975 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
1f2666fd48
commit
89fd39f42a
@@ -18,6 +18,7 @@
|
||||
#include <arch_thread_types.h>
|
||||
|
||||
#include <arch/x86/arch_altcodepatch.h>
|
||||
#include <arch/x86/arch_cpuasm.h>
|
||||
#include <arch/x86/descriptors.h>
|
||||
|
||||
#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);
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright 2018, Jérôme Duval, [email protected].
|
||||
* Copyright 2002-2009, Axel Dörfler, [email protected].
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* 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 */
|
||||
@@ -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 <SupportDefs.h>
|
||||
#include <boot/vfs.h>
|
||||
|
||||
|
||||
#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 */
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <boot/vfs.h>
|
||||
|
||||
#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 <boot/vfs.h>
|
||||
|
||||
void ucode_load(BootVolume& volume);
|
||||
|
||||
|
||||
#endif /* BOOT_ARCH_CPU_H */
|
||||
|
||||
Reference in New Issue
Block a user