linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal@in.ibm.com>
To: linux kernel mailing list <linux-kernel@vger.kernel.org>
Cc: Reloc Kernel List <fastboot@lists.osdl.org>,
	ebiederm@xmission.com, akpm@linux-foundation.org, ak@suse.de,
	hpa@zytor.com, magnus.damm@gmail.com, lwang@redhat.com,
	dzickus@redhat.com, pavel@suse.cz, rjw@sisk.pl
Subject: [PATCH 11/20] x86_64: wakeup.S misc cleanups
Date: Wed, 7 Mar 2007 12:43:20 +0530	[thread overview]
Message-ID: <20070307071320.GL23412@in.ibm.com> (raw)
In-Reply-To: <20070307065703.GA23412@in.ibm.com>



o Various cleanups. One of the main purpose of cleanups is that make
  wakeup.S as close as possible to trampoline.S.

o Following are the changes
	- Indentations for comments.
	- Changed the gdt table to compact form and to resemble the
	  one in trampoline.S
	- Take the jump to 32bit from real mode using ljmpl. Makes code
	  more readable.
	- After enabling long mode, directly take a long jump for 64bit
	  mode. No need to take an extra jump to "reach_comaptibility_mode"
	- Stack is not used after real mode. So don't load stack in
 	  32 bit mode.
	- No need to enable PGE here.
	- No need to do extra EFER read, anyway we trash the read contents.
	- No need to enable system call (EFER_SCE). Anyway it will be 
	  enabled when original EFER is restored.
	- No need to set MP, ET, NE, WP, AM bits in cr0. Very soon we will
  	  reload the original cr0 while restroing the processor state.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Vivek Goyal <vgoyal@in.ibm.com>
---

 arch/x86_64/kernel/acpi/wakeup.S |  112 +++++++++++++--------------------------
 1 file changed, 40 insertions(+), 72 deletions(-)

diff -puN arch/x86_64/kernel/acpi/wakeup.S~x86_64-wakeup.S-misc-cleanups arch/x86_64/kernel/acpi/wakeup.S
--- linux-2.6.21-rc2-reloc/arch/x86_64/kernel/acpi/wakeup.S~x86_64-wakeup.S-misc-cleanups	2007-03-07 01:27:32.000000000 +0530
+++ linux-2.6.21-rc2-reloc-root/arch/x86_64/kernel/acpi/wakeup.S	2007-03-07 01:27:32.000000000 +0530
@@ -30,11 +30,12 @@ wakeup_code:
 	cld
 	# setup data segment
 	movw	%cs, %ax
-	movw	%ax, %ds					# Make ds:0 point to wakeup_start
+	movw	%ax, %ds		# Make ds:0 point to wakeup_start
 	movw	%ax, %ss
-	mov	$(wakeup_stack - wakeup_code), %sp		# Private stack is needed for ASUS board
+					# Private stack is needed for ASUS board
+	mov	$(wakeup_stack - wakeup_code), %sp
 
-	pushl	$0						# Kill any dangerous flags
+	pushl	$0			# Kill any dangerous flags
 	popfl
 
 	movl	real_magic - wakeup_code, %eax
@@ -45,7 +46,7 @@ wakeup_code:
 	jz	1f
 	lcall   $0xc000,$3
 	movw	%cs, %ax
-	movw	%ax, %ds					# Bios might have played with that
+	movw	%ax, %ds		# Bios might have played with that
 	movw	%ax, %ss
 1:
 
@@ -75,9 +76,12 @@ wakeup_code:
 	jmp	1f
 1:
 
-	.byte 0x66, 0xea			# prefix + jmpi-opcode
-	.long	wakeup_32 - __START_KERNEL_map
-	.word	__KERNEL_CS
+	ljmpl   *(wakeup_32_vector - wakeup_code)
+
+	.balign 4
+wakeup_32_vector:
+	.long   wakeup_32 - __START_KERNEL_map
+	.word   __KERNEL32_CS, 0
 
 	.code32
 wakeup_32:
