Skip to content

Commit

Permalink
x86: use generic register name in the thread and tss structures
Browse files Browse the repository at this point in the history
This changes size-specific register names (eip/rip, esp/rsp, etc.) to
generic names in the thread and tss structures.

Signed-off-by: H. Peter Anvin <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
  • Loading branch information
H. Peter Anvin authored and Ingo Molnar committed Jan 30, 2008
1 parent 25149b6 commit faca622
Show file tree
Hide file tree
Showing 23 changed files with 99 additions and 101 deletions.
4 changes: 2 additions & 2 deletions arch/x86/kernel/asm-offsets_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ void foo(void)
OFFSET(pbe_orig_address, pbe, orig_address);
OFFSET(pbe_next, pbe, next);

/* Offset from the sysenter stack to tss.esp0 */
DEFINE(TSS_sysenter_esp0, offsetof(struct tss_struct, x86_tss.esp0) -
/* Offset from the sysenter stack to tss.sp0 */
DEFINE(TSS_sysenter_sp0, offsetof(struct tss_struct, x86_tss.sp0) -
sizeof(struct tss_struct));

DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ void __cpuinit cpu_init(void)
BUG();
enter_lazy_tlb(&init_mm, curr);

load_esp0(t, thread);
load_sp0(t, thread);
set_tss_desc(cpu,t);
load_TR_desc();
load_LDT(&init_mm.context);
Expand Down
15 changes: 8 additions & 7 deletions arch/x86/kernel/doublefault_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ static void doublefault_fn(void)
if (ptr_ok(tss)) {
struct i386_hw_tss *t = (struct i386_hw_tss *)tss;

printk(KERN_EMERG "eip = %08lx, esp = %08lx\n", t->eip, t->esp);
printk(KERN_EMERG "eip = %08lx, esp = %08lx\n",
t->ip, t->sp);

printk(KERN_EMERG "eax = %08lx, ebx = %08lx, ecx = %08lx, edx = %08lx\n",
t->eax, t->ebx, t->ecx, t->edx);
t->ax, t->bx, t->cx, t->dx);
printk(KERN_EMERG "esi = %08lx, edi = %08lx\n",
t->esi, t->edi);
t->si, t->di);
}
}

Expand All @@ -50,15 +51,15 @@ static void doublefault_fn(void)

