mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:18:11 +00:00
Kernel: Move all CPU feature initialization into cpu_setup()
..and do it very very early in boot.
This commit is contained in:
parent
210adaeca6
commit
6fea316611
4 changed files with 61 additions and 90 deletions
|
@ -578,7 +578,7 @@ bool g_cpu_supports_sse;
|
|||
bool g_cpu_supports_tsc;
|
||||
bool g_cpu_supports_umip;
|
||||
|
||||
void detect_cpu_features()
|
||||
void cpu_detect()
|
||||
{
|
||||
CPUID processor_info(0x1);
|
||||
g_cpu_supports_pae = (processor_info.edx() & (1 << 6));
|
||||
|
@ -612,17 +612,22 @@ void clac()
|
|||
: "cc");
|
||||
}
|
||||
|
||||
void x86_enable_pae()
|
||||
void cpu_setup()
|
||||
{
|
||||
// Turn on CR4.PAE
|
||||
asm volatile(
|
||||
"mov %cr4, %eax\n"
|
||||
"orl $0x20, %eax\n"
|
||||
"mov %eax, %cr4\n");
|
||||
}
|
||||
cpu_detect();
|
||||
|
||||
if (g_cpu_supports_sse) {
|
||||
sse_init();
|
||||
kprintf("x86: SSE support enabled\n");
|
||||
}
|
||||
|
||||
asm volatile(
|
||||
"movl %%cr0, %%eax\n"
|
||||
"orl $0x00010000, %%eax\n"
|
||||
"movl %%eax, %%cr0\n" ::
|
||||
: "%eax", "memory");
|
||||
kprintf("x86: WP support enabled\n");
|
||||
|
||||
void x86_enable_pge()
|
||||
{
|
||||
if (g_cpu_supports_pge) {
|
||||
// Turn on CR4.PGE so the CPU will respect the G bit in page tables.
|
||||
asm volatile(
|
||||
|
@ -633,39 +638,7 @@ void x86_enable_pge()
|
|||
} else {
|
||||
kprintf("x86: PGE support not detected\n");
|
||||
}
|
||||
}
|
||||
|
||||
void x86_enable_smep()
|
||||
{
|
||||
if (g_cpu_supports_smep) {
|
||||
// Turn on CR4.SMEP
|
||||
asm volatile(
|
||||
"mov %cr4, %eax\n"
|
||||
"orl $0x100000, %eax\n"
|
||||
"mov %eax, %cr4\n");
|
||||
kprintf("x86: SMEP support enabled\n");
|
||||
} else {
|
||||
kprintf("x86: SMEP support not detected\n");
|
||||
}
|
||||
}
|
||||
|
||||
void x86_enable_smap()
|
||||
{
|
||||
if (g_cpu_supports_smap) {
|
||||
// Turn on CR4.SMAP
|
||||
kprintf("x86: Enabling SMAP\n");
|
||||
asm volatile(
|
||||
"mov %cr4, %eax\n"
|
||||
"orl $0x200000, %eax\n"
|
||||
"mov %eax, %cr4\n");
|
||||
kprintf("x86: SMAP support enabled\n");
|
||||
} else {
|
||||
kprintf("x86: SMAP support not detected\n");
|
||||
}
|
||||
}
|
||||
|
||||
void x86_enable_nx()
|
||||
{
|
||||
if (g_cpu_supports_nx) {
|
||||
// Turn on IA32_EFER.NXE
|
||||
asm volatile(
|
||||
|
@ -677,13 +650,49 @@ void x86_enable_nx()
|
|||
} else {
|
||||
kprintf("x86: NX support not detected\n");
|
||||
}
|
||||
}
|
||||
|
||||
void x86_enable_wp()
|
||||
{
|
||||
asm volatile(
|
||||
"movl %%cr0, %%eax\n"
|
||||
"orl $0x00010000, %%eax\n"
|
||||
"movl %%eax, %%cr0\n" ::
|
||||
: "%eax", "memory");
|
||||
if (g_cpu_supports_smep) {
|
||||
// Turn on CR4.SMEP
|
||||
asm volatile(
|
||||
"mov %cr4, %eax\n"
|
||||
"orl $0x100000, %eax\n"
|
||||
"mov %eax, %cr4\n");
|
||||
kprintf("x86: SMEP support enabled\n");
|
||||
} else {
|
||||
kprintf("x86: SMEP support not detected\n");
|
||||
}
|
||||
|
||||
if (g_cpu_supports_smap) {
|
||||
// Turn on CR4.SMAP
|
||||
kprintf("x86: Enabling SMAP\n");
|
||||
asm volatile(
|
||||
"mov %cr4, %eax\n"
|
||||
"orl $0x200000, %eax\n"
|
||||
"mov %eax, %cr4\n");
|
||||
kprintf("x86: SMAP support enabled\n");
|
||||
} else {
|
||||
kprintf("x86: SMAP support not detected\n");
|
||||
}
|
||||
|
||||
if (g_cpu_supports_umip) {
|
||||
asm volatile(
|
||||
"mov %cr4, %eax\n"
|
||||
"orl $0x800, %eax\n"
|
||||
"mov %eax, %cr4\n");
|
||||
kprintf("x86: UMIP support enabled\n");
|
||||
}
|
||||
|
||||
if (g_cpu_supports_tsc) {
|
||||
asm volatile(
|
||||
"mov %cr4, %eax\n"
|
||||
"orl $0x4, %eax\n"
|
||||
"mov %eax, %cr4\n");
|
||||
kprintf("x86: RDTSC support restricted\n");
|
||||
}
|
||||
|
||||
if (g_cpu_supports_rdrand) {
|
||||
kprintf("x86: Using RDRAND for good randomness\n");
|
||||
} else {
|
||||
kprintf("x86: No RDRAND support detected. Randomness will be shitty\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -553,7 +553,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
void detect_cpu_features();
|
||||
void cpu_setup();
|
||||
extern bool g_cpu_supports_nx;
|
||||
extern bool g_cpu_supports_pae;
|
||||
extern bool g_cpu_supports_pge;
|
||||
|
@ -566,12 +566,6 @@ extern bool g_cpu_supports_umip;
|
|||
|
||||
void stac();
|
||||
void clac();
|
||||
void x86_enable_pae();
|
||||
void x86_enable_pge();
|
||||
void x86_enable_smep();
|
||||
void x86_enable_smap();
|
||||
void x86_enable_nx();
|
||||
void x86_enable_wp();
|
||||
|
||||
class SmapDisabler {
|
||||
public:
|
||||
|
|
|
@ -53,13 +53,6 @@ MemoryManager::MemoryManager()
|
|||
|
||||
parse_memory_map();
|
||||
|
||||
x86_enable_pae();
|
||||
x86_enable_pge();
|
||||
x86_enable_smep();
|
||||
x86_enable_smap();
|
||||
x86_enable_nx();
|
||||
x86_enable_wp();
|
||||
|
||||
asm volatile("movl %%eax, %%cr3" ::"a"(kernel_page_directory().cr3()));
|
||||
|
||||
setup_low_1mb();
|
||||
|
|
|
@ -277,7 +277,7 @@ extern "C" [[noreturn]] void init()
|
|||
if (cmdline && bad_prefix_check(reinterpret_cast<const char*>(cmdline), "serial_debug"))
|
||||
set_serial_debug(true);
|
||||
|
||||
detect_cpu_features();
|
||||
cpu_setup();
|
||||
|
||||
kmalloc_init();
|
||||
slab_alloc_init();
|
||||
|
@ -309,32 +309,7 @@ extern "C" [[noreturn]] void init()
|
|||
|
||||
kprintf("Starting SerenityOS...\n");
|
||||
|
||||
if (g_cpu_supports_sse) {
|
||||
sse_init();
|
||||
kprintf("x86: SSE support enabled\n");
|
||||
}
|
||||
|
||||
if (g_cpu_supports_umip) {
|
||||
asm volatile(
|
||||
"mov %cr4, %eax\n"
|
||||
"orl $0x800, %eax\n"
|
||||
"mov %eax, %cr4\n");
|
||||
kprintf("x86: UMIP support enabled\n");
|
||||
}
|
||||
|
||||
if (g_cpu_supports_tsc) {
|
||||
asm volatile(
|
||||
"mov %cr4, %eax\n"
|
||||
"orl $0x4, %eax\n"
|
||||
"mov %eax, %cr4\n");
|
||||
kprintf("x86: RDTSC support restricted\n");
|
||||
}
|
||||
|
||||
if (g_cpu_supports_rdrand) {
|
||||
kprintf("x86: Using RDRAND for good randomness\n");
|
||||
} else {
|
||||
kprintf("x86: No RDRAND support detected. Randomness will be shitty\n");
|
||||
}
|
||||
|
||||
__stack_chk_guard = get_good_random<u32>();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue