From 40a63ecb8888748e4435b9b236594712a99adad2 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Wed, 6 May 2020 17:00:41 +0200 Subject: [PATCH] Initial chainloading support --- CONFIG.md | 5 +++- qloader2.bin | Bin 32768 -> 32768 bytes src/main.c | 3 ++ src/protos/chainload.c | 61 +++++++++++++++++++++++++++++++++++++++++ src/protos/chainload.h | 6 ++++ 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/protos/chainload.c create mode 100644 src/protos/chainload.h diff --git a/CONFIG.md b/CONFIG.md index 78d89a048..609dc6f98 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -23,7 +23,7 @@ Some *local assignments* are shared between entries using any *protocol*, while * `TIMEOUT` - Specifies the timeout in seconds before the first *entry* is automatically booted. *Locally assignable (non protocol specific)* keys are: -* `PROTOCOL` - The boot protocol that will be used to boot the kernel. Valid protocols are: `linux`, `stivale`. +* `PROTOCOL` - The boot protocol that will be used to boot the kernel. Valid protocols are: `linux`, `stivale`, `chainload`. * `KERNEL_PROTO` - Alias of `PROTOCOL`. * `CMDLINE` - The command line string to be passed to the kernel. Can be omitted. * `KERNEL_CMDLINE` - Alias of `CMDLINE`. @@ -42,6 +42,9 @@ Some *local assignments* are shared between entries using any *protocol*, while * `MODULE_PARTITION` - Partition index of a module. * `MODULE_PATH` - The path to a module. * `MODULE_STRING` - A string to be passed to a module. +* chainload protocol: + * `DRIVE` - The drive to chainload. + * `PARTITION` - The partition to chainload. Note that one can define these 3 variable multiple times to specify multiple modules. The entries will be matched in order. E.g.: the 1st partition entry will be matched diff --git a/qloader2.bin b/qloader2.bin index 8337c452a6f1436e96c49c4d004160fcfef00ee7..f7ab14528e830d6e96f18efc892436e772add6b2 100644 GIT binary patch delta 5776 zcmZu#30PEDvc7%jMnte%Ho*nj7FilG=(r0AD!5Iwp|wF40R_B)=Q2KeH1lG*W6K+w z7Q(a4GMShWaWW=m91WV_GKzq-vWc2WbS6Gmm<#O~6a9!$CwHpu1>%>azwh32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s5Lr+0e zftDqng0zBUw)hn6Kq>hY{7->SWjQ5^A4vw@f*{s?3LY0ku^-T&FoE5zhvy43Rlmda zij-3LQQ^s7 z+KY6m1r4IOSptU?2dQ?U^hZfbDh|?mP?FM|I@rIGrKwd}=K_>UjwAPa+?M}rfKA1* z?7IfoQyi6i9ob`0LqE#=hsd~#*wdM>N6d>@wZ!7MaoAo$tmGVY7wg#ibD&+JWwqxZ zb49|aMfhi71QC0O$1WLcz{_X>>Pn?R-(L~LDw^Q*iYQjw1fOHGs|g;j$W*<5UKHPz zClH#W@EY_sx*@=y9lMFS~XSqJbXU; zR1|fvt28E9$p)SYP;ja4)W+1N)N|>$5~ #include #include +#include static char *cmdline; #define CMDLINE_MAX 1024 @@ -164,6 +165,8 @@ void main(int boot_drive) { stivale_load(cmdline, boot_drive); } else if (!strcmp(proto, "linux")) { linux_load(cmdline, boot_drive); + } else if (!strcmp(proto, "chainload")) { + chainload(); } else { panic("Invalid protocol specified"); } diff --git a/src/protos/chainload.c b/src/protos/chainload.c new file mode 100644 index 000000000..fef3bf1eb --- /dev/null +++ b/src/protos/chainload.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +void chainload(void) { + int part; { + char buf[32]; + if (!config_get_value(buf, 0, 32, "PARTITION")) { + panic("PARTITION not specified"); + } + part = (int)strtoui(buf); + } + int drive; { + char buf[32]; + if (!config_get_value(buf, 0, 32, "DRIVE")) { + panic("DRIVE not specified"); + } + drive = (int)strtoui(buf); + } + + deinit_vga_textmode(); + + struct part p; + get_part(&p, drive, part); + + read_partition(drive, &p, (void*)0x7c00, 0, 512); + + asm volatile ( + // Jump to real mode + "jmp 0x08:1f\n\t" + "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" + "jmp 0:2f\n\t" + "2:\n\t" + "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" + ".code32\n\t" + : + : "d" (drive) + ); +} diff --git a/src/protos/chainload.h b/src/protos/chainload.h new file mode 100644 index 000000000..43621937b --- /dev/null +++ b/src/protos/chainload.h @@ -0,0 +1,6 @@ +#ifndef __PROTOS__CHAINLOAD_H__ +#define __PROTOS__CHAINLOAD_H__ + +void chainload(void); + +#endif