2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
8 #include <aros/i386/cpucontext.h>
10 #ifdef __AROS_EXEC_LIBRARY__
12 /* regs_t is a black box here */
14 typedef struct ucontext
*regs_t
;
18 #include <sys/ucontext.h>
20 #define SIGCORE_NEED_SA_SIGINFO
22 typedef ucontext_t regs_t
;
24 #define SIGHANDLER bsd_sighandler
25 typedef void (*SIGHANDLER_T
)(int);
27 #define SC_DISABLE(sc) sc->uc_sigmask = KernelBase->kb_PlatformData->sig_int_mask
28 #define SC_ENABLE(sc) pd->iface->SigEmptySet(&(sc)->uc_sigmask)
30 /* work around silly renaming of struct members in OS X 10.5 */
31 #if __DARWIN_UNIX03 && defined(_STRUCT_X86_EXCEPTION_STATE32)
33 #define R0(context) ((context)->uc_mcontext->__ss.__eax)
34 #define R1(context) ((context)->uc_mcontext->__ss.__ebx)
35 #define R2(context) ((context)->uc_mcontext->__ss.__ecx)
36 #define R3(context) ((context)->uc_mcontext->__ss.__edx)
37 #define R4(context) ((context)->uc_mcontext->__ss.__edi)
38 #define R5(context) ((context)->uc_mcontext->__ss.__esi)
39 #define R6(context) ((context)->uc_mcontext->__ss.__eflags)
41 #define FP(context) ((context)->uc_mcontext->__ss.__ebp)
42 #define PC(context) ((context)->uc_mcontext->__ss.__eip)
43 #define SP(context) ((context)->uc_mcontext->__ss.__esp)
45 #define SS(context) ((context)->uc_mcontext->__ss.__ss)
46 #define CS(context) ((context)->uc_mcontext->__ss.__cs)
47 #define DS(context) ((context)->uc_mcontext->__ss.__ds)
48 #define ES(context) ((context)->uc_mcontext->__ss.__es)
49 #define FS(context) ((context)->uc_mcontext->__ss.__fs)
50 #define GS(context) ((context)->uc_mcontext->__ss.__gs)
52 #define FPSTATE(context) ((context)->uc_mcontext->__fs.__fpu_fcw)
56 #define R0(context) ((context)->uc_mcontext->ss.eax)
57 #define R1(context) ((context)->uc_mcontext->ss.ebx)
58 #define R2(context) ((context)->uc_mcontext->ss.ecx)
59 #define R3(context) ((context)->uc_mcontext->ss.edx)
60 #define R4(context) ((context)->uc_mcontext->ss.edi)
61 #define R5(context) ((context)->uc_mcontext->ss.esi)
62 #define R6(context) ((context)->uc_mcontext->ss.eflags)
64 #define FP(context) ((context)->uc_mcontext->ss.ebp)
65 #define PC(context) ((context)->uc_mcontext->ss.eip)
66 #define SP(context) ((context)->uc_mcontext->ss.esp)
68 #define SS(context) ((context)->uc_mcontext->ss.ss)
69 #define CS(context) ((context)->uc_mcontext->ss.cs)
70 #define DS(context) ((context)->uc_mcontext->ss.ds)
71 #define ES(context) ((context)->uc_mcontext->ss.es)
72 #define FS(context) ((context)->uc_mcontext->ss.fs)
73 #define GS(context) ((context)->uc_mcontext->ss.gs)
75 #define FPSTATE(context) ((context)->uc_mcontext->fs.fpu_fcw)
79 #define GLOBAL_SIGNAL_INIT(sighandler) \
80 static void sighandler ## _gate (int sig, int code, ucontext_t *sc) \
82 sighandler(sig, sc); \
85 #define SAVE_CPU(cc, sc) \
86 cc.Flags = ECF_SEGMENTS; \
105 * Restore CPU registers.
106 * Note that we do not restore segment registers because they
107 * are of own use by Darwin.
109 #define RESTORE_CPU(cc, sc) \
116 R6(sc) = cc.eflags; \
122 * Save all registers from UNIX signal context ss to AROS context cc.
123 * Saves SSE state only if the context has appropriate space for it.
124 * Note that Darwin does not save legacy 8087 frame.
126 #define SAVEREGS(cc, sc) \
127 SAVE_CPU((cc)->regs, sc); \
128 if ((cc)->regs.FXData) \
130 (cc)->regs.Flags |= ECF_FPX; \
131 CopyMemQuick(&FPSTATE(sc), (cc)->regs.FXData, sizeof(struct FPXContext)); \
135 * Restore all registers from AROS context to UNIX signal context.
136 * Check context flags to decide whether to restore SSE or not.
138 #define RESTOREREGS(cc, sc) \
139 RESTORE_CPU((cc)->regs, sc); \
140 if ((cc)->regs.Flags & ECF_FPX) \
141 CopyMemQuick((cc)->regs.FXData, &FPSTATE(sc), sizeof(struct FPXContext));
143 /* Print signal context. Used in crash handler. */
144 #define PRINT_SC(sc) \
145 bug (" ESP=%08x EBP=%08x EIP=%08x\n" \
146 " EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n" \
147 " EDI=%08x ESI=%08x EFLAGS=%08x\n" \
148 , SP(sc), FP(sc), PC(sc) \
149 , R0(sc), R1(sc), R2(sc), R3(sc) \
150 , R4(sc), R5(sc), R6(sc) \
153 #endif /* __AROS_EXEC_LIBRARY__ */
155 #define EXCEPTIONS_COUNT 17
157 struct AROSCPUContext
159 struct ExceptionContext regs
;