[PATCH 11/14] x86, boot: use rep movsq to move kernel on 64 bits

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: H. Peter Anvin <hpa@xxxxxxxxx>

rep movsq is the architecturally preferred way to move a block of
data.  It isn't the fastest way on all existing CPUs, but it it likely
to be in the future, and perhaps more importantly, we should encourage
the architecturally right thing to do.

This means saving and restoring %rsi around the copy code, which is
easily done by setting up the stack early.  However, we should not
copy .bss (which we are about to zero anyway); we should only copy up
to the *beginning* of .bss (just as on 32 bits.)

This also makes the code quite a bit more similar between 32 and 64 bits.

[ Impact: trivial optimization ]

Signed-off-by: H. Peter Anvin <hpa at zytor.com>
---
 arch/x86/boot/compressed/head_64.S |   41 ++++++++++++++++++++---------------
 1 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index 2678fdf..8bc8ed8 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -220,18 +220,30 @@ ENTRY(startup_64)
 #endif
 	leaq	z_extract_offset(%rbp), %rbx
 
-/* Copy the compressed kernel to the end of our buffer
+/*
+ * Set up the stack
+ */
+	leaq boot_stack_end(%rbx), %rsp
+
+/*
+ * Zero EFLAGS after setting rsp
+ */
+	pushq	$0
+	popfq
+
+/*
+ * Copy the compressed kernel to the end of our buffer
  * where decompression in place becomes safe.
  */
-	leaq	_end_before_pgt(%rip), %r8
-	leaq	_end_before_pgt(%rbx), %r9
-	movq	$_end_before_pgt /* - $startup_32 */, %rcx
-1:	subq	$8, %r8
-	subq	$8, %r9
-	movq	0(%r8), %rax
-	movq	%rax, 0(%r9)
-	subq	$8, %rcx
-	jnz	1b
+	pushq	%rsi		/* Kernel structure pointer */
+	leaq	(_bss-8)(%rip), %rsi
+	leaq	(_bss-8)(%rbx), %rdi
+	movq	$_bss /* - $startup_32 */, %rcx
+	shrq	$3, %rcx
+	std
+	rep	movsq
+	cld
+	popq	%rsi
 
 /*
  * Jump to the relocated address.
@@ -243,7 +255,7 @@ ENTRY(startup_64)
 relocated:
 
 /*
- * Clear BSS
+ * Clear BSS (stack is empty at this point)
  */
 	xorl	%eax, %eax
 	leaq    _edata(%rip), %rdi
@@ -253,13 +265,6 @@ relocated:
 	cld
 	rep	stosq
 
-	/* Setup the stack */
-	leaq	boot_stack_end(%rip), %rsp
-
-	/* zero EFLAGS after setting rsp */
-	pushq	$0
-	popfq
-
 /*
  * Do the decompression, and jump to the new kernel..
  */
-- 
1.6.0.6




[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux