diff options
Diffstat (limited to 'i386/i386/cpu_number.h')
-rw-r--r-- | i386/i386/cpu_number.h | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/i386/i386/cpu_number.h b/i386/i386/cpu_number.h index 9aef6370..67c19e9b 100644 --- a/i386/i386/cpu_number.h +++ b/i386/i386/cpu_number.h @@ -32,7 +32,8 @@ #if NCPUS > 1 -/* More-specific code must define cpu_number() and CPU_NUMBER. */ +#define MY(stm) %gs:PERCPU_##stm + #ifdef __i386__ #define CX(addr, reg) addr(,reg,4) #endif @@ -40,19 +41,79 @@ #define CX(addr, reg) addr(,reg,8) #endif -/* XXX For now */ -#define CPU_NUMBER(reg) movl $0,reg -#define cpu_number() 0 +#define CPU_NUMBER_NO_STACK(reg) \ + movl %cs:lapic, reg ;\ + movl %cs:APIC_ID(reg), reg ;\ + shrl $24, reg ;\ + movl %cs:CX(cpu_id_lut, reg), reg ;\ + +#ifdef __i386__ +/* Never call CPU_NUMBER_NO_GS(%esi) */ +#define CPU_NUMBER_NO_GS(reg) \ + pushl %esi ;\ + pushl %eax ;\ + pushl %ebx ;\ + pushl %ecx ;\ + pushl %edx ;\ + movl $1, %eax ;\ + cpuid ;\ + shrl $24, %ebx ;\ + movl %cs:CX(cpu_id_lut, %ebx), %esi ;\ + popl %edx ;\ + popl %ecx ;\ + popl %ebx ;\ + popl %eax ;\ + movl %esi, reg ;\ + popl %esi +#endif +#ifdef __x86_64__ +/* Never call CPU_NUMBER_NO_GS(%esi) */ +#define CPU_NUMBER_NO_GS(reg) \ + pushq %rsi ;\ + pushq %rax ;\ + pushq %rbx ;\ + pushq %rcx ;\ + pushq %rdx ;\ + movl $1, %eax ;\ + cpuid ;\ + shrl $24, %ebx ;\ + movl %cs:CX(cpu_id_lut, %ebx), %esi ;\ + popq %rdx ;\ + popq %rcx ;\ + popq %rbx ;\ + popq %rax ;\ + movl %esi, reg ;\ + popq %rsi +#endif + +#define CPU_NUMBER(reg) \ + movl MY(CPU_ID), reg; + +#ifndef __ASSEMBLER__ +#include <kern/cpu_number.h> +#include <i386/apic.h> +#include <i386/percpu.h> + +static inline int cpu_number_slow(void) +{ + return cpu_id_lut[apic_get_current_cpu()]; +} + +static inline int cpu_number(void) +{ + return percpu_get(int, cpu_id); +} +#endif #else /* NCPUS == 1 */ +#define MY(stm) (percpu_array + PERCPU_##stm) + +#define CPU_NUMBER_NO_STACK(reg) +#define CPU_NUMBER_NO_GS(reg) #define CPU_NUMBER(reg) #define CX(addr,reg) addr #endif /* NCPUS == 1 */ -#ifndef __ASSEMBLER__ -#include "kern/cpu_number.h" -#endif - #endif /* _I386_CPU_NUMBER_H_ */ |