Re: [GIT PULL] x86 setup: correct booting on 486 (revised)

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linus Torvalds
Date: Monday, November 5, 2007 - 10:15 am

On Sun, 4 Nov 2007, H. Peter Anvin wrote:

Ok, I'm obviously happier, but I have to admit that the original code was 
safer than the new code. It did both the short jump and the far jump 
before reloading any segments.

So I suspect the new code _works_ fine, but it's simply not as 
fundamentally safe as the old code was.

The old code did do some instructions in between the short jump and the 
far jump, but they were all the kind of instructions that didn't care 
about the PE bit: there was a _read_ of the segment descriptor value, but 
that's mode-independent (it's only the writes that matter), and the other 
instructions were bog-standard integer instructions.

So I would actually prefer some additional safety, with something like 
the appended..

This is TOTALLY UNTESTED! I checked with objdump that the result looks 
roughly ok, but I didn't really think through the segment base address in 
that long jump thing. Do we have the difference between flat mode and the 
16-bit bootup mode in some better way?

Hmm?

		Linus

--
 arch/x86/boot/pmjump.S |   25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/arch/x86/boot/pmjump.S b/arch/x86/boot/pmjump.S
index fa6bed1..587dc04 100644
--- a/arch/x86/boot/pmjump.S
+++ b/arch/x86/boot/pmjump.S
@@ -29,7 +29,11 @@
  */
 protected_mode_jump:
 	movl	%edx, %esi		# Pointer to boot_params table
-	movl	%eax, 2f		# Patch ljmpl instruction
+
+	xorl    %ecx, %ecx		# add data segment offset to
+	movw	%ds, %cx		# the "in_32_bit_mode" thing.
+	shll	$4, %ecx
+	addl 	%ecx, 2f
 
 	movw	$__BOOT_DS, %cx
 	xorl	%ebx, %ebx		# Per the 32-bit boot protocol
@@ -42,15 +46,20 @@ protected_mode_jump:
 	jmp	1f			# Short jump to serialize on 386/486
 1:
 
-	movw	%cx, %ds
-	movw	%cx, %es
-	movw	%cx, %fs
-	movw	%cx, %gs
-	movw	%cx, %ss
-
 	# Jump to the 32-bit entrypoint
 	.byte	0x66, 0xea		# ljmpl opcode
-2:	.long	0			# offset
+2:	.long	in_32_bit_mode		# offset
 	.word	__BOOT_CS		# segment
 
 	.size	protected_mode_jump, .-protected_mode_jump
+
+	.code32
+	.align 4
+in_32_bit_mode:
+	mov	%cx, %ds
+	mov	%cx, %es
+	mov	%cx, %fs
+	mov	%cx, %gs
+	mov	%cx, %ss
+	jmp	*%eax	
+	.size   in_32_bit_mode, .-in_32_bit_mode
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[GIT PULL] x86 setup: correct booting on 486 (revised), H. Peter Anvin, (Sun Nov 4, 7:16 pm)
[GIT PULL] x86 setup: correct booting on 486 (revised), H. Peter Anvin, (Sun Nov 4, 8:58 pm)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Linus Torvalds, (Mon Nov 5, 10:15 am)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), H. Peter Anvin, (Mon Nov 5, 10:56 am)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Linus Torvalds, (Mon Nov 5, 11:12 am)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), H. Peter Anvin, (Mon Nov 5, 11:32 am)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Linus Torvalds, (Mon Nov 5, 11:36 am)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Eric W. Biederman, (Mon Nov 5, 1:21 pm)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Jeremy Fitzhardinge, (Mon Nov 5, 1:51 pm)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Eric W. Biederman, (Mon Nov 5, 2:14 pm)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Eric W. Biederman, (Mon Nov 5, 2:58 pm)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Jeremy Fitzhardinge, (Mon Nov 5, 5:59 pm)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Jeremy Fitzhardinge, (Mon Nov 5, 6:18 pm)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Jeremy Fitzhardinge, (Tue Nov 6, 9:17 am)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Jeremy Fitzhardinge, (Tue Nov 6, 9:55 am)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), H. Peter Anvin, (Tue Nov 6, 10:00 am)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Eric W. Biederman, (Tue Nov 6, 10:04 am)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Eric W. Biederman, (Tue Nov 6, 10:09 am)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), H. Peter Anvin, (Tue Nov 6, 10:57 am)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), Eric W. Biederman, (Tue Nov 6, 11:27 am)
Re: [GIT PULL] x86 setup: correct booting on 486 (revised), H. Peter Anvin, (Tue Nov 6, 11:41 am)