@@ -96,65 +100,50 @@ wakeup_32:
 	jnc	bogus_cpu
 	movl	%edx,%edi
 	
-	movw	$__KERNEL_DS, %ax
-	movw	%ax, %ds
-	movw	%ax, %es
-	movw	%ax, %fs
-	movw	%ax, %gs
+	movl	$__KERNEL_DS, %eax
+	movl	%eax, %ds
 
-	movw	$__KERNEL_DS, %ax	
-	movw	%ax, %ss
-
-	mov	$(wakeup_stack - __START_KERNEL_map), %esp
 	movl	saved_magic - __START_KERNEL_map, %eax
 	cmpl	$0x9abcdef0, %eax
 	jne	bogus_32_magic
 
+	movw	$0x0e00 + 'i', %ds:(0xb8012)
+	movb	$0xa8, %al	;  outb %al, $0x80;
+
 	/*
 	 * Prepare for entering 64bits mode
 	 */
 
-	/* Enable PAE mode and PGE */
+	/* Enable PAE */
 	xorl	%eax, %eax
 	btsl	$5, %eax
-	btsl	$7, %eax
 	movl	%eax, %cr4
 
 	/* Setup early boot stage 4 level pagetables */
 	movl	$(wakeup_level4_pgt - __START_KERNEL_map), %eax
 	movl	%eax, %cr3
 
-	/* Setup EFER (Extended Feature Enable Register) */
-	movl	$MSR_EFER, %ecx
-	rdmsr
-	/* Fool rdmsr and reset %eax to avoid dependences */
-	xorl	%eax, %eax
 	/* Enable Long Mode */
+	xorl    %eax, %eax
 	btsl	$_EFER_LME, %eax
-	/* Enable System Call */
-	btsl	$_EFER_SCE, %eax
 
-	/* No Execute supported? */	
+	/* No Execute supported? */
 	btl	$20,%edi
 	jnc     1f
 	btsl	$_EFER_NX, %eax
-1:	
 				
 	/* Make changes effective */
+1:	movl    $MSR_EFER, %ecx
+	xorl    %edx, %edx
 	wrmsr
-	wbinvd
 
 	xorl	%eax, %eax
 	btsl	$31, %eax			/* Enable paging and in turn activate Long Mode */
 	btsl	$0, %eax			/* Enable protected mode */
-	btsl	$1, %eax			/* Enable MP */
-	btsl	$4, %eax			/* Enable ET */
-	btsl	$5, %eax			/* Enable NE */
-	btsl	$16, %eax			/* Enable WP */
-	btsl	$18, %eax			/* Enable AM */
 
 	/* Make changes effective */
 	movl	%eax, %cr0
+
 	/* At this point:
 		CR4.PAE must be 1
 		CS.L must be 0
@@ -162,11 +151,6 @@ wakeup_32:
 		Next instruction must be a branch
 		This must be on identity-mapped page
 	*/
-	jmp	reach_compatibility_mode
-reach_compatibility_mode:
-	movw	$0x0e00 + 'i', %ds:(0xb8012)
-	movb	$0xa8, %al	;  outb %al, $0x80; 	
-		
 	/*
 	 * At this point we're in long mode but in 32bit compatibility mode
 	 * with EFER.LME = 1, CS.L = 0, CS.D = 1 (and in turn
@@ -174,24 +158,19 @@ reach_compatibility_mode:
 	 * the new gdt/idt that has __KERNEL_CS with CS.L = 1.
 	 */
 
-	movw	$0x0e00 + 'n', %ds:(0xb8014)
-	movb	$0xa9, %al	;  outb %al, $0x80
-	
-	/* Load new GDT with the 64bit segment using 32bit descriptor */
-	movl	$(pGDT32 - __START_KERNEL_map), %eax
-	lgdt	(%eax)
-
-	movl    $(wakeup_jumpvector - __START_KERNEL_map), %eax
 	/* Finally jump in 64bit mode */
-	ljmp	*(%eax)
+	ljmp	*(wakeup_long64_vector - __START_KERNEL_map)
 
