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-01-22 03:55:40 +03:00
|
|
|
#include <lib/mbr.h>
|
|
|
|
#include <fs/echfs.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
|
|
|
|
2020-01-22 03:55:40 +03:00
|
|
|
#define QWORD_KERNEL "qword.bin"
|
|
|
|
|
2019-05-15 07:08:56 +03:00
|
|
|
void main(int boot_drive) {
|
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();
|
2019-05-31 08:19:02 +03:00
|
|
|
print("qLoader 2\n\n");
|
2020-01-21 13:42:17 +03:00
|
|
|
print("=> Boot drive: %x\n\n", boot_drive);
|
|
|
|
|
2020-01-22 03:55:40 +03:00
|
|
|
// Enumerate partitions.
|
|
|
|
struct mbr_part parts[4];
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
print("=> Checking for partition %d...", i);
|
|
|
|
int ret = mbr_get_part(&parts[i], boot_drive, i);
|
|
|
|
if (ret) {
|
|
|
|
print("Not found!\n");
|
|
|
|
} else {
|
|
|
|
print("Found!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the file from the chooen partition at 1 MiB.
|
|
|
|
int part = 1; // TODO: The boot partition is hardcoded for now.
|
|
|
|
print("=> Booting %s in partition %d\n", QWORD_KERNEL, part);
|
|
|
|
load_echfs_file(boot_drive, part, (void *)0x100000, QWORD_KERNEL);
|
|
|
|
|
|
|
|
// Boot the kernel.
|
|
|
|
asm volatile (
|
|
|
|
"jmp 0x100000"
|
|
|
|
:
|
|
|
|
: "b" ("")
|
|
|
|
: "memory"
|
|
|
|
);
|
2019-05-15 07:08:56 +03:00
|
|
|
}
|