struct tss_struct doublefault_tss __cacheline_aligned = {
.x86_tss = {
.esp0 = STACK_START,
.sp0 = STACK_START,
.ss0 = __KERNEL_DS,
.ldt = 0,
.io_bitmap_base = INVALID_IO_BITMAP_OFFSET,

.eip = (unsigned long) doublefault_fn,
.ip = (unsigned long) doublefault_fn,
/* 0x2 bit is always set */
.eflags = X86_EFLAGS_SF | 0x2,
.esp = STACK_START,
.flags = X86_EFLAGS_SF | 0x2,
.sp = STACK_START,
.es = __USER_DS,
.cs = __KERNEL_CS,
.ss = __KERNEL_DS,
Expand Down
6 changes: 3 additions & 3 deletions arch/x86/kernel/entry_32.S
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ ENTRY(ia32_sysenter_target)
CFI_SIGNAL_FRAME
CFI_DEF_CFA esp, 0
CFI_REGISTER esp, ebp
movl TSS_sysenter_esp0(%esp),%esp
movl TSS_sysenter_sp0(%esp),%esp
sysenter_past_esp:
/*
* No need to follow this irqs on/off section: the syscall
Expand Down Expand Up @@ -743,7 +743,7 @@ END(device_not_available)
* that sets up the real kernel stack. Check here, since we can't
* allow the wrong stack to be used.
*
* "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
* "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
* already pushed 3 words if it hits on the sysenter instruction:
* eflags, cs and eip.
*
Expand All @@ -755,7 +755,7 @@ END(device_not_available)
cmpw $__KERNEL_CS,4(%esp); \
jne ok; \
label: \
movl TSS_sysenter_esp0+offset(%esp),%esp; \
movl TSS_sysenter_sp0+offset(%esp),%esp; \
CFI_DEF_CFA esp, 0; \
CFI_UNDEFINED eip; \
pushfl; \
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/paravirt_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ struct pv_cpu_ops pv_cpu_ops = {
.write_ldt_entry = write_dt_entry,
.write_gdt_entry = write_dt_entry,
.write_idt_entry = write_dt_entry,
.load_esp0 = native_load_esp0,
.load_sp0 = native_load_sp0,

.irq_enable_syscall_ret = native_irq_enable_syscall_ret,
.iret = native_iret,
Expand Down
12 changes: 6 additions & 6 deletions arch/x86/kernel/process_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ EXPORT_PER_CPU_SYMBOL(cpu_number);
*/
unsigned long thread_saved_pc(struct task_struct *tsk)
{
return ((unsigned long *)tsk->thread.esp)[3];
return ((unsigned long *)tsk->thread.sp)[3];
}

/*
Expand Down Expand Up @@ -488,10 +488,10 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
childregs->ax = 0;
childregs->sp = sp;

p->thread.esp = (unsigned long) childregs;
p->thread.esp0 = (unsigned long) (childregs+1);
p->thread.sp = (unsigned long) childregs;
p->thread.sp0 = (unsigned long) (childregs+1);

p->thread.eip = (unsigned long) ret_from_fork;
p->thread.ip = (unsigned long) ret_from_fork;

savesegment(gs,p->thread.gs);

Expand Down Expand Up @@ -718,7 +718,7 @@ struct task_struct fastcall * __switch_to(struct task_struct *prev_p, struct tas
/*
* Reload esp0.
*/
load_esp0(tss, next);
load_sp0(tss, next);

/*
* Save away %gs. No need to save %fs, as it was saved on the
Expand Down Expand Up @@ -851,7 +851,7 @@ unsigned long get_wchan(struct task_struct *p)
if (!p || p == current || p->state == TASK_RUNNING)
return 0;
stack_page = (unsigned long)task_stack_page(p);
sp = p->thread.esp;
sp = p->thread.sp;
if (!stack_page || sp < stack_page || sp > top_esp+stack_page)
return 0;
/* include/asm-i386/system.h:switch_to() pushes bp last. */
Expand Down
16 changes: 8 additions & 8 deletions arch/x86/kernel/process_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
if (sp == ~0UL)
childregs->sp = (unsigned long)childregs;

p->thread.rsp = (unsigned long) childregs;
p->thread.rsp0 = (unsigned long) (childregs+1);
p->thread.userrsp = me->thread.userrsp;
p->thread.sp = (unsigned long) childregs;
p->thread.sp0 = (unsigned long) (childregs+1);
p->thread.usersp = me->thread.usersp;

set_tsk_thread_flag(p, TIF_FORK);

Expand Down Expand Up @@ -607,7 +607,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
/*
* Reload esp0, LDT and the page table pointer:
*/
tss->rsp0 = next->rsp0;
tss->sp0 = next->sp0;

/*
* Switch DS and ES.
Expand Down Expand Up @@ -666,8 +666,8 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
/*
* Switch the PDA and FPU contexts.
*/
prev->userrsp = read_pda(oldrsp);
write_pda(oldrsp, next->userrsp);
prev->usersp = read_pda(oldrsp);
write_pda(oldrsp, next->usersp);
write_pda(pcurrent, next_p);

write_pda(kernelstack,
Expand Down Expand Up @@ -769,9 +769,9 @@ unsigned long get_wchan(struct task_struct *p)
if (!p || p == current || p->state==TASK_RUNNING)
return 0;
stack = (unsigned long)task_stack_page(p);
if (p->thread.rsp < stack || p->thread.rsp > stack+THREAD_SIZE)
if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE)
return 0;
fp = *(u64 *)(p->thread.rsp);
fp = *(u64 *)(p->thread.sp);
do {
if (fp < (unsigned long)stack ||
fp > (unsigned long)stack+THREAD_SIZE)
Expand Down
8 changes: 4 additions & 4 deletions arch/x86/kernel/smpboot_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void __devinit initialize_secondary(void)
"movl %0,%%esp\n\t"
"jmp *%1"
:
:"m" (current->thread.esp),"m" (current->thread.eip));
:"m" (current->thread.sp),"m" (current->thread.ip));
}

/* Static state in head.S used to set up a CPU */
Expand Down Expand Up @@ -753,7 +753,7 @@ static inline struct task_struct * __cpuinit alloc_idle_task(int cpu)
/* initialize thread_struct. we really want to avoid destroy
* idle tread
*/
idle->thread.esp = (unsigned long)task_pt_regs(idle);
idle->thread.sp = (unsigned long)task_pt_regs(idle);
init_idle(idle, cpu);
return idle;
}
Expand Down Expand Up @@ -798,7 +798,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
per_cpu(current_task, cpu) = idle;
early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);

