Skip to content

Commit

Permalink
[int13] Zero all possible registers when jumping to a boot sector
Browse files Browse the repository at this point in the history
At least one boot sector (the DUET boot sector used for bootstrapping
EFI from a non-EFI system) fails to initialise the high words of
registers before using them in calculations, leading to undefined
behaviour.

Work around such broken boot sectors by explicitly zeroing the
contents of all registers apart from %cs:%ip and %ss:%sp.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Sep 14, 2012
1 parent 8509dbf commit 73eb3f1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/arch/i386/image/bootsector.c
Expand Up @@ -80,9 +80,22 @@ int call_bootsector ( unsigned int segment, unsigned int offset,
"movw %%ss, %%ax\n\t"
"movw %%ax, %%cs:saved_ss\n\t"
"movw %%sp, %%cs:saved_sp\n\t"
/* Jump to boot sector */
/* Prepare jump to boot sector */
"pushw %%bx\n\t"
"pushw %%di\n\t"
/* Clear all registers */
"xorl %%eax, %%eax\n\t"
"xorl %%ebx, %%ebx\n\t"
"xorl %%ecx, %%ecx\n\t"
"xorl %%edx, %%edx\n\t"
"xorl %%esi, %%esi\n\t"
"xorl %%edi, %%edi\n\t"
"xorl %%ebp, %%ebp\n\t"
"movw %%ax, %%ds\n\t"
"movw %%ax, %%es\n\t"
"movw %%ax, %%fs\n\t"
"movw %%ax, %%gs\n\t"
/* Jump to boot sector */
"sti\n\t"
"lret\n\t"
/* Preserved variables */
Expand Down

0 comments on commit 73eb3f1

Please sign in to comment.