kern
annotate src/proc.c @ 45:b8f02479e3f4
mainly additions to the VM to support processes etc. not complete
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 26 Jul 2011 02:41:33 +0300 |
parents | 5f6c5751ae05 |
children | f65b348780e3 |
rev | line source |
---|---|
nuclear@42 | 1 #include "proc.h" |
nuclear@42 | 2 #include "tss.h" |
nuclear@45 | 3 #include "vm.h" |
nuclear@42 | 4 |
nuclear@42 | 5 static struct process proc[MAX_PROC]; |
nuclear@42 | 6 static int cur_pid; |
nuclear@42 | 7 |
nuclear@42 | 8 void init_proc(void) |
nuclear@42 | 9 { |
nuclear@45 | 10 int proc_size_pg, img_start_pg; |
nuclear@45 | 11 void *img_start; |
nuclear@42 | 12 cur_pid = -1; |
nuclear@42 | 13 |
nuclear@42 | 14 /* prepare the first process */ |
nuclear@42 | 15 |
nuclear@42 | 16 /* allocate a chunk of memory for the process image |
nuclear@42 | 17 * and copy the code of test_proc there. |
nuclear@42 | 18 * (should be mapped at a fixed address) |
nuclear@42 | 19 */ |
nuclear@45 | 20 proc_size_pg = (test_proc_end - test_proc) / PGSIZE + 1; |
nuclear@45 | 21 if((img_start_pg = pgalloc(proc_size_pg, MEM_USER)) == -1) { |
nuclear@45 | 22 panic("failed to allocate space for the init process image\n"); |
nuclear@45 | 23 } |
nuclear@45 | 24 img_start = (void*)PAGE_TO_ADDR(img_start_pg); |
nuclear@45 | 25 memcpy(img_start, test_proc, proc_size_pg * PGSIZE); |
nuclear@45 | 26 |
nuclear@45 | 27 /* create the virtual address space for this process */ |
nuclear@45 | 28 proc[0].ctx.pgtbl_paddr = clone_vmem(); |
nuclear@45 | 29 |
nuclear@45 | 30 /* we don't need the image in this address space */ |
nuclear@45 | 31 unmap_pa |
nuclear@45 | 32 pgfree(img_start_pg, proc_size_pg); |
nuclear@45 | 33 |
nuclear@42 | 34 |
nuclear@42 | 35 /* fill in the proc[0].ctx with the appropriate process stack |
nuclear@42 | 36 * and instruction pointers |
nuclear@42 | 37 */ |
nuclear@42 | 38 |
nuclear@42 | 39 /* switch to it by calling a function that takes the context |
nuclear@42 | 40 * of the current process, plugs the values into the interrupt |
nuclear@42 | 41 * stack, and calls iret. |
nuclear@42 | 42 * (should also set ss0/sp0 in TSS before returning) |
nuclear@42 | 43 */ |
nuclear@42 | 44 } |
nuclear@42 | 45 |
nuclear@43 | 46 /* |
nuclear@42 | 47 void save_context(struct intr_frame *ifrm) |
nuclear@42 | 48 { |
nuclear@42 | 49 proc[cur_pid].ctx->regs = ifrm->regs; |
nuclear@42 | 50 proc[cur_pid].ctx->instr_ptr = ifrm->eip; |
nuclear@42 | 51 proc[cur_pid].ctx->stack_ptr = ifrm->esp; |
nuclear@42 | 52 proc[cur_pid].ctx->flags = ifrm->eflags; |
nuclear@43 | 53 }*/ |