setos

拙OS
Log | Files | Refs | LICENSE

hello.c (1415B)


      1 #include "uefi.h"
      2 #include "utils.h"
      3 
      4 EFI_SYSTEM_TABLE *SystemTable;
      5 
      6 EFI_STATUS
      7 EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab)
      8 {
      9 	// init global variable.
     10 	SystemTable = systab;
     11 
     12 	EFI_STATUS stat;
     13 	char s8[32];
     14 
     15 	// Output firmware bender.
     16 	SystemTable->ConOut->ClearScreen(SystemTable->ConOut);
     17 	printf("vendor: %s\n", wstr2str(SystemTable->FirmwareVendor, s8));
     18 
     19 	// Output memory map information.
     20 	UINTN                 mmsize = 8196;
     21 	char                  mmbuf[8196];
     22 	EFI_MEMORY_DESCRIPTOR *mmap;
     23 	UINTN                 mkey;
     24 	UINTN                 dsize;
     25 	UINT32                dver;
     26 	mmap = (EFI_MEMORY_DESCRIPTOR *) mmbuf;
     27 	stat = SystemTable->BootServices->GetMemoryMap(&mmsize, mmap, &mkey, &dsize, &dver);
     28 	if (stat != EFI_SUCCESS) {
     29 		return stat;
     30 	}
     31 
     32 	for (; mmap < (EFI_MEMORY_DESCRIPTOR *)(mmbuf + mmsize);
     33 		mmap = (EFI_MEMORY_DESCRIPTOR *) (((char *)mmap) + dsize)) {
     34 		if (mmap->Type != EfiConventionalMemory) {
     35 			continue;
     36 		}
     37 		printf("%d\t", mmap->Type);
     38 		printf("%x\t", mmap->VirtualStart);
     39 		printf("%x\t", mmap->PhysicalStart);
     40 		printf("%x\t", mmap->NumberOfPages);
     41 		printf("%x\n", mmap->Attribute);
     42 	}
     43 
     44 	// Echo back user input.
     45 	EFI_INPUT_KEY Key;
     46 	CHAR16 str[2] = {' ', '\0'};
     47 	while(1) {
     48 		SystemTable->ConIn->ReadKeyStroke(SystemTable->ConIn, &Key);
     49 		str[0] = Key.UnicodeChar;
     50 		SystemTable->ConOut->OutputString(SystemTable->ConOut, str);
     51 	}
     52 
     53 	return EFI_SUCCESS;
     54 }