-wakeup_jumpvector:
-	.long	wakeup_long64 - __START_KERNEL_map
-	.word	__KERNEL_CS
+	.balign 4
+wakeup_long64_vector:
+	.long   wakeup_long64 - __START_KERNEL_map
+	.word   __KERNEL_CS, 0
 
 .code64
 
-	/*	Hooray, we are in Long 64-bit mode (but still running in low memory) */
+	/* Hooray, we are in Long 64-bit mode (but still running in
+	 * low memory)
+	 */
 wakeup_long64:
 	/*
 	 * We must switch to a new descriptor in kernel space for the GDT
@@ -201,6 +180,9 @@ wakeup_long64:
 	 */
 	lgdt	cpu_gdt_descr - __START_KERNEL_map
 
+	movw	$0x0e00 + 'n', %ds:(0xb8014)
+	movb	$0xa9, %al	;  outb %al, $0x80
+
 	movw	$0x0e00 + 'u', %ds:(0xb8016)
 	
 	nop
@@ -227,33 +209,19 @@ wakeup_long64:
 
 	.align	64	
 gdta:
+	/* Its good to keep gdt in sync with one in trampoline.S */
 	.word	0, 0, 0, 0			# dummy
-
-	.word	0, 0, 0, 0			# unused
-
-	.word	0xFFFF				# 4Gb - (0x100000*0x1000 = 4Gb)
-	.word	0				# base address = 0
-	.word	0x9B00				# code read/exec. ??? Why I need 0x9B00 (as opposed to 0x9A00 in order for this to work?)
-	.word	0x00CF				# granularity = 4096, 386
-						#  (+5th nibble of limit)
-
-	.word	0xFFFF				# 4Gb - (0x100000*0x1000 = 4Gb)
-	.word	0				# base address = 0
-	.word	0x9200				# data read/write
-	.word	0x00CF				# granularity = 4096, 386
-						#  (+5th nibble of limit)
-# this is 64bit descriptor for code
-	.word	0xFFFF
-	.word	0
-	.word	0x9A00				# code read/exec
-	.word	0x00AF				# as above, but it is long mode and with D=0
+	/* ??? Why I need the accessed bit set in order for this to work? */
+	.quad   0x00cf9b000000ffff              # __KERNEL32_CS
+	.quad   0x00af9b000000ffff              # __KERNEL_CS
+	.quad   0x00cf93000000ffff              # __KERNEL_DS
 
 idt_48a:
 	.word	0				# idt limit = 0
 	.word	0, 0				# idt base = 0L
 
 gdt_48a:
-	.word	0x8000				# gdt limit=2048,
+	.word	0x800				# gdt limit=2048,
 						#  256 GDT entries
 	.word	0, 0				# gdt base (filled in later)
 	
@@ -263,7 +231,7 @@ video_mode:	.quad 0
 video_flags:	.quad 0
 
 bogus_real_magic:
-	movb	$0xba,%al	;  outb %al,$0x80		
+	movb	$0xba,%al	;  outb %al,$0x80
 	jmp bogus_real_magic
 
 bogus_32_magic:
