2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
9 #include <machine/psl.h>
10 #include <sys/types.h>
11 #include <sys/param.h>
12 #include <sys/ucontext.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 *
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)
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)
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 */
78 _STRUCT_X86_FLOAT_STATE64 fpstate
;
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) \
92 sighandler( sig, (sigcontext_t*)sc); \
95 #define SAVE_CPU(cc,sc) \
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); \
108 #define RESTORE_CPU(cc,sc) \
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]; \
121 #define SAVE_ERRNO(cc) \
123 (cc)->errno_backup = errno; \
126 #define RESTORE_ERRNO(cc) \
128 errno = (cc)->errno_backup; \
134 # define SAVE_FPU(cc,sc) \
136 (cc)->fpstate = FPSTATE(sc); \
139 # define RESTORE_FPU(cc,sc) \
141 FPSTATE(sc) = (cc)->fpstate; \
144 # define HAS_FPU(sc) 1
146 # define PREPARE_FPU(cc) \
153 # define SAVE_FPU(cc,sc) \
157 # define RESTORE_FPU(cc,sc) \
161 # define HAS_FPU(sc) 0
163 # define PREPARE_FPU(cc) \
169 #define PREPARE_INITIAL_FRAME(sp,startpc) \
171 GetCpuContext(task)->regs[7] = 0; \
172 GetCpuContext(task)->regs[8] = (startpc); \
175 #define PREPARE_INITIAL_CONTEXT(task,startpc) \
177 PREPARE_FPU(GetCpuContext(task)); \
180 #define SAVEREGS(task,sc) \
182 struct AROS_cpu_context *cc = GetCpuContext(task); \
183 GetSP(task) = (SP_TYPE *)SP(sc); \
190 #define RESTOREREGS(task,sc) \
192 struct AROS_cpu_context *cc = GetCpuContext(task); \
194 RESTORE_CPU(cc,sc); \
196 RESTORE_FPU(cc,sc); \
197 SP(sc) = (SP_TYPE *)GetSP(task); \
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 */