Module: xenomai-forge
Branch: master
Commit: d2201b6ba2a426ab3eaafc6336dadbe38f0d105f
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=d2201b6ba2a426ab3eaafc6336dadbe38f0d105f

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Dec 21 18:03:38 2012 +0100

x86: reunify more 32/64bit code

---

 include/asm-x86/switch_32.h     |   14 ++--
 include/asm-x86/thread.h        |   43 ++++----------
 kernel/cobalt/arch/x86/mayday.c |   30 +++-------
 kernel/cobalt/arch/x86/thread.c |  116 ++++++++++++++++----------------------
 4 files changed, 77 insertions(+), 126 deletions(-)

diff --git a/include/asm-x86/switch_32.h b/include/asm-x86/switch_32.h
index 0827916..b313108 100644
--- a/include/asm-x86/switch_32.h
+++ b/include/asm-x86/switch_32.h
@@ -59,10 +59,10 @@ static inline void xnarch_switch_threads(xnarchtcb_t 
*out_tcb,
                             "popl %%edi\n\t"
                             "popl %%ecx\n\t"
                             "popfl\n\t":       /* no output */
-                            :"m"(out_tcb->espp),
-                             "m"(out_tcb->eipp),
-                             "m"(in_tcb->espp),
-                             "m"(in_tcb->eipp),
+                            :"m"(out_tcb->spp),
+                             "m"(out_tcb->ipp),
+                             "m"(in_tcb->spp),
+                             "m"(in_tcb->ipp),
                              "b"(out_tcb),
                              "S"(in_tcb), "a"(outproc), "d"(inproc));
 
@@ -90,9 +90,9 @@ static inline void xnarch_switch_threads(xnarchtcb_t *out_tcb,
                             "=&c"(ecx_out),
                             "=S"(esi_out),
                             "=D"(edi_out), "+a"(outproc), "+d"(inproc)
-                            :"m"(out_tcb->espp),
-                             "m"(out_tcb->eipp),
-                             "m"(in_tcb->espp), "m"(in_tcb->eipp));
+                            :"m"(out_tcb->spp),
+                             "m"(out_tcb->ipp),
+                             "m"(in_tcb->spp), "m"(in_tcb->ipp));
 
 #endif /* GCC version < 3.2 */
 }
diff --git a/include/asm-x86/thread.h b/include/asm-x86/thread.h
index 6002c7b..43659d0 100644
--- a/include/asm-x86/thread.h
+++ b/include/asm-x86/thread.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2001-2007 Philippe Gerum <r...@xenomai.org>.
+ * Copyright (C) 2001-20012 Philippe Gerum <r...@xenomai.org>.
  * Copyright (C) 2004-2006 Gilles Chanteperdrix 
