Call CloseDevice() before DeleteIORequest(), and don't call
[AROS.git] / arch / x86_64-all / kernel / createcontext.c
blob01bb31a55882d3896fa97a383113753ca277dc6e
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Create an empty usable CPU context, x86_64 version.
6 Lang: english
7 */
9 #include <aros/kernel.h>
10 #include <aros/libcall.h>
12 #include <kernel_base.h>
13 #include <kernel_objects.h>
15 AROS_LH0(void *, KrnCreateContext,
16 struct KernelBase *, KernelBase, 18, Kernel)
19 AROS_LIBFUNC_INIT
21 struct ExceptionContext *ctx;
24 * Allocate common data block and FPU data block in one chunk.
25 * On native ports AROSCPUContext can be simply #define'd to ExceptionContext,
26 * so we refer to struct AROSCPUContext only for size calculation.
27 * Below we rely on the fact that returned address is 16-byte-aligned.
28 * MemChunk is two IPTRs, so this is true.
30 ctx = krnAllocCPUContext();
31 if (ctx)
33 UBYTE current_xmm[512+15];
34 UBYTE *curr = (UBYTE *)AROS_ROUNDUP2((IPTR)current_xmm, 16);
35 IPTR fpdata = (IPTR)ctx + AROS_ROUNDUP2(sizeof(struct AROSCPUContext), 16);
37 ctx->Flags = ECF_FPX;
38 ctx->FXData = (struct FPXContext *)fpdata;
40 /* Set up default values for some registers */
41 ctx->rflags = 0x3202;
43 /* These definitions may come from machine-specific kernel_cpu.h */
44 #ifdef USER_CS
45 ctx->Flags |= ECF_SEGMENTS;
46 ctx->cs = USER_CS;
47 ctx->ds = USER_DS;
48 ctx->es = USER_DS;
49 ctx->fs = USER_DS;
50 ctx->gs = USER_GS;
51 ctx->ss = USER_DS;
52 #endif
54 /* Init SSE context */
55 asm volatile(
56 " fxsave (%0)\n"
57 " fninit\n"
58 " fwait\n"
59 " fxsave (%1)\n"
60 " fxrstor (%0)\n"
61 ::"r"(curr), "r"(ctx->FXData):"cc");
64 return ctx;
66 AROS_LIBFUNC_EXIT