nuclear@42: #include "proc.h" nuclear@42: #include "tss.h" nuclear@45: #include "vm.h" nuclear@42: nuclear@42: static struct process proc[MAX_PROC]; nuclear@42: static int cur_pid; nuclear@42: nuclear@42: void init_proc(void) nuclear@42: { nuclear@45: int proc_size_pg, img_start_pg; nuclear@45: void *img_start; nuclear@42: cur_pid = -1; nuclear@42: nuclear@42: /* prepare the first process */ nuclear@42: nuclear@42: /* allocate a chunk of memory for the process image nuclear@42: * and copy the code of test_proc there. nuclear@42: * (should be mapped at a fixed address) nuclear@42: */ nuclear@45: proc_size_pg = (test_proc_end - test_proc) / PGSIZE + 1; nuclear@45: if((img_start_pg = pgalloc(proc_size_pg, MEM_USER)) == -1) { nuclear@45: panic("failed to allocate space for the init process image\n"); nuclear@45: } nuclear@45: img_start = (void*)PAGE_TO_ADDR(img_start_pg); nuclear@45: memcpy(img_start, test_proc, proc_size_pg * PGSIZE); nuclear@45: nuclear@45: /* create the virtual address space for this process */ nuclear@45: proc[0].ctx.pgtbl_paddr = clone_vmem(); nuclear@45: nuclear@45: /* we don't need the image in this address space */ nuclear@45: unmap_pa nuclear@45: pgfree(img_start_pg, proc_size_pg); nuclear@45: nuclear@42: nuclear@42: /* fill in the proc[0].ctx with the appropriate process stack nuclear@42: * and instruction pointers nuclear@42: */ nuclear@42: nuclear@42: /* switch to it by calling a function that takes the context nuclear@42: * of the current process, plugs the values into the interrupt nuclear@42: * stack, and calls iret. nuclear@42: * (should also set ss0/sp0 in TSS before returning) nuclear@42: */ nuclear@42: } nuclear@42: nuclear@43: /* nuclear@42: void save_context(struct intr_frame *ifrm) nuclear@42: { nuclear@42: proc[cur_pid].ctx->regs = ifrm->regs; nuclear@42: proc[cur_pid].ctx->instr_ptr = ifrm->eip; nuclear@42: proc[cur_pid].ctx->stack_ptr = ifrm->esp; nuclear@42: proc[cur_pid].ctx->flags = ifrm->eflags; nuclear@43: }*/