make fat.handler build again with debug enabled
[tangerine.git] / arch / i386-darwin / sigcore.h
blobfbcaab4cb5c9e17f65ce790d140a95b2a83c716b
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 <sys/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 ucontext_t sigcontext_t;
23 #define SIGHANDLER bsd_sighandler
24 #define SIGHANDLER_T __sighandler_t *
26 #define SP_TYPE long
27 #define CPU_NUMREGS 0
29 #define SC_DISABLE(sc) (sc->sc_mask = sig_int_mask)
30 #define SC_ENABLE(sc) (sigemptyset(&sc->sc_mask))
32 /* this is from wine's dlls/ntdll/signal_i386.c, which is under lgpl */
34 /* work around silly renaming of struct members in OS X 10.5 */
35 #if __DARWIN_UNIX03 && defined(_STRUCT_X86_EXCEPTION_STATE32)
37 #define R0(context) ((context)->uc_mcontext->__ss.__eax)
38 #define R1(context) ((context)->uc_mcontext->__ss.__ebx)
39 #define R2(context) ((context)->uc_mcontext->__ss.__ecx)
40 #define R3(context) ((context)->uc_mcontext->__ss.__edx)
41 #define R4(context) ((context)->uc_mcontext->__ss.__edi)
42 #define R5(context) ((context)->uc_mcontext->__ss.__esi)
43 #define R6(context) ((context)->uc_mcontext->__ss.__eflags)
45 #define FP(context) ((context)->uc_mcontext->__ss.__ebp)
46 #define PC(context) ((context)->uc_mcontext->__ss.__eip))
47 #define SP(context) ((context)->uc_mcontext->__ss.__esp))
49 #define FPSTATE(context) ((context)->uc_mcontext->__fs)
51 #else
53 #define R0(context) ((context)->uc_mcontext->ss.eax)
54 #define R0(context) ((context)->uc_mcontext->ss.eax)
55 #define R1(context) ((context)->uc_mcontext->ss.ebx)
56 #define R2(context) ((context)->uc_mcontext->ss.ecx)
57 #define R3(context) ((context)->uc_mcontext->ss.edx)
58 #define R4(context) ((context)->uc_mcontext->ss.edi)
59 #define R5(context) ((context)->uc_mcontext->ss.esi)
60 #define R6(context) ((context)->uc_mcontext->ss.eflags)
62 #define FP(context) ((context)->uc_mcontext->ss.ebp)
63 #define PC(context) ((context)->uc_mcontext->ss.eip))
64 #define SP(context) ((context)->uc_mcontext->ss.esp))
66 #define FPSTATE(context) ((context)->uc_mcontext->fs)
68 #endif
71 * We can't have an #ifdef based on FreeBSD here because this structure
72 * is (wrongly) accessed from rom/exec.
74 struct AROS_cpu_context
76 ULONG regs[9]; /* eax, ebx, ecx, edx, edi, esi, isp, fp, pc */
77 int errno_backup;
78 _STRUCT_X86_FLOAT_STATE64 fpstate;
79 int eflags;
82 #define SIZEOF_ALL_REGISTERS (sizeof(struct AROS_cpu_context))
83 #define GetCpuContext(task) ((struct AROS_cpu_context *)\
84 (GetIntETask(task)->iet_Context))
85 #define GetSP(task) (*(SP_TYPE **)(&task->tc_SPReg))
87 #define GLOBAL_SIGNAL_INIT \
88 static void sighandler (int sig, sigcontext_t * sc); \
90 static void SIGHANDLER (int sig, int code, struct sigcontext *sc) \
91 { \
92 sighandler( sig, (sigcontext_t*)sc); \
95 #define SAVE_CPU(cc,sc) \
96 do { \
97 (cc)->regs[0] = R0(sc); \
98 (cc)->regs[1] = R1(sc); \
99 (cc)->regs[2] = R2(sc); \
100 (cc)->regs[3] = R3(sc); \
101 (cc)->regs[4] = R4(sc); \
102 (cc)->regs[5] = R5(sc); \
103 (cc)->regs[6] = R6(sc); \
104 (cc)->regs[7] = FP(sc); \
105 (cc)->regs[8] = PC(sc); \
106 } while (0)
108 #define RESTORE_CPU(cc,sc) \
109 do { \
110 R0(sc) = (cc)->regs[0]; \
111 R1(sc) = (cc)->regs[1]; \
112 R2(sc) = (cc)->regs[2]; \
113 R3(sc) = (cc)->regs[3]; \
114 R4(sc) = (cc)->regs[4]; \
115 R5(sc) = (cc)->regs[5]; \
116 R6(sc) = (cc)->regs[6]; \
117 FP(sc) = (cc)->regs[7]; \
118 PC(sc) = (cc)->regs[8]; \
119 } while (0)
121 #define SAVE_ERRNO(cc) \
122 do { \
123 (cc)->errno_backup = errno; \
124 } while (0)
126 #define RESTORE_ERRNO(cc) \
127 do { \
128 errno = (cc)->errno_backup; \
129 } while (0)
132 #ifndef NO_FPU
134 # define SAVE_FPU(cc,sc) \
135 do { \
136 (cc)->fpstate = FPSTATE(sc); \
137 } while (0)
139 # define RESTORE_FPU(cc,sc) \
140 do { \
141 FPSTATE(sc) = (cc)->fpstate; \
142 } while (0)
144 # define HAS_FPU(sc) 1
146 # define PREPARE_FPU(cc) \
147 do { \
148 } while (0)
150 #else
151 /* NO FPU VERSION */
153 # define SAVE_FPU(cc,sc) \
154 do { \
155 } while (0)
157 # define RESTORE_FPU(cc,sc) \
158 do { \
159 } while (0)
161 # define HAS_FPU(sc) 0
163 # define PREPARE_FPU(cc) \
164 do { \
165 } while (0)
167 #endif
169 #define PREPARE_INITIAL_FRAME(sp,startpc) \
170 do { \
171 GetCpuContext(task)->regs[7] = 0; \
172 GetCpuContext(task)->regs[8] = (startpc); \
173 } while (0)
175 #define PREPARE_INITIAL_CONTEXT(task,startpc) \
176 do { \
177 PREPARE_FPU(GetCpuContext(task)); \
178 } while (0)
180 #define SAVEREGS(task,sc) \
181 do { \
182 struct AROS_cpu_context *cc = GetCpuContext(task); \
183 GetSP(task) = (SP_TYPE *)SP(sc); \
184 if (HAS_FPU(sc)) \
185 SAVE_FPU(cc,sc); \
186 SAVE_CPU(cc,sc); \
187 SAVE_ERRNO(cc); \
188 } while (0)
190 #define RESTOREREGS(task,sc) \
191 do { \
192 struct AROS_cpu_context *cc = GetCpuContext(task); \
193 RESTORE_ERRNO(cc); \
194 RESTORE_CPU(cc,sc); \
195 if (HAS_FPU(sc)) \
196 RESTORE_FPU(cc,sc); \
197 SP(sc) = (SP_TYPE *)GetSP(task); \
198 } while (0)
200 #define PRINT_SC(sc) \
201 printf (" SP=%08lx FP=%08lx PC=%08lx FPU=%s\n" \
202 " R0=%08lx R1=%08lx R2=%08lx R3=%08lx\n" \
203 " R4=%08lx R5=%08lx R6=%08lx\n" \
204 , SP(sc), FP(sc), PC(sc) \
205 , HAS_FPU(sc) ? "yes" : "no" \
206 , R0(sc), R1(sc), R2(sc), R3(sc) \
207 , R4(sc), R5(sc), R6(sc) \
210 #define PRINT_CPUCONTEXT(task) \
211 printf (" SP=%08lx FP=%08lx PC=%08lx\n" \
212 " R0=%08lx R1=%08lx R2=%08lx R3=%08lx\n" \
213 " R4=%08lx R5=%08lx R6=%08lx\n" \
214 , (ULONG)(GetSP(task)) \
215 , GetCpuContext(task)->fp, GetCpuContext(task)->pc, \
216 , GetCpuContext(task)->regs[0] \
217 , GetCpuContext(task)->regs[1] \
218 , GetCpuContext(task)->regs[2] \
219 , GetCpuContext(task)->regs[3] \
220 , GetCpuContext(task)->regs[4] \
221 , GetCpuContext(task)->regs[5] \
222 , GetCpuContext(task)->regs[6] \
225 #endif /* _SIGCORE_H */