kern

diff 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 diff
     1.1 --- a/src/proc.c	Mon Jul 25 11:29:57 2011 +0300
     1.2 +++ b/src/proc.c	Tue Jul 26 02:41:33 2011 +0300
     1.3 @@ -1,22 +1,36 @@
     1.4  #include "proc.h"
     1.5  #include "tss.h"
     1.6 +#include "vm.h"
     1.7  
     1.8  static struct process proc[MAX_PROC];
     1.9  static int cur_pid;
    1.10  
    1.11  void init_proc(void)
    1.12  {
    1.13 +	int proc_size_pg, img_start_pg;
    1.14 +	void *img_start;
    1.15  	cur_pid = -1;
    1.16  
    1.17  	/* prepare the first process */
    1.18  
    1.19 -	/* create the virtual address space for this process */
    1.20 -	proc[0].ctx.pgtbl_paddr = clone_vmem();
    1.21 -
    1.22  	/* allocate a chunk of memory for the process image
    1.23  	 * and copy the code of test_proc there.
    1.24  	 * (should be mapped at a fixed address)
    1.25  	 */
    1.26 +	proc_size_pg = (test_proc_end - test_proc) / PGSIZE + 1;
    1.27 +	if((img_start_pg = pgalloc(proc_size_pg, MEM_USER)) == -1) {
    1.28 +		panic("failed to allocate space for the init process image\n");
    1.29 +	}
    1.30 +	img_start = (void*)PAGE_TO_ADDR(img_start_pg);
    1.31 +	memcpy(img_start, test_proc, proc_size_pg * PGSIZE);
    1.32 +
    1.33 +	/* create the virtual address space for this process */
    1.34 +	proc[0].ctx.pgtbl_paddr = clone_vmem();
    1.35 +
    1.36 +	/* we don't need the image in this address space */
    1.37 +	unmap_pa
    1.38 +	pgfree(img_start_pg, proc_size_pg);
    1.39 +
    1.40  
    1.41  	/* fill in the proc[0].ctx with the appropriate process stack
    1.42  	 * and instruction pointers