Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1M2nAV-0003hi-Mh for mharc-grub-devel@gnu.org; Sat, 09 May 2009 10:04:47 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M2nAU-0003hd-Mx for grub-devel@gnu.org; Sat, 09 May 2009 10:04:46 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M2nAQ-0003hP-RS for grub-devel@gnu.org; Sat, 09 May 2009 10:04:46 -0400 Received: from [199.232.76.173] (port=41127 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M2nAQ-0003hM-Og for grub-devel@gnu.org; Sat, 09 May 2009 10:04:42 -0400 Received: from mail-ew0-f162.google.com ([209.85.219.162]:36293) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M2nAP-0007w4-S1 for grub-devel@gnu.org; Sat, 09 May 2009 10:04:42 -0400 Received: by ewy6 with SMTP id 6so2573766ewy.42 for ; Sat, 09 May 2009 07:04:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=RQL3GmgTTBNhVvybAXw24FxD87WpMZXJDTwfep9qSTY=; b=lAGXygHhgEjiCwTAQXLlWz9HU5R+k2xeqehCtEDTP8F/+9UzZIEcqAdfhmnSukriZo OyaPUtqw5edHzKZQYPU1rLtcaBd0aoMhkqjvHpy7Wfi17jL7QOvUfpy6h/agaAlPiGgU 35f8Uegxww4lLdowPDrDhVJRIEYT2aAFjjDHM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=mZHoTyiXZIeUDTSMRsqx8z9isasdylOSq039B7sLIK9yZmq5T3qeo5CX9bhmt3HTAi EbrFh+u0RWb5PbjyLMPNN4RitGx9qmLZKSTJRsh4b8qphEXrCmB/bWxd/60Xc1yAEFrz quMTJri3n4J0TUeRF+bxB5AifYDYultVyGv3k= MIME-Version: 1.0 Received: by 10.210.105.8 with SMTP id d8mr850511ebc.24.1241877880031; Sat, 09 May 2009 07:04:40 -0700 (PDT) In-Reply-To: <1241875621.22837.24.camel@accesodirecto.casa> References: <49E3E0FB.1070907@verizon.net> <1240021094.19677.29.camel@accesodirecto.casa> <1241308934.4290.79.camel@accesodirecto.casa> <1241384352.2442.133.camel@ct> <1241393832.6586.35.camel@accesodirecto.casa> <1241409431.26483.33.camel@mj> <1241635288.4535.6.camel@accesodirecto.casa> <1241875621.22837.24.camel@accesodirecto.casa> Date: Sat, 9 May 2009 16:04:40 +0200 Message-ID: From: "Vladimir 'phcoder' Serbinenko" To: The development of GRUB 2 Content-Type: multipart/alternative; boundary=0015174beee4e4ca2f04697b3920 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: Re: status grub2 port of grub-legasy map command X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 May 2009 14:04:46 -0000 --0015174beee4e4ca2f04697b3920 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello 2009/5/9 Javier Mart=EDn > El s=E1b, 09-05-2009 a las 11:17 +0200, Vladimir 'phcoder' Serbinenko > escribi=F3: > > +/* Realmode far ptr (2 * 16b) to the previous INT13h handler. */ > > +extern grub_uint32_t grub_drivemap_int13_oldhandler; > > I prefer it to be 2 variables because of the way they interract so > > nobody would do something like (char *) > > grub_drivemap_int13_oldhandler; > Two variables? I don't understand. You want the CS and IP parts of the > far pointer separated? Yes. Especially that in .S you declared it as two words. But it's not an absolute must > Why would anyone try to use it like you said? The > comment explicits that it is a realmode pointer, and as such it is not > usable as a linear pmode pointer. > > > +/* The type "void" is used for imported assembly labels, takes no > > storage and > > + serves just to take the address with &label. Do NOT put void* > > here. */ > > +/* Start of the handler bundle. */ > > +extern void grub_drivemap_int13_handler_base; > > The common practice is to use declarations like > > extern char grub_drivemap_int13_handler_base[]; > > it makes pointer arithmetics easy > That variable is used only twice in the code: one in a call to memcpy > and another one inside the macro INT13_OFFSET. It would still be so even > if it were changed to a char array, with the added risk that a char > array can be modified with almost nothing to gain (as casts would still > be needed). The casts are needed if you declare it as char foo[]; If someone modifies an array he does it on purpose > In fact, I'm declaring all the labels as "const void" so > no-one tries to overwrite the "master" data instead of the deployed > data. > > > +typedef struct drivemap_node > > +{ > > + grub_uint8_t newdrive; > > + grub_uint8_t redirto; > > + struct drivemap_node *next; > > +} drivemap_node_t; > > Here you could reuse Bean's list functions > After examining the API, I think such a change would be too invasive for > a "mature" patch right now. However, once the patch is in and drivemap > is working for everyone, I can work on modifying it to use > . The biggest hurdle I see is that there is no way to > automatically maintain "key" uniqueness like the current methods do, so > an iteration over the list would be required. > > As a side note/rant, desperately needs documentation > comments for other developers to be able to actually use it without > wondering if they're going into the darkness. In particular I need to > know what grub_list_insert does without delving into "list.c" (for > example: "if all tests fail, will the item be inserted last or not at > all?"). This rant also applies to other grub include files. > > > > It's not necessary to try to open the disk actually because for some > > reason biosdisk module may be not loaded (e.g. grub may use ata) and > > loading it may cause nasty effects (e.g. conflict between ata and > > biosdisk) > > Same applies for revparse_biosdisk. And if user wants to map to > > unexistant disk it's ok. So just use tryparse_diskstring > Hmm... this is a profound design issue: you are arguing that drivemap > should not care about actual BIOS disks, but just their drive numbers, > and let you map 0x86 to 0x80 even if you have no (hd6). I do not agree, > since the main use for GRUB is a bootloader, not a test platform (which > would be the only reason to perform that kind of mappings which are sure > to cause havoc). Thus, by default drivemap only lets you perform > mappings that will work - any stress tester is free to modify the code. > > Regarding opening the disk, the biosdisk interface does not assure in > any way (and again there is almost no API documentation) that hd0 will > be 0x80, though it's the sensible thing to expect. However, expecting > sensible things from an unstable API prone to redesigns (like the > command API, for example) Mapping something to non-existant drive makes the drive non-existant. I think it's fair It's almost guaranteed that numbering of disks won't change > usually leads to nasty surprises later on, so > unless 1) the biosdisk interface so specifies and 2) hdN will _always_ > refer to biosdisk and not another possible handler, I think the check is > a Good Thing (tm). It's not if it may hang when you use ata.mod > > > > + if ((str[0] =3D=3D 'f' || str[0] =3D=3D 'h') && str[1] =3D=3D 'd') > > change this to something like > > if (! ((str[0] =3D=3D 'f' || str[0] =3D=3D 'h') && str[1] =3D=3D 'd')) > > return ... > > It makes code nicer by avoiding unnecessary long else > I think the "else" you were talking about was one line long, but it was > not needed anyways and so I've removed it. > > > + grub_errno =3D GRUB_ERR_NONE; > > No need to set grub_errno explicitely unless you want to ignore an > > error > I may have got it wrong, but I think that functions like strtoul only > _set_ errno if there _has_ been an error, but leave it unchanged if > there hasn't. As I want to check if the conversion failed, I need to > have the variable to check in a known pre-state. > If grub_errno is set at the begining of the function then either scripting or your code has a bug > > > + unsigned long drivenum =3D grub_strtoul (str + 2, 0, 0); > > + if (grub_errno !=3D GRUB_ERR_NONE || drivenum > 127) > > I think it's enough to just check the range > See above. > > > + { > > + /* N not a number or out of range. */ > > + goto fail; > > Since at fail you have just a return, just put a return here with > > informative error message > The function was rearranged so only the first goto is required now. > +fail: + return grub_error (GRUB_ERR_BAD_ARGUMENT, "device format \"%s\" " + "invalid: must be (f|h)dN, with 0 <=3D N < 128", str); I don't see a clear benefit of using goto here. Perhaps providing a separat= e informative messages for 2 fail cases is a better option > > > + } > > + else > > else is unnecessary, just continue with the code > I fear you don't give me enough context to find this one. If it was > inside tryparse_diskstring, it has been removed. > > > + if (cmd->state[OPTIDX_LIST].set || 0 =3D=3D argc) > > argc =3D=3D 0 sounds better. Also moving list function to a separate > > function is a good idea > Ok, changed. I'd just like to remark that if someone slipped and changed > the line to "argc =3D 0" it would pass unnoticed by the compiler, while "= 0 > =3D argc" would create a compile-time error. It's what warnings are for > Regarding slicing the listing > functionality, I don't see the advantages. > It makes code more readable and avoids long else clause > > + push %bp > > + mov %sp, %bp > > You don't need to change bp. Just use sp. In this case it makes code > > easier > That would make it more difficult to address passed parameters like the > flags at [BP+6] because their location would depend on the current > status of SP (which might change depending on code above the relevant > lines). I checked and can say that removing bp code makes the rest actually easier. If you don't see how tell me I'll modify it > I think that trying to shave off those 4 or so bytes would make > the code unnecessarily more complicated, which is usually a no-no when > assembly is involved. Besides, this prolog sequence and the > corresponding epilog before returning is practically a standard in x86. > > > + lcall *% > > cs:GRUB_DRIVEMAP_INT13H_OFFSET(grub_drivemap_int13_oldhandler) > > + pop %bp /* The pushed flags were removed by iret. */ > > Use rather: > > pushf > > lcall *% > > cs:GRUB_DRIVEMAP_INT13H_OFFSET(grub_drivemap_int13_oldhandler) > Why would we want to save our current flags? We want the old int13 > handler to receive the flags it would have received if the drivemap > int13 handler were not present, that is, the original caller flags which > were stored above CS:IP in the stack when the "int $0x13" call was > issued. The comment means that "iret" pops not just CS:IP but also the > flags, so we can proceed directly to popping %bp. > > > Also remember to restore original %dl after the call > I think there is no need to do so, because BIOS calls modify %dl anyway. > Then you can remove %bp and just make a long jump. This way int 13 handler recieves the original stack intact > > > > Could you also prepare a changelog entry for it? > Hmm... I don't really know how to write it, given that both files are > new and the patch does not modify any other GRUB function. Am I supposed > to also declare the modifications in the rmk files? (written in mailer so identation is wrong) * conf/i386-pc.rmk (pkglib_MODULES): add drivemap.mod (drivemap_mod_SOURCES): new variable (drivemap_mod_CFLAGS): likewise (drivemap_mod_LDFLAGS): likewise (drivemap_mod_ASFLAGS): likewise * commands/i386/pc/drivemap.c: new file * commands/i386/pc/drivemap_int13h.S: likewise > > -- > -- Lazy, Oblivious, Recurrent Disaster -- Habbit > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel > > --=20 Regards Vladimir 'phcoder' Serbinenko --0015174beee4e4ca2f04697b3920 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello

