2020-05-06 18:00:41 +03:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <protos/chainload.h>
|
|
|
|
#include <lib/part.h>
|
|
|
|
#include <lib/config.h>
|
|
|
|
#include <lib/blib.h>
|
|
|
|
#include <drivers/disk.h>
|
2020-09-02 10:55:56 +03:00
|
|
|
#include <lib/term.h>
|
2020-05-06 18:00:41 +03:00
|
|
|
|
|
|
|
void chainload(void) {
|
|
|
|
int part; {
|
|
|
|
char buf[32];
|
|
|
|
if (!config_get_value(buf, 0, 32, "PARTITION")) {
|
2020-05-13 19:13:17 +03:00
|
|
|
part = -1;
|
|
|
|
} else {
|
|
|
|
part = (int)strtoui(buf);
|
2020-05-06 18:00:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
int drive; {
|
|
|
|
char buf[32];
|
|
|
|
if (!config_get_value(buf, 0, 32, "DRIVE")) {
|
|
|
|
panic("DRIVE not specified");
|
|
|
|
}
|
|
|
|
drive = (int)strtoui(buf);
|
|
|
|
}
|
|
|
|
|
2020-09-02 10:55:56 +03:00
|
|
|
term_deinit();
|
2020-05-06 18:00:41 +03:00
|
|
|
|
2020-05-13 19:13:17 +03:00
|
|
|
if (part != -1) {
|
|
|
|
struct part p;
|
|
|
|
get_part(&p, drive, part);
|
2020-05-06 18:00:41 +03:00
|
|
|
|
2020-05-13 19:13:17 +03:00
|
|
|
read_partition(drive, &p, (void *)0x7c00, 0, 512);
|
|
|
|
} else {
|
|
|
|
read(drive, (void *)0x7c00, 0, 512);
|
|
|
|
}
|
2020-05-06 18:00:41 +03:00
|
|
|
|
2020-09-16 18:22:05 +03:00
|
|
|
asm volatile (
|
2020-05-06 18:00:41 +03:00
|
|
|
// Jump to real mode
|
2020-09-16 18:22:05 +03:00
|
|
|
"jmp 0x08:1f\n\t"
|
2020-05-06 18:00:41 +03:00
|
|
|
"1: .code16\n\t"
|
|
|
|
"mov ax, 0x10\n\t"
|
|
|
|
"mov ds, ax\n\t"
|
|
|
|
"mov es, ax\n\t"
|
|
|
|
"mov fs, ax\n\t"
|
|
|
|
"mov gs, ax\n\t"
|
|
|
|
"mov ss, ax\n\t"
|
|
|
|
"mov eax, cr0\n\t"
|
|
|
|
"and al, 0xfe\n\t"
|
|
|
|
"mov cr0, eax\n\t"
|
2020-09-16 18:22:05 +03:00
|
|
|
"jmp 0x0000:1f\n\t"
|
2020-08-27 01:44:16 +03:00
|
|
|
"1:\n\t"
|
2020-05-06 18:00:41 +03:00
|
|
|
"mov ax, 0\n\t"
|
|
|
|
"mov ds, ax\n\t"
|
|
|
|
"mov es, ax\n\t"
|
|
|
|
"mov fs, ax\n\t"
|
|
|
|
"mov gs, ax\n\t"
|
|
|
|
"mov ss, ax\n\t"
|
|
|
|
"push 0\n\t"
|
|
|
|
"push 0x7c00\n\t"
|
|
|
|
"retf\n\t"
|
2020-09-16 18:22:05 +03:00
|
|
|
".code32\n\t"
|
|
|
|
:
|
2020-05-06 18:00:41 +03:00
|
|
|
: "d" (drive)
|
2020-07-24 16:38:55 +03:00
|
|
|
: "memory"
|
2020-05-06 18:00:41 +03:00
|
|
|
);
|
|
|
|
}
|