我正在运行一个经典的例子,为在qemu上运行的uefi应用程序设置一个计时器。我正在运行的代码:
#include <efi.h>
#include <efilib.h>
#include <eficon.h>
#define second 10000000
EFI_STATUS
EFIAPI
efi_main (EFI_HANDLE img, EFI_SYSTEM_TABLE *sys) {
EFI_EVENT timer_event;
EFI_STATUS stat;
InitializeLib(img, sys);
// This succeeds, though I've tried with EVT_TIMER and EFI_EVENT_TIMER
stat = sys->
BootServices->CreateEvent(EVT_TIMER, TPL_APPLICATION, NULL,
NULL, &timer_event);
// This returns 2 == invalid parameter, however I want SetTimer to
// return 0 == success
stat = sys->
BootServices->SetTimer(timer_event, TimerRelative, 10000);
if (stat == EFI_INVALID_PARAMETER) Print(L"This always prints :(");
while(1){}
return EFI_SUCCESS;
}
我启动的命令是这样的:
qemu-system-x86_64 -smp 3 -rtc clock=host -nographic -enable-kvm -m 4096 -cpu host -usb -device usb-kbd -drive if=pflash,format=raw,readonly,file=/usr/share/edk2.git/ovmf-x64/OVMF-pure-efi.fd -drive file=$BASE_DIR/qos.img,index=0,format=raw
在阅读了规范,edk2源代码和示例引用之后,我不确定是什么导致了这个问题,但看起来我在这里做的正确。我的设置中有什么奇怪的东西吗?我把代码简化为最简单的东西。也许有一个错误?
NotifyTpl = TPL_APPLICATION
在CreateEvent()
毫无意义。你需要至少使用TPL_CALLBACK
。请参阅UEFI-2.7规范中的“表23. TPL限制”,其中包括“事件通知级别> TPL_APPLICATION”。