2020-08-27 01:44:16 +03:00
|
|
|
#include <lib/asm.h>
|
|
|
|
|
|
|
|
ASM_BASIC(
|
2019-05-30 16:59:25 +03:00
|
|
|
".section .entry\n\t"
|
2020-04-29 17:53:05 +03:00
|
|
|
|
|
|
|
// Zero out .bss
|
|
|
|
"xor al, al\n\t"
|
2020-08-11 18:43:39 +03:00
|
|
|
"mov edi, OFFSET bss_begin\n\t"
|
|
|
|
"mov ecx, OFFSET bss_end\n\t"
|
|
|
|
"sub ecx, OFFSET bss_begin\n\t"
|
2020-04-29 17:53:05 +03:00
|
|
|
"rep stosb\n\t"
|
|
|
|
|
2020-08-11 18:43:39 +03:00
|
|
|
"jmp main\n\t"
|
2019-05-15 07:08:56 +03:00
|
|
|
);
|
|
|
|
|
2020-08-29 21:02:16 +03:00
|
|
|
#include <limine.h>
|
2019-05-30 16:59:25 +03:00
|
|
|
#include <drivers/vga_textmode.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-05-03 00:38:57 +03:00
|
|
|
#include <lib/e820.h>
|
2020-06-05 18:51:33 +03:00
|
|
|
#include <lib/memmap.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-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-04-21 19:27:05 +03:00
|
|
|
|
2019-05-15 07:08:56 +03:00
|
|
|
void main(int boot_drive) {
|
2020-01-22 03:55:40 +03:00
|
|
|
// Initial prompt.
|
2019-05-30 16:59:25 +03:00
|
|
|
init_vga_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-04-15 14:21:44 +03:00
|
|
|
print("Boot drive: %x\n", boot_drive);
|
2020-01-21 13:42:17 +03:00
|
|
|
|
2020-04-15 14:21:44 +03:00
|
|
|
// Look for config file.
|
|
|
|
print("Searching for config file...\n");
|
|
|
|
struct part parts[4];
|
|
|
|
for (int i = 0; ; i++) {
|
|
|
|
if (i == 4) {
|
|
|
|
panic("Config file not found.");
|
|
|
|
}
|
|
|
|
print("Checking partition %d...\n", i);
|
|
|
|
int ret = get_part(&parts[i], boot_drive, i);
|
2020-01-22 03:55:40 +03:00
|
|
|
if (ret) {
|
2020-04-15 14:21:44 +03:00
|
|
|
print("Partition not found.\n");
|
2020-01-22 03:55:40 +03:00
|
|
|
} else {
|
2020-04-15 14:21:44 +03:00
|
|
|
print("Partition found.\n");
|
|
|
|
if (!init_config(boot_drive, i)) {
|
|
|
|
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-06-05 21:27:52 +03:00
|
|
|
char *cmdline = menu();
|
2020-04-22 18:47:25 +03:00
|
|
|
|
2020-05-03 00:38:57 +03:00
|
|
|
init_e820();
|
2020-06-05 18:51:33 +03:00
|
|
|
init_memmap();
|
2020-05-03 00:38:57 +03:00
|
|
|
|
2020-05-06 17:38:45 +03:00
|
|
|
char proto[32];
|
|
|
|
if (!config_get_value(proto, 0, 32, "KERNEL_PROTO")) {
|
|
|
|
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-03-25 23:05:14 +03:00
|
|
|
if (!strcmp(proto, "stivale")) {
|
2020-05-06 17:38:45 +03:00
|
|
|
stivale_load(cmdline, boot_drive);
|
2020-08-11 18:43:39 +03:00
|
|
|
} else if (!strcmp(proto, "stivale2")) {
|
|
|
|
stivale2_load(cmdline, boot_drive);
|
2020-04-19 11:14:49 +03:00
|
|
|
} else if (!strcmp(proto, "linux")) {
|
2020-05-06 17:38:45 +03:00
|
|
|
linux_load(cmdline, boot_drive);
|
2020-05-06 18:00:41 +03:00
|
|
|
} else if (!strcmp(proto, "chainload")) {
|
|
|
|
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
|
|
|
}
|