QEMU UEFI应用程序始终为SetTimer返回无效参数

时间:2019-03-22 05:44:29

标签: operating-system kernel qemu uefi

我正在运行一个经典示例,该示例为在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源和示例参考之后,我不确定是什么引起了这个问题,但是看起来我在这里做对了。我的装置中有些奇怪的东西吗?我将代码简化为最简单的代码。也许有个错误?

1 个答案:

答案 0 :(得分:0)

NotifyTpl = TPL_APPLICATIONCreateEvent()中没有任何意义。您至少需要使用TPL_CALLBACK。请参阅UEFI-2.7规范中的“表23. TPL限制”,其中包括“事件通知级别> TPL_APPLICATION”。