最近常看EFI的code,所以就順便整理一下一些C的資料結構的東東。
1.EFI中都是喜歡使用雙向鏈結串列(doubly linked list)
在雙向鏈結串列中的節點(Node)至少有2個欄位,一個為向後結欄 (BackLink) ,另一個為向前鏈結欄 ( ForwardLink ) 。其必要的宣告為:
typedef struct node *node_ptr ;
typedef struct node {
node_ptr Flink ;
node_ptr Blink ;
} ;
2.插入鏈結串列可以從頭插入或是從尾插入兩種,底下是圖示來表示這兩種差別。
InsertHeadList();
InsertTailList();
這些鏈結的運用在EFI中隨處可見,所以在這邊留下筆記來紀錄一下學習心得!
4 則留言:
我是 HY
最近在寫 EFI shell 底下的 App
以下是我的 sample code
>>>
#include "efi.h"
#include "efilib.h"
#define FILE_ATTRIB_CREATENEW EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE
static EFI_STATUS WaitForKeyOrReset(VOID)
{
EFI_STATUS Status;
EFI_INPUT_KEY key;
UINTN index;
for(;;) {
Status = ST->ConIn->ReadKeyStroke(ST->ConIn, &key);
if (Status == EFI_NOT_READY)
BS->WaitForEvent(1, &ST->ConIn->WaitForKey, &index);
else
break;
}
if (!EFI_ERROR(Status)) {
if (key.ScanCode == SCAN_ESC)
RT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
}
return Status;
}
EFI_STATUS
EFIAPI
MyfileioMain (IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status;
EFI_HANDLE *DestAddr;
EFI_LOADED_IMAGE *FileHandle01;
EFI_DEVICE_PATH *FileHandle02;
EFI_FILE_IO_INTERFACE *FileHandle03;
EFI_FILE *FileHandle04;
EFI_FILE *FileHandle05;
CHAR16 *FileName;
CHAR16 *BufferA, *BufferB, *BufferC, *Space_Key;
UINTN BufferSize = 8, BufferSizeKeySpace = 2;
int Bit0, Bit1, Key_Space;
FileName = L"NewFile.txt";
Space_Key = L" ";
BufferA = L"ABCD";
BufferB = L"EFGH";
BufferC = L"IJKL";
Bit0 = 0xff;
Bit1 = 0xfe;
Key_Space = 0x0020;
InitializeLib (ImageHandle, SystemTable);
DestAddr = AllocatePool (BufferSize);
Print (L"Value of Bit0 is %x\n", Bit0);
Print (L"Value of Bit1 is %x\n", Bit1);
Status = BS->HandleProtocol(ImageHandle, &LoadedImageProtocol, (VOID*)&FileHandle01);
if (EFI_ERROR(Status)) {
Print (L"Could not obtain Image, FileHandle01 err code is %x\n",Status);
return EFI_LOAD_ERROR;
}
Status = BS->HandleProtocol(FileHandle01->DeviceHandle,&DevicePathProtocol,(VOID*)&FileHandle02);
if (EFI_ERROR(Status)) {
Print (L"Could not obtain Device Path, FileHandle02 err code is %x\n",Status);
return EFI_LOAD_ERROR;
}
Status = BS->HandleProtocol (FileHandle01->DeviceHandle,&FileSystemProtocol,(VOID*)&FileHandle03);
if (EFI_ERROR(Status)) {
Print (L"Could not obtain File System, FileHandle03 err code is %x\n",Status);
return EFI_LOAD_ERROR;
}
Status = FileHandle03->OpenVolume(FileHandle03, &FileHandle04);
if (EFI_ERROR(Status)) {
Print (L"Could not open volume, FileHandle04 err code is %x\n",Status);
return EFI_LOAD_ERROR;
}
Status = FileHandle04->Open(FileHandle04, &FileHandle05, FileName, FILE_ATTRIB_CREATENEW, 0x20);
if (EFI_ERROR(Status)) {
Print (L"Could not open file, FileHandle05 err code is %x\n",Status);
return EFI_LOAD_ERROR;
}
...
<<<
請參考
HY
小華您好
請問我要怎麼從bios,uefi,firmware這些領域入門比較好,如果說我要增加經驗的話,我該怎麼著手,儘管我不是業界的人...
我想在進入業界之前,試著磨練自己的實力,一直找不到好方法....
我就開門見山直說了
我是某間BIOS Vender的Manager
看了你的部落格覺得你的實力很好
想高薪挖角你
若你有意願請打0952902726
這跟那天你交我的Insert VBIOS 關念是不是相似
張貼留言