Xenomai  3.0-rc7
thread.h
1 /*
2  * Copyright (C) 2005 Stelian Pop
3  *
4  * Xenomai is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Xenomai is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Xenomai; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 #ifndef _COBALT_ARM_ASM_THREAD_H
20 #define _COBALT_ARM_ASM_THREAD_H
21 
22 #include <asm-generic/xenomai/thread.h>
23 
24 #ifdef CONFIG_XENO_ARCH_FPU
25 #ifdef CONFIG_VFP
26 #include <asm/vfp.h>
27 #endif /* CONFIG_VFP */
28 #endif /* !CONFIG_XENO_ARCH_FPU */
29 
30 struct xnarchtcb {
31  struct xntcb core;
32 #ifdef CONFIG_XENO_ARCH_FPU
33 #ifdef CONFIG_VFP
34  union vfp_state *fpup;
35 #define xnarch_fpu_ptr(tcb) ((tcb)->fpup)
36 #else
37 #define xnarch_fpu_ptr(tcb) NULL
38 #endif
39 #endif
40  struct {
41  unsigned long pc;
42  unsigned long r0;
43 #ifdef __ARM_EABI__
44  unsigned long r7;
45 #endif
46 #ifdef CONFIG_ARM_THUMB
47  unsigned long psr;
48 #endif
49  } mayday;
50 };
51 
52 #define xnarch_fault_regs(d) ((d)->regs)
53 #define xnarch_fault_trap(d) ((d)->exception)
54 #define xnarch_fault_code(d) (0)
55 #define xnarch_fault_pc(d) ((d)->regs->ARM_pc - (thumb_mode((d)->regs) ? 2 : 4)) /* XXX ? */
56 
57 #define xnarch_fault_pf_p(d) ((d)->exception == IPIPE_TRAP_ACCESS)
58 #define xnarch_fault_bp_p(d) ((current->ptrace & PT_PTRACED) && \
59  ((d)->exception == IPIPE_TRAP_BREAK || \
60  (d)->exception == IPIPE_TRAP_UNDEFINSTR))
61 
62 #define xnarch_fault_notify(d) (!xnarch_fault_bp_p(d))
63 
64 void xnarch_switch_to(struct xnthread *out, struct xnthread *in);
65 
66 static inline void xnarch_enter_root(struct xnthread *root) { }
67 
68 int xnarch_escalate(void);
69 
70 #if defined(CONFIG_XENO_ARCH_FPU) && defined(CONFIG_VFP)
71 
72 static inline void xnarch_init_root_tcb(struct xnthread *thread)
73 {
74  struct xnarchtcb *tcb = xnthread_archtcb(thread);
75  tcb->fpup = NULL;
76 }
77 
78 void xnarch_init_shadow_tcb(struct xnthread *thread);
79 
80 int xnarch_fault_fpu_p(struct ipipe_trap_data *d);
81 
82 void xnarch_leave_root(struct xnthread *root);
83 
84 void xnarch_save_fpu(struct xnthread *thread);
85 
86 void xnarch_switch_fpu(struct xnthread *from, struct xnthread *thread);
87 
88 int xnarch_handle_fpu_fault(struct xnthread *from,
89  struct xnthread *to, struct ipipe_trap_data *d);
90 
91 #else /* !CONFIG_XENO_ARCH_FPU || !CONFIG_VFP */
92 
93 static inline void xnarch_init_root_tcb(struct xnthread *thread) { }
94 static inline void xnarch_init_shadow_tcb(struct xnthread *thread) { }
95 
96 /*
97  * Userland may raise FPU faults with FPU-enabled kernels, regardless
98  * of whether real-time threads actually use FPU, so we simply ignore
99  * these faults.
100  */
101 static inline int xnarch_fault_fpu_p(struct ipipe_trap_data *d)
102 {
103  return 0;
104 }
105 
106 static inline void xnarch_leave_root(struct xnthread *root) { }
107 
108 static inline void xnarch_save_fpu(struct xnthread *thread) { }
109 
110 static inline void xnarch_switch_fpu(struct xnthread *f, struct xnthread *t) { }
111 
112 static inline int xnarch_handle_fpu_fault(struct xnthread *from,
113  struct xnthread *to, struct ipipe_trap_data *d)
114 {
115  return 0;
116 }
117 #endif /* !CONFIG_XENO_ARCH_FPU || !CONFIG_VFP */
118 
119 static inline void xnarch_enable_kfpu(void) { }
120 
121 static inline void xnarch_disable_kfpu(void) { }
122 
123 #endif /* !_COBALT_ARM_ASM_THREAD_H */