Module: xenomai-rpm
Branch: queue/mayday
Commit: 5fb1ac89b0170cc153b54e7fb6884bb5f63db6dd
URL:    
http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=5fb1ac89b0170cc153b54e7fb6884bb5f63db6dd

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Jun  6 16:25:36 2010 +0200

x86: enable MAYDAY support

---

 include/asm-x86/bits/shadow_32.h |  111 ++++++++++++++++++++++++++++++++++++++
 include/asm-x86/bits/shadow_64.h |   71 ++++++++++++++++++++++++
 include/asm-x86/system_32.h      |    7 +++
 include/asm-x86/system_64.h      |    7 +++
 4 files changed, 196 insertions(+), 0 deletions(-)

diff --git a/include/asm-x86/bits/shadow_32.h b/include/asm-x86/bits/shadow_32.h
index 9fc37a2..40ccc62 100644
--- a/include/asm-x86/bits/shadow_32.h
+++ b/include/asm-x86/bits/shadow_32.h
@@ -49,4 +49,115 @@ static void xnarch_schedule_tail(struct task_struct *prev)
        wrap_switch_iobitmap(prev, rthal_processor_id());
 }
 
+#ifdef XNARCH_HAVE_MAYDAY
+
+static inline void xnarch_setup_mayday_page(void *page)
+{
+       /*
+        * We want this code to appear at the top of the MAYDAY page:
+        *
+        *      b8 2b 02 00 0c          mov    $<mux_code>,%eax
+        *      bd 00 00 00 00          mov    $0x0,%ebp
+        * if HAVE_SEP
+        *      65 ff 15 10 00 00 00    call   *%gs:0x10
+        * else
+        *      cd 80                   int    $0x80
+        * endif
+        *      0f 0b                   ud2a
+        *
+        * We intentionally don't mess with EFLAGS here, so that we
+        * don't have to save/restore it in handle/fixup code.
+        *
+        * Also note that if SEP is present, we always assume NPTL on
+        * the user side.
+        */
+       static const struct {
+               struct __attribute__ ((__packed__)) {
+                       u8 op;
+                       u32 imm;
+               } mov_eax;
+               struct __attribute__ ((__packed__)) {
+                       u8 op;
+                       u32 imm;
+               } mov_ebp;
+               struct __attribute__ ((__packed__)) {
+                       u8 op[3];
+                       u32 moffs;
+               } syscall;
+               u16 bug;
+       } code_sep = {
+               .mov_eax = {
+                       .op = 0xb8,
+                       .imm = __xn_mux_code(0, __xn_sys_mayday)
+               },
+               .mov_ebp = {
+                       .op = 0xbd,
+                       .imm = 0
+               },
+               .syscall = {
+                       .op = {
+                               0x65, 0xff, 0x15
+                       },
+                       .moffs = 0x10
+               },
+               .bug = 0x0b0f,
+       };
+
+       static const struct {
+               struct __attribute__ ((__packed__)) {
+                       u8 op;
+                       u32 imm;
+               } mov_eax;
+               struct __attribute__ ((__packed__)) {
+                       u8 op;
+                       u32 imm;
+               } mov_ebp;
+               u16 syscall;
+               u16 bug;
+       } code_nosep = {
+               .mov_eax = {
+                       .op = 0xb8,
+                       .imm = __xn_mux_code(0, __xn_sys_mayday)
+               },
+               .mov_ebp = {
+                       .op = 0xbd,
+                       .imm = 0
+               },
+               .syscall = 0x80cd,
+               .bug = 0x0b0f,
+       };
+
+       if (cpu_has_sep)
+               memcpy(page, &code_sep, sizeof(code_sep));
+       else
+               memcpy(page, &code_nosep, sizeof(code_nosep));
+
+       /* no cache flush required. */
+}
+
+static inline void xnarch_call_mayday(void)
+{
+       rthal_return_intercept(current);
+}
+
+static inline void xnarch_handle_mayday(struct xnarchtcb *tcb,
+                                       struct pt_regs *regs,
+                                       unsigned long tramp)
+{
+       tcb->mayday.eip = regs->x86reg_ip;
+       tcb->mayday.eax = regs->x86reg_ax;
+       tcb->mayday.ebp = regs->x86reg_bp;
+       regs->x86reg_ip = tramp;
+}
+
+static inline void xnarch_fixup_mayday(struct xnarchtcb *tcb,
+                                      struct pt_regs *regs)
+{
+       regs->x86reg_ip = tcb->mayday.eip;
+       regs->x86reg_ax = tcb->mayday.eax;
+       regs->x86reg_bp = tcb->mayday.ebp;
+}
+
+#endif /* XNARCH_HAVE_MAYDAY */
+
 #endif /* !_XENO_ASM_X86_BITS_SHADOW_32_H */
