Skip to content

Commit

Permalink
x86: use descriptor's functions instead of inline assembly
Browse files Browse the repository at this point in the history
This patch provides a new set of functions for managing the descriptor
tables that can be used instead of putting the raw assembly in .c files.

Remodeling of store_tr() suggested by Frederik Deweerdt.

[ tglx: arch/x86 adaptation ]

Signed-off-by: Glauber de Oliveira Costa <gcosta@redhat.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Glauber de Oliveira Costa authored and Thomas Gleixner committed Oct 19, 2007
1 parent 9d975eb commit 9d1c6e7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion arch/x86/kernel/head64.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void __init x86_64_start_kernel(char * real_mode_data)

for (i = 0; i < IDT_ENTRIES; i++)
set_intr_gate(i, early_idt_handler);
asm volatile("lidt %0" :: "m" (idt_descr));
load_idt((const struct desc_ptr *)&idt_descr);

early_printk("Kernel alive\n");

Expand Down
3 changes: 2 additions & 1 deletion arch/x86/kernel/reboot_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <linux/sched.h>
#include <asm/io.h>
#include <asm/delay.h>
#include <asm/desc.h>
#include <asm/hw_irq.h>
#include <asm/system.h>
#include <asm/pgtable.h>
Expand Down Expand Up @@ -136,7 +137,7 @@ void machine_emergency_restart(void)
}

case BOOT_TRIPLE:
__asm__ __volatile__("lidt (%0)": :"r" (&no_idt));
load_idt((const struct desc_ptr *)&no_idt);
__asm__ __volatile__("int3");

reboot_type = BOOT_KBD;
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/setup64.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ void __cpuinit cpu_init (void)
memcpy(cpu_gdt(cpu), cpu_gdt_table, GDT_SIZE);

cpu_gdt_descr[cpu].size = GDT_SIZE;
asm volatile("lgdt %0" :: "m" (cpu_gdt_descr[cpu]));
asm volatile("lidt %0" :: "m" (idt_descr));
load_gdt((const struct desc_ptr *)&cpu_gdt_descr[cpu]);
load_idt((const struct desc_ptr *)&idt_descr);

memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
syscall_init();
Expand Down
11 changes: 6 additions & 5 deletions arch/x86/kernel/suspend_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ void __save_processor_state(struct saved_context *ctxt)
/*
* descriptor tables
*/
asm volatile ("sgdt %0" : "=m" (ctxt->gdt_limit));
asm volatile ("sidt %0" : "=m" (ctxt->idt_limit));
asm volatile ("str %0" : "=m" (ctxt->tr));
store_gdt((struct desc_ptr *)&ctxt->gdt_limit);
store_idt((struct desc_ptr *)&ctxt->idt_limit);
store_tr(ctxt->tr);

/* XMM0..XMM15 should be handled by kernel_fpu_begin(). */
/*
Expand Down Expand Up @@ -91,8 +91,9 @@ void __restore_processor_state(struct saved_context *ctxt)
* now restore the descriptor tables to their proper values
* ltr is done i fix_processor_context().
*/
asm volatile ("lgdt %0" :: "m" (ctxt->gdt_limit));
asm volatile ("lidt %0" :: "m" (ctxt->idt_limit));
load_gdt((const struct desc_ptr *)&ctxt->gdt_limit);
load_idt((const struct desc_ptr *)&ctxt->idt_limit);


/*
* segment registers
Expand Down
30 changes: 30 additions & 0 deletions include/asm-x86/desc_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ extern struct desc_struct cpu_gdt_table[GDT_ENTRIES];
#define load_LDT_desc() asm volatile("lldt %w0"::"r" (GDT_ENTRY_LDT*8))
#define clear_LDT() asm volatile("lldt %w0"::"r" (0))

static inline unsigned long __store_tr(void)
{
unsigned long tr;

asm volatile ("str %w0":"=r" (tr));
return tr;
}

#define store_tr(tr) (tr) = __store_tr()

/*
* This is the ldt that every process will get unless we need
* something other than this.
Expand All @@ -31,6 +41,16 @@ extern struct desc_ptr cpu_gdt_descr[];
/* the cpu gdt accessor */
#define cpu_gdt(_cpu) ((struct desc_struct *)cpu_gdt_descr[_cpu].address)

static inline void load_gdt(const struct desc_ptr *ptr)
{
asm volatile("lgdt %w0"::"m" (*ptr));
}

static inline void store_gdt(struct desc_ptr *ptr)
{
asm("sgdt %w0":"=m" (*ptr));
}

static inline void _set_gate(void *adr, unsigned type, unsigned long func, unsigned dpl, unsigned ist)
{
struct gate_struct s;
Expand Down Expand Up @@ -71,6 +91,16 @@ static inline void set_system_gate_ist(int nr, void *func, unsigned ist)
_set_gate(&idt_table[nr], GATE_INTERRUPT, (unsigned long) func, 3, ist);
}

static inline void load_idt(const struct desc_ptr *ptr)
{
asm volatile("lidt %w0"::"m" (*ptr));
}

static inline void store_idt(struct desc_ptr *dtr)
{
asm("sidt %w0":"=m" (*dtr));
}

static inline void set_tssldt_descriptor(void *ptr, unsigned long tss, unsigned type,
unsigned size)
{
Expand Down

0 comments on commit 9d1c6e7

Please sign in to comment.