2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
8 #include <aros/x86_64/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.__rax)
34 #define R1(context) ((context)->uc_mcontext->__ss.__rbx)
35 #define R2(context) ((context)->uc_mcontext->__ss.__rcx)
36 #define R3(context) ((context)->uc_mcontext->__ss.__rdx)
37 #define R4(context) ((context)->uc_mcontext->__ss.__rdi)
38 #define R5(context) ((context)->uc_mcontext->__ss.__rsi)
39 #define R6(context) ((context)->uc_mcontext->__ss.__rflags)
40 #define R8(context) ((context)->uc_mcontext->__ss.__r8)
41 #define R9(context) ((context)->uc_mcontext->__ss.__r9)
42 #define R10(context) ((context)->uc_mcontext->__ss.__r10)
43 #define R11(context) ((context)->uc_mcontext->__ss.__r11)
44 #define R12(context) ((context)->uc_mcontext->__ss.__r12)
45 #define R13(context) ((context)->uc_mcontext->__ss.__r13)
46 #define R14(context) ((context)->uc_mcontext->__ss.__r14)
47 #define R15(context) ((context)->uc_mcontext->__ss.__r15)
49 #define FP(context) ((context)->uc_mcontext->__ss.__rbp)
50 #define PC(context) ((context)->uc_mcontext->__ss.__rip)
51 #define SP(context) ((context)->uc_mcontext->__ss.__rsp)
53 #define CS(context) ((context)->uc_mcontext->__ss.__cs)
54 #define FS(context) ((context)->uc_mcontext->__ss.__fs)
55 #define GS(context) ((context)->uc_mcontext->__ss.__gs)
57 #define FPSTATE(context) ((context)->uc_mcontext->__fs.__fpu_fcw)
61 #define R0(context) ((context)->uc_mcontext->ss.eax)
62 #define R1(context) ((context)->uc_mcontext->ss.ebx)
63 #define R2(context) ((context)->uc_mcontext->ss.ecx)
64 #define R3(context) ((context)->uc_mcontext->ss.edx)
65 #define R4(context) ((context)->uc_mcontext->ss.edi)
66 #define R5(context) ((context)->uc_mcontext->ss.esi)
67 #define R6(context) ((context)->uc_mcontext->ss.eflags)
68 #define R8(context) ((context)->uc_mcontext->ss.r8)
69 #define R9(context) ((context)->uc_mcontext->ss.r9)
70 #define R10(context) ((context)->uc_mcontext->ss.r10)
71 #define R11(context) ((context)->uc_mcontext->ss.r11)
72 #define R12(context) ((context)->uc_mcontext->ss.r12)
73 #define R13(context) ((context)->uc_mcontext->ss.r13)
74 #define R14(context) ((context)->uc_mcontext->ss.r14)
75 #define R15(context) ((context)->uc_mcontext->ss.r15)
77 #define FP(context) ((context)->uc_mcontext->ss.ebp)
78 #define PC(context) ((context)->uc_mcontext->ss.eip)
79 #define SP(context) ((context)->uc_mcontext->ss.esp)
81 #define CS(context) ((context)->uc_mcontext->ss.cs)
82 #define FS(context) ((context)->uc_mcontext->ss.fs)
83 #define GS(context) ((context)->uc_mcontext->ss.gs)
85 #define FPSTATE(context) ((context)->uc_mcontext->fs.fpu_fcw)
89 #define GLOBAL_SIGNAL_INIT(sighandler) \
90 static void sighandler ## _gate (int sig, int code, ucontext_t *sc) \
92 sighandler(sig, sc); \
97 * Unfortunately Darwin doesn't provide us with values of all segment registers.
98 * We can't do anything with it.
100 #define SAVE_CPU(cc, sc) \
101 cc.Flags = ECF_SEGMENTS; \
108 cc.rflags = R6(sc); \
125 * Restore CPU registers.
126 * Note that we do not restore segment registers because they
127 * are of own use by Darwin.
129 #define RESTORE_CPU(cc, sc) \
136 R6(sc) = cc.rflags; \
150 * Save all registers from UNIX signal context to AROS context.
151 * Save also SSE state if the context has buffer. ECF_FPX will be set
152 * if SSE state was copied.
154 #define SAVEREGS(cc, sc) \
155 SAVE_CPU((cc)->regs, sc); \
156 if ((cc)->regs.FXData) \
158 (cc)->regs.Flags |= ECF_FPX; \
159 CopyMemQuick(&FPSTATE(sc), (cc)->regs.FXData, sizeof(struct FPXContext)); \
163 * Restore all registers from AROS context to UNIX signal context.
164 * Check context flags to decide whether to restore SSE or not.
166 #define RESTOREREGS(cc, sc) \
167 RESTORE_CPU((cc)->regs, sc); \
168 if ((cc)->regs.Flags & ECF_FPX) \
169 CopyMemQuick((cc)->regs.FXData, &FPSTATE(sc), sizeof(struct FPXContext));
171 /* Print signal context. Used in crash handler. */
172 #define PRINT_SC(sc) \
173 bug (" RSP=%016lx RBP=%016lx RIP=%016lx\n" \
174 " RAX=%016lx RBX=%016lx RCX=%016lx RDX=%016lx\n" \
175 " RDI=%016lx RSI=%016lx RFLAGS=%016lx\n" \
176 " R8 =%016lx R9 =%016lx R10=%016lx R11=%016lx\n" \
177 " R12=%016lx R13=%016lx R14=%016lx R15=%016lx\n" \
178 , SP(sc), FP(sc), PC(sc) \
179 , R0(sc), R1(sc), R2(sc), R3(sc) \
180 , R4(sc), R5(sc), R6(sc), R8(sc), R9(sc) \
181 , R10(sc), R11(sc), R12(sc), R13(sc), R14(sc), R15(sc) \
184 #endif /* __AROS_EXEC_LIBRARY__ */
186 #define EXCEPTIONS_COUNT 17
188 struct AROSCPUContext
190 struct ExceptionContext regs
;