2009/5/9 Javier Mart=EDn <lordhabbit@gmail.com>
El s=E1b, 09-05-2009 a las 11:17 +0200, Vladimir 'phcoder' Serbinen= ko
escribi=F3:
> +/* Realmode far ptr (2 * 16b) to the previous INT13= h handler. =A0*/
> +extern grub_uint32_t grub_drivemap_int13_oldhandler;
> I prefer it to be 2 variables because of the way they interract so
> nobody would do something like (char *)
> grub_drivemap_int13_oldhandler;
Two variables? I don't understand. You want the CS and IP parts o= f the
far pointer separated?
Yes. Especially that in .S you dec= lared it as two words. But it's not an absolute must
Why would anyone try to use it like you said? The
comment explicits that it is a realmode pointer, and as such it is not
usable as a linear pmode pointer.

> +/* The type "void" is used for imported assembly labels, ta= kes no
> storage and
> + =A0 serves just to take the address with &label. =A0Do NOT put v= oid*
> here. =A0*/
> +/* Start of the handler bundle. =A0*/
> +extern void grub_drivemap_int13_handler_base;
> The common practice is to use declarations like
> extern char grub_drivemap_int13_handler_base[];
> it makes pointer arithmetics easy
That variable is used only twice in the code: one in a call to memcpy=
and another one inside the macro INT13_OFFSET. It would still be so even if it were changed to a char array, with the added risk that a char
array can be modified with almost nothing to gain (as casts would still
be needed).
The casts are needed if you declare it as cha= r foo[];
If someone modifies an array he does it on purpose
In fact, I'm declaring all the labels as "const void" so
no-one tries to overwrite the "master" data instead of the deploy= ed
data.

