Created
April 23, 2013 12:08
-
-
Save 0xeuclid/5443044 to your computer and use it in GitHub Desktop.
This program demo how INIT_LIST works in EFI system. By using typedef (FUNC_POINTER)(fun_arg1,fun_arg2,...) We can write make as BootOptionDpMatchingFunctions = \ LocateDevicePathTest,\ PartitionDevicePathTest,\ UsbClassDevicePathTest,\ BbsDevicePathTest,\ AmiBbsDevicePathTest,\ AmiDeviceNameDevicePathTest,\ DeviceTypeDevicePathTest, And there'…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************* | |
[Name]: | |
init_list.c | |
[Description]: | |
This is example to describe: | |
[Author]: | |
[email protected] | |
[Revision]: 2013/4/23 下午 07:41:52 | |
[Note]: | |
This program demo how INIT_LIST works in EFI system. | |
By using typedef (FUNC_POINTER)(fun_arg1,fun_arg2,...) | |
We can write make as | |
BootOptionDpMatchingFunctions = \ | |
LocateDevicePathTest,\ | |
PartitionDevicePathTest,\ | |
UsbClassDevicePathTest,\ | |
BbsDevicePathTest,\ | |
AmiBbsDevicePathTest,\ | |
AmiDeviceNameDevicePathTest,\ | |
DeviceTypeDevicePathTest, | |
And there'll be \D arg in make file for C using, ex: | |
INIT_LIST_DEFINES=/D"INIT_LIST=$(INIT_LIST)" | |
Thus, the term "EndOfInitList" becomes dummy value, | |
it will always be defined to NULL : | |
INIT_FUNCTION* InitList[] = {INIT_LIST NULL}; | |
*********************************************************/ | |
#include<stdio.h> | |
//EFI definition >>> | |
typedef int EFI_STATUS; | |
typedef unsigned int UINTN; | |
typedef void VOID; | |
#define IN | |
#define OUT | |
//<<< | |
//Make file definition simulating >>> | |
#define INIT_LIST \ | |
fun1, \ | |
fun2, \ | |
fun3, | |
//<<< | |
//Function definition >>> | |
EFI_STATUS fun1(VOID* x, VOID* y){ return 1 ;} | |
EFI_STATUS fun2(VOID* x, VOID* y){ return 2 ;} | |
EFI_STATUS fun3(VOID* x, VOID* y){ return 3 ;} | |
//<<< | |
typedef EFI_STATUS (INIT_FUNCTION)(IN VOID* ImageHandle, IN VOID *SystemTable); | |
VOID InitParts(IN VOID* ImageHandle, IN VOID *SystemTable) ; | |
INIT_FUNCTION INIT_LIST EndOfInitList; | |
INIT_FUNCTION* InitList[] = {INIT_LIST NULL}; | |
//---MAIN: | |
int main(){ | |
InitParts(0,0) ; | |
return 0; | |
} | |
VOID InitParts(IN VOID* ImageHandle, IN VOID *SystemTable) | |
{ | |
UINTN i; | |
for(i=0; InitList[i]; i++) printf("%d\n", InitList[i](ImageHandle,SystemTable) ); | |
} | |
/* | |
Output: | |
1 | |
2 | |
3 | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment