Skip to content

Commit

Permalink
Merge pull request #3 from mytbk/mybranch
Browse files Browse the repository at this point in the history
Fix some errors in building with Linux GCC
Thanks a lot. All look good to me. 
Only one comment on Add missing EFIAPI. It's fine  to have it, but it's not necessary.
There is a discuss on EFIAPI in http://feishare.com/efimail/messages/20140317-0730-Re__edk2__EFIAPI_Calling_Convention-_Kinney__Michael_D_.html

just some words copied from there:
"All public interfaces of a UEFI module must follow the UEFI calling
convention. Public interfaces include the image entry point, UEFI
event handlers, and protocol member functions. The type EFIAPI is
used to indicate conformance to the calling conventions defined in
this section. Non public interfaces, such as private functions and
static library calls, are not required to follow the UEFI calling
conventions and may be optimized by the compiler"
  • Loading branch information
zhenghuadai committed Apr 23, 2016
2 parents 3c45991 + af6d4b6 commit cb70d44
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 30 deletions.
27 changes: 25 additions & 2 deletions book/Event/TestEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ void WaitKey()
EFI_INPUT_KEY Key;

Status = gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &Index);
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
if (EFI_ERROR(Status)) {
Print(L"WaitKey: WaitForEvent Error!\n");
}
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
if (EFI_ERROR(Status)) {
Print(L"WaitKey: ReadKeyStroke Error!\n");
}
}

/** example 2
Expand Down Expand Up @@ -110,6 +116,10 @@ EFI_STATUS TestNotify()
Status = gBS->CreateEvent(EVT_NOTIFY_WAIT, TPL_NOTIFY, (EFI_EVENT_NOTIFY)myEventNoify , (VOID*)NULL, &myEvent);
Status = gBS->WaitForEvent(1, &myEvent, &index);
Status = gBS->CloseEvent(myEvent);

if (EFI_ERROR(Status)) {
return Status;
}
return EFI_SUCCESS;
}

Expand All @@ -134,10 +144,19 @@ EFI_STATUS TestEventSingal()
Print(L"Test EVT_TIMER | EVT_NOTIFY_SIGNAL");
// 生成Timer事件,并设置触发函数
Status = gBS->CreateEvent(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK, (EFI_EVENT_NOTIFY)myEventNoify30, (VOID*)L"Hello! Time Out!", &myEvent);
if (EFI_ERROR(Status)) {
Print(L"TestEventSignal: CreateEvent error %d!\n", Status);
}
// 设置Timer等待时间为10秒,属性为循环等待
Status = gBS->SetTimer(myEvent,TimerPeriodic , 10 * 1000 * 1000);
if (EFI_ERROR(Status)) {
Print(L"TestEventSignal: SetTimer error %d!\n", Status);
}
WaitKey();
Status = gBS->CloseEvent(myEvent);
if (EFI_ERROR(Status)) {
Print(L"TestEventSignal: CloseEvent error %d!\n", Status);
}
return EFI_SUCCESS;
}

Expand All @@ -159,6 +178,9 @@ testMouseSimple()
NULL,
(VOID**)&mouse
);
if (EFI_ERROR(Status)) {
Print(L"testMouseSimple: LocateProtocol error %d!\n", Status);
}
// 重置鼠标设备
Status = mouse->Reset(mouse, TRUE);
// 将鼠标事件放到等待事件数组
Expand Down Expand Up @@ -192,7 +214,8 @@ testMouseSimple()
}


EFI_STATUS UefiMain(
EFI_STATUS EFIAPI
UefiMain(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
Expand Down
7 changes: 4 additions & 3 deletions book/FileIo/TestFileIo.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <Protocol/SimpleTextInEx.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/EfiShell.h>
#include <guid/FileInfo.h>
#include <Guid/FileInfo.h>
#include <Uutil.h>

EFI_STATUS TestOpen()
Expand Down Expand Up @@ -348,7 +348,7 @@ EFI_STATUS TestAsyncWrite(EFI_FILE_PROTOCOL* File)
return Status;
}

VOID ReadNotification(EFI_EVENT event, VOID* Context)
VOID EFIAPI ReadNotification(EFI_EVENT event, VOID* Context)
{
EFI_FILE_IO_TOKEN *ReadToken = (EFI_FILE_IO_TOKEN *)Context;
// 检查ReadToken.Status;
Expand Down Expand Up @@ -450,7 +450,8 @@ EFI_STATUS TestVar(CONST CHAR16* var)

}

EFI_STATUS UefiMain(
EFI_STATUS EFIAPI
UefiMain(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
Expand Down
4 changes: 2 additions & 2 deletions book/GUIbasics/String/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ EFI_STATUS InitShellLib()
{
if(gEfiShellProtocol == NULL)
{
gBS -> LocateProtocol(&gEfiShellProtocolGuid, NULL, &gEfiShellProtocol);
gBS -> LocateProtocol(&gEfiShellProtocolGuid, NULL, (VOID**)&gEfiShellProtocol);
}
if(gEfiShellParametersProtocol == NULL)
{
Expand Down Expand Up @@ -90,7 +90,7 @@ ShellAppMain (
IN CHAR16 **Argv
)
{
EFI_GUID mStrPackageGuid = { 0xedd31def, 0xf262, 0xc24e, 0xa2, 0xe4, 0xde, 0xf7, 0xde, 0xcd, 0xcd, 0xee };
EFI_GUID mStrPackageGuid = { 0xedd31def, 0xf262, 0xc24e, {0xa2, 0xe4, 0xde, 0xf7, 0xde, 0xcd, 0xcd, 0xee} };
//首先注册字符串资源文件:将我们的字符串package加入到Hii数据库中
EFI_HANDLE HiiHandle = HiiAddPackages (&mStrPackageGuid , gImageHandle, exampleStrings, NULL);
//通过字符串标识符访问字符串。
Expand Down
4 changes: 3 additions & 1 deletion book/Hob/Hob.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ testHotKey()
return Status;
}

EFI_STATUS UefiMain(
EFI_STATUS
EFIAPI
UefiMain(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
Expand Down
2 changes: 1 addition & 1 deletion book/Shell/Execute/Execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ShellAppMain (
EFI_STATUS RStatus = 0;
EFI_SHELL_PROTOCOL *mEfiShellProtocol;
CHAR16* Environment[] = { L"Var1=1", L"Var2=2", 0};
Status = gBS -> LocateProtocol( &gEfiShellProtocolGuid, NULL, &mEfiShellProtocol);
Status = gBS -> LocateProtocol( &gEfiShellProtocolGuid, NULL, (VOID**)&mEfiShellProtocol);
Status = mEfiShellProtocol -> Execute(&gImageHandle, L"-nomap ls fs0:", NULL, &RStatus);
Print(L"Execute return %r with Status %d\n", Status, RStatus);
Status = mEfiShellProtocol -> Execute(&gImageHandle, L"-nomap -noversion -nostartup exit 1", NULL, &RStatus);
Expand Down
2 changes: 1 addition & 1 deletion book/Shell/Execute2/Execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ShellAppMain (
EFI_STATUS RStatus = 0;
CHAR16* Environment[] = { L"Var1=1", L"Var2=2", 0};
if(gEfiShellProtocol == NULL){
Status = gBS -> LocateProtocol( &gEfiShellProtocolGuid, NULL, &gEfiShellProtocol);
Status = gBS -> LocateProtocol( &gEfiShellProtocolGuid, NULL, (VOID**)&gEfiShellProtocol);
}
Status = ShellExecute(&gImageHandle, L"-nomap ls fs0:", FALSE, NULL, &RStatus);
Print(L"Execute return %r with Status %d\n", Status, RStatus);
Expand Down
7 changes: 6 additions & 1 deletion book/infs/Debug/Main.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#include <Uefi.h>
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
_asm int 3
#ifdef _MSC_VER
_asm int 3;
#else
asm("int $0x03");
#endif
SystemTable -> ConOut-> OutputString(SystemTable->ConOut, L"HelloWorld\n");
return EFI_SUCCESS;
}
Expand Down
1 change: 1 addition & 0 deletions book/infs/UefiMain/UefiMain.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Uefi.h>
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
Expand Down
8 changes: 7 additions & 1 deletion book/mouse/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ testMouseSimple()
NULL,
(VOID**)&mouse
);
if (EFI_ERROR(Status)) {
Print(L"Error locating Simple Pointer Protocol.\n");
return Status;
}
// 重置鼠标设备
Status = mouse->Reset(mouse, TRUE);
// 将鼠标事件放到等待事件数组
Expand Down Expand Up @@ -56,7 +60,9 @@ testMouseSimple()
return EFI_SUCCESS;
}

EFI_STATUS UefiMain(
EFI_STATUS
EFIAPI
UefiMain(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
Expand Down
6 changes: 3 additions & 3 deletions book/sstdPkg/Include/sstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
extern "C"{
#endif

#include <Library\MemoryAllocationLib.h>
#include <Library\BaseMemoryLib.h>
#include <Library\BaseLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseLib.h>

#define malloc(size) AllocatePool ((UINTN) size)
#define free(ptr) FreePool(ptr)
Expand Down
12 changes: 6 additions & 6 deletions book/sstdPkg/Library/sstdall.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
extern "C" {
#include <Uefi.h>
#include <Library\BaseLib.h>
#include <Library/BaseLib.h>
#undef NULL
#define NULL 0
typedef void (__cdecl *_PVFV)(void);
typedef int (__cdecl *_PIFV)(void);
typedef void (__cdecl *_PVFI)(int);
typedef void (EFIAPI *_PVFV)(void);
typedef int (EFIAPI *_PIFV)(void);
typedef void (EFIAPI *_PVFI)(int);
_PVFV *atexits = (_PVFV*)NULL;
int num_atexit = 0;
int max_atexit =-1;
Expand All @@ -16,7 +16,7 @@ int max_atexit =-1;
nonzero if it fails.
**/
int
atexit(void (*handler)(void))
atexit(_PVFV handler)
{
if(handler == NULL)
return 0;
Expand All @@ -38,7 +38,7 @@ atexit(void (*handler)(void))

}

