rulimine/common/entry.s3.c

131 lines
3.5 KiB
C
Raw Normal View History

2021-12-31 12:58:05 +03:00
#include <stddef.h>
#include <stdint.h>
#include <stdnoreturn.h>
2020-09-02 10:55:56 +03:00
#include <lib/term.h>
#include <lib/real.h>
2022-08-27 00:44:47 +03:00
#include <lib/misc.h>
#include <lib/libc.h>
2020-04-15 14:21:44 +03:00
#include <lib/part.h>
2020-01-22 09:13:19 +03:00
#include <lib/config.h>
2020-11-15 19:56:10 +03:00
#include <lib/trace.h>
2020-09-18 21:02:10 +03:00
#include <sys/e820.h>
#include <sys/a20.h>
#include <sys/idt.h>
2021-11-25 23:51:41 +03:00
#include <sys/gdt.h>
2020-05-10 01:38:27 +03:00
#include <lib/print.h>
2020-04-14 06:20:55 +03:00
#include <fs/file.h>
2020-03-25 03:04:18 +03:00
#include <lib/elf.h>
2020-09-20 13:03:44 +03:00
#include <mm/pmm.h>
2020-06-05 21:27:52 +03:00
#include <menu.h>
2020-11-05 03:37:45 +03:00
#include <pxe/pxe.h>
#include <pxe/tftp.h>
#include <drivers/disk.h>
#include <sys/lapic.h>
#include <lib/readline.h>
2020-04-21 19:27:05 +03:00
void stage3_common(void);
2021-03-04 00:38:28 +03:00
#if defined (UEFI)
extern symbol __image_base;
2021-12-31 12:58:05 +03:00
noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
2021-03-02 12:23:43 +03:00
gST = SystemTable;
gBS = SystemTable->BootServices;
gRT = SystemTable->RuntimeServices;
efi_image_handle = ImageHandle;
2021-03-02 12:23:43 +03:00
2021-05-06 05:31:05 +03:00
EFI_STATUS status;
gST->ConOut->EnableCursor(gST->ConOut, false);
term_fallback();
2021-09-21 19:56:20 +03:00
status = gBS->SetWatchdogTimer(0, 0x10000, 0, NULL);
if (status) {
print("WARNING: Failed to disable watchdog timer!\n");
}
2021-03-05 08:10:58 +03:00
init_memmap();
2021-11-25 23:51:41 +03:00
init_gdt();
#if defined (__x86_64__)
if ((uintptr_t)__image_base > 0x100000000) {
panic(false, "Limine does not support being loaded above 4GiB");
}
#endif
2021-03-04 11:15:10 +03:00
disk_create_index();
2021-03-04 00:38:28 +03:00
boot_volume = NULL;
2021-05-06 05:31:05 +03:00
EFI_HANDLE current_handle = ImageHandle;
for (size_t j = 0; j < 25; j++) {
if (current_handle == NULL) {
could_not_match:
print("WARNING: Could not meaningfully match the boot device handle with a volume.\n");
print(" Using the first volume containing a Limine configuration!\n");
for (size_t i = 0; i < volume_index_i; i++) {
2021-10-21 02:27:05 +03:00
struct file_handle *f;
bool old_cif = case_insensitive_fopen;
case_insensitive_fopen = true;
2021-10-21 02:27:05 +03:00
if ((f = fopen(volume_index[i], "/limine.cfg")) == NULL
&& (f = fopen(volume_index[i], "/limine/limine.cfg")) == NULL
2021-10-21 02:27:05 +03:00
&& (f = fopen(volume_index[i], "/boot/limine.cfg")) == NULL
&& (f = fopen(volume_index[i], "/boot/limine/limine.cfg")) == NULL
2021-10-21 02:27:05 +03:00
&& (f = fopen(volume_index[i], "/EFI/BOOT/limine.cfg")) == NULL) {
case_insensitive_fopen = old_cif;
continue;
}
case_insensitive_fopen = old_cif;
2021-10-21 02:27:05 +03:00
fclose(f);
if (volume_index[i]->backing_dev != NULL) {
boot_volume = volume_index[i]->backing_dev;
} else {
boot_volume = volume_index[i];
}
break;
}
if (boot_volume != NULL) {
stage3_common();
}
2021-12-11 21:58:00 +03:00
panic(false, "No volume contained a Limine configuration file");
}
2021-05-06 05:31:05 +03:00
EFI_GUID loaded_img_prot_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
EFI_LOADED_IMAGE_PROTOCOL *loaded_image = NULL;
2021-03-04 00:38:28 +03:00
status = gBS->HandleProtocol(current_handle, &loaded_img_prot_guid,
(void **)&loaded_image);
2021-03-04 00:38:28 +03:00
2021-05-06 05:31:05 +03:00
if (status) {
goto could_not_match;
2021-05-06 05:31:05 +03:00
}
2021-03-04 00:38:28 +03:00
2021-05-06 05:31:05 +03:00
boot_volume = disk_volume_from_efi_handle(loaded_image->DeviceHandle);
if (boot_volume != NULL) {
2021-05-06 05:31:05 +03:00
stage3_common();
}
2021-05-06 05:31:05 +03:00
current_handle = loaded_image->ParentHandle;
}
goto could_not_match;
2021-03-02 12:23:43 +03:00
}
#endif
2021-12-31 12:58:05 +03:00
noreturn void stage3_common(void) {
init_flush_irqs();
init_io_apics();
menu(true);
2020-04-15 14:21:44 +03:00
}