[lcrash] ADD: Finish off AcpiInitialize

This commit is contained in:
xwashere 2024-04-09 14:01:02 -04:00
parent d4bb65f49b
commit 76de467bdc
Signed by: XWasHere
GPG Key ID: 042F8BFA1B0EF93B
5 changed files with 142 additions and 0 deletions

53
lcrash/acpi/acpi.c Normal file
View File

@ -0,0 +1,53 @@
#include "acpi.h"
#include "../types.h"
#include "../lnxboot.h"
#include "../util.h"
#include "../efi/memmap.h"
#include "../efi/guid.h"
#include "../efi/efi.h"
bool AcpiIsPresent = false;
struct AcpiRSDP* AcpiTheRSDP = 0;
void AcpiInitialize() {
// Check boot params
if (BootBootParams->acpi_rsdp_addr) {
AcpiTheRSDP = BootBootParams->acpi_rsdp_addr;
goto found;
}
// Check firmware
if (EfiPresent()) {
const struct EfiSystemTable* SystemTable = EfiGetSystemTable();
const struct EfiConfigurationTable* ConfigurationTable = EfiTranslatePointer(SystemTable->ConfigurationTable);
for (int i = 0; i < SystemTable->NumberOfTableEntries; i++) { // this used to break because the cckernel decided to give me one last fuck you
// and corrupt random portions of code, i really really hate DEFLATE.
if (CompareMemory(&ConfigurationTable[i].VendorGuid, &EFI_ACPI_20_TABLE_GUID, sizeof(EfiGuid))) {
AcpiTheRSDP = ConfigurationTable[i].VendorTable;
goto found;
}
}
}
goto fail;
found: // Is this a valid ACPI table?
if (!CompareMemory(AcpiTheRSDP->Signature, "RSD PTR ", 8)) goto fail;
// Check the sum
u8 Sum = 0;
for (int i = 0; i < sizeof(struct AcpiRSDP); i++) Sum += ((u8*)AcpiTheRSDP)[i];
if (Sum != 0) goto fail;
AcpiIsPresent = true;
return;
fail: AcpiIsPresent = false;
return;
}
bool AcpiPresent() { return AcpiIsPresent; }
struct AcpiRSDP* AcpiGetRSDP() { return AcpiTheRSDP; }

45
lcrash/efi/efi.c Normal file
View File

@ -0,0 +1,45 @@
#include "efi.h"
#include "../types.h"
#include "../lnxboot.h"
#include "./memmap.h"
static bool IsPresent = false;
// XXX: This was static but something got fucked up when it was.
// investigate later
const struct EfiSystemTable* SystemTable = 0;
void EfiInitialize() {
// Get the system table
if ((BootBootParams->efi_info.EfiSystemTable | BootBootParams->efi_info.EfiSystemTableHigh) != 0) {
SystemTable = (struct EfiSystemTable*)(
(uptr)BootBootParams->efi_info.EfiSystemTable |
((uptr)BootBootParams->efi_info.EfiSystemTableHigh << 32)
);
} else goto fail;
// Load the memory map
if ((BootBootParams->efi_info.EfiMemoryMap | BootBootParams->efi_info.EfiMemoryMapHigh) != 0) {
if (BootBootParams->efi_info.EfiMemoryDescriptionSize == 0) goto fail;
EfiLoadStoredMemoryMap(
(struct EfiMemoryDescription*)(
(u64)BootBootParams->efi_info.EfiMemoryMap |
((u64)BootBootParams->efi_info.EfiMemoryMapHigh << 32)
),
BootBootParams->efi_info.EfiMemoryMapSize / BootBootParams->efi_info.EfiMemoryDescriptionSize,
BootBootParams->efi_info.EfiMemoryDescriptionSize
);
} else goto fail;
IsPresent = true;
return;
fail: IsPresent = false;
return;
}
bool EfiPresent() { return IsPresent; }
const struct EfiSystemTable* EfiGetSystemTable() { return SystemTable; }

18
lcrash/efi/efi.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include "../types.h"
/**
* Initialize EFI code if EFI is present
*/
void EfiInitialize();
/**
* Check if EFI is present
*/
bool EfiPresent();
/**
* Get the EFI system table
*/
const struct EfiSystemTable* EfiGetSystemTable();

4
lcrash/lnxboot.c Normal file
View File

@ -0,0 +1,4 @@
#include "lnxboot.h"
struct setup_info* BootSetupInfo = 0;
struct boot_params* BootBootParams = 0;

22
lcrash/main.c Normal file
View File

@ -0,0 +1,22 @@
/// lcrash entry point
/// super awesome...
#include "types.h"
#include "lnxboot.h"
#include "efi/efi.h"
[[noreturn]]
void entry64(struct boot_params* BootParams) {
BootBootParams = BootParams;
BootSetupInfo = (void*)BootParams + 0x1f1;
// Initialize EFI code if we had EFI
EfiInitialize();
// Initialize ACPI code if we have ACPI
AcpiInitialize();
// Hang :)
while (1) {}
}