2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
6 #include <aros/i386/cpucontext.h>
8 #ifndef __AROS_EXEC_LIBRARY__
10 #include <machine/psl.h>
11 #include <sys/types.h>
12 #include <sys/param.h>
16 typedef struct sigcontext regs_t
;
17 #define SIGHANDLER bsd_sighandler
18 #define SIGHANDLER_T __sighandler_t *
20 #define SC_DISABLE(sc) (sc->sc_mask = KernelBase->kb_PlatformData->sig_int_mask)
21 #define SC_ENABLE(sc) (pd->iface->SigEmptySet(&sc->sc_mask))
23 #define SP(sc) (sc->sc_esp)
24 #define FP(sc) (sc->sc_ebp)
25 #define PC(sc) (sc->sc_eip)
27 #define R0(sc) (sc->sc_eax)
28 #define R1(sc) (sc->sc_ebx)
29 #define R2(sc) (sc->sc_ecx)
30 #define R3(sc) (sc->sc_edx)
31 #define R4(sc) (sc->sc_edi)
32 #define R5(sc) (sc->sc_esi)
33 #define R6(sc) (sc->sc_efl)
35 #define GLOBAL_SIGNAL_INIT(sighandler) \
36 static void sighandler ## _gate (int sig, int code, struct sigcontext *sc) \
38 sighandler( sig, (regs_t*)sc); \
41 /* Save and restore the CPU GPRs in the CPU context */
42 #define SAVE_CPU(cc, sc) \
54 #define RESTORE_CPU(cc, sc) \
61 R6(sc) = sc->sc_efl = (sc->sc_efl & ~PSL_USERCHANGE) | (cc.eflags & PSL_USERCHANGE); \
66 #if __FreeBSD_version >= 500001
68 * This is the FreeBSD 5.x and higher version
70 #define SAVE_FPU(cc, sc) \
74 (cc)->fpformat = (sc)->sc_fpformat; \
75 (cc)->ownedfp = (sc)->sc_ownedfp; \
76 switch (cc)->ownedfp \
78 case _MC_FPOWNED_PCB: \
80 dest = (cc)->regs.FPXData; \
81 len = sizeof(struct FPXContext); \
83 case _MC_FPOWNED_FPU: \
85 dest = (cc)->regs.FPUData; \
86 len = sizeof(struct FPUContext); \
94 (cc)->regs.Flags |= flag; \
95 CopyMemQuick(sc->sc_fpstate, dest, len); \
99 #define RESTORE_FPU(cc, sc) \
103 if ((cc)->fpformat) \
105 (sc)->sc_fpformat = (cc)->fpformat; \
106 (sc)->sc_ownedfp = (cc)->ownedfp; \
108 switch (sc)->sc_ownedfp \
110 case _MC_FPOWNED_PCB: \
112 data = (cc)->regs.FPXData; \
113 len = sizeof(struct FPXContext); \
115 case _MC_FPOWNED_FPU: \
117 data = (cc)->regs.FPUData; \
118 len = sizeof(struct FPUContext); \
124 if ((cc)->regs.Flags & flag) \
125 CopyMemQuick(data, sc->sc_fpstate, len); \
131 * FreeBSD 4 and below have a different context format.
132 * Note that SSE is not supported at all. And on SSE machines
133 * legacy FPU context will not be saved (we don't define USE_LEGACY_8087
134 * in order to save some memory).
135 * This should not really matter because FreeBSD v4 is ancient history.
137 #define SAVE_FPU(cc, sc) \
140 (cc)->Flags |= ECF_FPU; \
141 CopyMemQuick(sc->sc_fpregs, (cc)->FPUData, sizeof(struct FPUContext)); \
144 #define RESTORE_FPU(cc, sc) \
145 if ((cc)->Flags & ECF_FPU) \
146 CopyMemQuick((cc)->FPUData, sc->sc_fpregs, sizeof(struct FPUContext));
150 #define SAVEREGS(cc, sc) \
151 SAVE_CPU((cc)->regs, sc); \
152 (cc)->isp = sc->sc_isp; \
153 SAVE_FPU((cc), sc); \
155 #define RESTOREREGS(cc, sc) \
156 RESTORE_CPU((cc)->regs, sc); \
157 sc->sc_isp = (cc)->isp; \
158 RESTORE_FPU((cc), sc);
160 #define PRINT_SC(sc) \
161 bug(" SP=%08lx FP=%08lx PC=%08lx\n" \
162 " R0=%08lx R1=%08lx R2=%08lx R3=%08lx\n" \
163 " R4=%08lx R5=%08lx R6=%08lx\n" \
164 , SP(sc), FP(sc), PC(sc) \
165 , R0(sc), R1(sc), R2(sc), R3(sc) \
166 , R4(sc), R5(sc), R6(sc) \
169 #endif /* __AROS_EXEC_LIBRARY__ */
171 #define EXCEPTIONS_COUNT 17
173 struct AROSCPUContext
175 struct ExceptionContext regs
; /* Public portion */
176 ULONG isp
; /* Host-specific stuff follows */