---
i386/i386/cpu_number.h | 40 ++++++++++++++++++++++++++++------------
x86_64/locore.S | 4 ++--
2 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/i386/i386/cpu_number.h b/i386/i386/cpu_number.h
index f7bf2578..f76a49de 100644
--- a/i386/i386/cpu_number.h
+++ b/i386/i386/cpu_number.h
@@ -41,15 +41,25 @@
#define CX(addr, reg) addr(,reg,8)
#endif
-/* Slow version, always works.
- * Call with 32 bit wide reg on i386
- * Call with 64 bit wide reg on x86_64 */
+/* Slow version, always works. */
+#ifdef __i386__
#define CPU_NUMBER_NO_STACK(reg) \
- mov %cs:lapic, reg ;\
- mov %cs:APIC_ID(reg), reg ;\
- shr $24, reg ;\
- and %cs:apic_id_mask, reg ;\
- mov %cs:CX(cpu_id_lut, reg), reg ;\
+ movl %cs:lapic, reg ;\
+ movl %cs:APIC_ID(reg), reg ;\
+ shrl $24, reg ;\
+ andl %cs:apic_id_mask, reg ;\
+ movl %cs:CX(cpu_id_lut, reg), reg
+#endif
+#ifdef __x86_64__
+/* Clobbers %r8, need to input 32/64 bit regs */
+#define CPU_NUMBER_NO_STACK(reg32, reg64)\
+ movq %cs:lapic, %r8 ;\
+ movl %cs:APIC_ID(%r8), %r8d ;\
+ shrl $24, %r8d ;\
+ andb %cs:apic_id_mask, %r8b ;\
+ leaq cpu_id_lut(%rip), reg64 ;\
+ movl %cs:(reg64, %r8, 8), reg32
+#endif
/* Fast version, requires a stack */
#ifdef __i386__
@@ -82,9 +92,10 @@
pushq %rdx ;\
movl $1, %eax ;\
cpuid ;\
- shrq $24, %rbx ;\
- andq %cs:apic_id_mask, %rbx ;\
- movq %cs:CX(cpu_id_lut, %rbx), %rsi ;\
+ shrl $24, %ebx ;\
+ andb %cs:apic_id_mask, %bl ;\
+ leaq cpu_id_lut(%rip), %rsi ;\
+ movl %cs:(%rsi, %rbx, 4), %esi ;\
popq %rdx ;\
popq %rcx ;\
popq %rbx ;\
@@ -117,7 +128,12 @@ static inline int cpu_number(void)
#define MY(stm) (percpu_array + PERCPU_##stm)
-#define CPU_NUMBER_NO_STACK(reg)
+#ifdef __x86_64__
+#define CPU_NUMBER_NO_STACK(reg32, reg64)
+#endif
+#ifdef __i386__
+#define CPU_NUMBER_NO_STACK(reg)
+#endif
#define CPU_NUMBER_NO_GS(reg)
#define CPU_NUMBER(reg)
#define CX(addr,reg) addr
diff --git a/x86_64/locore.S b/x86_64/locore.S
index 5043cf7a..f8133ad9 100644
--- a/x86_64/locore.S
+++ b/x86_64/locore.S
@@ -1181,7 +1181,7 @@ syscall_entry_2:
movq %rdx,R_CS(%rsp) /* fix cs */
movq %rbx,R_EFLAGS(%rsp) /* fix eflags */
- CPU_NUMBER_NO_STACK(%rdx)
+ CPU_NUMBER_NO_STACK(%edx, %rdx)
TIME_TRAP_SENTRY
movq CX(EXT(kernel_stack),%rdx),%rbx
@@ -1421,7 +1421,7 @@ ENTRY(syscall64)
mov %r10,%rcx /* fix arg3 location according to C ABI
*/
/* switch to kernel stack, then we can enable interrupts */
- CPU_NUMBER_NO_STACK(%r11)
+ CPU_NUMBER_NO_STACK(%r11d, %r11)
movq CX(EXT(kernel_stack),%r11),%rsp
sti
--
2.45.2