<gilles.chanteperd...@xenomai.org>.
  * Copyright (C) 2004 The HYADES Project (http://www.hyades-itea.org).
  *
@@ -37,37 +37,24 @@ struct xnarchtcb {
        x86_fpustate i387 __attribute__ ((aligned (16)));
        unsigned int stacksize;
        unsigned long *stackbase;
-#ifdef CONFIG_X86_32
-       unsigned long esp;
-       unsigned long eip;
-#else /* CONFIG_X86_64 */
-       unsigned long rsp;
-       unsigned long rip;
-       unsigned long *rspp;
-       unsigned long *ripp;
+       unsigned long sp;
+       unsigned long *spp;
+       unsigned long ip;
+       unsigned long *ipp;
+       x86_fpustate *fpup;
 #ifdef CONFIG_CC_STACKPROTECTOR
        unsigned long canary;
 #endif
-#endif /* CONFIG_X86_64 */
        struct {
-               unsigned long eip;
-               unsigned long eax;
-#ifdef CONFIG_X86_32
-               unsigned long esp;
-#endif
+               unsigned long ip;
+               unsigned long ax;
+               unsigned long sp;
        } mayday;
-
        struct task_struct *user_task;
        struct task_struct *active_task;
-
-       unsigned long *espp;
-       unsigned long *eipp;
-       x86_fpustate *fpup;
-
        unsigned is_root: 1;
        unsigned ts_usedfpu: 1;
        unsigned cr0_ts: 1;
-
        struct xnthread *self;
        int imask;
        const char *name;
@@ -84,20 +71,16 @@ struct xnarchtcb {
 #warning "Xenomai: outdated gcc/x86_32 release detected"
 #error "           please upgrade to gcc 3.2 or later"
 #endif
-
 #define XNARCH_THREAD_STACKSZ 4096
+#else /* CONFIG_X86_64 */
+#define XNARCH_THREAD_STACKSZ 8192
+#endif /* CONFIG_X86_64 */
 
 static inline int xnarch_shadow_p(struct xnarchtcb *tcb, struct task_struct 
*task)
 {
-       return tcb->espp == &task->thread.sp;
+       return tcb->spp == &task->thread.sp;
 }
 
-#else /* CONFIG_X86_64 */
-
-#define XNARCH_THREAD_STACKSZ 8192
-
-#endif /* CONFIG_X86_64 */
-
 #define xnarch_stack_size(tcb)  ((tcb)->stacksize)
 #define xnarch_stack_base(tcb) ((tcb)->stackbase)
 #define xnarch_stack_end(tcb)  ((caddr_t)(tcb)->stackbase - (tcb)->stacksize)
diff --git a/kernel/cobalt/arch/x86/mayday.c b/kernel/cobalt/arch/x86/mayday.c
index 354731e..44e1a9c 100644
--- a/kernel/cobalt/arch/x86/mayday.c
+++ b/kernel/cobalt/arch/x86/mayday.c
@@ -92,22 +92,6 @@ void xnarch_setup_mayday_page(void *page)
        /* no cache flush required. */
 }
 
-void xnarch_handle_mayday(struct xnarchtcb *tcb, struct pt_regs *regs,
-                         unsigned long tramp)
-{
-       tcb->mayday.esp = regs->sp;
-       tcb->mayday.eip = regs->ip;
-       tcb->mayday.eax = regs->ax;
-       regs->ip = tramp;
-}
-
-void xnarch_fixup_mayday(struct xnarchtcb *tcb, struct pt_regs *regs)
-{
-       regs->ip = tcb->mayday.eip;
-       regs->ax = tcb->mayday.eax;
-       regs->sp = tcb->mayday.esp;
-}
-
 #else /* CONFIG_X86_64 */
 
 void xnarch_setup_mayday_page(void *page)
@@ -143,22 +127,24 @@ void xnarch_setup_mayday_page(void *page)
        /* no cache flush required. */
 }
 
+#endif /* CONFIG_X86_64 */
+
 void xnarch_handle_mayday(struct xnarchtcb *tcb, struct pt_regs *regs,
                          unsigned long tramp)
 {
-       tcb->mayday.eip = regs->ip;
-       tcb->mayday.eax = regs->ax;
+       tcb->mayday.sp = regs->sp;
+       tcb->mayday.ip = regs->ip;
+       tcb->mayday.ax = regs->ax;
        regs->ip = tramp;
 }
 
 void xnarch_fixup_mayday(struct xnarchtcb *tcb, struct pt_regs *regs)
 {
-       regs->ip = tcb->mayday.eip;
-       regs->ax = tcb->mayday.eax;
+       regs->ip = tcb->mayday.ip;
+       regs->ax = tcb->mayday.ax;
+       regs->sp = tcb->mayday.sp;
 }
 
-#endif /* CONFIG_X86_64 */
-
 void xnarch_call_mayday(struct task_struct *p)
 {
        ipipe_raise_mayday(p);
diff --git a/kernel/cobalt/arch/x86/thread.c b/kernel/cobalt/arch/x86/thread.c
index b6ecb4b..0da951b 100644
--- a/kernel/cobalt/arch/x86/thread.c
+++ b/kernel/cobalt/arch/x86/thread.c
@@ -27,6 +27,8 @@
 #include <nucleus/heap.h>
 #include <nucleus/clock.h>
 
+asmlinkage static void thread_trampoline(struct xnarchtcb *tcb);
+
 #ifdef CONFIG_X86_32
 
 static inline void do_switch_threads(struct xnarchtcb *out_tcb,
@@ -56,39 +58,27 @@ static inline void do_switch_threads(struct xnarchtcb 
*out_tcb,
                             "=&c"(ecx_out),
                             "=S"(esi_out),
                             "=D"(edi_out), "+a"(outproc), "+d"(inproc)
-                            :"m"(out_tcb->espp),
-                             "m"(out_tcb->eipp),
-                             "m"(in_tcb->espp), "m"(in_tcb->eipp));
-}
-
-asmlinkage static void thread_trampoline(struct xnthread *self,
-                                        int imask, void (*entry) (void *),
-                                        void *cookie)
-{
-       /* xnpod_welcome_thread() will do clts() if needed. */
-       stts();
-       xnpod_welcome_thread(self, imask);
-       entry(cookie);
-       xnpod_delete_thread(self);
+                            :"m"(out_tcb->spp),
+                             "m"(out_tcb->ipp),
+                             "m"(in_tcb->spp), "m"(in_tcb->ipp));
 }
 
 void xnarch_init_thread(struct xnarchtcb *tcb,
                        void (*entry) (void *), void *cookie,
                        int imask, struct xnthread *thread, char *name)
 {
-       unsigned long **psp = (unsigned long **)&tcb->esp;
+       unsigned long **psp = (unsigned long **)&tcb->sp;
 
-       tcb->eip = (unsigned long)&thread_trampoline;
-       tcb->esp = (unsigned long)tcb->stackbase;
+       tcb->ip = (unsigned long)thread_trampoline;
+       tcb->sp = (unsigned long)tcb->stackbase;
        *psp = (unsigned long *)
                (((unsigned long)*psp + tcb->stacksize - 0x10) & ~0xf);
-       *--(*psp) = (unsigned long)cookie;
-       *--(*psp) = (unsigned long)entry;
-       *--(*psp) = (unsigned long)imask;
-       *--(*psp) = (unsigned long)thread;
+       *--(*psp) = (unsigned long)tcb;
        *--(*psp) = 0;
 }
 
+#define thread_prologue                do { } while (0)
+
 #else /* CONFIG_X86_64 */
 
 struct xnarch_x8664_initstack {
@@ -210,26 +200,19 @@ struct xnarch_x8664_initstack {
                             : "memory", "cc" __SWITCH_CLOBBER_LIST);   \
        })
 
