[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Re-factor current.h. It now requires no sub-architecture portions, and



ChangeSet 1.1449.1.1, 2005/05/18 17:36:44+01:00, kaf24@xxxxxxxxxxxxxxxxxxxx

        Re-factor current.h. It now requires no sub-architecture portions, and
        stack offset calculations are cleaned up by introduction of a
        cpu_info structure.
        Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>



 b/xen/arch/x86/setup.c               |    3 +
 b/xen/arch/x86/smpboot.c             |    6 ++-
 b/xen/include/asm-x86/current.h      |   60 ++++++++++++++++++++++++++++--
 b/xen/include/asm-x86/smp.h          |    3 +
 xen/include/asm-x86/x86_32/current.h |   66 ---------------------------------
 xen/include/asm-x86/x86_64/current.h |   68 -----------------------------------
 6 files changed, 64 insertions(+), 142 deletions(-)


diff -Nru a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
--- a/xen/arch/x86/setup.c      2005-05-18 13:03:56 -04:00
+++ b/xen/arch/x86/setup.c      2005-05-18 13:03:56 -04:00
@@ -317,6 +317,8 @@
     t->ss0  = __HYPERVISOR_DS;
     t->esp0 = get_stack_bottom();
 #elif defined(CONFIG_X86_64)
+    /* Bottom-of-stack must be 16-byte aligned or CPU will force it! :-o */
+    BUG_ON((get_stack_bottom() & 15) != 0);
     t->rsp0 = get_stack_bottom();
 #endif
     set_tss_desc(nr,t);
@@ -483,6 +485,7 @@
 
     /* Must do this early -- e.g., spinlocks rely on get_current(). */
     set_current(&idle0_exec_domain);
+    set_processor_id(0);
 
     /* We initialise the serial devices very early so we can get debugging. */
     serial_init_stage1();
diff -Nru a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c
--- a/xen/arch/x86/smpboot.c    2005-05-18 13:03:56 -04:00
+++ b/xen/arch/x86/smpboot.c    2005-05-18 13:03:56 -04:00
@@ -402,6 +402,7 @@
     extern void cpu_init(void);
 
     set_current(idle_task[cpu]);
+    set_processor_id(cpu);
 
     percpu_traps_init();
 
@@ -677,10 +678,11 @@
 
     stack = (void *)alloc_xenheap_pages(STACK_ORDER);
 #if defined(__i386__)
-    stack_start.esp = __pa(stack) + STACK_SIZE - STACK_RESERVED;
+    stack_start.esp = __pa(stack);
 #elif defined(__x86_64__)
-    stack_start.esp = (unsigned long)stack + STACK_SIZE - STACK_RESERVED;
+    stack_start.esp = (unsigned long)stack;
 #endif
+    stack_start.esp += STACK_SIZE - sizeof(struct cpu_info);
 
     /* Debug build: detect stack overflow by setting up a guard page. */
     memguard_guard_stack(stack);
diff -Nru a/xen/include/asm-x86/current.h b/xen/include/asm-x86/current.h
--- a/xen/include/asm-x86/current.h     2005-05-18 13:03:56 -04:00
+++ b/xen/include/asm-x86/current.h     2005-05-18 13:03:56 -04:00
@@ -1,6 +1,56 @@
+/******************************************************************************
+ * current.h
+ * 
+ * Information structure that lives at the bottom of the per-cpu Xen stack.
+ */
 
-#ifdef __x86_64__
-#include <asm/x86_64/current.h>
-#else
-#include <asm/x86_32/current.h>
-#endif
+#ifndef __X86_CURRENT_H__
+#define __X86_CURRENT_H__
+
+#include <xen/config.h>
+#include <public/xen.h>
+#include <asm/page.h>
+
+struct exec_domain;
+
+struct cpu_info {
+    struct cpu_user_regs guest_cpu_user_regs;
+    unsigned int         processor_id;
+    struct exec_domain  *current_ed;
+};
+
+static inline struct cpu_info *get_cpu_info(void)
+{
+    struct cpu_info *cpu_info;
+    __asm__ ( "and %%"__OP"sp,%0; or %2,%0"
+              : "=r" (cpu_info)
+              : "0" (~(STACK_SIZE-1)), "i" (STACK_SIZE-sizeof(struct cpu_info))
+        );
+    return cpu_info;
+}
+
+#define get_current()         (get_cpu_info()->current_ed)
+#define set_current(_ed)      (get_cpu_info()->current_ed = (_ed))
+#define current               (get_current())
+
+#define get_processor_id()    (get_cpu_info()->processor_id)
+#define set_processor_id(_id) (get_cpu_info()->processor_id = (_id))
+
+#define guest_cpu_user_regs() (&get_cpu_info()->guest_cpu_user_regs)
+
+/*
+ * Get the bottom-of-stack, as stored in the per-CPU TSS. This actually points
+ * into the middle of cpu_info.guest_cpu_user_regs, at the section that
+ * precisely corresponds to a CPU trap frame.
+ */
+#define get_stack_bottom()                      \
+    ((unsigned long)&get_cpu_info()->guest_cpu_user_regs.es)
+
+#define reset_stack_and_jump(__fn)              \
+    __asm__ __volatile__ (                      \
+        "mov %0,%%"__OP"sp; jmp "STR(__fn)      \
+        : : "r" (guest_cpu_user_regs()) )
+
+#define schedule_tail(_ed) (((_ed)->arch.schedule_tail)(_ed))
+
+#endif /* __X86_CURRENT_H__ */
diff -Nru a/xen/include/asm-x86/smp.h b/xen/include/asm-x86/smp.h
--- a/xen/include/asm-x86/smp.h 2005-05-18 13:03:56 -04:00
+++ b/xen/include/asm-x86/smp.h 2005-05-18 13:03:56 -04:00
@@ -8,6 +8,7 @@
 #include <xen/config.h>
 #include <xen/kernel.h>
 #include <xen/cpumask.h>
+#include <asm/current.h>
 #endif
 
 #ifdef CONFIG_X86_LOCAL_APIC
@@ -48,7 +49,7 @@
  * from the initial startup. We map APIC_BASE very early in page_setup(),
  * so this is correct in the x86 case.
  */
-#define __smp_processor_id() (current->processor)
+#define __smp_processor_id() (get_processor_id())
 
 extern cpumask_t cpu_callout_map;
 extern cpumask_t cpu_callin_map;
diff -Nru a/xen/include/asm-x86/x86_32/current.h 
b/xen/include/asm-x86/x86_32/current.h
--- a/xen/include/asm-x86/x86_32/current.h      2005-05-18 13:03:56 -04:00
+++ /dev/null   Wed Dec 31 16:00:00 196900
@@ -1,66 +0,0 @@
-
-#ifndef _X86_CURRENT_H
-#define _X86_CURRENT_H
-
-struct domain;
-
-#define STACK_RESERVED \
-    (sizeof(struct cpu_user_regs) + sizeof(struct domain *))
-
-static inline struct exec_domain *get_current(void)
-{
-    struct exec_domain *ed;
-    __asm__ ( "orl %%esp,%0; andl $~3,%0; movl (%0),%0" 
-              : "=r" (ed) : "0" (STACK_SIZE-4) );
-    return ed;
-}
- 
-#define current get_current()
-
-static inline void set_current(struct exec_domain *ed)
-{
-    __asm__ ( "orl %%esp,%0; andl $~3,%0; movl %1,(%0)" 
-              : : "r" (STACK_SIZE-4), "r" (ed) );    
-}
-
-static inline struct cpu_user_regs *guest_cpu_user_regs(void)
-{
-    struct cpu_user_regs *cpu_user_regs;
-    __asm__ ( "andl %%esp,%0; addl %2,%0"
-              : "=r" (cpu_user_regs) 
-              : "0" (~(STACK_SIZE-1)), "i" (STACK_SIZE-STACK_RESERVED) );
-    return cpu_user_regs;
-}
-
-/*
- * Get the bottom-of-stack, as stored in the per-CPU TSS. This is actually
- * 20 bytes before the real bottom of the stack to allow space for:
- *  domain pointer, DS, ES, FS, GS.
- */
-static inline unsigned long get_stack_bottom(void)
-{
-    unsigned long p;
-    __asm__ ( "andl %%esp,%0; addl %2,%0" 
-              : "=r" (p)
-              : "0" (~(STACK_SIZE-1)), "i" (STACK_SIZE-20) );
-    return p;
-}
-
-#define reset_stack_and_jump(__fn)                                \
-    __asm__ __volatile__ (                                        \
-        "movl %0,%%esp; jmp "STR(__fn)                            \
-        : : "r" (guest_cpu_user_regs()) )
-
-#define schedule_tail(_ed) ((_ed)->arch.schedule_tail)(_ed)
-
-#endif /* _X86_CURRENT_H */
-
-/*
- * Local variables:
- * mode: C
- * c-set-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff -Nru a/xen/include/asm-x86/x86_64/current.h 
b/xen/include/asm-x86/x86_64/current.h
--- a/xen/include/asm-x86/x86_64/current.h      2005-05-18 13:03:56 -04:00
+++ /dev/null   Wed Dec 31 16:00:00 196900
@@ -1,68 +0,0 @@
-
-#ifndef _X86_64_CURRENT_H
-#define _X86_64_CURRENT_H
-
-struct domain;
-
-#define STACK_RESERVED \
-    (sizeof(struct cpu_user_regs) + sizeof(struct domain *) + 8)
-
-static inline struct exec_domain *get_current(void)
-{
-    struct exec_domain *ed;
-    __asm__ ( "orq %%rsp,%0; andq $~7,%0; movq (%0),%0" 
-              : "=r" (ed) : "0" (STACK_SIZE-8) );
-    return ed;
-}
- 
-#define current get_current()
-
-static inline void set_current(struct exec_domain *ed)
-{
-    __asm__ ( "orq %%rsp,%0; andq $~7,%0; movq %1,(%0)" 
-              : : "r" (STACK_SIZE-8), "r" (ed) );    
-}
-
-static inline struct cpu_user_regs *guest_cpu_user_regs(void)
-{
-    struct cpu_user_regs *cpu_user_regs;
-    __asm__( "andq %%rsp,%0; addq %2,%0"
-           : "=r" (cpu_user_regs)
-           : "0" (~(STACK_SIZE-1)), "i" (STACK_SIZE-STACK_RESERVED) ); 
-    return cpu_user_regs;
-}
-
-/*
- * Get the bottom-of-stack, as stored in the per-CPU TSS. This is actually
- * 48 bytes before the real bottom of the stack to allow space for:
- * domain pointer, padding, DS, ES, FS, GS. The padding is required to
- * have the stack pointer 16-byte aligned: the amount we subtract from
- * STACK_SIZE *must* be a multiple of 16.
- */
-static inline unsigned long get_stack_bottom(void)
-{
-    unsigned long p;
-    __asm__( "andq %%rsp,%0; addq %2,%0"
-           : "=r" (p)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.