ソースを参照

[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 12年前
コミット
73eb3f17db
1個のファイルの変更14行の追加1行の削除
  1. 14
    1
      src/arch/i386/image/bootsector.c

+ 14
- 1
src/arch/i386/image/bootsector.c ファイルの表示

@@ -80,9 +80,22 @@ int call_bootsector ( unsigned int segment, unsigned int offset,
80 80
 					   "movw %%ss, %%ax\n\t"
81 81
 					   "movw %%ax, %%cs:saved_ss\n\t"
82 82
 					   "movw %%sp, %%cs:saved_sp\n\t"
83
-					   /* Jump to boot sector */
83
+					   /* Prepare jump to boot sector */
84 84
 					   "pushw %%bx\n\t"
85 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 99
 					   "sti\n\t"
87 100
 					   "lret\n\t"
88 101
 					   /* Preserved variables */

読み込み中…
キャンセル
保存