revert commit 56204.
[AROS.git] / arch / all-freebsd / kernel / cpu_i386.h
blob1e59338e744e6455caa6b4894058c4142b1a45df
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
4 */
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>
13 #include <ucontext.h>
14 #include <signal.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) \
37 { \
38 sighandler( sig, (regs_t*)sc); \
41 /* Save and restore the CPU GPRs in the CPU context */
42 #define SAVE_CPU(cc, sc) \
43 cc.eax = R0(sc); \
44 cc.ebx = R1(sc); \
45 cc.ecx = R2(sc); \
46 cc.edx = R3(sc); \
47 cc.edi = R4(sc); \
48 cc.esi = R5(sc); \
49 cc.eflags = R6(sc); \
50 cc.ebp = FP(sc); \
51 cc.eip = PC(sc); \
52 cc.esp = SP(sc);
54 #define RESTORE_CPU(cc, sc) \
55 R0(sc) = cc.eax; \
56 R1(sc) = cc.ebx; \
57 R2(sc) = cc.ecx; \
58 R3(sc) = cc.edx; \
59 R4(sc) = cc.edi; \
60 R5(sc) = cc.esi; \
61 R6(sc) = sc->sc_efl = (sc->sc_efl & ~PSL_USERCHANGE) | (cc.eflags & PSL_USERCHANGE); \
62 FP(sc) = cc.ebp; \
63 PC(sc) = cc.eip; \
64 SP(sc) = cc.esp;
66 #if __FreeBSD_version >= 500001
68 * This is the FreeBSD 5.x and higher version
70 #define SAVE_FPU(cc, sc) \
71 { \
72 APTR dest; \
73 ULONG flag, len; \
74 (cc)->fpformat = (sc)->sc_fpformat; \
75 (cc)->ownedfp = (sc)->sc_ownedfp; \
76 switch (cc)->ownedfp \
77 { \
78 case _MC_FPOWNED_PCB: \
79 flag = ECF_FPX; \
80 dest = (cc)->regs.FPXData; \
81 len = sizeof(struct FPXContext); \
82 break; \
83 case _MC_FPOWNED_FPU: \
84 flag = ECF_FPU; \
85 dest = (cc)->regs.FPUData; \
86 len = sizeof(struct FPUContext); \
87 break; \
88 default: \
89 dest = NULL; \
90 break; \
91 } \
92 if (dest) \
93 { \
94 (cc)->regs.Flags |= flag; \
95 CopyMemQuick(sc->sc_fpstate, dest, len); \
96 } \
99 #define RESTORE_FPU(cc, sc) \
101 APTR data; \
102 ULONG flag, len; \
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: \
111 flag = ECF_FPX; \
112 data = (cc)->regs.FPXData; \
113 len = sizeof(struct FPXContext); \
114 break; \
115 case _MC_FPOWNED_FPU: \
116 flag = ECF_FPU; \
117 data = (cc)->regs.FPUData; \
118 len = sizeof(struct FPUContext); \
119 break; \
120 default: \
121 data = NULL; \
122 break; \
124 if ((cc)->regs.Flags & flag) \
125 CopyMemQuick(data, sc->sc_fpstate, len); \
128 #else
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) \
138 if ((cc)->FPUData) \
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));
148 #endif
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 */
177 int fpformat;
178 int ownedfp;
179 int errno_backup;