> +typedef struct drivemap_node
> +{
> + =A0grub_uint8_t newdrive;
> + =A0grub_uint8_t redirto;
> + =A0struct drivemap_node *next;
> +} drivemap_node_t;
> Here you could reuse Bean's list functions
After examining the API, I think such a change would be too invasive = for
a "mature" patch right now. However, once the patch is in and dri= vemap
is working for everyone, I can work on modifying it to use
<grub/list.h>. The biggest hurdle I see is that there is no way to automatically maintain "key" uniqueness like the current methods = do, so
an iteration over the list would be required.

As a side note/rant, <grub/list.h> desperately needs documentation comments for other developers to be able to actually use it without
wondering if they're going into the darkness. In particular I need to know what grub_list_insert does without delving into "list.c" (fo= r
example: "if all tests fail, will the item be inserted last or not at<= br> all?"). This rant also applies to other grub include files.


> It's not necessary to try to open the disk actually because for so= me
> reason biosdisk module may be not loaded (e.g. grub may use ata) and > loading it may cause nasty effects (e.g. conflict between ata and
> biosdisk)
> Same applies for revparse_biosdisk. And if user wants to map to
> unexistant disk it's ok. So just use tryparse_diskstring
Hmm... this is a profound design issue: you are arguing that drivemap=
should not care about actual BIOS disks, but just their drive numbers,
and let you map 0x86 to 0x80 even if you have no (hd6). I do not agree,
since the main use for GRUB is a bootloader, not a test platform (which
would be the only reason to perform that kind of mappings which are sure to cause havoc). Thus, by default drivemap only lets you perform
mappings that will work - any stress tester is free to modify the code.

