Skip to content

Commit

Permalink
[PATCH] x86: more asm cleanups
Browse files Browse the repository at this point in the history
Some more assembler cleanups I noticed along the way.

Signed-off-by: Zachary Amsden <zach@vmware.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Zachary Amsden authored and Linus Torvalds committed Sep 5, 2005
1 parent 4f0cb8d commit f2ab446
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 50 deletions.
9 changes: 3 additions & 6 deletions arch/i386/kernel/cpu/intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,13 @@ static void __devinit Intel_errata_workarounds(struct cpuinfo_x86 *c)
*/
static int __devinit num_cpu_cores(struct cpuinfo_x86 *c)
{
unsigned int eax;
unsigned int eax, ebx, ecx, edx;

if (c->cpuid_level < 4)
return 1;

__asm__("cpuid"
: "=a" (eax)
: "0" (4), "c" (0)
: "bx", "dx");

/* Intel has a non-standard dependency on %ecx for this CPUID level. */
cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
if (eax & 0x1f)
return ((eax >> 26) + 1);
else
Expand Down
2 changes: 1 addition & 1 deletion arch/i386/kernel/crash.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static int crash_nmi_callback(struct pt_regs *regs, int cpu)
disable_local_APIC();
atomic_dec(&waiting_for_crash_ipi);
/* Assume hlt works */
__asm__("hlt");
halt();
for(;;);

return 1;
Expand Down
10 changes: 2 additions & 8 deletions arch/i386/kernel/machine_kexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ static void set_idt(void *newidt, __u16 limit)
curidt.size = limit;
curidt.address = (unsigned long)newidt;

__asm__ __volatile__ (
"lidtl %0\n"
: : "m" (curidt)
);
load_idt(&curidt);
};


Expand All @@ -108,10 +105,7 @@ static void set_gdt(void *newgdt, __u16 limit)
curgdt.size = limit;
curgdt.address = (unsigned long)newgdt;

__asm__ __volatile__ (
"lgdtl %0\n"
: : "m" (curgdt)
);
load_gdt(&curgdt);
};

static void load_segments(void)
Expand Down
31 changes: 6 additions & 25 deletions arch/i386/kernel/msr.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,42 +46,23 @@

static struct class *msr_class;

/* Note: "err" is handled in a funny way below. Otherwise one version
of gcc or another breaks. */

static inline int wrmsr_eio(u32 reg, u32 eax, u32 edx)
{
int err;

asm volatile ("1: wrmsr\n"
"2:\n"
".section .fixup,\"ax\"\n"
"3: movl %4,%0\n"
" jmp 2b\n"
".previous\n"
".section __ex_table,\"a\"\n"
" .align 4\n" " .long 1b,3b\n" ".previous":"=&bDS" (err)
:"a"(eax), "d"(edx), "c"(reg), "i"(-EIO), "0"(0));

err = wrmsr_safe(reg, eax, edx);
if (err)
err = -EIO;
return err;
}

static inline int rdmsr_eio(u32 reg, u32 *eax, u32 *edx)
{
int err;

asm volatile ("1: rdmsr\n"
"2:\n"
".section .fixup,\"ax\"\n"
"3: movl %4,%0\n"
" jmp 2b\n"
".previous\n"
".section __ex_table,\"a\"\n"
" .align 4\n"
" .long 1b,3b\n"
".previous":"=&bDS" (err), "=a"(*eax), "=d"(*edx)
:"c"(reg), "i"(-EIO), "0"(0));

err = rdmsr_safe(reg, eax, edx);
if (err)
err = -EIO;
return err;
}

Expand Down
2 changes: 1 addition & 1 deletion arch/i386/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static inline void play_dead(void)
*/
local_irq_disable();
while (1)
__asm__ __volatile__("hlt":::"memory");
halt();
}
#else
static inline void play_dead(void)
Expand Down
14 changes: 6 additions & 8 deletions arch/i386/mach-voyager/voyager_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,9 @@ voyager_power_off(void)
#endif
}
/* and wait for it to happen */
for(;;) {
__asm("cli");
__asm("hlt");
}
local_irq_disable();
for(;;)
halt();
}

/* copied from process.c */
Expand Down Expand Up @@ -278,10 +277,9 @@ machine_restart(char *cmd)
outb(basebd | 0x08, VOYAGER_MC_SETUP);
outb(0x02, catbase + 0x21);
}
for(;;) {
asm("cli");
asm("hlt");
}
local_irq_disable();
for(;;)
halt();
}

void
Expand Down
2 changes: 1 addition & 1 deletion arch/i386/mach-voyager/voyager_smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ smp_stop_cpu_function(void *dummy)
cpu_clear(smp_processor_id(), cpu_online_map);
local_irq_disable();
for(;;)
__asm__("hlt");
halt();
}

static DEFINE_SPINLOCK(call_lock);
Expand Down
15 changes: 15 additions & 0 deletions include/asm-i386/msr.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ static inline void wrmsrl (unsigned long msr, unsigned long long val)
: "c" (msr), "0" (a), "d" (b), "i" (-EFAULT));\
ret__; })

/* rdmsr with exception handling */
#define rdmsr_safe(msr,a,b) ({ int ret__; \
asm volatile("2: rdmsr ; xorl %0,%0\n" \
"1:\n\t" \
".section .fixup,\"ax\"\n\t" \
"3: movl %4,%0 ; jmp 1b\n\t" \
".previous\n\t" \
".section __ex_table,\"a\"\n" \
" .align 4\n\t" \
" .long 2b,3b\n\t" \
".previous" \
: "=r" (ret__), "=a" (*(a)), "=d" (*(b)) \
: "c" (msr), "i" (-EFAULT));\
ret__; })

#define rdtsc(low,high) \
__asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))

Expand Down

0 comments on commit f2ab446

Please sign in to comment.