EFI_GUID gMyCustomProtocolGuid = {0x}; // 替换GUID
//A4F610BB-CBA1-01E0-1135-FB00E055C6AF
typedef struct _MY_CUSTOM_PROTOCOL {
UINT32 Version;
EFI_STATUS (EFIAPI *Function)(IN UINTN Number);
} MY_CUSTOM_PROTOCOL;
VOID
EFIAPI
CallbackFunction(
IN EFI_EVENT Event,
IN VOID *Context
);
EFI_STATUS
EFIAPI
InitializeMyDriver(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status = EFI_SUCCESS;
MY_CUSTOM_PROTOCOL *Protocol = NULL;
EFI_EVENT Event;
EFI_HANDLE Handle = NULL;
DEBUG((EFI_D_INFO, "[MyDriver] Initializing...\n"));
Status = gBS->AllocatePool(
EfiBootServicesData,
sizeof(MY_CUSTOM_PROTOCOL),
(VOID**)&Protocol
);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "[MyDriver] Memory allocation failed! %r\n", Status));
return Status;
}
Protocol->Revision = 1;
Protocol->Function = CallbackFunction;
Status = gBS->CreateEventEx(
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
CallbackFunction,
NULL,
&gEfiEventReadyToBootGuid,
&Event
);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "[MyDriver] Event creation failed! %r\n", Status));
gBS->FreePool(Protocol);
return Status;
}
Status = gBS->InstallProtocolInterface(
&Handle,
&gMyCustomProtocolGuid,
EFI_NATIVE_INTERFACE,
Protocol
);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "[MyDriver] Protocol installation failed! %r\n", Status));
gBS->CloseEvent(Event);
gBS->FreePool(Protocol);
return Status;
}
DEBUG((EFI_D_INFO, "[MyDriver] Initialization completed successfully\n"));
return Status;
}
VOID
EFIAPI
CallbackFunction(
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
EFI_EVENT TimerEvent;
Print("Callback function hit!\n");
Print("2s to wait")
// Create a function
Status = gBS->CreateEvent(EVT_TIMER, 0, NULL, NULL, &TimerEvent);
if (EFI_ERROR(Status)) return Status;
// Set a timer
Status = gBS->SetTimer(TimerEvent, TimerRelative, 20000000);
if (EFI_ERROR(Status)) {
gBS->CloseEvent(TimerEvent);
return Status;
}
gBS->WaitForEvent(1, &TimerEvent, NULL);
Print("Resume after pause!\n");
gBS->CloseEvent(TimerEvent);
return EFI_SUCCESS;
}