added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / all-freebsd / exec / sigcore.h
blob5b4f3aef9906a7564963b928990fa7b42ead76e8
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) (*--sp = (SP_TYPE)(val))
19 #define _POP(sp) (*sp++)
21 typedef struct sigcontext sigcontext_t;
22 #define SIGHANDLER bsd_sighandler
23 #define SIGHANDLER_T __sighandler_t *
25 #define SP_TYPE long
26 #define CPU_NUMREGS 0
28 #define SC_DISABLE(sc) (sc->sc_mask = sig_int_mask)
29 #define SC_ENABLE(sc) (sigemptyset(&sc->sc_mask))
31 #define SP(sc) (sc->sc_esp)
32 #define FP(sc) (sc->sc_ebp)
33 #define PC(sc) (sc->sc_eip)
35 #define R0(sc) (sc->sc_eax)
36 #define R1(sc) (sc->sc_ebx)
37 #define R2(sc) (sc->sc_ecx)
38 #define R3(sc) (sc->sc_edx)
39 #define R4(sc) (sc->sc_edi)
40 #define R5(sc) (sc->sc_esi)
41 #define R6(sc) (sc->sc_isp)
44 * We can't have an #ifdef based on FreeBSD here because this structure
45 * is (wrongly) accessed from rom/exec.
47 struct AROS_cpu_context
49 ULONG regs[9]; /* eax, ebx, ecx, edx, edi, esi, isp, fp, pc */
50 int errno_backup;
51 union
53 struct
55 int fpformat;
56 int ownedfp;
57 int fpstate[128] __attribute__ ((aligned (16)));
59 acc_f5;
61 struct
63 int fpstate[17];
65 acc_f4;
67 acc_u;
69 int eflags;
72 #define SIZEOF_ALL_REGISTERS (sizeof(struct AROS_cpu_context))
73 #define GetCpuContext(task) ((struct AROS_cpu_context *)\
74 (GetIntETask(task)->iet_Context))
75 #define GetSP(task) (*(SP_TYPE **)(&task->tc_SPReg))
77 #define GLOBAL_SIGNAL_INIT \
78 static void sighandler (int sig, sigcontext_t * sc); \
80 static void SIGHANDLER (int sig, int code, struct sigcontext *sc) \
81 { \
82 sighandler( sig, (sigcontext_t*)sc); \
85 #define SAVE_CPU(cc,sc) \
86 do { \
87 (cc)->regs[0] = R0(sc); \
88 (cc)->regs[1] = R1(sc); \
89 (cc)->regs[2] = R2(sc); \
90 (cc)->regs[3] = R3(sc); \
91 (cc)->regs[4] = R4(sc); \
92 (cc)->regs[5] = R5(sc); \
93 (cc)->regs[6] = R6(sc); \
94 (cc)->regs[7] = FP(sc); \
95 (cc)->regs[8] = PC(sc); \
96 } while (0)
98 #define RESTORE_CPU(cc,sc) \
99 do { \
100 R0(sc) = (cc)->regs[0]; \
101 R1(sc) = (cc)->regs[1]; \
102 R2(sc) = (cc)->regs[2]; \
103 R3(sc) = (cc)->regs[3]; \
104 R4(sc) = (cc)->regs[4]; \
105 R5(sc) = (cc)->regs[5]; \
106 R6(sc) = (cc)->regs[6]; \
107 FP(sc) = (cc)->regs[7]; \
108 PC(sc) = (cc)->regs[8]; \
109 } while (0)
111 #define SAVE_ERRNO(cc) \
112 do { \
113 (cc)->errno_backup = errno; \
114 } while (0)
116 #define RESTORE_ERRNO(cc) \
117 do { \
118 errno = (cc)->errno_backup; \
119 } while (0)
121 #ifndef NO_FPU
123 # if __FreeBSD_version >= 500001
125 * This is the FreeBSD 5.x and higher version
127 # define SAVE_FPU(cc,sc) \
128 do { \
129 int i_; \
130 (cc)->acc_u.acc_f5.fpformat = (sc)->sc_fpformat; \
131 (cc)->acc_u.acc_f5.ownedfp = (sc)->sc_ownedfp; \
132 for(i_ = 0; i_ < 128; ++i_) \
133 (cc)->acc_u.acc_f5.fpstate[i_] = (sc)->sc_fpstate[i_]; \
134 } while (0)
136 # define RESTORE_FPU(cc,sc) \
137 do { \
138 int i_; \
139 (sc)->sc_fpformat = (cc)->acc_u.acc_f5.fpformat; \
140 (sc)->sc_ownedfp = (cc)->acc_u.acc_f5.ownedfp; \
141 for(i_ = 0; i_ < 128; ++i_) \
142 (sc)->sc_fpstate[i_] = (cc)->acc_u.acc_f5.fpstate[i_]; \
143 } while (0)
145 # define HAS_FPU(sc) \
147 ((sc)->sc_ownedfp != _MC_FPOWNED_NONE) \
148 && \
149 ((sc)->sc_fpformat != _MC_FPFMT_NODEV) \
152 # define PREPARE_FPU(cc) \
153 do { \
154 (cc)->acc_u.acc_f5.fpformat = _MC_FPFMT_NODEV; \
155 (cc)->acc_u.acc_f5.ownedfp = _MC_FPOWNED_NONE; \
156 } while (0)
158 # else
161 * FreeBSD 4 and below have a different context format.
163 # define SAVE_FPU(cc,sc) \
164 do { \
165 int i_; \
166 for (i_ = 0; i_ < 28; i_++) \
167 (cc)->acc_u.acc_f4.fpstate[i_] = (sc)->sc_fpregs[i_]; \
168 } while (0)
170 # define RESTORE_FPU(cc,sc) \
171 do { \
172 int i_; \
173 for (i_ = 0; i_ < 28; i_++) \
174 (sc)->sc_fpregs[i_] = (cc)->acc_u.acc_f4.fpstate[i_]; \
175 } while (0)
177 # define HAS_FPU(sc) 0
179 # define PREPARE_FPU(cc) \
180 do { \
181 asm volatile("fninit\n\t" \
182 "fnsave %0\n\t" \
183 "fwait" : "=m" ((cc)->acc_u.acc_f4.fpstate) \
184 ); \
185 } while (0)
187 # endif
189 #else
190 /* NO FPU VERSION */
192 # define SAVE_FPU(cc,sc) \
193 do { \
194 } while (0)
196 # define RESTORE_FPU(cc,sc) \
197 do { \
198 } while (0)
200 # define HAS_FPU(sc) 0
202 # define PREPARE_FPU(cc) \
203 do { \
204 } while (0)
206 #endif
208 #define PREPARE_INITIAL_FRAME(sp,startpc) \
209 do { \
210 GetCpuContext(task)->regs[7] = 0; \
211 GetCpuContext(task)->regs[8] = (startpc); \
212 } while (0)
214 #define PREPARE_INITIAL_CONTEXT(task,startpc) \
215 do { \
216 PREPARE_FPU(GetCpuContext(task)); \
217 } while (0)
219 #define SAVEREGS(task,sc) \
220 do { \
221 struct AROS_cpu_context *cc = GetCpuContext(task); \
222 GetSP(task) = (SP_TYPE *)SP(sc); \
223 if (HAS_FPU(sc)) \
224 SAVE_FPU(cc,sc); \
225 SAVE_CPU(cc,sc); \
226 SAVE_ERRNO(cc); \
227 cc->eflags = sc->sc_efl & PSL_USERCHANGE; \
228 } while (0)
230 #define RESTOREREGS(task,sc) \
231 do { \
232 struct AROS_cpu_context *cc = GetCpuContext(task); \
233 RESTORE_ERRNO(cc); \
234 RESTORE_CPU(cc,sc); \
235 if (HAS_FPU(sc)) \
236 RESTORE_FPU(cc,sc); \
237 SP(sc) = (SP_TYPE *)GetSP(task); \
238 sc->sc_efl = (sc->sc_efl & ~PSL_USERCHANGE) | cc->eflags; \
239 } while (0)
241 #define PRINT_SC(sc) \
242 printf (" SP=%08lx FP=%08lx PC=%08lx FPU=%s\n" \
243 " R0=%08lx R1=%08lx R2=%08lx R3=%08lx\n" \
244 " R4=%08lx R5=%08lx R6=%08lx\n" \
245 , SP(sc), FP(sc), PC(sc) \
246 , HAS_FPU(sc) ? "yes" : "no" \
247 , R0(sc), R1(sc), R2(sc), R3(sc) \
248 , R4(sc), R5(sc), R6(sc) \
251 #define PRINT_CPUCONTEXT(task) \
252 printf (" SP=%08lx FP=%08lx PC=%08lx\n" \
253 " R0=%08lx R1=%08lx R2=%08lx R3=%08lx\n" \
254 " R4=%08lx R5=%08lx R6=%08lx\n" \
255 , (ULONG)(GetSP(task)) \
256 , GetCpuContext(task)->fp, GetCpuContext(task)->pc, \
257 , GetCpuContext(task)->regs[0] \
258 , GetCpuContext(task)->regs[1] \
259 , GetCpuContext(task)->regs[2] \
260 , GetCpuContext(task)->regs[3] \
261 , GetCpuContext(task)->regs[4] \
262 , GetCpuContext(task)->regs[5] \
263 , GetCpuContext(task)->regs[6] \
266 #endif /* _SIGCORE_H */