prism2.device: Compiler delint
[AROS.git] / arch / i386-all / kernel / createcontext.c
blob06afc1d9e3bb93ff9f3dffb083e6a26db06c4477
1 #include <aros/kernel.h>
2 #include <aros/libcall.h>
3 #include <aros/i386/cpucontext.h>
5 #include <kernel_base.h>
6 #include <kernel_objects.h>
8 #ifndef SIZEOF_8087_FRAME
9 #define SIZEOF_8087_FRAME sizeof(struct FPUContext)
10 #endif
12 AROS_LH0(void *, KrnCreateContext,
13 struct KernelBase *, KernelBase, 18, Kernel)
16 AROS_LIBFUNC_INIT
18 struct ExceptionContext *ctx;
21 * Allocate common data block and FPU data block in one chunk.
22 * On native ports AROSCPUContext can be simply #define'd to ExceptionContext,
23 * so we refer struct AROSCPUContext only for size calculation.
25 ctx = krnAllocCPUContext();
26 if (ctx)
28 IPTR fpdata = (IPTR)ctx + sizeof(struct AROSCPUContext);
30 ctx->Flags = KernelBase->kb_ContextFlags; /* kb_ContextFlags on i386 hold only FPU bits */
31 ctx->eflags = 0x3202; /* Set up default values for some registers */
33 /* These definitions may come from machine-specific kernel_cpu.h */
34 #ifdef USER_CS
35 ctx->Flags |= ECF_SEGMENTS;
36 ctx->cs = USER_CS;
37 ctx->ds = USER_DS;
38 ctx->es = USER_DS;
39 ctx->fs = USER_DS;
40 ctx->gs = USER_DS;
41 ctx->ss = USER_DS;
42 #endif
44 if (!KernelBase->kb_ContextFlags)
46 /* Don't do any of the following if we don't support FPU at all */
47 return ctx;
50 if (ctx->Flags & ECF_FPU)
52 ctx->FPData = (struct FPUContext *)fpdata;
53 fpdata += SIZEOF_8087_FRAME;
56 if (ctx->Flags & ECF_FPX)
58 UBYTE current_xmm[512+15];
59 UBYTE *curr = (UBYTE *)(((IPTR)current_xmm + 15) & ~15);
61 fpdata = (fpdata + 15) & ~15;
62 ctx->FXData = (struct FPXContext *)fpdata;
64 asm volatile(
65 " fxsave (%0)\n"
66 " fninit\n"
67 " fwait\n"
68 " fxsave (%1)\n"
69 " andl %2, %2\n"
70 " je 1f\n"
71 " fnsave (%2)\n"
72 "1: fxrstor (%0)\n"
73 ::"r"(curr), "r"(ctx->FXData), "r"(ctx->FPData):"cc");
75 else if (ctx->Flags & ECF_FPU)
77 UBYTE curr[112];
79 /* fnsave implies fninit, so we don't need to do it explicitly */
80 asm volatile(
81 " fnsave (%0)\n"
82 " fnsave (%1)\n"
83 " frstor (%0)\n"
84 ::"r"(curr), "r"(ctx->FPData):"cc");
88 return ctx;
90 AROS_LIBFUNC_EXIT