Documented GVF_SAVE_VAR alongside other flags, and removed a query/doubt
[AROS.git] / arch / x86_64-pc / kernel / kernel_cpu.c
blob906085866d24fbe669834bba0ae087fe814a6c74
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/lists.h>
7 #include <exec/tasks.h>
8 #include <exec/execbase.h>
9 #include <hardware/intbits.h>
10 #include <proto/exec.h>
12 #include "kernel_base.h"
13 #include "kernel_intern.h"
14 #include "kernel_intr.h"
15 #include "kernel_scheduler.h"
17 void cpu_Dispatch(struct ExceptionContext *regs)
19 struct Task *task;
20 struct ExceptionContext *ctx;
22 /*
23 * Is the list of ready tasks empty? Well, increment the idle switch cound and halt CPU.
24 * It should be extended by some plugin mechanism which would put CPU and whole machine
25 * into some more sophisticated sleep states (ACPI?)
27 while (!(task = core_Dispatch()))
29 /* Sleep almost forever ;) */
30 __asm__ __volatile__("sti; hlt; cli");
32 if (SysBase->SysFlags & SFF_SoftInt)
33 core_Cause(INTB_SOFTINT, 1l << INTB_SOFTINT);
36 /* TODO: Handle exception
37 if (task->tc_Flags & TF_EXCEPT)
38 Exception(); */
40 /* Get task's context */
41 ctx = task->tc_UnionETask.tc_ETask->et_RegFrame;
43 /*
44 * Restore the fpu, mmx, xmm state
45 * TODO: Change to the lazy saving of the XMM state!!!!
47 if (ctx->Flags & ECF_FPX)
48 asm volatile("fxrstor (%0)"::"r"(ctx->FXData));
51 * Leave interrupt and jump to the new task.
52 * We will restore CPU state right from this buffer,
53 * so no need to copy anything.
55 core_LeaveInterrupt(ctx);
58 void cpu_Switch(struct ExceptionContext *regs)
60 struct Task *task = SysBase->ThisTask;
61 struct ExceptionContext *ctx = task->tc_UnionETask.tc_ETask->et_RegFrame;
64 * Copy current task's context into the ETask structure. Note that context on stack
65 * misses SSE data pointer.
67 CopyMemQuick(regs, ctx, sizeof(struct ExceptionContext) - sizeof(struct FPXContext *));
70 * Copy the fpu, mmx, xmm state
71 * TODO: Change to the lazy saving of the XMM state!!!!
73 asm volatile("fxsave (%0)"::"r"(ctx->FXData));
75 /* We have the complete data now */
76 ctx->Flags = ECF_SEGMENTS | ECF_FPX;
78 /* Set task's tc_SPReg */
79 task->tc_SPReg = (APTR)regs->rsp;
81 core_Switch();