Step to UEFI (140)ProtocolsPerHandle 的例子

Boot Services 提供了 ProtocolsPerHandle 函数,用它可以取得一个 Handle上面的 Protocols。这里编写程序用来验证一下。
函数原型在 UEFI Specification 中可以看到:

pph

编写程序,取得当前 Application 上面的 Protocol:

/** @file
    A simple, basic, application showing how the Hello application could be
    built using the "Standard C Libraries" from StdLib.

    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
    This program and the accompanying materials
    are licensed and made available under the terms and conditions of the BSD License
    which accompanies this distribution. The full text of the license may be found at
    http://opensource.org/licenses/bsd-license.

    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Library/BaseLib.h>
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>

extern EFI_BOOT_SERVICES         *gBS;

EFI_STATUS
EFIAPI
UefiMain (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
        EFI_GUID     **ProtocolBuffer;
        UINTN        ProtocolCount;
        EFI_STATUS   Status;
        UINTN        i;
        
        Status = gBS->ProtocolsPerHandle(ImageHandle, &ProtocolBuffer, &ProtocolCount);
        if (EFI_ERROR (Status)) {
                //
                // TheHandle is not valid, so do not add to handle list
                //
                Print(L"Can't get Protcols on ImageHandle\n");
                return 0;
        }

        Print(L"Protocol list\n");        
        for (i=0;i<ProtocolCount;i++)   {
                Print(L"%g \n",ProtocolBuffer[i]);
        }
        FreePool (ProtocolBuffer);
        

        return 0;
}

 

运行结果如下(NT32虚拟机中运行结果):

pph2

在 DEC 文件中查找这些 GUID对应的 Protocol,如下:

752F3136-4E16-4FDC-A22A-E5F46812F4CA gEfiShellParametersProtocolGuid
BC62157E-3E33-4FEC-9920-2D3B36D750DF gEfiLoadedImageDevicePathProtocolGuid
5B1B31A1-9562-11D2-8E3F-00A0C969723B gEfiLoadedImageProtocolGuid

源代码和EFI下载:
sd

发表评论

电子邮件地址不会被公开。 必填项已用*标注