Kernel: Enable basic paging
This commit is contained in:
parent
3e8590687f
commit
5d7a767f8b
|
@ -3,6 +3,7 @@
|
||||||
#include <kernel/IDT.h>
|
#include <kernel/IDT.h>
|
||||||
#include <kernel/IO.h>
|
#include <kernel/IO.h>
|
||||||
#include <kernel/kprint.h>
|
#include <kernel/kprint.h>
|
||||||
|
#include <kernel/Paging.h>
|
||||||
#include <kernel/panic.h>
|
#include <kernel/panic.h>
|
||||||
#include <kernel/PIC.h>
|
#include <kernel/PIC.h>
|
||||||
#include <kernel/Serial.h>
|
#include <kernel/Serial.h>
|
||||||
|
@ -210,6 +211,7 @@ namespace APIC
|
||||||
static void ParseMADT(RSDPDescriptor* rsdp)
|
static void ParseMADT(RSDPDescriptor* rsdp)
|
||||||
{
|
{
|
||||||
RSDT* root = (RSDT*)(rsdp->revision == 2 ? ((RSDPDescriptor20*)rsdp)->xsdt_address : rsdp->rsdt_address);
|
RSDT* root = (RSDT*)(rsdp->revision == 2 ? ((RSDPDescriptor20*)rsdp)->xsdt_address : rsdp->rsdt_address);
|
||||||
|
Paging::MapRSDP((uint32_t)root & 0xFFC00000);
|
||||||
uint32_t sdt_entry_count = (root->header.length - sizeof(root->header)) / (rsdp->revision == 2 ? 8 : 4);
|
uint32_t sdt_entry_count = (root->header.length - sizeof(root->header)) / (rsdp->revision == 2 ? 8 : 4);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < sdt_entry_count; i++)
|
for (uint32_t i = 0; i < sdt_entry_count; i++)
|
||||||
|
@ -370,6 +372,11 @@ namespace APIC
|
||||||
if (s_local_apic == 0 || s_io_apic == 0)
|
if (s_local_apic == 0 || s_io_apic == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if ((s_io_apic & 0xFFC00000) != (s_local_apic & 0xFFC00000))
|
||||||
|
Kernel::panic("lapic and ioapic are not in the same 4 MiB are");
|
||||||
|
|
||||||
|
Paging::MapAPIC(s_io_apic & 0xFFC00000);
|
||||||
|
|
||||||
// Enable Local APIC
|
// Enable Local APIC
|
||||||
SetMSR(IA32_APIC_BASE, (s_local_apic & 0xFFFFF000) | IA32_APIC_BASE_ENABLE, 0);
|
SetMSR(IA32_APIC_BASE, (s_local_apic & 0xFFFFF000) | IA32_APIC_BASE_ENABLE, 0);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
#include <kernel/Paging.h>
|
||||||
|
#include <kernel/panic.h>
|
||||||
|
|
||||||
|
namespace Paging
|
||||||
|
{
|
||||||
|
|
||||||
|
static uint32_t s_page_directory[1024] __attribute__((aligned(4096)));
|
||||||
|
static uint32_t s_page_table[1024] __attribute__((aligned(4096)));
|
||||||
|
static uint32_t s_page_table_framebuffer[1024] __attribute__((aligned(4096)));
|
||||||
|
static uint32_t s_page_table_rsdp[1024] __attribute__((aligned(4096)));
|
||||||
|
static uint32_t s_page_table_apic[1024] __attribute__((aligned(4096)));
|
||||||
|
|
||||||
|
void Initialize()
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < 1024; i++)
|
||||||
|
s_page_directory[i] = 0x00000002;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < 1024; i++)
|
||||||
|
s_page_table[i] = (i << 12) | 0x03;
|
||||||
|
s_page_directory[0] = (uint32_t)s_page_table | 0x03;
|
||||||
|
|
||||||
|
asm volatile(
|
||||||
|
"movl %%eax, %%cr3;"
|
||||||
|
"movl %%cr0, %%eax;"
|
||||||
|
"orl $0x80000001, %%eax;"
|
||||||
|
"movl %%eax, %%cr0;"
|
||||||
|
:: "a"(s_page_directory)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapFramebuffer(uint32_t address)
|
||||||
|
{
|
||||||
|
uint32_t pd_index = address >> 22;
|
||||||
|
|
||||||
|
if (!(s_page_directory[pd_index] & (1 << 0)))
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < 1024; i++)
|
||||||
|
s_page_table_framebuffer[i] = address | (i << 12) | 0x03;
|
||||||
|
s_page_directory[pd_index] = (uint32_t)s_page_table_framebuffer | 0x03;
|
||||||
|
for (uint32_t i = 0; i < 1024; i++)
|
||||||
|
asm volatile("invlpg (%0)" :: "r" (address | (i << 12)) : "memory");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapRSDP(uint32_t address)
|
||||||
|
{
|
||||||
|
uint32_t pd_index = address >> 22;
|
||||||
|
|
||||||
|
if (!(s_page_directory[pd_index] & (1 << 0)))
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < 1024; i++)
|
||||||
|
s_page_table_rsdp[i] = address | (i << 12) | 0x03;
|
||||||
|
s_page_directory[pd_index] = (uint32_t)s_page_table_rsdp | 0x03;
|
||||||
|
for (uint32_t i = 0; i < 1024; i++)
|
||||||
|
asm volatile("invlpg (%0)" :: "r" (address | (i << 12)) : "memory");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapAPIC(uint32_t address)
|
||||||
|
{
|
||||||
|
uint32_t pd_index = address >> 22;
|
||||||
|
|
||||||
|
if (!(s_page_directory[pd_index] & (1 << 0)))
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < 1024; i++)
|
||||||
|
s_page_table_apic[i] = address | (i << 12) | 0x03;
|
||||||
|
s_page_directory[pd_index] = (uint32_t)s_page_table_apic | 0x03;
|
||||||
|
for (uint32_t i = 0; i < 1024; i++)
|
||||||
|
asm volatile("invlpg (%0)" :: "r" (address | (i << 12)) : "memory");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
#include <kernel/IO.h>
|
#include <kernel/IO.h>
|
||||||
#include <kernel/kmalloc.h>
|
#include <kernel/kmalloc.h>
|
||||||
#include <kernel/multiboot.h>
|
#include <kernel/multiboot.h>
|
||||||
|
#include <kernel/Paging.h>
|
||||||
#include <kernel/panic.h>
|
#include <kernel/panic.h>
|
||||||
#include <kernel/Serial.h>
|
#include <kernel/Serial.h>
|
||||||
#include <kernel/VESA.h>
|
#include <kernel/VESA.h>
|
||||||
|
@ -82,6 +83,8 @@ namespace VESA
|
||||||
s_height = framebuffer.height;
|
s_height = framebuffer.height;
|
||||||
s_mode = framebuffer.type;
|
s_mode = framebuffer.type;
|
||||||
|
|
||||||
|
Paging::MapFramebuffer(framebuffer.addr & 0xFFC00000);
|
||||||
|
|
||||||
if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_GRAPHICS)
|
if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_GRAPHICS)
|
||||||
{
|
{
|
||||||
if (s_bpp != 24 && s_bpp != 32)
|
if (s_bpp != 24 && s_bpp != 32)
|
||||||
|
|
|
@ -10,5 +10,6 @@ $(ARCHDIR)/CPUID.o \
|
||||||
$(ARCHDIR)/font.o \
|
$(ARCHDIR)/font.o \
|
||||||
$(ARCHDIR)/GDT.o \
|
$(ARCHDIR)/GDT.o \
|
||||||
$(ARCHDIR)/IDT.o \
|
$(ARCHDIR)/IDT.o \
|
||||||
|
$(ARCHDIR)/Paging.o \
|
||||||
$(ARCHDIR)/TTY.o \
|
$(ARCHDIR)/TTY.o \
|
||||||
$(ARCHDIR)/VESA.o \
|
$(ARCHDIR)/VESA.o \
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
namespace Paging
|
||||||
|
{
|
||||||
|
|
||||||
|
void Initialize();
|
||||||
|
|
||||||
|
void MapFramebuffer(uint32_t address);
|
||||||
|
void MapRSDP(uint32_t address);
|
||||||
|
void MapAPIC(uint32_t address);
|
||||||
|
|
||||||
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
#include <kernel/kmalloc.h>
|
#include <kernel/kmalloc.h>
|
||||||
#include <kernel/kprint.h>
|
#include <kernel/kprint.h>
|
||||||
#include <kernel/multiboot.h>
|
#include <kernel/multiboot.h>
|
||||||
|
#include <kernel/Paging.h>
|
||||||
#include <kernel/panic.h>
|
#include <kernel/panic.h>
|
||||||
#include <kernel/PIC.h>
|
#include <kernel/PIC.h>
|
||||||
#include <kernel/PIT.h>
|
#include <kernel/PIT.h>
|
||||||
|
@ -50,6 +51,8 @@ extern "C" void kernel_main(multiboot_info_t* mbi, uint32_t magic)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Paging::Initialize();
|
||||||
|
|
||||||
s_multiboot_info = mbi;
|
s_multiboot_info = mbi;
|
||||||
|
|
||||||
if (!VESA::Initialize())
|
if (!VESA::Initialize())
|
||||||
|
|
Loading…
Reference in New Issue