aboutsummaryrefslogtreecommitdiffstats
path: root/arch/i386/kernel/head.S
diff options
context:
space:
mode:
authorJeremy Fitzhardinge <jeremy@goop.org>2006-12-06 20:14:02 -0500
committerAndi Kleen <andi@basil.nowhere.org>2006-12-06 20:14:02 -0500
commitf95d47caae5302a63d92be9a0292abc90e2a14e1 (patch)
treecfa963975d104c56aba28df6c941759175ed4b98 /arch/i386/kernel/head.S
parent62111195800d80c66cdc69063ea3145878c99fbf (diff)
[PATCH] i386: Use %gs as the PDA base-segment in the kernel
This patch is the meat of the PDA change. This patch makes several related changes: 1: Most significantly, %gs is now used in the kernel. This means that on entry, the old value of %gs is saved away, and it is reloaded with __KERNEL_PDA. 2: entry.S constructs the stack in the shape of struct pt_regs, and this is passed around the kernel so that the process's saved register state can be accessed. Unfortunately struct pt_regs doesn't currently have space for %gs (or %fs). This patch extends pt_regs to add space for gs (no space is allocated for %fs, since it won't be used, and it would just complicate the code in entry.S to work around the space). 3: Because %gs is now saved on the stack like %ds, %es and the integer registers, there are a number of places where it no longer needs to be handled specially; namely context switch, and saving/restoring the register state in a signal context. 4: And since kernel threads run in kernel space and call normal kernel code, they need to be created with their %gs == __KERNEL_PDA. Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com> Signed-off-by: Andi Kleen <ak@suse.de> Cc: Chuck Ebbert <76306.1226@compuserve.com> Cc: Zachary Amsden <zach@vmware.com> Cc: Jan Beulich <jbeulich@novell.com> Cc: Andi Kleen <ak@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org>
Diffstat (limited to 'arch/i386/kernel/head.S')
-rw-r--r--arch/i386/kernel/head.S31
1 files changed, 27 insertions, 4 deletions
diff --git a/arch/i386/kernel/head.S b/arch/i386/kernel/head.S
index 4a83384c5a6..5b14e95ac8b 100644
--- a/arch/i386/kernel/head.S
+++ b/arch/i386/kernel/head.S
@@ -302,6 +302,7 @@ is386: movl $2,%ecx # set MP
302 movl %eax,%cr0 302 movl %eax,%cr0
303 303
304 call check_x87 304 call check_x87
305 call setup_pda
305 lgdt cpu_gdt_descr 306 lgdt cpu_gdt_descr
306 lidt idt_descr 307 lidt idt_descr
307 ljmp $(__KERNEL_CS),$1f 308 ljmp $(__KERNEL_CS),$1f
@@ -312,10 +313,13 @@ is386: movl $2,%ecx # set MP
312 movl %eax,%ds 313 movl %eax,%ds
313 movl %eax,%es 314 movl %eax,%es
314 315
315 xorl %eax,%eax # Clear FS/GS and LDT 316 xorl %eax,%eax # Clear FS and LDT
316 movl %eax,%fs 317 movl %eax,%fs
317 movl %eax,%gs
318 lldt %ax 318 lldt %ax
319
320 movl $(__KERNEL_PDA),%eax
321 mov %eax,%gs
322
319 cld # gcc2 wants the direction flag cleared at all times 323 cld # gcc2 wants the direction flag cleared at all times
320 pushl $0 # fake return address for unwinder 324 pushl $0 # fake return address for unwinder
321#ifdef CONFIG_SMP 325#ifdef CONFIG_SMP
@@ -346,6 +350,23 @@ check_x87:
346 ret 350 ret
347 351
348/* 352/*
353 * Point the GDT at this CPU's PDA. On boot this will be
354 * cpu_gdt_table and boot_pda; for secondary CPUs, these will be
355 * that CPU's GDT and PDA.
356 */
357setup_pda:
358 /* get the PDA pointer */
359 movl start_pda, %eax
360
361 /* slot the PDA address into the GDT */
362 mov cpu_gdt_descr+2, %ecx
363 mov %ax, (__KERNEL_PDA+0+2)(%ecx) /* base & 0x0000ffff */
364 shr $16, %eax
365 mov %al, (__KERNEL_PDA+4+0)(%ecx) /* base & 0x00ff0000 */
366 mov %ah, (__KERNEL_PDA+4+3)(%ecx) /* base & 0xff000000 */
367 ret
368
369/*
349 * setup_idt 370 * setup_idt
350 * 371 *
351 * sets up a idt with 256 entries pointing to 372 * sets up a idt with 256 entries pointing to
@@ -484,6 +505,8 @@ ENTRY(empty_zero_page)
484 * This starts the data section. 505 * This starts the data section.
485 */ 506 */
486.data 507.data
508ENTRY(start_pda)
509 .long boot_pda
487 510
488ENTRY(stack_start) 511ENTRY(stack_start)
489 .long init_thread_union+THREAD_SIZE 512 .long init_thread_union+THREAD_SIZE
@@ -525,7 +548,7 @@ idt_descr:
525 548
526# boot GDT descriptor (later on used by CPU#0): 549# boot GDT descriptor (later on used by CPU#0):
527 .word 0 # 32 bit align gdt_desc.address 550 .word 0 # 32 bit align gdt_desc.address
528cpu_gdt_descr: 551ENTRY(cpu_gdt_descr)
529 .word GDT_ENTRIES*8-1 552 .word GDT_ENTRIES*8-1
530 .long cpu_gdt_table 553 .long cpu_gdt_table
531 554
@@ -585,7 +608,7 @@ ENTRY(cpu_gdt_table)
585 .quad 0x004092000000ffff /* 0xc8 APM DS data */ 608 .quad 0x004092000000ffff /* 0xc8 APM DS data */
586 609
587 .quad 0x00c0920000000000 /* 0xd0 - ESPFIX SS */ 610 .quad 0x00c0920000000000 /* 0xd0 - ESPFIX SS */
588 .quad 0x0000000000000000 /* 0xd8 - PDA */ 611 .quad 0x00cf92000000ffff /* 0xd8 - PDA */
589 .quad 0x0000000000000000 /* 0xe0 - unused */ 612 .quad 0x0000000000000000 /* 0xe0 - unused */
590 .quad 0x0000000000000000 /* 0xe8 - unused */ 613 .quad 0x0000000000000000 /* 0xe8 - unused */
591 .quad 0x0000000000000000 /* 0xf0 - unused */ 614 .quad 0x0000000000000000 /* 0xf0 - unused */