-asmlinkage void __thread_head(void);
+#define thread_prologue                                                        
\
+asm volatile(".globl __thread_prologue\n\t"                            \
+              "__thread_prologue:\n\t"                                 \
+              init_kernel_canary                                       \
+              "popq    %%rbp\n\t"                                      \
+              "popfq\n\t"                                              \
+              "popq    %%rdi\n\t"                                      \
+              "ret\n\t"                                                \
+              : init_canary_oparam                                     \
+              : /* no input */                                         \
+              : "cc", "memory" __HEAD_CLOBBER_LIST)
 
-asmlinkage void thread_trampoline(struct xnarchtcb *tcb)
-{
-       /* xnpod_welcome_thread() will do clts() if needed. */
-       stts();
-       xnpod_welcome_thread(tcb->self, tcb->imask);
-       tcb->entry(tcb->cookie);
-       xnpod_delete_thread(tcb->self);
-       asm volatile(".globl __thread_head\n\t"                         \
-                    "__thread_head:\n\t"                               \
-                    init_kernel_canary                                 \
-                    "popq      %%rbp\n\t"                              \
-                    "popfq\n\t"                                        \
-                    "popq      %%rdi\n\t"                              \
-                    "ret\n\t"                                          \
-                    : init_canary_oparam                               \
-                    : /* no input */                                   \
-                    : "cc", "memory" __HEAD_CLOBBER_LIST);
-}
+asmlinkage void __thread_prologue(void);
 
 void xnarch_init_thread(struct xnarchtcb *tcb,
                        void (*entry)(void *), void *cookie,
@@ -254,8 +237,8 @@ void xnarch_init_thread(struct xnarchtcb *tcb,
        tcb->canary = (unsigned long)xnclock_read_raw() ^ childregs->arg;
        childregs->canary = tcb->canary;
 #endif
-       tcb->rsp = (unsigned long)childregs;
-       tcb->rip = (unsigned long)&__thread_head; /* Will branch there at 
startup. */
+       tcb->sp = (unsigned long)childregs;
+       tcb->ip = (unsigned long)__thread_prologue; /* Will branch there at 
startup. */
        tcb->entry = entry;
        tcb->cookie = cookie;
        tcb->self = thread;
@@ -265,6 +248,16 @@ void xnarch_init_thread(struct xnarchtcb *tcb,
 
 #endif /* CONFIG_X86_64 */
 
+asmlinkage static void thread_trampoline(struct xnarchtcb *tcb)
+{
+       /* xnpod_welcome_thread() will do clts() if needed. */
+       stts();
+       xnpod_welcome_thread(tcb->self, tcb->imask);
+       tcb->entry(tcb->cookie);
+       xnpod_delete_thread(tcb->self);
+       thread_prologue;
+}
+
 void xnarch_leave_root(struct xnarchtcb *rootcb)
 {
        ipipe_notify_root_preemption();
@@ -274,8 +267,8 @@ void xnarch_leave_root(struct xnarchtcb *rootcb)
        rootcb->ts_usedfpu = wrap_test_fpu_used(current) != 0;
        rootcb->cr0_ts = (read_cr0() & 8) != 0;
 #ifdef CONFIG_X86_64
-       rootcb->rspp = &current->thread.sp;
-       rootcb->ripp = &current->thread.rip;
+       rootcb->spp = &current->thread.sp;
+       rootcb->ipp = &current->thread.rip;
 #endif
        /* So that xnarch_save_fpu() will operate on the right FPU area. */
        if (rootcb->cr0_ts || rootcb->ts_usedfpu)
@@ -335,8 +328,8 @@ void xnarch_switch_to(struct xnarchtcb *out_tcb, struct 
xnarchtcb *in_tcb)
        }
 #else /* CONFIG_X86_64 */
        do_switch_threads(prev, next,
-                         out_tcb->rspp, in_tcb->rspp,
-                         out_tcb->ripp, in_tcb->ripp,
+                         out_tcb->spp, in_tcb->spp,
+                         out_tcb->ipp, in_tcb->ipp,
                          switch_canary(in_tcb));
 #endif /* CONFIG_X86_64 */
 
@@ -534,14 +527,9 @@ void xnarch_init_root_tcb(struct xnarchtcb *tcb,
 {
        tcb->user_task = current;
        tcb->active_task = NULL;
-#ifdef CONFIG_X86_32
-       tcb->esp = 0;
-       tcb->espp = &tcb->esp;
-       tcb->eipp = &tcb->eip;
-#else
-       tcb->rspp = &tcb->rsp;
-       tcb->ripp = &tcb->rip;
-#endif
+       tcb->sp = 0;
+       tcb->spp = &tcb->sp;
+       tcb->ipp = &tcb->ip;
        tcb->fpup = NULL;
        tcb->entry = NULL;
        tcb->cookie = NULL;
@@ -559,13 +547,12 @@ void xnarch_init_shadow_tcb(struct xnarchtcb *tcb,
 
        tcb->user_task = task;
        tcb->active_task = NULL;
+       tcb->sp = 0;
+       tcb->spp = &task->thread.sp;
 #ifdef CONFIG_X86_32
-       tcb->esp = 0;
-       tcb->espp = &task->thread.sp;
-       tcb->eipp = &task->thread.ip;
+       tcb->ipp = &task->thread.ip;
 #else
-       tcb->rspp = &task->thread.sp;
-       tcb->ripp = &task->thread.rip; /* <!> raw naming intended. */
+       tcb->ipp = &task->thread.rip; /* <!> raw naming intended. */
 #endif
        tcb->fpup = x86_fpustate_ptr(&task->thread);
        tcb->entry = NULL;
@@ -579,14 +566,9 @@ void xnarch_init_tcb(struct xnarchtcb *tcb)
 {
        tcb->user_task = NULL;
        tcb->active_task = NULL;
-#ifdef CONFIG_X86_32
-       tcb->espp = &tcb->esp;
-       tcb->eipp = &tcb->eip;
-#else
-       tcb->rspp = &tcb->rsp;
-       tcb->ripp = &tcb->rip;
-       tcb->mayday.eip = 0;
-#endif
+       tcb->spp = &tcb->sp;
+       tcb->ipp = &tcb->ip;
+       tcb->mayday.ip = 0;
        tcb->fpup = &tcb->i387;
        tcb->is_root = 0;
 }


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to