idle->thread.eip = (unsigned long) start_secondary;
idle->thread.ip = (unsigned long) start_secondary;
/* start_eip had better be page-aligned! */
start_eip = setup_trampoline();

Expand All @@ -808,7 +808,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
/* So we see what's up */
printk("Booting processor %d/%d ip %lx\n", cpu, apicid, start_eip);
/* Stack for startup_32 can be just as for start_secondary onwards */
stack_start.sp = (void *) idle->thread.esp;
stack_start.sp = (void *) idle->thread.sp;

irq_ctx_init(cpu);

Expand Down
6 changes: 3 additions & 3 deletions arch/x86/kernel/smpboot_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ static int __cpuinit do_boot_cpu(int cpu, int apicid)
c_idle.idle = get_idle_for_cpu(cpu);

if (c_idle.idle) {
c_idle.idle->thread.rsp = (unsigned long) (((struct pt_regs *)
c_idle.idle->thread.sp = (unsigned long) (((struct pt_regs *)
(THREAD_SIZE + task_stack_page(c_idle.idle))) - 1);
init_idle(c_idle.idle, cpu);
goto do_rest;
Expand Down Expand Up @@ -613,8 +613,8 @@ static int __cpuinit do_boot_cpu(int cpu, int apicid)

start_rip = setup_trampoline();

init_rsp = c_idle.idle->thread.rsp;
per_cpu(init_tss,cpu).rsp0 = init_rsp;
init_rsp = c_idle.idle->thread.sp;
per_cpu(init_tss,cpu).sp0 = init_rsp;
initial_code = start_secondary;
clear_tsk_thread_flag(c_idle.idle, TIF_FORK);

Expand Down
6 changes: 3 additions & 3 deletions arch/x86/kernel/traps_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
unsigned long dummy;
stack = &dummy;
if (task != current)
stack = (unsigned long *)task->thread.esp;
stack = (unsigned long *)task->thread.sp;
}

#ifdef CONFIG_FRAME_POINTER
Expand All @@ -173,7 +173,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
asm ("movl %%ebp, %0" : "=r" (bp) : );
} else {
/* bp is the last reg pushed by switch_to */
bp = *(unsigned long *) task->thread.esp;
bp = *(unsigned long *) task->thread.sp;
}
}
#endif
Expand Down Expand Up @@ -253,7 +253,7 @@ static void show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,

if (sp == NULL) {
if (task)
sp = (unsigned long*)task->thread.esp;
sp = (unsigned long*)task->thread.sp;
else
sp = (unsigned long *)&sp;
}
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/traps_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
unsigned long dummy;
stack = &dummy;
if (tsk && tsk != current)
stack = (unsigned long *)tsk->thread.rsp;
stack = (unsigned long *)tsk->thread.sp;
}

/*
Expand Down Expand Up @@ -366,7 +366,7 @@ _show_stack(struct task_struct *tsk, struct pt_regs *regs, unsigned long *sp)

if (sp == NULL) {
if (tsk)
sp = (unsigned long *)tsk->thread.rsp;
sp = (unsigned long *)tsk->thread.sp;
else
sp = (unsigned long *)&sp;
}
Expand Down
16 changes: 8 additions & 8 deletions arch/x86/kernel/vm86_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ struct pt_regs * fastcall save_v86_state(struct kernel_vm86_regs * regs)
}

tss = &per_cpu(init_tss, get_cpu());
current->thread.esp0 = current->thread.saved_esp0;
current->thread.sp0 = current->thread.saved_sp0;
current->thread.sysenter_cs = __KERNEL_CS;
load_esp0(tss, &current->thread);
current->thread.saved_esp0 = 0;
load_sp0(tss, &current->thread);
current->thread.saved_sp0 = 0;
put_cpu();

ret = KVM86->regs32;
Expand Down Expand Up @@ -207,7 +207,7 @@ asmlinkage int sys_vm86old(struct pt_regs regs)
int tmp, ret = -EPERM;

tsk = current;
if (tsk->thread.saved_esp0)
if (tsk->thread.saved_sp0)
goto out;
tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
offsetof(struct kernel_vm86_struct, vm86plus) -
Expand Down Expand Up @@ -256,7 +256,7 @@ asmlinkage int sys_vm86(struct pt_regs regs)

/* we come here only for functions VM86_ENTER, VM86_ENTER_NO_BYPASS */
ret = -EPERM;
if (tsk->thread.saved_esp0)
if (tsk->thread.saved_sp0)
goto out;
v86 = (struct vm86plus_struct __user *)regs.cx;
tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
Expand Down Expand Up @@ -318,15 +318,15 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
* Save old state, set default return value (%ax) to 0
*/
info->regs32->ax = 0;
tsk->thread.saved_esp0 = tsk->thread.esp0;
tsk->thread.saved_sp0 = tsk->thread.sp0;
tsk->thread.saved_fs = info->regs32->fs;
savesegment(gs, tsk->thread.saved_gs);

