From: Vivek Goyal <vgoyal@in.ibm.com>
To: Pavel Machek <pavel@ucw.cz>
Cc: linux kernel mailing list <linux-kernel@vger.kernel.org>,
Reloc Kernel List <fastboot@lists.osdl.org>,
ebiederm@xmission.com, akpm@osdl.org, ak@suse.de, hpa@zytor.com,
magnus.damm@gmail.com, lwang@redhat.com, dzickus@redhat.com,
rjw@sisk.pl
Subject: Re: [PATCH 12/20] x86_64: wakeup.S Misc cleanup
Date: Fri, 17 Nov 2006 20:25:15 -0500 [thread overview]
Message-ID: <20061118012515.GC4321@in.ibm.com> (raw)
In-Reply-To: <20061118001907.GD9188@elf.ucw.cz>
On Sat, Nov 18, 2006 at 01:19:07AM +0100, Pavel Machek wrote:
> Hi!
>
> > 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>
>
> ACK, minor nitpicks:
>
> > + /* ??? Why I need the accessed bit set in order for this to work? */
>
> Yes, I'd like to know :-).
>
I don't know. :-( May be it is present because in original code also
it is present. I just changed it from 9b00 to 9a00 for __KERNEL32_CS
and __KERNEL_CS to mark the entry unaccessed and it works fine for me.
Eric, any thoughts on this. ?
> > + .quad 0x00cf9b000000ffff # __KERNEL32_CS
> > + .quad 0x00af9b000000ffff # __KERNEL_CS
> > + .quad 0x00cf93000000ffff # __KERNEL_DS
>
> Can we get a comment telling us what to keep it in sync with?
>
Ok. Just added a line mentioning that keep it in sync with trampoline.S
Please find attached the revised patch.
Thanks
Vivek
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: 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.19-rc5-git2-reloc/arch/x86_64/kernel/acpi/wakeup.S~x86_64-wakeup.S-misc-cleanups 2006-11-17 00:29:30.000000000 -0500
+++ linux-2.6.19-rc5-git2-reloc-root/arch/x86_64/kernel/acpi/wakeup.S 2006-11-17 10:01:10.000000000 -0500
@@ -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:
+ /* Good to keep gdt in sync with the 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:
_
next prev parent reply other threads:[~2006-11-18 1:25 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-17 22:34 [RFC][PATCH 0/20] x86_64: Relocatable bzImage (V3) Vivek Goyal
2006-11-17 22:36 ` [PATCH 1/20] x86_64: Align data segment to PAGE_SIZE boundary Vivek Goyal
2006-11-17 22:37 ` [PATCH 2/20] x86_64: Assembly safe page.h and pgtable.h Vivek Goyal
2006-11-18 8:49 ` Andi Kleen
2006-11-18 13:19 ` Vivek Goyal
2006-11-17 22:38 ` [PATCH 3/20] x86_64: Kill temp_boot_pmds Vivek Goyal
2006-11-17 22:39 ` [PATCH 4/20] x86_64: Cleanup the early boot page table Vivek Goyal
2006-11-17 22:40 ` [PATCH 5/20] x86_64: Fix early printk to use standard ISA mapping Vivek Goyal
2006-11-17 22:41 ` [PATCH 6/20] x86_64: Modify copy bootdata to use virtual addresses Vivek Goyal
2006-11-17 22:42 ` [PATCH 7/20] x86_64: cleanup segments Vivek Goyal
2006-11-17 22:44 ` [PATCH 8/20] x86_64: Add EFER to the set registers saved by save_processor_state Vivek Goyal
2006-11-18 0:11 ` Pavel Machek
2006-11-17 22:45 ` [PATCH 9/20] x86_64: 64bit PIC SMP trampoline Vivek Goyal
2006-11-18 0:27 ` Pavel Machek
2006-11-18 0:33 ` Vivek Goyal
2006-11-18 0:38 ` Pavel Machek
2006-11-17 22:47 ` [PATCH 10/20] x86_64: wakeup.S Remove dead code Vivek Goyal
2006-11-18 0:14 ` Pavel Machek
2006-11-17 22:48 ` [PATCH 11/20] x86_64: wakeup.S Rename labels to reflect right register names Vivek Goyal
2006-11-18 0:15 ` Pavel Machek
2006-11-17 22:49 ` [PATCH 12/20] x86_64: wakeup.S Misc cleanup Vivek Goyal
2006-11-18 0:19 ` Pavel Machek
2006-11-18 1:25 ` Vivek Goyal [this message]
2006-11-17 22:51 ` [PATCH 13/20] x86_64: 64bit PIC ACPI wakeup trampoline Vivek Goyal
2006-11-18 0:20 ` Pavel Machek
2006-11-17 22:52 ` [PATCH 14/20] x86_64: Modify discover_ebda to use virtual address Vivek Goyal
2006-11-17 22:54 ` [PATCH 15/20] x86_64: Remove the identity mapping as early as possible Vivek Goyal
2006-11-17 22:55 ` [PATCH 16/20] x86_64: __pa and __pa_symbol address space separation Vivek Goyal
2006-11-17 22:56 ` [PATCH 17/20] x86_64: Remove CONFIG_PHYSICAL_START Vivek Goyal
2006-11-18 1:14 ` Magnus Damm
2006-11-18 2:45 ` Vivek Goyal
2006-11-20 10:02 ` Magnus Damm
2006-11-17 22:57 ` [PATCH 18/20] x86_64: Relocatable kernel support Vivek Goyal
2006-11-18 5:49 ` Oleg Verych
2006-11-18 6:49 ` Andi Kleen
2006-11-17 22:58 ` [PATCH 19/20] x86_64: Extend bzImage protocol for relocatable kernel Vivek Goyal
2006-11-18 0:30 ` H. Peter Anvin
2006-11-18 0:37 ` Vivek Goyal
2006-11-18 0:45 ` H. Peter Anvin
2006-11-18 1:47 ` Vivek Goyal
2006-11-17 22:59 ` [PATCH 20/20] x86_64: Move CPU verification code to common file Vivek Goyal
2006-11-18 5:21 ` Oleg Verych
2006-11-18 6:38 ` Andi Kleen
2006-11-18 6:41 ` H. Peter Anvin
[not found] ` <20061118070101.GA14673@flower.upol.cz>
2006-11-18 6:59 ` H. Peter Anvin
2006-11-18 7:22 ` Oleg Verych
2006-11-18 7:32 ` H. Peter Anvin
2006-11-18 8:10 ` reboot, not loop forever (Re: [PATCH 20/20] x86_64: Move CPU verification code to common file) Oleg Verych
2006-11-18 8:06 ` [PATCH 20/20] x86_64: Move CPU verification code to common file Andi Kleen
2006-11-18 8:16 ` H. Peter Anvin
2006-11-18 8:29 ` Andi Kleen
2006-11-18 10:55 ` Paul Mackerras
2006-11-18 10:58 ` Andi Kleen
2006-11-18 12:59 ` Vivek Goyal
2006-11-18 17:46 ` Pavel Machek
2006-11-18 8:52 ` [RFC][PATCH 0/20] x86_64: Relocatable bzImage (V3) Andi Kleen
2006-11-18 13:14 ` Vivek Goyal
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=20061118012515.GC4321@in.ibm.com \
--to=vgoyal@in.ibm.com \
--cc=ak@suse.de \
--cc=akpm@osdl.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@ucw.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
Powered by JetHome