diff --git a/include/asm-x86/bits/shadow_64.h b/include/asm-x86/bits/shadow_64.h
index ddaa86a..41a266f 100644
--- a/include/asm-x86/bits/shadow_64.h
+++ b/include/asm-x86/bits/shadow_64.h
@@ -52,4 +52,75 @@ static void xnarch_schedule_tail(struct task_struct *prev)
 {
 }
 
+#ifdef XNARCH_HAVE_MAYDAY
+
+static inline void xnarch_setup_mayday_page(void *page)
+{
+       /*
+        * We want this code to appear at the top of the MAYDAY page:
+        *
+        *      b8 2b 02 00 0c          mov    $<mux_code>,%eax
+        *      49 c7 c1 00 00 00 00    mov    $0x0,%r9
+        *      0f 05                   syscall
+        *      0f 0b                   ud2a
+        *
+        * We intentionally don't mess with EFLAGS here, so that we
+        * don't have to save/restore it in handle/fixup code.
+        */
+       static const struct {
+               struct __attribute__ ((__packed__)) {
+                       u8 op;
+                       u32 imm;
+               } mov_eax;
+               struct __attribute__ ((__packed__)) {
+                       u8 op[3];
+                       u32 imm;
+               } mov_r9;
+               u16 syscall;
+               u16 bug;
+       } code = {
+               .mov_eax = {
+                       .op = 0xb8,
+                       .imm = __xn_mux_code(0, __xn_sys_mayday)
+               },
+               .mov_r9 = {
+                       .op = {
+                               0x49, 0xc7, 0xc1
+                       },
+                       .imm = 0
+               },
+               .syscall = 0x050f,
+               .bug = 0x0b0f,
+       };
+
+       memcpy(page, &code, sizeof(code));
+
+       /* no cache flush required. */
+}
+
+static inline void xnarch_call_mayday(void)
+{
+       rthal_return_intercept(current);
+}
+
+static inline void xnarch_handle_mayday(struct xnarchtcb *tcb,
+                                       struct pt_regs *regs,
+                                       unsigned long tramp)
+{
+       tcb->mayday.eip = regs->x86reg_ip;
+       tcb->mayday.eax = regs->x86reg_ax;
+       tcb->mayday.r9 = regs->r9;
+       regs->x86reg_ip = tramp;
+}
+
+static inline void xnarch_fixup_mayday(struct xnarchtcb *tcb,
+                                      struct pt_regs *regs)
+{
+       regs->x86reg_ip = tcb->mayday.eip;
+       regs->x86reg_ax = tcb->mayday.eax;
+       regs->r9 = tcb->mayday.r9;
+}
+
+#endif /* XNARCH_HAVE_MAYDAY */
+
 #endif /* !_XENO_ASM_X86_BITS_SHADOW_64_H */
diff --git a/include/asm-x86/system_32.h b/include/asm-x86/system_32.h
index d15aff0..efefe9b 100644
--- a/include/asm-x86/system_32.h
+++ b/include/asm-x86/system_32.h
@@ -48,6 +48,13 @@ typedef struct xnarchtcb {      /* Per-thread arch-dependent 
block */
     unsigned long *stackbase;   /* Stack space */
     unsigned long esp;          /* Saved ESP for kernel-based threads */
     unsigned long eip;          /* Saved EIP for kernel-based threads */
+#ifdef XNARCH_HAVE_MAYDAY
+       struct {
+               unsigned long eip;
+               unsigned long eax;
+               unsigned long ebp;
+       } mayday;
+#endif
 
     /* User mode side */
     struct task_struct *user_task;      /* Shadowed user-space task */
diff --git a/include/asm-x86/system_64.h b/include/asm-x86/system_64.h
index 4de8693..26d7fe5 100644
--- a/include/asm-x86/system_64.h
+++ b/include/asm-x86/system_64.h
@@ -47,6 +47,13 @@ typedef struct xnarchtcb {      /* Per-thread arch-dependent 
block */
        struct task_struct *user_task; /* Shadowed user-space task */
        struct task_struct *active_task; /* Active user-space task */
        x86_fpustate *fpup;     /* &i387 or &user->thread.i387 */
+#ifdef XNARCH_HAVE_MAYDAY
+       struct {
+               unsigned long eip;
+               unsigned long eax;
+               unsigned long r9;
+       } mayday;
+#endif
 
        /* Private context for kernel threads. */
        x86_fpustate i387;


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to