From a3bc7cc0cd20a133a6f11537eb51b0dc252fefc0 Mon Sep 17 00:00:00 2001 From: Paul Bolle Date: Fri, 4 Jun 2010 14:14:49 +0200 Subject: chain.c32: add support for loading GRUB stage2 This adds (basic) support for GRUB stage2 image files. Loading a stage2 image will probably give you a GRUB prompt, with GRUB's "root" set at "(hd0)" (ie, entire first disk). Maybe the "root" will differ in less common setups. (One can of course select another disk and/or partition with GRUB's "root" command.) This has only been tested with version 3.2 stage2 images (as used by GRUB 0.97). I'm not familiair with differences with other versions. GRUB's loading mechanism allows to somehow provide stage2 with the selected disk and partition, BSD slice, etc. (ie, to tell stage2 what it's "root" is). I don't yet understand the notation used in that mechanism. Besides, since stage2 images will not necessarily be loaded from the disk (and partition, etc.) they were installed to, it seems best to just use the first disk. GRUB stage1_5 image files load quite similarly. However, for some reason, a short test only got those images to print an error ("Error 17"). This could be related to the partition info these images are provided with when they're loaded. I have never used stage1_5 images, and do not know how to properly use and configure those, so my test stopped there, and stage1_5 images are not supported. Signed-off-by: Paul Bolle Signed-off-by: H. Peter Anvin --- com32/modules/chain.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/com32/modules/chain.c b/com32/modules/chain.c index ad746ee7..93bba4ea 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -63,6 +63,10 @@ * equivalent to seg=0x70 file= sethidden, * used with DOS' io.sys. * + * grub=: + * same as seg=0x800 file= & jumping to seg 0x820, + * used with GRUB stage2 files. + * * swap: * if the disk is not fd0/hd0, install a BIOS stub which swaps * the drive numbers. @@ -101,6 +105,7 @@ static struct options { bool swap; bool hide; bool sethidden; + bool grub; } opt; struct data_area { @@ -679,6 +684,7 @@ static void usage(void) " freedos= load FreeDOS kernel.sys\n" " msdos= load MS-DOS io.sys\n" " pcdos= load PC-DOS ibmbio.com\n" + " grub= load GRUB stage2\n" " seg= jump to :0000 instead of 0000:7C00\n" " swap swap drive numbers, if bootdisk is not fd0/hd0\n" " hide hide primary partitions, except selected partition\n" @@ -742,6 +748,10 @@ int main(int argc, char *argv[]) opt.seg = 0x70; /* MS-DOS 2.0+ wants this address */ opt.loadfile = argv[i] + 6; opt.sethidden = true; + } else if (!strncmp(argv[i], "grub=", 5)) { + opt.seg = 0x800; /* stage2 wants this address */ + opt.loadfile = argv[i] + 5; + opt.grub = true; } else if (!strcmp(argv[i], "swap")) { opt.swap = true; } else if (!strcmp(argv[i], "noswap")) { @@ -945,6 +955,15 @@ int main(int argc, char *argv[]) } } + if (opt.grub) { + regs.ip = 0x200; /* jump 0x200 bytes into the loadfile */ + + /* 0xffffff00 seems to be GRUB ways to record that it's + "root" is the whole disk (and not a partition). */ + *(uint32_t *) ((unsigned char *) data[ndata].data + 0x208) = + 0xffffff00ul; + } + ndata++; } -- cgit v1.2.1