From 3fa7d9d1fad9cfc100aab4d6003f225fc28f1b18 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Sat, 29 Jan 2022 11:54:38 +0100 Subject: [PATCH] chainload: Assume boot drive if DRIVE parameter is omitted --- CONFIG.md | 4 ++-- stage23/protos/chainload.c | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) 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 `xx`. If the resolution is not available, Limine will pick another one automatically. Omitting `` 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"); + 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; } - val = strtoui(drive_config, NULL, 10); - if (val < 1 || val > 256) { - panic(true, "chainload: BIOS drive number outside range 1-256"); - } - 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);