_

  parent reply	other threads:[~2007-03-07  7:29 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-07  6:57 [PATCH 0/20] x86_64 Relocatable bzImage support (V4) Vivek Goyal
2007-03-07  6:59 ` [PATCH 1/20] x86_64: Assembly safe page.h and pgtable.h Vivek Goyal
2007-03-07 19:24   ` Sam Ravnborg
2007-03-08  6:01     ` Vivek Goyal
2007-03-08  6:16       ` Eric W. Biederman
2007-03-07  7:00 ` [PATCH 2/20] x86_64: Kill temp boot pmds Vivek Goyal
2007-03-07  7:02 ` [PATCH 3/20] x86_64: Clean up the early boot page table Vivek Goyal
2007-03-07  7:03 ` [PATCH 4/20] x86_64: Fix early printk to use standard ISA mapping Vivek Goyal
2007-03-07  7:04 ` [PATCH 5/20] x86_64: modify copy_bootdata to use virtual addresses Vivek Goyal
2007-03-07  7:06 ` [PATCH 6/20] x86_64: cleanup segments Vivek Goyal
2007-03-07  7:08 ` [PATCH 7/20] x86_64: Add EFER to the register set saved by save_processor_state Vivek Goyal
2007-03-07  7:09 ` [PATCH 8/20] x86_64: 64bit PIC SMP trampoline Vivek Goyal
2007-03-07  7:10 ` [PATCH 9/20] x86_64: Get rid of dead code in suspend resume Vivek Goyal
2007-03-07  7:12 ` [PATCH 10/20] x86_64: wakeup.S rename registers to reflect right names Vivek Goyal
2007-03-07 22:30   ` Pavel Machek
2007-03-07  7:13 ` Vivek Goyal [this message]
2007-03-07 22:40   ` [PATCH 11/20] x86_64: wakeup.S misc cleanups Pavel Machek
2007-03-08  4:25     ` Vivek Goyal
2007-03-07 22:41   ` Pavel Machek
2007-03-08  4:29     ` Vivek Goyal
2007-03-08 11:43       ` Pavel Machek
2007-03-08 16:45         ` [Fastboot] " Lombard, David N
2007-03-07  7:14 ` [PATCH 12/20] x86_64: 64bit ACPI wakeup trampoline Vivek Goyal
2007-03-07 22:45   ` Pavel Machek
2007-03-07 22:57     ` [Fastboot] " Bernhard Walle
2007-03-08  4:58     ` Vivek Goyal
2007-03-08 11:44       ` Pavel Machek
2007-03-07  7:16 ` [PATCH 13/20] x86_64: Modify discover_ebda to use virtual addresses Vivek Goyal
2007-03-07  7:17 ` [PATCH 14/20] x86_64: Remove the identity mapping as early as possible Vivek Goyal
2007-03-07  7:18 ` [PATCH 15/20] Move swsusp __pa() dependent code to arch portion Vivek Goyal
2007-03-07 22:47   ` Pavel Machek
2007-03-08  5:34     ` Vivek Goyal
2007-03-08 11:47       ` Pavel Machek
2007-03-07  7:20 ` [PATCH 16/20] swsusp: do not use virt_to_page on kernel data address Vivek Goyal
2007-03-07 22:49   ` Pavel Machek
2007-03-08  5:17     ` Vivek Goyal
2007-03-08 11:47       ` Pavel Machek
2007-03-07 22:50   ` Pavel Machek
2007-03-07 23:15     ` Nigel Cunningham
2007-03-08  5:04     ` Vivek Goyal
2007-03-08 11:44       ` Pavel Machek
2007-03-07  7:21 ` [PATCH 17/20] x86_64: __pa and __pa_symbol address space separation Vivek Goyal
2007-03-07  7:22 ` [PATCH 18/20] x86_64: Relocatable Kernel Support Vivek Goyal
2007-03-07  7:24 ` [PATCH 19/20] x86_64: Extend bzImage protocol for relocatable bzImage Vivek Goyal
2007-03-07  7:25 ` [PATCH 20/20] x86_64: Move cpu verification code to common file Vivek Goyal
2007-03-07 15:07 ` [PATCH 0/20] x86_64 Relocatable bzImage support (V4) Arjan van de Ven
2007-03-07 19:08   ` Eric W. Biederman
2007-03-07 20:49   ` Nigel Cunningham
2007-03-07 23:15     ` Nigel Cunningham
2007-03-08  4:40       ` Vivek Goyal
2007-03-08  8:07         ` Nigel Cunningham
2007-03-08  8:27           ` Vivek Goyal
2007-03-08  7:48       ` Vivek Goyal
2007-03-08  3:36   ` Vivek Goyal
2007-03-14 23:10 ` Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070307071320.GL23412@in.ibm.com \
    --to=vgoyal@in.ibm.com \
    --cc=ak@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=dzickus@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=fastboot@lists.osdl.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lwang@redhat.com \
    --cc=magnus.damm@gmail.com \
    --cc=pavel@suse.cz \
    --cc=rjw@sisk.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).