在引入 CLIB 之前,获得 SystemTable 等等是非常简单的事情,入口参数上直接就能取得。但是引入了 CLIB 之后似乎没有那么直白了。研究了一下发现,用下面的语句可以轻松解决:
extern EFI_SYSTEM_TABLE *gST;
随手写个程序测试
/** @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 <Uefi.h> #include <Library/UefiLib.h> #include <Library/ShellCEntryLib.h> #include <stdio.h> #include <wchar.h> extern EFI_SYSTEM_TABLE *gST; /*** Demonstrates basic workings of the main() function by displaying a welcoming message. Note that the UEFI command line is composed of 16-bit UCS2 wide characters. The easiest way to access the command line parameters is to cast Argv as: wchar_t **wArgv = (wchar_t **)Argv; @param[in] Argc Number of argument tokens pointed to by Argv. @param[in] Argv Array of Argc pointers to command line tokens. @retval 0 The application exited normally. @retval Other An error occurred. ***/ int EFIAPI main ( IN int Argc, IN char **Argv ) { gST -> ConOut -> OutputString (gST->ConOut,L"Hello,www.lab-z.com\n"); return EFI_SUCCESS; }
运行结果
程序太简单就不上了。
【补充】在 http://biosren.com/viewthread.php?tid=7295&highlight= 有个朋友问了同样的问题,最后他的解决方式是:
加入头文件 #include Library/UefiBootServicesTableLib.h ,这个头文件的内容是
#ifndef __UEFI_BOOT_SERVICES_TABLE_LIB_H__
#define __UEFI_BOOT_SERVICES_TABLE_LIB_H__
///
/// Cache the Image Handle
///
extern EFI_HANDLE gImageHandle;
///
/// Cache pointer to the EFI System Table
///
extern EFI_SYSTEM_TABLE *gST;
///
/// Cache pointer to the EFI Boot Services Table
///
extern EFI_BOOT_SERVICES *gBS;
#endif
所以和前面提到的解决方法还是相同的