extern "C" int __cdecl _purecall ( void )
extern "C" int EFIAPI _purecall ( void )
{
return 0 ;
}
Expand Down
4 changes: 3 additions & 1 deletion book/std/sstd/Testsstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ VOID Test()
free(pStr);
}

EFI_STATUS UefiMain(
EFI_STATUS
EFIAPI
UefiMain(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
Expand Down
15 changes: 12 additions & 3 deletions book/systemtable/BS/BS.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <Uefi.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DebugLib.h>
EFI_STATUS
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
Expand All @@ -17,12 +18,20 @@ UefiMain (
CHAR16* vendor = SystemTable->FirmwareVendor;
//输出固件供应商的名字
SystemTable -> ConOut-> OutputString(SystemTable->ConOut, vendor);
_asm int 3;
#ifdef _MSC_VER
_asm int 3;
#else
asm("int $0x03");
#endif
// 取得当前的MapKey
gBS->GetMemoryMap(&MemMapSize, MemMap, &MapKey, &DesSize, &DesVersion);
// 结束Boot Services
gBS->ExitBootServices(ImageHandle, MapKey);
_asm int 3;
#ifdef _MSC_VER
_asm int 3;
#else
asm("int $0x03");
#endif
ASSERT(SystemTable -> BootServices == NULL);

//SystemTable -> ConOut-> OutputString(SystemTable->ConOut, L"Crash!\n");
Expand Down
7 changes: 6 additions & 1 deletion book/systemtable/ST/ST.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <Uefi.h>
EFI_STATUS UefiMain (
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
Expand All @@ -11,6 +13,9 @@ EFI_STATUS UefiMain (
//¶ÁÈ¡¼üÅÌ
SystemTable->BootServices->WaitForEvent(1, &SystemTable ->ConIn->WaitForKey, &Index);
Status = SystemTable ->ConIn->ReadKeyStroke (SystemTable->ConIn, &Key);
if (EFI_ERROR(Status)) {
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Error reading key stroke!\n");
}
StrBuffer[0] = Key.UnicodeChar;
StrBuffer[1] = '\n';
SystemTable -> ConOut-> OutputString(SystemTable->ConOut, StrBuffer);
Expand Down
4 changes: 3 additions & 1 deletion book/systemtable/gRT/RT.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <Library/UefiLib.h>
#define INIT_NAME_BUFFER_SIZE 128
#define INIT_DATA_BUFFER_SIZE 1024
EFI_STATUS UefiMain (
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
Expand Down
8 changes: 7 additions & 1 deletion book/systemtable/gST/ST.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <Uefi.h>
#include <Library/UefiBootServicesTableLib.h>
EFI_STATUS UefiMain (
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
Expand All @@ -13,6 +15,10 @@ EFI_STATUS UefiMain (
//¶ÁÈ¡¼üÅÌ
gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &Index);
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
if (EFI_ERROR(Status)) {
gST->ConOut->OutputString(gST->ConOut, L"ReadKeyStroke error.\n");
return Status;
}
StrBuffer[0] = Key.UnicodeChar;
StrBuffer[1] = '\n';
gST -> ConOut-> OutputString(gST ->ConOut, StrBuffer);
Expand Down
6 changes: 4 additions & 2 deletions book/systemtable/memory/BSmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EFI_STATUS TestMMap()
if(Status != EFI_BUFFER_TOO_SMALL){
return Status;
}
Status = gBS->AllocatePool(EfiBootServicesData, MemoryMapSize, &MemoryMap);
Status = gBS->AllocatePool(EfiBootServicesData, MemoryMapSize, (void**)&MemoryMap);
Status = gBS->GetMemoryMap(&MemoryMapSize, MemoryMap, &MapKey, &DescriptorSize, &DescriptorVersion);
for( i = 0; i< MemoryMapSize / (DescriptorSize); i++)
{
Expand Down Expand Up @@ -66,7 +66,9 @@ EFI_STATUS TestAllocateAnyPages()
return Status;
}

EFI_STATUS UefiMain (
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
Expand Down
1 change: 1 addition & 0 deletions book/thread/setjmp/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Library/BaseLib.h>
#include <Library/MemoryAllocationLib.h>
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
Expand Down

0 comments on commit cb70d44

Please sign in to comment.