Generic reboot() for grub-invaders
Fabian Greffrath
greffrath at leat.rub.de
Fri Sep 18 13:22:46 UTC 2009
Dear Robert et al,
I already raised this issue about 1,5 years ago but without further
success: I want to implement a reboot() function in grub-invaders that
makes the machine restart when the ESC-key is pressed [1]. Currently
there is no other way to get out of the game - once started - than
rebooting the machine anyway.
The solution I suggested at that time was a simple call to the BIOS
(taken from GRUB itself), but you (i.e. Robert) were right to remark
that this solution will not work with EFI, coreboot or OpenFirmware
machines - so I dropped this patch. However, I still have this idea on
the mind and today I wanted to see how "the others" do it, since
memtest86{,+} both offer to reboot when ESC is pressed. I found the
following functions to be responsible for rebooting in the sources:
memtest86 (lib.c:86):
inline void reboot(void)
{
/* tell the BIOS to do a warm start */
*((unsigned short *)0x472) = 0x1234;
outb(0xfe,0x64);
}
memtest86+ (test.h:214):
static inline void reboot(void)
{
asm(
"movl %cr0,%eax\n\t"
"andl $0x00000011,%eax\n\t"
"orl $0x60000000,%eax\n\t"
"movl %eax,%cr0\n\t"
"movl %eax,%cr3\n\t"
"movl %cr0,%ebx\n\t"
"andl $0x60000000,%ebx\n\t"
"jz f\n\t"
".byte 0x0f,0x09\n\t" /* Invalidate and flush cache */
"f: andb $0x10,%al\n\t"
"movl %eax,%cr0\n\t"
"movw $0x0010,%ax\n\t"
"movw %ax,%ds\n\t"
"movw %ax,%es\n\t"
"movw %ax,%fs\n\t"
"movw %ax,%gs\n\t"
"movw %ax,%ss\n\t"
"ljmp $0xffff,$0x0000\n\t");
}
While both functions look completely different, I found that in GRUB2
grub-reboot() is implemented in a way similar to how memtest86 does
it, i.e. via the keyboard controler. Would you say that this is the
appropriate *portable* way to implement a reboot (so that it can also
be adopted to grub-invaders) or am I missing something?
Thank you very much for reading (and answering)! ;)
Cheers,
Fabian
[1] http://lists.gnu.org/archive/html/grub-devel/2008-01/msg00386.html
--
Dipl.-Phys. Fabian Greffrath
Ruhr-Universität Bochum
Lehrstuhl für Energieanlagen und Energieprozesstechnik (LEAT)
Universitätsstr. 150, IB 3/134
D-44780 Bochum
Telefon: +49 (0)234 / 32-26334
Fax: +49 (0)234 / 32-14227
E-Mail: greffrath at leat.ruhr-uni-bochum.de
More information about the Pkg-grub-devel
mailing list