nouveau.hidd: disable warnings about not initialized variables
[AROS.git] / arch / i386-all / kernel / createcontext.c
blob0726759c5bac2ef77e231e1a7dcfe6c10b9391e3
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/kernel.h>
7 #include <aros/libcall.h>
8 #include <aros/i386/cpucontext.h>
10 #include <kernel_base.h>
11 #include <kernel_objects.h>
13 #ifndef SIZEOF_8087_FRAME
14 #define SIZEOF_8087_FRAME sizeof(struct FPUContext)
15 #endif
17 AROS_LH0(void *, KrnCreateContext,
18 struct KernelBase *, KernelBase, 18, Kernel)
21 AROS_LIBFUNC_INIT
23 struct ExceptionContext *ctx;
26 * Allocate common data block and FPU data block in one chunk.
27 * On native ports AROSCPUContext can be simply #define'd to ExceptionContext,
28 * so we refer struct AROSCPUContext only for size calculation.
30 ctx = krnAllocCPUContext();
31 if (ctx)
33 IPTR fpdata = (IPTR)ctx + sizeof(struct AROSCPUContext);
35 ctx->Flags = KernelBase->kb_ContextFlags; /* kb_ContextFlags on i386 hold only FPU bits */
36 ctx->eflags = 0x3202; /* Set up default values for some registers */
38 /* These definitions may come from machine-specific kernel_cpu.h */
39 #ifdef USER_CS
40 ctx->Flags |= ECF_SEGMENTS;
41 ctx->cs = USER_CS;
42 ctx->ds = USER_DS;
43 ctx->es = USER_DS;
44 ctx->fs = USER_DS;
45 ctx->gs = USER_DS;
46 ctx->ss = USER_DS;
47 #endif
49 if (!KernelBase->kb_ContextFlags)
51 /* Don't do any of the following if we don't support FPU at all */
52 return ctx;
55 if (ctx->Flags & ECF_FPU)
57 ctx->FPData = (struct FPUContext *)fpdata;
58 fpdata += SIZEOF_8087_FRAME;
61 if (ctx->Flags & ECF_FPX)
63 UBYTE current_xmm[512+15];
64 UBYTE *curr = (UBYTE *)(((IPTR)current_xmm + 15) & ~15);
66 fpdata = (fpdata + 15) & ~15;
67 ctx->FXData = (struct FPXContext *)fpdata;
69 asm volatile(
70 " fxsave (%0)\n"
71 " fninit\n"
72 " fwait\n"
73 " fxsave (%1)\n"
74 " andl %2, %2\n"
75 " je 1f\n"
76 " fnsave (%2)\n"
77 "1: fxrstor (%0)\n"
78 ::"r"(curr), "r"(ctx->FXData), "r"(ctx->FPData):"cc");
80 else if (ctx->Flags & ECF_FPU)
82 UBYTE curr[112];
84 /* fnsave implies fninit, so we don't need to do it explicitly */
85 asm volatile(
86 " fnsave (%0)\n"
87 " fnsave (%1)\n"
88 " frstor (%0)\n"
89 ::"r"(curr), "r"(ctx->FPData):"cc");
93 return ctx;
95 AROS_LIBFUNC_EXIT