2019-05-15 07:08:56 +03:00
|
|
|
asm (
|
2019-05-30 16:59:25 +03:00
|
|
|
".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"
|
|
|
|
);
|
|
|
|
|
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-04-14 06:20:55 +03:00
|
|
|
#include <fs/file.h>
|
2020-01-25 04:05:19 +03:00
|
|
|
#include <sys/interrupt.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-04-19 11:14:49 +03:00
|
|
|
#include <protos/linux.h>
|
2020-01-21 13:42:17 +03:00
|
|
|
|
|
|
|
extern symbol bss_begin;
|
|
|
|
extern symbol bss_end;
|
2019-05-15 07:08:56 +03:00
|
|
|
|
|
|
|
void main(int boot_drive) {
|
2020-04-14 06:20:55 +03:00
|
|
|
struct file_handle f;
|
2020-03-15 02:12:09 +03:00
|
|
|
|
2020-01-21 13:42:17 +03:00
|
|
|
// Zero out .bss section
|
|
|
|
for (uint8_t *p = bss_begin; p < bss_end; p++)
|
|
|
|
*p = 0;
|
|
|
|
|
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
|
|
|
|
|
|
|
init_idt();
|
|
|
|
|
2019-05-31 08:19:02 +03:00
|
|
|
print("qLoader 2\n\n");
|
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-03-28 04:52:59 +03:00
|
|
|
int drive, part, timeout;
|
2020-04-15 14:21:44 +03:00
|
|
|
char path[128], cmdline[128], proto[64], buf[32];
|
2020-01-22 09:13:19 +03:00
|
|
|
|
2020-04-15 14:21:44 +03:00
|
|
|
if (!config_get_value(buf, 0, 32, "KERNEL_DRIVE")) {
|
|
|
|
print("KERNEL_DRIVE not specified, using boot drive (%x)", boot_drive);
|
|
|
|
drive = boot_drive;
|
2020-01-22 09:13:19 +03:00
|
|
|
} else {
|
2020-04-15 14:21:44 +03:00
|
|
|
drive = (int)strtoui(buf);
|
|
|
|
}
|
|
|
|
if (!config_get_value(buf, 0, 64, "TIMEOUT")) {
|
|
|
|
timeout = 5;
|
|
|
|
} else {
|
|
|
|
timeout = (int)strtoui(buf);
|
2020-01-22 09:13:19 +03:00
|
|
|
}
|
2020-04-15 14:21:44 +03:00
|
|
|
config_get_value(buf, 0, 32, "KERNEL_PARTITION");
|
|
|
|
part = (int)strtoui(buf);
|
|
|
|
config_get_value(path, 0, 128, "KERNEL_PATH");
|
|
|
|
config_get_value(cmdline, 0, 128, "KERNEL_CMDLINE");
|
|
|
|
config_get_value(proto, 0, 64, "KERNEL_PROTO");
|
2020-01-22 09:13:19 +03:00
|
|
|
|
2020-04-15 14:21:44 +03:00
|
|
|
print("\n\n");
|
2020-03-28 04:52:59 +03:00
|
|
|
for (int i = timeout; i; i--) {
|
2020-01-25 05:06:56 +03:00
|
|
|
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-04-15 14:21:44 +03:00
|
|
|
print("\n\n");
|
2020-01-25 05:06:56 +03:00
|
|
|
|
2020-04-14 06:20:55 +03:00
|
|
|
fopen(&f, drive, part, path);
|
2020-01-22 03:55:40 +03:00
|
|
|
|
2020-03-25 23:05:14 +03:00
|
|
|
if (!strcmp(proto, "stivale")) {
|
2020-03-31 11:48:24 +03:00
|
|
|
stivale_load(&f, cmdline);
|
2020-04-19 11:14:49 +03:00
|
|
|
} else if (!strcmp(proto, "linux")) {
|
|
|
|
linux_load(&f, cmdline);
|
2020-03-25 23:05:14 +03:00
|
|
|
} else if (!strcmp(proto, "qword")) {
|
2020-04-14 06:20:55 +03:00
|
|
|
fread(&f, (void *)0x100000, 0, f.size);
|
2020-03-25 23:05:14 +03:00
|
|
|
// Boot the kernel.
|
|
|
|
asm volatile (
|
|
|
|
"cli\n\t"
|
|
|
|
"jmp 0x100000\n\t"
|
|
|
|
:
|
|
|
|
: "b" (cmdline)
|
|
|
|
: "memory"
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
print("Invalid protocol specified: `%s`.\n", proto);
|
|
|
|
for (;;);
|
|
|
|
}
|
2020-04-15 14:21:44 +03:00
|
|
|
}
|