diff --git a/drivers/acpi.cpp b/drivers/acpi.cpp index 29c2bfc..a09410c 100644 --- a/drivers/acpi.cpp +++ b/drivers/acpi.cpp @@ -653,6 +653,50 @@ UINT32 ACPIPowerButtonPressed(void *) { return 0; } +void ACPIFoundDevice(const char *name, ACPI_HANDLE object) { + if (0 == EsCRTstrcmp(name, "PCI0")) { + ACPI_BUFFER buffer = {}; + ACPI_STATUS status = AcpiGetIrqRoutingTable(object, &buffer); + if (status != AE_BUFFER_OVERFLOW) return; + buffer.Pointer = EsHeapAllocate(buffer.Length, false, K_FIXED); + EsDefer(EsHeapFree(buffer.Pointer, buffer.Length, K_FIXED)); + if (!buffer.Pointer) return; + status = AcpiGetIrqRoutingTable(object, &buffer); + if (status != AE_OK) return; + ACPI_PCI_ROUTING_TABLE *table = (ACPI_PCI_ROUTING_TABLE *) buffer.Pointer; + + while (table->Length) { + KernelLog(LOG_INFO, "ACPI", "PRT entry", "length: %d; pin: %d; address: %x; source index: %d; source: %z\n", + table->Length, table->Pin, table->Address, table->SourceIndex, table->Source); + table = (ACPI_PCI_ROUTING_TABLE *) ((uint8_t *) table + table->Length); + } + } else if (0 == EsCRTmemcmp(name, "LNK", 3)) { + ACPI_BUFFER buffer = {}; + ACPI_STATUS status = AcpiGetCurrentResources(object, &buffer); + if (status != AE_BUFFER_OVERFLOW) return; + buffer.Pointer = EsHeapAllocate(buffer.Length, false, K_FIXED); + EsDefer(EsHeapFree(buffer.Pointer, buffer.Length, K_FIXED)); + if (!buffer.Pointer) return; + status = AcpiGetCurrentResources(object, &buffer); + if (status != AE_OK) return; + ACPI_RESOURCE *resource = (ACPI_RESOURCE *) buffer.Pointer; + + while (resource->Type != ACPI_RESOURCE_TYPE_END_TAG) { + if (resource->Type == ACPI_RESOURCE_TYPE_IRQ) { + KernelLog(LOG_INFO, "ACPI", "IRQ resource", "count: %d; first: %d\n", + resource->Data.Irq.InterruptCount, resource->Data.Irq.Interrupts[0]); + } else if (resource->Type == ACPI_RESOURCE_TYPE_EXTENDED_IRQ) { + KernelLog(LOG_INFO, "ACPI", "IRQ resource", "count: %d; first: %d; (extended)\n", + resource->Data.ExtendedIrq.InterruptCount, resource->Data.ExtendedIrq.Interrupts[0]); + } + + resource = (ACPI_RESOURCE *) ((uint8_t *) resource + resource->Length); + } + + // TODO. + } +} + #endif void ACPIInitialise2() { @@ -675,10 +719,17 @@ void ACPIInitialise2() { AcpiGetDevices(nullptr, [] (ACPI_HANDLE object, uint32_t, void *, void **) -> ACPI_STATUS { ACPI_DEVICE_INFO *information; AcpiGetObjectInfo(object, &information); - KernelLog(LOG_INFO, "ACPI", "device object", "Found device object '%c%c%c%c' with HID '%z' and UID '%z'.\n", - (char) (information->Name >> 0), (char) (information->Name >> 8), (char) (information->Name >> 16), (char) (information->Name >> 24), - (information->Valid & ACPI_VALID_HID) ? information->HardwareId.String : "??", + + char name[5]; + EsMemoryCopy(name, &information->Name, 4); + name[4] = 0; + + KernelLog(LOG_INFO, "ACPI", "device object", "Found device object '%z' with HID '%z' and UID '%z'.\n", + name, (information->Valid & ACPI_VALID_HID) ? information->HardwareId.String : "??", (information->Valid & ACPI_VALID_UID) ? information->UniqueId.String : "??"); + + ACPIFoundDevice(name, object); + ACPI_FREE(information); return AE_OK; }, nullptr, &result); diff --git a/util/build.c b/util/build.c index 71d9717..e092cb0 100644 --- a/util/build.c +++ b/util/build.c @@ -479,7 +479,15 @@ void Run(int emulator, int log, int debug) { CallSystem("VBoxManage storageattach Essence --storagectl AHCI --port 0 --device 0 --type hdd --medium none"); CallSystem("VBoxManage closemedium disk bin/vbox.vdi --delete"); - CallSystem("VBoxManage convertfromraw bin/drive bin/vbox.vdi --format VDI"); + if (IsOptionEnabled("Emulator.GenerateVDIForUEFI")) { + CallSystem("util/uefi.sh"); + CallSystem("VBoxManage convertfromraw bin/uefi_drive bin/vbox.vdi --format VDI"); + CallSystem("VBoxManage modifyvm Essence --firmware efi"); + } else { + CallSystem("VBoxManage convertfromraw bin/drive bin/vbox.vdi --format VDI"); + CallSystem("VBoxManage modifyvm Essence --firmware bios"); + } + CallSystem("VBoxManage storageattach Essence --storagectl AHCI --port 0 --device 0 --type hdd --medium bin/vbox.vdi"); CallSystem("VBoxManage startvm --putenv VBOX_GUI_DBG_ENABLED=true Essence"); diff --git a/util/build_common.h b/util/build_common.h index 1257c44..9ce6937 100644 --- a/util/build_common.h +++ b/util/build_common.h @@ -304,6 +304,7 @@ Option options[] = { { "Emulator.Cores", OPTION_TYPE_STRING, { .s = "1" } }, { "Emulator.PrimaryDriveMB", OPTION_TYPE_STRING, { .s = "1024" } }, { "Emulator.SecondaryDriveMB", OPTION_TYPE_STRING, { .s = NULL } }, + { "Emulator.GenerateVDIForUEFI", OPTION_TYPE_BOOL, { .b = false } }, { "General.first_application", OPTION_TYPE_STRING, { .s = NULL } }, { "General.wallpaper", OPTION_TYPE_STRING, { .s = NULL } }, { "General.installation_state", OPTION_TYPE_STRING, { .s = "0" } }, diff --git a/util/uefi.sh b/util/uefi.sh index 02b6e62..af65163 100755 --- a/util/uefi.sh +++ b/util/uefi.sh @@ -22,6 +22,7 @@ sudo losetup --offset `fdisk -l bin/uefi_drive | grep 'EFI System' | awk '{print sudo mount /dev/loop0 mount sudo mkdir -p mount/EFI/BOOT sudo cp bin/uefi mount/EFI/BOOT/BOOTX64.EFI +sudo cp bin/uefi mount/es.efi sudo cp bin/Kernel.esx mount/eskernel.esx sudo cp bin/uefi_loader mount/esloader.bin sudo cp bin/iid.dat mount/esiid.dat @@ -31,4 +32,4 @@ rmdir mount dd if=bin/drive of=bin/uefi_drive bs=512 count=`fdisk -l bin/drive | grep 'Linux' | awk '{print $5}'` skip=`fdisk -l bin/drive | grep 'Linux' | awk '{print $3}'` seek=`fdisk -l bin/uefi_drive | grep 'Linux filesystem' | awk '{print $2}'` conv=notrunc -qemu-system-x86_64 -bios /usr/share/ovmf/x64/OVMF.fd -drive file=bin/uefi_drive,format=raw,media=disk,index=0 -s -device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0,id=mykeyboard -device usb-mouse,bus=xhci.0,id=mymouse +# qemu-system-x86_64 -bios /usr/share/ovmf/x64/OVMF.fd -drive file=bin/uefi_drive,format=raw,media=disk,index=0 -s -device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0,id=mykeyboard -device usb-mouse,bus=xhci.0,id=mymouse