=
Regarding opening the disk, the biosdisk interface does not assure in
any way (and again there is almost no API documentation) that hd0 will
be 0x80, though it's the sensible thing to expect. However, expecting sensible things from an unstable API prone to redesigns (like the
command API, for example)
Mapping something to non-ex= istant drive makes the drive non-existant. I think it's fair
It's almost guaranteed that numbering of disks won't change
=A0
u= sually leads to nasty surprises later on, so
unless 1) the biosdisk interface so specifies and 2) hdN will _always_
refer to biosdisk and not another possible handler, I think the check is a Good Thing (tm).
It's not if it may hang when you us= e ata.mod


> + =A0if ((str[0] =3D=3D 'f' || str[0] =3D=3D 'h') &= ;& str[1] =3D=3D 'd')
> change this to something like
> if (! ((str[0] =3D=3D 'f' || str[0] =3D=3D 'h') &&= amp; str[1] =3D=3D 'd'))
> =A0 =A0return ...
> It makes code nicer by avoiding unnecessary long else
I think the "else" you were talking about was one line long= , but it was
not needed anyways and so I've removed it.

=
> + =A0 =A0 =A0grub_errno =3D GRUB_ERR_NONE;
> No need to set grub_errno explicitely unless you wan= t to ignore an
> error
I may have got it wrong, but I think that functions like strtoul only=
_set_ errno if there _has_ been an error, but leave it unchanged if
there hasn't. As I want to check if the conversion failed, I need to have the variable to check in a known pre-state.
If grub_errno is set at the begining of the function then= either scripting or your code has a bug

> + =A0 =A0 =A0unsigned long drivenum =3D grub_strtoul (str + 2, 0, 0);<= br>
> + =A0 =A0 =A0if (grub_errno !=3D GRUB_ERR_NONE || dr= ivenum > 127)
> I think it's enough to just check the range
See above.

