kern
view 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 |
line source
1 #include "proc.h"
2 #include "tss.h"
3 #include "vm.h"
5 static struct process proc[MAX_PROC];
6 static int cur_pid;
8 void init_proc(void)
9 {
10 int proc_size_pg, img_start_pg;
11 void *img_start;
12 cur_pid = -1;
14 /* prepare the first process */
16 /* allocate a chunk of memory for the process image
17 * and copy the code of test_proc there.
18 * (should be mapped at a fixed address)
19 */
20 proc_size_pg = (test_proc_end - test_proc) / PGSIZE + 1;
21 if((img_start_pg = pgalloc(proc_size_pg, MEM_USER)) == -1) {
22 panic("failed to allocate space for the init process image\n");
23 }
24 img_start = (void*)PAGE_TO_ADDR(img_start_pg);
25 memcpy(img_start, test_proc, proc_size_pg * PGSIZE);
27 /* create the virtual address space for this process */
28 proc[0].ctx.pgtbl_paddr = clone_vmem();
30 /* we don't need the image in this address space */
31 unmap_pa
32 pgfree(img_start_pg, proc_size_pg);
35 /* fill in the proc[0].ctx with the appropriate process stack
36 * and instruction pointers
37 */
39 /* switch to it by calling a function that takes the context
40 * of the current process, plugs the values into the interrupt
41 * stack, and calls iret.
42 * (should also set ss0/sp0 in TSS before returning)
43 */
44 }
46 /*
47 void save_context(struct intr_frame *ifrm)
48 {
49 proc[cur_pid].ctx->regs = ifrm->regs;
50 proc[cur_pid].ctx->instr_ptr = ifrm->eip;
51 proc[cur_pid].ctx->stack_ptr = ifrm->esp;
52 proc[cur_pid].ctx->flags = ifrm->eflags;
53 }*/