From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1LpsPZ-0002C7-03 for mharc-grub-devel@gnu.org; Fri, 03 Apr 2009 19:02:57 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LpsPW-0002BW-Se for grub-devel@gnu.org; Fri, 03 Apr 2009 19:02:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LpsPS-0002AU-7X for grub-devel@gnu.org; Fri, 03 Apr 2009 19:02:54 -0400 Received: from [199.232.76.173] (port=43647 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LpsPS-0002AR-18 for grub-devel@gnu.org; Fri, 03 Apr 2009 19:02:50 -0400 Received: from gateway09.websitewelcome.com ([67.18.14.9]:59983) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1LpsPR-0006Ug-EC for grub-devel@gnu.org; Fri, 03 Apr 2009 19:02:49 -0400 Received: (qmail 17714 invoked from network); 3 Apr 2009 23:03:57 -0000 Received: from gator297.hostgator.com (74.53.228.114) by gateway09.websitewelcome.com with SMTP; 3 Apr 2009 23:03:57 -0000 Received: from [65.61.115.34] (port=40881 helo=localhost) by gator297.hostgator.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) (envelope-from ) id 1LpsPO-0001wN-LQ; Fri, 03 Apr 2009 18:02:47 -0500 Date: Fri, 3 Apr 2009 16:02:40 -0700 From: Colin D Bennett To: The development of GRUB 2 Message-ID: <20090403160240.189e35cf@gibibit.com> In-Reply-To: <49D68B82.2080001@gmail.com> References: <200904040340.33570.okuji@enbug.org> <200904040512.15522.okuji@enbug.org> <49D68B82.2080001@gmail.com> X-Mailer: Claws Mail 3.7.1 (GTK+ 2.14.7; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/ziRgyW0h6kIQ.L6AMD8rseJ"; protocol="application/pgp-signature"; micalg=PGP-SHA1 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator297.hostgator.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - gibibit.com X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: phcoder@gmail.com Subject: Re: [PATCH] Split of normal mode (version 2) 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: Fri, 03 Apr 2009 23:02:55 -0000 --Sig_/ziRgyW0h6kIQ.L6AMD8rseJ Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Sat, 04 Apr 2009 00:19:46 +0200 phcoder wrote: > > setjmp is required for the switch between rescue mode and normal mode.= =20 >=20 > It isn't. You can just call the corresponding function. What's wrong=20 > with such approach? So you could have something like ------------- void grub_main () { //... // Try to start up in normal mode normal (); } void normal () { // do stuff // User asked for rescue mode: rescue (); } void rescue () { // do stuff // User asked for normal mode: normal (); } ------------- What if you switch back and forth between normal and rescue mode many times in a row? The stack will grow with each call and eventually the stack will overflow and Bad Things will happen. Granted, you'd have to switch many times to overflow the stack, but it is a sub-optimal situation. You could have something like: ------------- // In this context, grub_main acts as a dispatcher // so that normal and rescue mode can be switched without // unbounded growing of the stack. enum mode { RESCUE, NORMAL }; void grub_main () { enum mode next_mode; //... // Try to start up in normal mode next_mode =3D NORMAL; while (1) { switch (next_mode) { case RESCUE: next_mode =3D rescue (); break; case NORMAL: next_mode =3D normal (); break; default: // Panic! } } } enum mode normal () { // do stuff // User asked for rescue mode: return RESCUE; } enum mode rescue () { // do stuff // User asked for normal mode: return NORMAL; } ------------- Now you could also return function pointers instead of using switch/case with enum constants, but it's the same concept. Then setjmp is another similar way to do it without implementing a central dispatcher like grub_main above. At least that's how I think of it. Regards, Colin --Sig_/ziRgyW0h6kIQ.L6AMD8rseJ Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.11 (GNU/Linux) iEYEARECAAYFAknWlZIACgkQokx8fzcGbYeYRgCgiPBjDWU/W6AE2P4NsPjXX/+Q 6EoAn0J8rTgi9ZmF2EKNYrkQ/yB4aCKU =PibV -----END PGP SIGNATURE----- --Sig_/ziRgyW0h6kIQ.L6AMD8rseJ--