Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / all-freebsd / exec / sigcore.h
blob93af3986bbe1722c2eaf3cdbf1bd73bd9da85e14
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #ifndef _SIGCORE_H
7 #define _SIGCORE_H
9 #include <machine/psl.h>
10 #include <sys/types.h>
11 #include <sys/param.h>
12 #include <ucontext.h>
13 #include <signal.h>
14 #include <errno.h>
15 #include "etask.h"
17 /* Put a value of type SP_TYPE on the stack or get it off the stack. */
18 #define _PUSH(sp,val) \
19 do { \
20 SP_TYPE **stackp = (sp); \
21 --*stackp; \
22 **stackp = (SP_TYPE)(val); \
23 } while (0)
24 #define _POP(sp) (*sp++)
26 typedef struct sigcontext sigcontext_t;
27 #define SIGHANDLER bsd_sighandler
28 #define SIGHANDLER_T __sighandler_t *
30 #define SP_TYPE long
31 #define CPU_NUMREGS 0
33 #define SC_DISABLE(sc) (sc->sc_mask = sig_int_mask)
34 #define SC_ENABLE(sc) (sigemptyset(&sc->sc_mask))
36 #define SP(sc) (sc->sc_esp)
37 #define FP(sc) (sc->sc_ebp)
38 #define PC(sc) (sc->sc_eip)
40 #define R0(sc) (sc->sc_eax)
41 #define R1(sc) (sc->sc_ebx)
42 #define R2(sc) (sc->sc_ecx)
43 #define R3(sc) (sc->sc_edx)
44 #define R4(sc) (sc->sc_edi)
45 #define R5(sc) (sc->sc_esi)
46 #define R6(sc) (sc->sc_isp)
49 * We can't have an #ifdef based on FreeBSD here because this structure
50 * is (wrongly) accessed from rom/exec.
52 struct AROS_cpu_context
54 ULONG regs[9]; /* eax, ebx, ecx, edx, edi, esi, isp, fp, pc */
55 int errno_backup;
56 union
58 struct
60 int fpformat;
61 int ownedfp;
62 int fpstate[128] __attribute__ ((aligned (16)));
64 acc_f5;
66 struct
68 int fpstate[17];
70 acc_f4;
72 acc_u;
74 int eflags;
75 struct AROS_cpu_context *sc;
78 #undef SIZEOF_ALL_REGISTERS
79 #define SIZEOF_ALL_REGISTERS (sizeof(struct AROS_cpu_context))
80 #define GetCpuContext(task) ((struct AROS_cpu_context *)\
81 (GetIntETask(task)->iet_Context))
82 #define GetSP(task) ((SP_TYPE **)(&task->tc_SPReg))
84 #define GLOBAL_SIGNAL_INIT \
85 static void sighandler (int sig, sigcontext_t * sc); \
87 static void SIGHANDLER (int sig, int code, struct sigcontext *sc) \
88 { \
89 sighandler( sig, (sigcontext_t*)sc); \
92 #define SAVE_CPU(cc,sc) \
93 do { \
94 (cc)->regs[0] = R0(sc); \
95 (cc)->regs[1] = R1(sc); \
96 (cc)->regs[2] = R2(sc); \
97 (cc)->regs[3] = R3(sc); \
98 (cc)->regs[4] = R4(sc); \
99 (cc)->regs[5] = R5(sc); \
100 (cc)->regs[6] = R6(sc); \
101 (cc)->regs[7] = FP(sc); \
102 (cc)->regs[8] = PC(sc); \
103 } while (0)
105 #define RESTORE_CPU(cc,sc) \
106 do { \
107 R0(sc) = (cc)->regs[0]; \
108 R1(sc) = (cc)->regs[1]; \
109 R2(sc) = (cc)->regs[2]; \
110 R3(sc) = (cc)->regs[3]; \
111 R4(sc) = (cc)->regs[4]; \
112 R5(sc) = (cc)->regs[5]; \
113 R6(sc) = (cc)->regs[6]; \
114 FP(sc) = (cc)->regs[7]; \
115 PC(sc) = (cc)->regs[8]; \
116 } while (0)
118 #define SAVE_ERRNO(cc) \
119 do { \
120 (cc)->errno_backup = errno; \
121 } while (0)
123 #define RESTORE_ERRNO(cc) \
124 do { \
125 errno = (cc)->errno_backup; \
126 } while (0)
128 #ifndef NO_FPU
130 # if __FreeBSD_version >= 500001
132 * This is the FreeBSD 5.x and higher version
134 # define SAVE_FPU(cc,sc) \
135 do { \
136 int i_; \
137 (cc)->acc_u.acc_f5.fpformat = (sc)->sc_fpformat; \
138 (cc)->acc_u.acc_f5.ownedfp = (sc)->sc_ownedfp; \
139 for(i_ = 0; i_ < 128; ++i_) \
140 (cc)->acc_u.acc_f5.fpstate[i_] = (sc)->sc_fpstate[i_]; \
141 } while (0)
143 # define RESTORE_FPU(cc,sc) \
144 do { \
145 int i_; \
146 (sc)->sc_fpformat = (cc)->acc_u.acc_f5.fpformat; \
147 (sc)->sc_ownedfp = (cc)->acc_u.acc_f5.ownedfp; \
148 for(i_ = 0; i_ < 128; ++i_) \
149 (sc)->sc_fpstate[i_] = (cc)->acc_u.acc_f5.fpstate[i_]; \
150 } while (0)
152 # define HAS_FPU(sc) \
154 ((sc)->sc_ownedfp != _MC_FPOWNED_NONE) \
155 && \
156 ((sc)->sc_fpformat != _MC_FPFMT_NODEV) \
159 # define PREPARE_FPU(cc) \
160 do { \
161 (cc)->acc_u.acc_f5.fpformat = _MC_FPFMT_NODEV; \
162 (cc)->acc_u.acc_f5.ownedfp = _MC_FPOWNED_NONE; \
163 } while (0)
165 # else
168 * FreeBSD 4 and below have a different context format.
170 # define SAVE_FPU(cc,sc) \
171 do { \
172 int i_; \
173 for (i_ = 0; i_ < 28; i_++) \
174 (cc)->acc_u.acc_f4.fpstate[i_] = (sc)->sc_fpregs[i_]; \
175 } while (0)
177 # define RESTORE_FPU(cc,sc) \
178 do { \
179 int i_; \
180 for (i_ = 0; i_ < 28; i_++) \
181 (sc)->sc_fpregs[i_] = (cc)->acc_u.acc_f4.fpstate[i_]; \
182 } while (0)
184 # define HAS_FPU(sc) 0
186 # define PREPARE_FPU(cc) \
187 do { \
188 asm volatile("fninit\n\t" \
189 "fnsave %0\n\t" \
190 "fwait" : "=m" ((cc)->acc_u.acc_f4.fpstate) \
191 ); \
192 } while (0)
194 # endif
196 #else
197 /* NO FPU VERSION */
199 # define SAVE_FPU(cc,sc) \
200 do { \
201 } while (0)
203 # define RESTORE_FPU(cc,sc) \
204 do { \
205 } while (0)
207 # define HAS_FPU(sc) 0
209 # define PREPARE_FPU(cc) \
210 do { \
211 } while (0)
213 #endif
215 #define SETUP_EXCEPTION(sc,arg) \
216 do { \
217 _PUSH(GetSP(SysBase->ThisTask), arg); \
218 _PUSH(GetSP(SysBase->ThisTask), arg); \
219 } while (0)
221 #define PREPARE_INITIAL_FRAME(sp,startpc) \
222 do { \
223 GetCpuContext(task)->regs[7] = 0; \
224 GetCpuContext(task)->regs[8] = (startpc); \
225 } while (0)
227 #define PREPARE_INITIAL_CONTEXT(task,startpc) \
228 do { \
229 PREPARE_FPU(GetCpuContext(task)); \
230 } while (0)
232 #define SAVEREGS(task,sc) \
233 do { \
234 struct AROS_cpu_context *cc = GetCpuContext(task); \
235 SP_TYPE **sp = GetSP(task); \
236 *sp = (SP_TYPE *)SP(sc); \
237 if (HAS_FPU(sc)) \
238 SAVE_FPU(cc,sc); \
239 SAVE_CPU(cc,sc); \
240 SAVE_ERRNO(cc); \
241 cc->eflags = sc->sc_efl & PSL_USERCHANGE; \
242 } while (0)
244 #define RESTOREREGS(task,sc) \
245 do { \
246 struct AROS_cpu_context *cc = GetCpuContext(task); \
247 SP_TYPE **sp; \
248 RESTORE_ERRNO(cc); \
249 RESTORE_CPU(cc,sc); \
250 if (HAS_FPU(sc)) \
251 RESTORE_FPU(cc,sc); \
252 sp = GetSP(task); \
253 SP(sc) = (typeof(SP(sc))) *sp; \
254 sc->sc_efl = (sc->sc_efl & ~PSL_USERCHANGE) | cc->eflags; \
255 } while (0)
257 #define PRINT_SC(sc) \
258 printf (" SP=%08lx FP=%08lx PC=%08lx FPU=%s\n" \
259 " R0=%08lx R1=%08lx R2=%08lx R3=%08lx\n" \
260 " R4=%08lx R5=%08lx R6=%08lx\n" \
261 , SP(sc), FP(sc), PC(sc) \
262 , HAS_FPU(sc) ? "yes" : "no" \
263 , R0(sc), R1(sc), R2(sc), R3(sc) \
264 , R4(sc), R5(sc), R6(sc) \
267 #define PRINT_CPUCONTEXT(task) \
268 printf (" SP=%08lx FP=%08lx PC=%08lx\n" \
269 " R0=%08lx R1=%08lx R2=%08lx R3=%08lx\n" \
270 " R4=%08lx R5=%08lx R6=%08lx\n" \
271 , (ULONG)(*GetSP(task)) \
272 , GetCpuContext(task)->fp, \
273 , GetCpuContext(task)->pc, \
274 , GetCpuContext(task)->regs[0] \
275 , GetCpuContext(task)->regs[1] \
276 , GetCpuContext(task)->regs[2] \
277 , GetCpuContext(task)->regs[3] \
278 , GetCpuContext(task)->regs[4] \
279 , GetCpuContext(task)->regs[5] \
280 , GetCpuContext(task)->regs[6] \
283 #endif /* _SIGCORE_H */