104 lines
2.3 KiB
C
Raw Normal View History

2019-05-31 07:19:02 +02:00
#include <stdint.h>
#include <stddef.h>
#include <stdarg.h>
2020-11-05 00:50:01 +01:00
#include <lib/libc.h>
2020-01-22 05:02:12 +01:00
#include <lib/blib.h>
2020-05-10 00:38:27 +02:00
#include <lib/print.h>
2020-11-15 17:56:10 +01:00
#include <lib/trace.h>
#include <lib/real.h>
#include <fs/file.h>
#include <mm/pmm.h>
2020-10-01 02:12:13 +02:00
2021-03-02 10:23:43 +01:00
#if defined (uefi)
EFI_SYSTEM_TABLE *gST;
EFI_BOOT_SERVICES *gBS;
EFI_RUNTIME_SERVICES *gRT;
EFI_HANDLE efi_image_handle;
EFI_MEMORY_DESCRIPTOR *efi_mmap = NULL;
UINTN efi_mmap_size = 0, efi_desc_size = 0, efi_desc_ver = 0;
2021-03-02 10:23:43 +01:00
#endif
2021-05-11 06:46:42 +02:00
bool verbose = false;
bool parse_resolution(int *width, int *height, int *bpp, const char *buf) {
int res[3] = {0};
const char *first = buf;
for (int i = 0; i < 3; i++) {
const char *last;
int x = strtoui(first, &last, 10);
if (first == last)
break;
res[i] = x;
if (*last == 0)
break;
first = last + 1;
}
if (res[0] == 0 || res[1] == 0)
return false;
if (res[2] == 0)
res[2] = 32;
*width = res[0], *height = res[1], *bpp = res[2];
return true;
}
2020-09-30 17:29:07 +02:00
// This integer sqrt implementation has been adapted from:
// https://stackoverflow.com/questions/1100090/looking-for-an-efficient-integer-square-root-algorithm-for-arm-thumb2
uint64_t sqrt(uint64_t a_nInput) {
uint64_t op = a_nInput;
uint64_t res = 0;
uint64_t one = (uint64_t)1 << 62;
// "one" starts at the highest power of four <= than the argument.
while (one > op) {
one >>= 2;
}
while (one != 0) {
if (op >= res + one) {
op = op - (res + one);
res = res + 2 * one;
}
res >>= 1;
one >>= 2;
}
return res;
}
#if defined (uefi)
bool efi_boot_services_exited = false;
bool efi_exit_boot_services(void) {
EFI_STATUS status;
EFI_MEMORY_DESCRIPTOR tmp_mmap[1];
UINTN mmap_size = sizeof(tmp_mmap);
UINTN mmap_key = 0, desc_size = 0, desc_ver = 0;
uefi_call_wrapper(gBS->GetMemoryMap, 5,
&mmap_size, tmp_mmap, &mmap_key, &desc_size, &desc_ver);
status = uefi_call_wrapper(gBS->ExitBootServices, 2, efi_image_handle, mmap_key);
if (status)
2021-03-13 03:21:01 +01:00
panic("efi: Failed to exit boot services");
asm volatile ("cli" ::: "memory");
2021-03-10 01:23:44 +01:00
pmm_reclaim_uefi_mem();
efi_boot_services_exited = true;
2021-05-11 06:46:42 +02:00
printv("efi: Exited boot services.\n");
return true;
}
#endif