2020-08-29 21:02:16 +03:00
|
|
|
#include <limine.h>
|
2020-09-02 10:55:56 +03:00
|
|
|
#include <lib/term.h>
|
2019-05-31 06:47:13 +03:00
|
|
|
#include <lib/real.h>
|
2020-01-22 07:02:12 +03:00
|
|
|
#include <lib/blib.h>
|
2020-03-25 23:05:14 +03:00
|
|
|
#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-09-18 21:02:10 +03:00
|
|
|
#include <sys/e820.h>
|
2020-10-15 12:35:49 +03:00
|
|
|
#include <sys/a20.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-09-27 18:39:30 +03:00
|
|
|
#include <mm/mtrr.h>
|
2020-03-25 23:05:14 +03:00
|
|
|
#include <protos/stivale.h>
|
2020-08-11 18:43:39 +03:00
|
|
|
#include <protos/stivale2.h>
|
2020-04-19 11:14:49 +03:00
|
|
|
#include <protos/linux.h>
|
2020-05-06 18:00:41 +03:00
|
|
|
#include <protos/chainload.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>
|
2020-04-21 19:27:05 +03:00
|
|
|
|
2020-11-05 03:37:45 +03:00
|
|
|
void entry(uint8_t _boot_drive, int pxe_boot) {
|
2020-10-17 07:23:11 +03:00
|
|
|
boot_drive = _boot_drive;
|
|
|
|
|
2020-09-27 18:39:30 +03:00
|
|
|
mtrr_save();
|
|
|
|
|
2020-09-02 10:55:56 +03:00
|
|
|
term_textmode();
|
2020-01-25 04:05:19 +03:00
|
|
|
|
2020-08-29 21:02:16 +03:00
|
|
|
print("Limine " LIMINE_VERSION "\n\n");
|
2020-04-24 19:26:08 +03:00
|
|
|
|
2020-10-15 12:35:49 +03:00
|
|
|
if (!a20_enable())
|
|
|
|
panic("Could not enable A20 line");
|
|
|
|
|
2020-10-18 07:23:39 +03:00
|
|
|
part_create_index();
|
2020-11-05 03:37:45 +03:00
|
|
|
init_e820();
|
|
|
|
init_memmap();
|
2020-11-09 16:29:53 +03:00
|
|
|
|
2020-11-05 03:37:45 +03:00
|
|
|
if (pxe_boot) {
|
|
|
|
pxe_init();
|
|
|
|
if(init_config_pxe()) {
|
|
|
|
panic("failed to load config file");
|
2020-04-15 14:21:44 +03:00
|
|
|
}
|
2020-11-05 03:37:45 +03:00
|
|
|
print("config loaded");
|
|
|
|
} else {
|
|
|
|
print("Boot drive: %x\n", boot_drive);
|
|
|
|
// Look for config file.
|
|
|
|
print("Searching for config file...\n");
|
|
|
|
for (int i = 0; ; i++) {
|
2020-11-09 17:04:53 +03:00
|
|
|
struct part part;
|
2020-11-05 03:37:45 +03:00
|
|
|
print("Checking partition %d...\n", i);
|
2020-11-09 17:04:53 +03:00
|
|
|
int ret = part_get(&part, boot_drive, i);
|
|
|
|
switch (ret) {
|
|
|
|
case INVALID_TABLE:
|
|
|
|
panic("Partition table of boot drive is invalid.");
|
|
|
|
case END_OF_TABLE:
|
|
|
|
panic("Config file not found.");
|
|
|
|
case NO_PARTITION:
|
|
|
|
print("Partition not found.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
print("Partition found.\n");
|
|
|
|
if (!init_config_disk(&part)) {
|
|
|
|
print("Config file found and loaded.\n");
|
|
|
|
break;
|
2020-01-22 09:13:19 +03:00
|
|
|
}
|
2020-01-22 03:55:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 00:07:10 +03:00
|
|
|
char *cmdline = menu();
|
2020-09-02 10:55:56 +03:00
|
|
|
|
2020-09-02 11:31:39 +03:00
|
|
|
char proto[32];
|
2020-11-01 12:31:35 +03:00
|
|
|
if (!config_get_value(proto, 0, 32, "PROTOCOL")) {
|
|
|
|
panic("PROTOCOL not specified");
|
2020-04-25 21:33:26 +03:00
|
|
|
}
|
2020-01-22 03:55:40 +03:00
|
|
|
|
2020-09-02 11:31:39 +03:00
|
|
|
if (!strcmp(proto, "stivale")) {
|
2020-10-17 07:23:11 +03:00
|
|
|
stivale_load(cmdline);
|
2020-09-02 11:31:39 +03:00
|
|
|
} else if (!strcmp(proto, "stivale2")) {
|
2020-10-17 07:23:11 +03:00
|
|
|
stivale2_load(cmdline);
|
2020-09-02 11:31:39 +03:00
|
|
|
} else if (!strcmp(proto, "linux")) {
|
2020-10-17 07:23:11 +03:00
|
|
|
linux_load(cmdline);
|
2020-09-02 11:31:39 +03:00
|
|
|
} else if (!strcmp(proto, "chainload")) {
|
2020-05-06 18:00:41 +03:00
|
|
|
chainload();
|
2020-03-25 23:05:14 +03:00
|
|
|
} else {
|
2020-04-24 19:26:08 +03:00
|
|
|
panic("Invalid protocol specified");
|
2020-03-25 23:05:14 +03:00
|
|
|
}
|
2020-04-15 14:21:44 +03:00
|
|
|
}
|