diff --git a/OVMFbin/OVMF_VARS-pure-efi.fd b/OVMFbin/OVMF_VARS-pure-efi.fd index 500991e..eee6b9e 100644 Binary files a/OVMFbin/OVMF_VARS-pure-efi.fd and b/OVMFbin/OVMF_VARS-pure-efi.fd differ diff --git a/kernel/bin/CustomOS.img b/kernel/bin/CustomOS.img index 9955a6b..9db85be 100644 Binary files a/kernel/bin/CustomOS.img and b/kernel/bin/CustomOS.img differ diff --git a/kernel/bin/kernel.elf b/kernel/bin/kernel.elf index a27439b..1544f9d 100755 Binary files a/kernel/bin/kernel.elf and b/kernel/bin/kernel.elf differ diff --git a/kernel/lib/kernel.o b/kernel/lib/kernel.o index 49acf50..d0b11eb 100644 Binary files a/kernel/lib/kernel.o and b/kernel/lib/kernel.o differ diff --git a/kernel/lib/kernelUtil.o b/kernel/lib/kernelUtil.o index 4f5a5a9..44bf972 100644 Binary files a/kernel/lib/kernelUtil.o and b/kernel/lib/kernelUtil.o differ diff --git a/kernel/src/acpi.h b/kernel/src/acpi.h new file mode 100644 index 0000000..48ff176 --- /dev/null +++ b/kernel/src/acpi.h @@ -0,0 +1,33 @@ +#pragma once +#include + +namespace ACPI { + struct RSDP2 { + unsigned char Signature[8]; + uint8_t Checksum; + uint8_t OEMID[6]; + uint8_t Revision; + uint32_t RSDTAddress; + uint32_t Length; + uint64_t XSDTAddress; + uint8_t ExtendedChecksum; + uint8_t Reserved[3]; + }__attribute__((packed)); + + struct SDTHeader { + unsigned char Signature[4]; + uint32_t Length; + uint8_t Revision; + uint8_t Checksum; + uint8_t OEMID[6]; + uint8_t OEMTableID[8]; + uint32_t OEMRevision; + uint32_t CreatorID; + uint32_t CreatorRevision; + }__attribute__((packed)); + + struct MCFGHeader { + SDTHeader Header; + uint64_t Reserved; + }__attribute__((packed)); +}; \ No newline at end of file diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index ae73fcd..101b97b 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -6,14 +6,6 @@ extern "C" void _start(BootInfo* bootInfo) { GlobalRenderer->Print(to_hstring((uint64_t)bootInfo->rsdp)); GlobalRenderer->Next(); - GlobalRenderer->PutChar(*(uint8_t*)bootInfo->rsdp); - GlobalRenderer->PutChar(*((uint8_t*)bootInfo->rsdp + 1)); - GlobalRenderer->PutChar(*((uint8_t*)bootInfo->rsdp + 2)); - GlobalRenderer->PutChar(*((uint8_t*)bootInfo->rsdp + 3)); - GlobalRenderer->PutChar(*((uint8_t*)bootInfo->rsdp + 4)); - GlobalRenderer->PutChar(*((uint8_t*)bootInfo->rsdp + 5)); - GlobalRenderer->PutChar(*((uint8_t*)bootInfo->rsdp + 6)); - GlobalRenderer->PutChar(*((uint8_t*)bootInfo->rsdp + 7)); while (true) { ProcessMousePacket(); diff --git a/kernel/src/kernelUtil.cpp b/kernel/src/kernelUtil.cpp index e40017e..72aea4c 100644 --- a/kernel/src/kernelUtil.cpp +++ b/kernel/src/kernelUtil.cpp @@ -13,6 +13,9 @@ extern "C" void __stack_chk_fail(void) { KernelInfo kernelInfo; PageTableManager pageTableManager = NULL; void PrepareMemory(BootInfo* bootInfo){ + GlobalRenderer->Print(" - Locking kernel pages..."); + GlobalRenderer->Next(); + uint64_t mMapEntries = bootInfo->mMapSize / bootInfo->mMapDescriptorSize; GlobalAllocator = PageFrameAllocator(); @@ -23,6 +26,9 @@ void PrepareMemory(BootInfo* bootInfo){ GlobalAllocator.LockPages(&_KernelStart, kernelPages); + GlobalRenderer->Print(" - Setting up page table manager..."); + GlobalRenderer->Next(); + PageTable* PML4 = (PageTable*)GlobalAllocator.RequestPage(); memset(PML4, 0, 0x1000); @@ -53,6 +59,21 @@ void SetIDTGate(void* handler, uint8_t entryOffset, uint8_t type_attr, uint8_t s interrupt->selector = selector; } +void PrepareACPI(BootInfo* bootInfo) { + ACPI::SDTHeader* xsdt = (ACPI::SDTHeader*)(bootInfo->rsdp->XSDTAddress); + + int entries = (xsdt->Length - sizeof(ACPI::SDTHeader)) / 8; + for (int t = 0; t < entries; t++) { + ACPI::SDTHeader* newSDTHeader = (ACPI::SDTHeader*)*(uint64_t*)((uint64_t)xsdt + sizeof(ACPI::SDTHeader) + (t * 8)); + for (int i = 0; i < 4; i++) { + GlobalRenderer->PutChar(newSDTHeader->Signature[i]); + } + GlobalRenderer->PutChar(' '); + } + + GlobalRenderer->Next(); +} + void PrepareInterrupts() { idtr.Limit = 0x0FFF; idtr.Offset = (uint64_t)GlobalAllocator.RequestPage(); @@ -88,13 +109,11 @@ KernelInfo InitializeKernel(BootInfo* bootInfo){ gdtDescriptor.Offset = (uint64_t)&DefaultGDT; LoadGDT(&gdtDescriptor); - GlobalRenderer->Print("Preparing memory... (this doesn't always work, you may need to restart. sorry.)"); + GlobalRenderer->Print("Preparing memory..."); GlobalRenderer->Next(); PrepareMemory(bootInfo); - //memset(bootInfo->framebuffer->BaseAddress, 0, bootInfo->framebuffer->BufferSize); - GlobalRenderer->Print("Setting up interrupts..."); GlobalRenderer->Next(); @@ -104,6 +123,10 @@ KernelInfo InitializeKernel(BootInfo* bootInfo){ GlobalRenderer->Next(); InitPS2Mouse(); + GlobalRenderer->Print("Setting up ACPI..."); + GlobalRenderer->Next(); + PrepareACPI(bootInfo); + outb(PIC1_DATA, 0b11111001); // unmask 2nd interrupt outb(PIC2_DATA, 0b11101111); diff --git a/kernel/src/kernelUtil.h b/kernel/src/kernelUtil.h index d562392..5c9d102 100644 --- a/kernel/src/kernelUtil.h +++ b/kernel/src/kernelUtil.h @@ -12,6 +12,7 @@ #include "paging/paging.h" #include "paging/PageTableManager.h" #include "userinput/mouse.h" +#include "acpi.h" struct BootInfo { Framebuffer* framebuffer; @@ -19,7 +20,7 @@ struct BootInfo { EFI_MEMORY_DESCRIPTOR* mMap; uint64_t mMapSize; uint64_t mMapDescriptorSize; - void* rsdp; + ACPI::RSDP2* rsdp; }; extern uint64_t _KernelStart;