Преглед изворни кода

[int13] Zero all possible registers when jumping to a boot sector

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>
tags/v1.20.1
Michael Brown пре 11 година
родитељ
комит
73eb3f17db
1 измењених фајлова са 14 додато и 1 уклоњено
  1. 14
    1
      src/arch/i386/image/bootsector.c

+ 14
- 1
src/arch/i386/image/bootsector.c Прегледај датотеку

80
 					   "movw %%ss, %%ax\n\t"
80
 					   "movw %%ss, %%ax\n\t"
81
 					   "movw %%ax, %%cs:saved_ss\n\t"
81
 					   "movw %%ax, %%cs:saved_ss\n\t"
82
 					   "movw %%sp, %%cs:saved_sp\n\t"
82
 					   "movw %%sp, %%cs:saved_sp\n\t"
83
-					   /* Jump to boot sector */
83
+					   /* Prepare jump to boot sector */
84
 					   "pushw %%bx\n\t"
84
 					   "pushw %%bx\n\t"
85
 					   "pushw %%di\n\t"
85
 					   "pushw %%di\n\t"
86
+					   /* Clear all registers */
87
+					   "xorl %%eax, %%eax\n\t"
88
+					   "xorl %%ebx, %%ebx\n\t"
89
+					   "xorl %%ecx, %%ecx\n\t"
90
+					   "xorl %%edx, %%edx\n\t"
91
+					   "xorl %%esi, %%esi\n\t"
92
+					   "xorl %%edi, %%edi\n\t"
93
+					   "xorl %%ebp, %%ebp\n\t"
94
+					   "movw %%ax, %%ds\n\t"
95
+					   "movw %%ax, %%es\n\t"
96
+					   "movw %%ax, %%fs\n\t"
97
+					   "movw %%ax, %%gs\n\t"
98
+					   /* Jump to boot sector */
86
 					   "sti\n\t"
99
 					   "sti\n\t"
87
 					   "lret\n\t"
100
 					   "lret\n\t"
88
 					   /* Preserved variables */
101
 					   /* Preserved variables */

Loading…
Откажи
Сачувај