Changeset View
Changeset View
Standalone View
Standalone View
stand/efi/boot1/boot1.c
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
const UINTN num_boot_modules = nitems(boot_modules); | const UINTN num_boot_modules = nitems(boot_modules); | ||||
static EFI_GUID BlockIoProtocolGUID = BLOCK_IO_PROTOCOL; | static EFI_GUID BlockIoProtocolGUID = BLOCK_IO_PROTOCOL; | ||||
static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL; | static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL; | ||||
static EFI_GUID LoadedImageGUID = LOADED_IMAGE_PROTOCOL; | static EFI_GUID LoadedImageGUID = LOADED_IMAGE_PROTOCOL; | ||||
static EFI_GUID ConsoleControlGUID = EFI_CONSOLE_CONTROL_PROTOCOL_GUID; | static EFI_GUID ConsoleControlGUID = EFI_CONSOLE_CONTROL_PROTOCOL_GUID; | ||||
/* | static EFI_PHYSICAL_ADDRESS heap; | ||||
imp: why is this deleted? It should, imho, be separate from all this... | |||||
tsoomeAuthorUnsubmitted Done Inline Actionsat some point the linker did start to complain about duplicate symbols Malloc, Free, Calloc (defined in boot1.c and libsa). But yes, I will do separate commit for it. I was just pushing whole set to phab for completeness. tsoome: at some point the linker did start to complain about duplicate symbols Malloc, Free, Calloc… | |||||
* Provide Malloc / Free / Calloc backed by EFIs AllocatePool / FreePool which ensures | static UINTN heapsize; | ||||
* memory is correctly aligned avoiding EFI_INVALID_PARAMETER returns from | |||||
* EFI methods. | |||||
*/ | |||||
void * | |||||
Malloc(size_t len, const char *file __unused, int line __unused) | |||||
{ | |||||
void *out; | |||||
if (BS->AllocatePool(EfiLoaderData, len, &out) == EFI_SUCCESS) | |||||
return (out); | |||||
return (NULL); | |||||
} | |||||
void | |||||
Free(void *buf, const char *file __unused, int line __unused) | |||||
{ | |||||
if (buf != NULL) | |||||
(void)BS->FreePool(buf); | |||||
} | |||||
void * | |||||
Calloc(size_t n1, size_t n2, const char *file, int line) | |||||
{ | |||||
size_t bytes; | |||||
void *res; | |||||
bytes = n1 * n2; | |||||
if ((res = Malloc(bytes, file, line)) != NULL) | |||||
bzero(res, bytes); | |||||
return (res); | |||||
} | |||||
/* | /* | ||||
* try_boot only returns if it fails to load the loader. If it succeeds | * try_boot only returns if it fails to load the loader. If it succeeds | ||||
* it simply boots, otherwise it returns the status of last EFI call. | * it simply boots, otherwise it returns the status of last EFI call. | ||||
*/ | */ | ||||
EFI_STATUS | EFI_STATUS | ||||
try_boot(const boot_module_t *mod, dev_info_t *dev, void *loaderbuf, size_t loadersize) | try_boot(const boot_module_t *mod, dev_info_t *dev, void *loaderbuf, size_t loadersize) | ||||
{ | { | ||||
size_t bufsize, cmdsize; | size_t bufsize, cmdsize; | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab) | ||||
CHAR16 *text; | CHAR16 *text; | ||||
/* Basic initialization*/ | /* Basic initialization*/ | ||||
ST = Xsystab; | ST = Xsystab; | ||||
IH = Ximage; | IH = Ximage; | ||||
BS = ST->BootServices; | BS = ST->BootServices; | ||||
RS = ST->RuntimeServices; | RS = ST->RuntimeServices; | ||||
heapsize = 64 * 1024 * 1024; | |||||
status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData, | |||||
EFI_SIZE_TO_PAGES(heapsize), &heap); | |||||
if (status != EFI_SUCCESS) { | |||||
ST->ConOut->OutputString(ST->ConOut, | |||||
__DECONST(CHAR16 *, | |||||
L"Failed to allocate memory for heap.\r\n")); | |||||
BS->Exit(IH, status, 0, NULL); | |||||
} | |||||
setheap((void *)(uintptr_t)heap, (void *)(uintptr_t)(heap + heapsize)); | |||||
/* Set up the console, so printf works. */ | /* Set up the console, so printf works. */ | ||||
status = BS->LocateProtocol(&ConsoleControlGUID, NULL, | status = BS->LocateProtocol(&ConsoleControlGUID, NULL, | ||||
(VOID **)&ConsoleControl); | (VOID **)&ConsoleControl); | ||||
if (status == EFI_SUCCESS) | if (status == EFI_SUCCESS) | ||||
(void)ConsoleControl->SetMode(ConsoleControl, | (void)ConsoleControl->SetMode(ConsoleControl, | ||||
EfiConsoleControlScreenText); | EfiConsoleControlScreenText); | ||||
/* | /* | ||||
* Reset the console enable the cursor. Later we'll choose a better | * Reset the console enable the cursor. Later we'll choose a better | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | for (dev = *devinfop; dev->next != NULL; dev = dev->next) | ||||
; | ; | ||||
dev->next = devinfo; | dev->next = devinfo; | ||||
} | } | ||||
void | void | ||||
efi_exit(EFI_STATUS s) | efi_exit(EFI_STATUS s) | ||||
{ | { | ||||
BS->FreePages(heap, EFI_SIZE_TO_PAGES(heapsize)); | |||||
BS->Exit(IH, s, 0, NULL); | BS->Exit(IH, s, 0, NULL); | ||||
} | } | ||||
void | void | ||||
exit(int error __unused) | exit(int error __unused) | ||||
{ | { | ||||
efi_exit(EFI_LOAD_ERROR); | efi_exit(EFI_LOAD_ERROR); | ||||
} | } | ||||
Show All 38 Lines |
why is this deleted? It should, imho, be separate from all this...