limine/src/main.c

95 lines
2.4 KiB
C
Raw Normal View History

2019-05-15 07:08:56 +03:00
asm (
".section .entry\n\t"
2019-05-15 07:08:56 +03:00
"xor dh, dh\n\t"
"push edx\n\t"
"call main\n\t"
);
#include <drivers/vga_textmode.h>
#include <lib/real.h>
2020-01-22 07:02:12 +03:00
#include <lib/blib.h>
#include <lib/mbr.h>
2020-01-22 09:13:19 +03:00
#include <lib/config.h>
#include <fs/echfs.h>
2020-01-25 04:05:19 +03:00
#include <sys/interrupt.h>
2020-01-21 13:42:17 +03:00
2020-01-22 09:13:19 +03:00
#define CONFIG_NAME "qloader2.cfg"
2020-01-21 13:42:17 +03:00
extern symbol bss_begin;
extern symbol bss_end;
2019-05-15 07:08:56 +03:00
2020-01-22 09:13:19 +03:00
static int config_loaded = 0;
2019-05-15 07:08:56 +03:00
void main(int boot_drive) {
2020-03-15 02:12:09 +03:00
struct echfs_file_handle f;
2020-01-21 13:42:17 +03:00
// Zero out .bss section
for (uint8_t *p = bss_begin; p < bss_end; p++)
*p = 0;
// Initial prompt.
init_vga_textmode();
2020-01-25 04:05:19 +03:00
init_idt();
2019-05-31 08:19:02 +03:00
print("qLoader 2\n\n");
2020-01-22 09:13:19 +03:00
print("=> Boot drive: %x\n", boot_drive);
2020-01-21 13:42:17 +03:00
// Enumerate partitions.
struct mbr_part parts[4];
for (int i = 0; i < 4; i++) {
2020-01-22 09:13:19 +03:00
print("=> Checking for partition %d...\n", i);
int ret = mbr_get_part(&parts[i], boot_drive, i);
if (ret) {
2020-01-22 09:13:19 +03:00
print(" Not found!\n");
} else {
2020-01-22 09:13:19 +03:00
print(" Found!\n");
if (!config_loaded) {
2020-03-15 02:12:09 +03:00
if (!echfs_open(&f, boot_drive, i, CONFIG_NAME)) {
echfs_read(&f, (void *)0x100000, 0, f.dir_entry.size);
2020-01-22 09:13:19 +03:00
config_loaded = 1;
print(" Config file found and loaded!\n");
}
}
}
}
2020-01-22 09:13:19 +03:00
int drive, part;
char path[128], cmdline[128];
if (config_loaded) {
char buf[32];
config_get_value(buf, 32, (void*)0x100000, "KERNEL_DRIVE");
drive = (int)strtoui(buf);
config_get_value(buf, 32, (void*)0x100000, "KERNEL_PARTITION");
part = (int)strtoui(buf);
config_get_value(path, 128, (void*)0x100000, "KERNEL_PATH");
config_get_value(cmdline, 128, (void*)0x100000, "KERNEL_CMDLINE");
} else {
print(" !! NO CONFIG FILE FOUND ON BOOT DRIVE !!");
for (;;);
}
2020-01-25 05:06:56 +03:00
print("\n");
for (int i = 3; i; i--) {
print("\rBooting in %d (press any key to edit command line)...", i);
if (pit_sleep_and_quit_on_keypress(18)) {
print("\n\n> ");
gets(cmdline, cmdline, 128);
break;
}
}
2020-03-15 02:12:09 +03:00
echfs_open(&f, drive, part, path);
echfs_read(&f, (void *)0x100000, 0, f.dir_entry.size);
// Boot the kernel.
asm volatile (
"cli\n\t"
"jmp 0x100000\n\t"
:
2020-01-22 09:13:19 +03:00
: "b" (cmdline)
: "memory"
);
2019-05-15 07:08:56 +03:00
}