[metal] Add a uprintf() routine, for non-emergency boot logging (#905)

* [metal] Add a uprintf() routine, for non-emergency boot logging
* [metal] _Really_ push forward timing of VGA TTY initialization
* [metal] Do something useful with uprintf()
* [metal] Locate some ACPI tables, for later hardware detection

Specifically the code now tries to find the ACPI RSDP,
RSDT/XSDT, FADT, & MADT tables, whether in legacy BIOS
bootup mode or in a UEFI bootup.  These are useful for
figuring out how to (re)enable asynchronous interrupts
in legacy 8259 PIC mode.
This commit is contained in:
tkchia 2023-10-26 05:32:20 +08:00 committed by GitHub
parent 062b2d776e
commit ed17d3008b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 999 additions and 36 deletions

View file

@ -43,6 +43,8 @@ struct EfiArgs {
static EFI_GUID kEfiLoadedImageProtocol = LOADED_IMAGE_PROTOCOL;
static EFI_GUID kEfiGraphicsOutputProtocol = GRAPHICS_OUTPUT_PROTOCOL;
static const EFI_GUID kEfiAcpi20TableGuid = ACPI_20_TABLE_GUID;
static const EFI_GUID kEfiAcpi10TableGuid = ACPI_10_TABLE_GUID;
extern const char vga_console[];
extern void _EfiPostboot(struct mman *, uint64_t *, uintptr_t, char **);
@ -117,6 +119,25 @@ static void EfiInitVga(struct mman *mm, EFI_SYSTEM_TABLE *SystemTable) {
GraphMode->FrameBufferSize, 0);
}
static void EfiInitAcpi(struct mman *mm, EFI_SYSTEM_TABLE *SystemTable) {
void *rsdp1 = NULL, *rsdp2 = NULL;
uintptr_t n = SystemTable->NumberOfTableEntries, i;
EFI_CONFIGURATION_TABLE *tab;
for (i = 0, tab = SystemTable->ConfigurationTable; i < n; ++i, ++tab) {
EFI_GUID *guid = &tab->VendorGuid;
if (memcmp(guid, &kEfiAcpi20TableGuid, sizeof(EFI_GUID)) == 0) {
rsdp2 = tab->VendorTable;
} else if (memcmp(guid, &kEfiAcpi20TableGuid, sizeof(EFI_GUID)) == 0) {
rsdp1 = tab->VendorTable;
}
}
if (rsdp2) {
mm->pc_acpi_rsdp = (uintptr_t)rsdp2;
} else {
mm->pc_acpi_rsdp = (uintptr_t)rsdp1;
}
}
/**
* EFI Application Entrypoint.
*
@ -203,6 +224,11 @@ __msabi EFI_STATUS EfiMain(EFI_HANDLE ImageHandle,
*/
if (_weaken(vga_console)) EfiInitVga(mm, SystemTable);
/*
* Gets a pointer to the ACPI RSDP.
*/
EfiInitAcpi(mm, SystemTable);
/*
* Asks UEFI which parts of our RAM we're allowed to use.
*/

View file

@ -39,9 +39,12 @@ struct mman {
struct { /* 0x1d48 — starting cursor pos. */
unsigned short y, x;
} pc_video_curs_info;
unsigned short pc_video_char_height; /* 0x1d4c — character height (useful
for setting cursor shape
in text mode) */
unsigned short pc_video_char_height; /* 0x1d4c — character height (useful
for setting cursor shape
in text mode) */
uint64_t pc_acpi_rsdp; /* 0x1d50 — pointer to ACPI RSDP;
NULL means to search for
it in legacy BIOS areas */
};
COSMOPOLITAN_C_END_