> + =A0 =A0{
> + =A0 =A0 =A0/* N not a number or out of range. =A0*/
> + =A0 =A0 =A0goto fail;
> Since at fail you have just a return, just put a return here with
> informative error message
The function was rearranged so only the first goto is required now.
+fail:
+=A0 return grub_error (GRUB_ERR_BAD_ARGUMENT, "device format \"%= s\" "
+=A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0 "invalid: must be (f|h)dN, with 0 &l= t;=3D N < 128", str);
I don't see a clear benefit of using goto here. Perhaps providing a separate informative messages for 2 fail cases is a better option
=A0
> + =A0 =A0}
> + =A0 =A0 =A0else
> else is unnecessary, just continue with the code
I fear you don't give me enough context to find this one. If it w= as
inside tryparse_diskstring, it has been removed.

> + =A0if (cmd->state[OPTIDX_LIST].set || 0 =3D=3D argc)
> argc =3D=3D 0 sounds better. Also moving list functi= on to a separate
> function is a good idea
Ok, changed. I'd just like to remark that if someone slipped and = changed
the line to "argc =3D 0" it would pass unnoticed by the compiler,= while "0
=3D argc" would create a compile-time error.
It'= s what warnings are for
Regarding slicing the listing
functionality, I don't see the advantages.
It makes code more readable and avoids long else clause <= br>
> + =A0 =A0 =A0 push =A0 =A0%bp
> + =A0 =A0 =A0 mov =A0 =A0 %sp, %bp
> You don't need to change bp. Just use sp. In this case it makes co= de
> easier
That would make it more difficult to address passed parameters like t= he
flags at [BP+6] because their location would depend on the current
status of SP (which might change depending on code above the relevant
lines).
I checked and can say that removing bp code makes= the rest actually easier. If you don't see how tell me I'll modify= it
I think that trying to shave off those 4 or so bytes would make
the code unnecessarily more complicated, which is usually a no-no when
assembly is involved. Besides, this prolog sequence and the
corresponding epilog before returning is practically a standard in x86.

> + =A0 =A0 =A0 lcall =A0 *%
> cs:GRUB_DRIVEMAP_INT13H_OFFSET(grub_drivemap_int13_o= ldhandler)
> + =A0 =A0 =A0 pop =A0 =A0 %bp /* The pushed flags were removed by iret= . =A0*/
> Use rather:
> pushf
> lcall =A0 *%
> cs:GRUB_DRIVEMAP_INT13H_OFFSET(grub_drivemap_int13_oldhandler)
Why would we want to save our current flags? We want the old int13 handler to receive the flags it would have received if the drivemap
int13 handler were not present, that is, the original caller flags which were stored above CS:IP in the stack when the "int $0x13" call wa= s
issued. The comment means that "iret" pops not just CS:IP but als= o the
flags, so we can proceed directly to popping %bp.

> Also remember to restore original %dl after the call
I think there is no need to do so, because BIOS calls modify %dl anyw= ay.
Then you can remove %bp and just = make a long jump. This way int 13 handler recieves the original stack intac= t


> Could you also prepare a changelog entry for it?
Hmm... I don't really know how to write it, given that both files= are
new and the patch does not modify any other GRUB function. Am I supposed to also declare the modifications in the rmk files?
(writt= en in mailer so identation is wrong)
<your contact line&g= t;

=A0=A0 <short description>
* conf/i386-pc.rmk (pkglib_MO= DULES): add drivemap.mod
(drivemap_mod_SOURCES): new variable
(drivemap_mod_CFLAGS): likewise
= (drivemap_mod_LDFLAGS): likewise
(drivemap_mod_ASFLAGS): likewise

* commands/i386/pc/drivemap.c: new file
* commands/i386/pc/drivemap_= int13h.S: likewise

--
-- Lazy, Oblivious, Recurrent Disa= ster -- Habbit

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel




--
Regards
Vladimir= 'phcoder' Serbinenko
--0015174beee4e4ca2f04697b3920--