-
Notifications
You must be signed in to change notification settings - Fork 0
/
efi_main.c
82 lines (64 loc) · 2.17 KB
/
efi_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
BIG THANK YOU TO THE FOLLOWING PEOPLE WHO HELPED ME TO MAKE THIS OS POSSIBLE
ANGEL
QUESO
JESTERJUNK
STRYKER
AND ALL OF MY YOUTUBE SUBSCRIBERS
*/
#include "EFI/efilib.h"
#include "EFI/gdt.h"
EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *system)
{
InitEFI(image, system);
HitAnyKey();
uint64_t ENTRY_POINT = 0;
void* OSBuffer = readFile(u"los-efi\\loader.bin", &ENTRY_POINT);
uint8_t* OSloader = (uint8_t*)OSBuffer;
if(OSBuffer == NULL)
{
setTextColor(EFI_RED);
wprintf(u"ERROR : OSBuffer is NULL !\r\n");
setTextColor(EFI_GREEN);
}
if(ENTRY_POINT <= 0)
{
setTextColor(EFI_RED);
wprintf(u"ERROR : Entry Point is ZERO !\r\n");
setTextColor(EFI_GREEN);
}
// RSDP
EFI_CONFIGURATION_TABLE* configTable = SystemTable->ConfigurationTable;
unsigned long long* tempRSDP = NULL;
for(uint64_t index = 0; index < SystemTable->NumberOfTableEntries; index++)
{
if(CompareGuid(&configTable[index].VendorGuid, &ACPI_20_TABLE_GUID))
{
if(strcmp((char*)"RSD PTR ", (char*)configTable->VendorTable) == 0)
{
tempRSDP = (void*)configTable->VendorTable;
}
}
configTable++;
}
// Memory Map
uint64_t MemoryMapSize = 0;
EFI_MEMORY_DESCRIPTOR *MemoryMap = NULL;
uint64_t MapKey = 0;
uint64_t DescriptorSize = 0;
uint32_t DescriptorVersion = 0;
SystemTable->BootServices->GetMemoryMap(&MemoryMapSize, MemoryMap, &MapKey, &DescriptorSize, &DescriptorVersion);
MemoryMapSize += 2 * DescriptorSize;
SystemTable->BootServices->AllocatePool(2, MemoryMapSize, (void **)&MemoryMap);
SystemTable->BootServices->GetMemoryMap(&MemoryMapSize, MemoryMap, &MapKey, &DescriptorSize, &DescriptorVersion);
biStruct.MMap = MemoryMap;
biStruct.MMapSize = MemoryMapSize;
biStruct.MMapDescriptorSize = DescriptorSize;
biStruct.rsdp = tempRSDP;
void (*KernelBinFile)(BLOCKINFO*) = ((__attribute__((ms_abi)) void (*)(BLOCKINFO*)) &OSloader[ENTRY_POINT]);
SystemTable->BootServices->ExitBootServices(ImageHandle, MapKey);
gdt_init();
KernelBinFile(&biStruct);
while(1){__asm__ ("hlt");}
return ERROR_STATUS;
}