chainload: Assume boot drive if DRIVE parameter is omitted
diff --git a/CONFIG.md b/CONFIG.md
index ae2c5591..5259f53f 100644
--- a/CONFIG.md
+++ b/CONFIG.md
@@ -123,8 +123,8 @@ Some keys take *URIs* as values; these are described in the next section.
* `KASLR` - For relocatable kernels, if set to `no`, disable kernel address space layout randomisation. KASLR is enabled by default.
* `TEXTMODE` - If set to `yes`, prefer text mode if the kernel has no video mode requirements. (Only for stivale2)
* Chainload protocol on BIOS:
- * `DRIVE` - The 1-based BIOS drive to chainload.
- * `PARTITION` - The 1-based BIOS partition to chainload, if omitted, chainload drive.
+ * `DRIVE` - The 1-based BIOS drive to chainload, if omitted, assume boot drive.
+ * `PARTITION` - The 1-based BIOS partition to chainload, if omitted, chainload drive (MBR).
* Chainload protocol on UEFI:
* `IMAGE_PATH` - URI of the EFI application to chainload.
* `RESOLUTION` - The resolution to be used. This setting takes the form of `<width>x<height>x<bpp>`. If the resolution is not available, Limine will pick another one automatically. Omitting `<bpp>` will default to 32.
diff --git a/stage23/protos/chainload.c b/stage23/protos/chainload.c
index f76a1b21..15960789 100644
--- a/stage23/protos/chainload.c
+++ b/stage23/protos/chainload.c
@@ -87,20 +87,21 @@ void chainload(char *config) {
int drive; {
char *drive_config = config_get_value(config, 0, "DRIVE");
if (drive_config == NULL) {
- panic(true, "chainload: DRIVE not specified");
- }
- val = strtoui(drive_config, NULL, 10);
- if (val < 1 || val > 256) {
- panic(true, "chainload: BIOS drive number outside range 1-256");
+ drive = boot_volume->index;
+ } else {
+ val = strtoui(drive_config, NULL, 10);
+ if (val < 1 || val > 256) {
+ panic(true, "chainload: BIOS drive number outside range 1-256");
+ }
+ drive = val;
}
- drive = val;
}
+ struct volume *p = volume_get_by_coord(false, drive, part);
+
size_t rows, cols;
init_vga_textmode(&rows, &cols, false);
- struct volume *p = volume_get_by_coord(false, drive, part);
-
volume_read(p, (void *)0x7c00, 0, 512);
spinup(p->drive);
