X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=kitten%2Farch%2Fx86_64%2Fkernel%2Ftask.c;fp=kitten%2Farch%2Fx86_64%2Fkernel%2Ftask.c;h=5254b9c58248847b1eeecf77ba19b780a0ed2a6d;hb=66a1a4c7a9edcd7d8bc207aca093d694a6e6b5b2;hp=0000000000000000000000000000000000000000;hpb=f7cf9c19ecb0a589dd45ae0d2c91814bd3c2acc2;p=palacios.git diff --git a/kitten/arch/x86_64/kernel/task.c b/kitten/arch/x86_64/kernel/task.c new file mode 100644 index 0000000..5254b9c --- /dev/null +++ b/kitten/arch/x86_64/kernel/task.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +int +arch_task_create(struct task_struct *task, + const start_state_t *start_state) +{ + struct pt_regs *regs; + kaddr_t kstack_top; + kaddr_t initial_ksp; + + regs = ((struct pt_regs *)((kaddr_t)task + TASK_SIZE)) - 1; + kstack_top = (kaddr_t)(regs + 1); + initial_ksp = (kaddr_t)regs; + + task->arch.thread.rsp0 = kstack_top; + task->arch.thread.rsp = initial_ksp; + task->arch.thread.userrsp = start_state->stack_ptr; + + /* Mark this as a new-task... arch_context_switch() checks this flag */ + task->arch.flags = TF_NEW_TASK; + + /* Task's address space is from [0, task->addr_limit) */ + task->arch.addr_limit = PAGE_OFFSET; + + /* Initialize FPU state */ + task->arch.thread.i387.fxsave.cwd = 0x37f; + task->arch.thread.i387.fxsave.mxcsr = 0x1f80; + + /* CPU control unit uses these fields to start the user task running */ + if (start_state->aspace_id == KERNEL_ASPACE_ID) { + regs->ss = __KERNEL_DS; + regs->rsp = (vaddr_t)task + TASK_SIZE; + regs->eflags = (1 << 9); /* enable interrupts */ + regs->cs = __KERNEL_CS; + } else { + regs->ss = __USER_DS; + regs->rsp = start_state->stack_ptr; + regs->eflags = (1 << 9); /* enable interrupts */ + regs->cs = __USER_CS; + } + regs->rip = start_state->entry_point; + + return 0; +}