tss = &per_cpu(init_tss, get_cpu());
tsk->thread.esp0 = (unsigned long) &info->VM86_TSS_ESP0;
tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
if (cpu_has_sep)
tsk->thread.sysenter_cs = 0;
load_esp0(tss, &tsk->thread);
load_sp0(tss, &tsk->thread);
put_cpu();

tsk->thread.screen_bitmap = info->screen_bitmap;
Expand Down
10 changes: 5 additions & 5 deletions arch/x86/kernel/vmi_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static struct {
void (*cpuid)(void /* non-c */);
void (*_set_ldt)(u32 selector);
void (*set_tr)(u32 selector);
void (*set_kernel_stack)(u32 selector, u32 esp0);
void (*set_kernel_stack)(u32 selector, u32 sp0);
void (*allocate_page)(u32, u32, u32, u32, u32);
void (*release_page)(u32, u32);
void (*set_pte)(pte_t, pte_t *, unsigned);
Expand Down Expand Up @@ -214,17 +214,17 @@ static void vmi_set_tr(void)
vmi_ops.set_tr(GDT_ENTRY_TSS*sizeof(struct desc_struct));
}

static void vmi_load_esp0(struct tss_struct *tss,
static void vmi_load_sp0(struct tss_struct *tss,
struct thread_struct *thread)
{
tss->x86_tss.esp0 = thread->esp0;
tss->x86_tss.sp0 = thread->sp0;

/* This can only happen when SEP is enabled, no need to test "SEP"arately */
if (unlikely(tss->x86_tss.ss1 != thread->sysenter_cs)) {
tss->x86_tss.ss1 = thread->sysenter_cs;
wrmsr(MSR_IA32_SYSENTER_CS, thread->sysenter_cs, 0);
}
vmi_ops.set_kernel_stack(__KERNEL_DS, tss->x86_tss.esp0);
vmi_ops.set_kernel_stack(__KERNEL_DS, tss->x86_tss.sp0);
}

static void vmi_flush_tlb_user(void)
Expand Down Expand Up @@ -793,7 +793,7 @@ static inline int __init activate_vmi(void)
para_fill(pv_cpu_ops.write_ldt_entry, WriteLDTEntry);
para_fill(pv_cpu_ops.write_gdt_entry, WriteGDTEntry);
para_fill(pv_cpu_ops.write_idt_entry, WriteIDTEntry);
para_wrap(pv_cpu_ops.load_esp0, vmi_load_esp0, set_kernel_stack, UpdateKernelStack);
para_wrap(pv_cpu_ops.load_sp0, vmi_load_sp0, set_kernel_stack, UpdateKernelStack);
para_fill(pv_cpu_ops.set_iopl_mask, SetIOPLMask);
para_fill(pv_cpu_ops.io_delay, IODelay);

Expand Down
6 changes: 3 additions & 3 deletions arch/x86/lguest/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,10 @@ static void lguest_time_init(void)
* segment), the privilege level (we're privilege level 1, the Host is 0 and
* will not tolerate us trying to use that), the stack pointer, and the number
* of pages in the stack. */
static void lguest_load_esp0(struct tss_struct *tss,
static void lguest_load_sp0(struct tss_struct *tss,
struct thread_struct *thread)
{
lazy_hcall(LHCALL_SET_STACK, __KERNEL_DS|0x1, thread->esp0,
lazy_hcall(LHCALL_SET_STACK, __KERNEL_DS|0x1, thread->sp0,
THREAD_SIZE/PAGE_SIZE);
}

Expand Down Expand Up @@ -957,7 +957,7 @@ __init void lguest_init(void)
pv_cpu_ops.cpuid = lguest_cpuid;
pv_cpu_ops.load_idt = lguest_load_idt;
pv_cpu_ops.iret = lguest_iret;
pv_cpu_ops.load_esp0 = lguest_load_esp0;
pv_cpu_ops.load_sp0 = lguest_load_sp0;
pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
pv_cpu_ops.set_ldt = lguest_set_ldt;
pv_cpu_ops.load_tls = lguest_load_tls;
Expand Down
Loading

0 comments on commit faca622

Please sign in to comment.