Skip to contentSkip to conversation

Zero some registers in linux_trampoline

PATCH New Colin Watson 1 participant 1 message Aug 24, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Zero some registers in linux_trampoline

linux/Documentation/x86/boot.txt specifies that:

At entry, the CPU must be in 32-bit protected mode with paging disabled; a GDT must be loaded with the descriptors for selectors __BOOT_CS(0x10) and __BOOT_DS(0x18); both descriptors must be 4G flat segment; __BOOS_CS must have execute/read permission, and __BOOT_DS must have read/write permission; CS must be __BOOT_CS and DS, ES, SS must be __BOOT_DS; interrupt must be disabled; %esi must hold the base address of the struct boot_params; %ebp, %edi and %ebx must be zero.

In the linux_trampoline used in a 64-bit EFI target, we jump to the contents of %edi, so that at least is certainly non-compliant with the specification above. I don't know about %ebp and %ebx but it would be good to make sure.

How about the following patch?

2010-08-24 Colin Watson <[email protected]>

* loader/i386/linux_trampoline.S (cont2): Zero %ebp, %edi, and %ebx before jumping to the kernel, per the Linux 32-bit boot protocol specification.

=== modified file 'loader/i386/linux_trampoline.S'

i386/linux_trampoline.S +5 -1
@@ -93,8 +93,12 @@ cont2:
 	.code32
 
 	mov %ebx, %esi
+	mov %edi, %ecx
+	xor %ebp, %ebp
+	xor %edi, %edi
+	xor %ebx, %ebx
 
-	jmp *%edi
+	jmp *%ecx
 
 	/* GDT. */
 	.p2align 4
Signature · 1 line
Colin Watson                                       [[email protected]]