From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1TzTqd-0006eq-0q for mharc-grub-devel@gnu.org; Sun, 27 Jan 2013 10:08:43 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzTqU-0006YS-1i for grub-devel@gnu.org; Sun, 27 Jan 2013 10:08:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TzTqS-0003iY-Ff for grub-devel@gnu.org; Sun, 27 Jan 2013 10:08:33 -0500 Received: from mail-wi0-x22a.google.com ([2a00:1450:400c:c05::22a]:43626) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzTqS-0003iU-5m for grub-devel@gnu.org; Sun, 27 Jan 2013 10:08:32 -0500 Received: by mail-wi0-f170.google.com with SMTP id cb5so54726wib.1 for ; Sun, 27 Jan 2013 07:08:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:x-enigmail-version:content-type; bh=fyJnP+wQwbERzv1bKBZLlHsFde0j43Md6hawnIrwNEM=; b=HSFIKpi0biSBMKQzmVhlzZJHc2GsgBuROdtZeBoPvRKRJTNn6GFUkA+aYdJuzbBgHW BWpBJmmwPEuA4KqMkLy5LK2MUALVjdevT8m6FJKr2WQTK/cOn1/GEEDioXj4/4cxhjg1 tCIS042TFur1S8H0DF9EtrLkfU9yYTDvUtn6SDOVNLUGmpnggQ5dlgyX5x+9XeQ27jQW tZA35rIuWEBALqDH6suOeYgutGTTsx3V4aCWD0CqbJtsnK0A/bmK6XN8U2cpBQ0K4DXA NRCSwgFsNrvNthMxvhmPtlZ5C8YVz6ylaZlsJEkZqanwkwDoT6FVHld02HbvD6sALoTC t8JQ== X-Received: by 10.180.90.106 with SMTP id bv10mr5482189wib.12.1359299310554; Sun, 27 Jan 2013 07:08:30 -0800 (PST) Received: from debian.x201.phnet (33-233.197-178.cust.bluewin.ch. [178.197.233.33]) by mx.google.com with ESMTPS id bw9sm7689907wib.5.2013.01.27.07.08.27 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 27 Jan 2013 07:08:29 -0800 (PST) Message-ID: <510542E9.6020403@gmail.com> Date: Sun, 27 Jan 2013 16:08:25 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20121122 Icedove/10.0.11 MIME-Version: 1.0 To: grub-devel@gnu.org Subject: Re: [PATCH] Improve FreeDOS direct loading support compatibility. References: <4FF82A25.9070504@gmail.com> In-Reply-To: X-Enigmail-Version: 1.4.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig7D29F20950D7C00AA192EC78" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22a X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Jan 2013 15:08:41 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig7D29F20950D7C00AA192EC78 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Committed with minor problems fixed. Thanks. On 08.07.2012 10:28, C. Masloch wrote: > diff --git a/ChangeLog b/ChangeLog > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,3 +1,18 @@ > +2012-06-30 C. Masloch > + > + Improve FreeDOS direct loading support compatibility. > + > + * include/grub/i386/relocator.h (grub_relocator16_state): > + New member ebp. > + * grub-core/lib/i386/relocator.c (grub_relocator16_ebp): New extern > + variable. > + (grub_relocator16_boot): Handle %ebp. > + * grub-core/lib/i386/relocator16.S: Likewise. > + * grub-core/loader/i386/pc/freedos.c: > + Load BPB to pass kernel which partition to load from. > + Check that kernel file is not too large. > + Set register dl to BIOS unit number as well. > + > 2012-06-27 Vladimir Serbinenko > =20 > * configure.ac: Bump version to 2.00. > diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/reloca= tor.c > --- a/grub-core/lib/i386/relocator.c > +++ b/grub-core/lib/i386/relocator.c > @@ -54,6 +54,7 @@ > extern grub_uint32_t grub_relocator16_edx; > extern grub_uint32_t grub_relocator16_ebx; > extern grub_uint32_t grub_relocator16_esi; > +extern grub_uint32_t grub_relocator16_ebp; > =20 > extern grub_uint16_t grub_relocator16_keep_a20_enabled; > =20 > @@ -225,6 +226,7 @@ > grub_relocator16_ss =3D state.ss; > grub_relocator16_sp =3D state.sp; > =20 > + grub_relocator16_ebp =3D state.ebp; > grub_relocator16_ebx =3D state.ebx; > grub_relocator16_edx =3D state.edx; > grub_relocator16_esi =3D state.esi; > diff --git a/grub-core/lib/i386/relocator16.S b/grub-core/lib/i386/relo= cator16.S > --- a/grub-core/lib/i386/relocator16.S > +++ b/grub-core/lib/i386/relocator16.S > @@ -259,6 +259,11 @@ > VARIABLE(grub_relocator16_ebx) > .long 0 > =20 > + /* movl imm32, %ebp. */ > + .byte 0x66, 0xbd > +VARIABLE(grub_relocator16_ebp) > + .long 0 > + > /* Cleared direction flag is of no problem with any current > payload and makes this implementation easier. */ > cld > diff --git a/grub-core/loader/i386/pc/freedos.c b/grub-core/loader/i386= /pc/freedos.c > --- a/grub-core/loader/i386/pc/freedos.c > +++ b/grub-core/loader/i386/pc/freedos.c > @@ -32,6 +32,7 @@ > #include > #include > #include > +#include > =20 > GRUB_MOD_LICENSE ("GPLv3+"); > =20 > @@ -40,8 +41,23 @@ > static grub_uint32_t ebx =3D 0xffffffff; > =20 > #define GRUB_FREEDOS_SEGMENT 0x60 > +#define GRUB_FREEDOS_ADDR (GRUB_FREEDOS_SEGMENT << 4) > #define GRUB_FREEDOS_STACK_SEGMENT 0x1fe0 > -#define GRUB_FREEDOS_STACK_POINTER 0x8000 > +#define GRUB_FREEDOS_STACK_BPB_POINTER 0x7c00 > +#define GRUB_FREEDOS_BPB_ADDR ((GRUB_FREEDOS_STACK_SEGMENT << 4= ) \ > + + GRUB_FREEDOS_STACK_BPB_POINTE= R) > + > +/* FreeDOS boot.asm passes register sp as exactly this. Importantly, > + it must point below the BPB (to avoid overwriting any of it). */ > +#define GRUB_FREEDOS_STACK_POINTER (GRUB_FREEDOS_STACK_BPB_POI= NTER \ > + - 0x60) > + > +/* In this, the additional 8192 bytes are the stack reservation; the > + remaining parts trivially give the maximum allowed size. */ > +#define GRUB_FREEDOS_MAX_SIZE ((GRUB_FREEDOS_STACK_SEGMENT << 4= ) \ > + + GRUB_FREEDOS_STACK_POINTER \ > + - GRUB_FREEDOS_ADDR \ > + - 8192) > =20 > static grub_err_t > grub_freedos_boot (void) > @@ -49,14 +65,29 @@ > struct grub_relocator16_state state =3D {=20 > .cs =3D GRUB_FREEDOS_SEGMENT, > .ip =3D 0, > - .ds =3D 0, > + > + /* This is not strictly necessary for the current FreeDOS kernel > + but improves potential compatibility with others. > + There is no harm in setting this. */ > + .ds =3D GRUB_FREEDOS_STACK_SEGMENT, > .es =3D 0, > .fs =3D 0, > .gs =3D 0, > .ss =3D GRUB_FREEDOS_STACK_SEGMENT, > .sp =3D GRUB_FREEDOS_STACK_POINTER, > + .ebp =3D GRUB_FREEDOS_STACK_BPB_POINTER, > .ebx =3D ebx, > - .edx =3D 0, > + > + /* This is not strictly necessary for the current FreeDOS kernel > + but is crucial for potential compatibility with the load > + protocols of other DOS-like kernels and loaders (including > + the older FreeDOS kernel releases called DOS-C). > + (Among those, FreeDOS's new load protocol must be considered > + a special case in that it doesn't require register dl to pass > + the unit number. Incidentally, the current FreeDOS boot.asm > + does pass it in both registers.) > + There is no harm in setting this. */ > + .edx =3D ebx, > .a20 =3D 1 > }; > grub_video_set_mode ("text", 0, 0); > @@ -79,8 +110,9 @@ > { > grub_file_t file =3D 0; > grub_err_t err; > - void *kernelsys; > + void *bs, *kernelsys; > grub_size_t kernelsyssize; > + grub_device_t dev; > =20 > if (argc =3D=3D 0) > return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"))= ; > @@ -95,12 +127,52 @@ > if (! file) > goto fail; > =20 > + { > + grub_relocator_chunk_t ch; > + err =3D grub_relocator_alloc_chunk_addr (rel, &ch, GRUB_FREEDOS_BP= B_ADDR, > + GRUB_DISK_SECTOR_SIZE); > + if (err) > + goto fail; > + bs =3D get_virtual_current_address (ch); > + } > + > ebx =3D grub_get_root_biosnumber (); > + dev =3D grub_device_open (0); > + > + if (dev && dev->disk) > + { > + err =3D grub_disk_read (dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, = bs); > + if (err) > + { > + grub_device_close (dev); > + goto fail; > + } > + grub_chainloader_patch_bpb (bs, dev, ebx); > + } > + > + if (dev) > + grub_device_close (dev); > =20 > kernelsyssize =3D grub_file_size (file); > + > + /* This check could be considered optional, but it provides a more > + specific error message than grub_relocator_alloc_chunk_addr would= , > + and additionally it insures that a little is set aside for the > + initial stack as well. > + Quirkily, because of its size constraints FreeDOS's original load= er > + doesn't perform such a check at all (and crashes instead). The fi= le > + size limit is documented though. */ > + if (kernelsyssize > GRUB_FREEDOS_MAX_SIZE) > + { > + grub_error (GRUB_ERR_BAD_OS, > + "file `%s' is too large for a valid" > + " FreeDOS kernel.sys", argv[0]); > + goto fail; > + } > + > { > grub_relocator_chunk_t ch; > - err =3D grub_relocator_alloc_chunk_addr (rel, &ch, GRUB_FREEDOS_SE= GMENT << 4, > + err =3D grub_relocator_alloc_chunk_addr (rel, &ch, GRUB_FREEDOS_AD= DR, > kernelsyssize); > if (err) > goto fail; > diff --git a/include/grub/i386/relocator.h b/include/grub/i386/relocato= r.h > --- a/include/grub/i386/relocator.h > +++ b/include/grub/i386/relocator.h > @@ -49,6 +49,7 @@ > grub_uint32_t ebx; > grub_uint32_t edx; > grub_uint32_t esi; > + grub_uint32_t ebp; > int a20; > }; > =20 --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------enig7D29F20950D7C00AA192EC78 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iF4EAREKAAYFAlEFQukACgkQNak7dOguQgmHFwD/VajQ+4qMmuIP2YTrl29VMlLa vXCGr+zLYA3c1j8QxZUA+wUpjwZH7Oi1p0djFuHdFF55X/bsrIJOvU9cc6NU43mo =DwWB -----END PGP SIGNATURE----- --------------enig7D29F20950D7C00AA192EC78--