kern

diff src/proc.c @ 49:50730d42d2d3

fuck yeah, now do priviledge levels and TSS
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 30 Jul 2011 07:21:54 +0300
parents f65b348780e3
children 1d8877d12de0
line diff
     1.1 --- a/src/proc.c	Thu Jul 28 17:56:05 2011 +0300
     1.2 +++ b/src/proc.c	Sat Jul 30 07:21:54 2011 +0300
     1.3 @@ -26,12 +26,13 @@
     1.4  	 * and copy the code of test_proc there.
     1.5  	 * (should be mapped at a fixed address)
     1.6  	 */
     1.7 -	proc_size_pg = (test_proc_end - test_proc) / PGSIZE + 1;
     1.8 +	/*proc_size_pg = (test_proc_end - test_proc) / PGSIZE + 1;
     1.9  	if((img_start_pg = pgalloc(proc_size_pg, MEM_USER)) == -1) {
    1.10  		panic("failed to allocate space for the init process image\n");
    1.11  	}
    1.12  	img_start = (void*)PAGE_TO_ADDR(img_start_pg);
    1.13 -	memcpy(img_start, test_proc, proc_size_pg * PGSIZE);
    1.14 +	memcpy(img_start, test_proc, proc_size_pg * PGSIZE);*/
    1.15 +	img_start = test_proc;
    1.16  
    1.17  	/* instruction pointer at the beginning of the process image */
    1.18  	proc[0].ctx.instr_ptr = (uint32_t)img_start;
    1.19 @@ -47,8 +48,8 @@
    1.20  	proc[0].ctx.pgtbl_paddr = clone_vm();
    1.21  
    1.22  	/* we don't need the image and the stack in this address space */
    1.23 -	unmap_page_range(img_start_pg, proc_size_pg);
    1.24 -	pgfree(img_start_pg, proc_size_pg);
    1.25 +	/*unmap_page_range(img_start_pg, proc_size_pg);
    1.26 +	pgfree(img_start_pg, proc_size_pg);*/
    1.27  
    1.28  	unmap_page(stack_pg);
    1.29  	pgfree(stack_pg, 1);
    1.30 @@ -69,6 +70,7 @@
    1.31  	struct intr_frame ifrm;
    1.32  	struct context *ctx = &proc[pid].ctx;
    1.33  
    1.34 +
    1.35  	cur_pid = pid;
    1.36  
    1.37  	ifrm.inum = ifrm.err = 0;
    1.38 @@ -76,10 +78,19 @@
    1.39  	ifrm.regs = ctx->regs;
    1.40  	ifrm.eflags = ctx->flags;
    1.41  
    1.42 +	ifrm.err = 0xbadf00d;
    1.43 +
    1.44 +	asm volatile (
    1.45 +		"pushf\n\t"
    1.46 +		"popl %0\n\t"
    1.47 +		: "=a" (ifrm.eflags)
    1.48 +	);
    1.49 +
    1.50  	ifrm.eip = ctx->instr_ptr;
    1.51 -	ifrm.cs = SEGM_KCODE;	/* XXX change this when we setup the TSS */
    1.52 -	ifrm.esp = ctx->stack_ptr;
    1.53 -	ifrm.ss = SEGM_KDATA;	/* XXX */
    1.54 +	ifrm.cs = selector(SEGM_KCODE, 0);	/* XXX change this when we setup the TSS */
    1.55 +	ifrm.esp = 0;/*ctx->stack_ptr;			/* this will only be used when we switch to userspace */
    1.56 +	ifrm.regs.esp = ctx->stack_ptr;		/* ... until then... */
    1.57 +	ifrm.ss = 0;/*selector(SEGM_KDATA, 0);	/* XXX */
    1.58  
    1.59  	/* switch to the vm of the process */
    1.60  	set_pgdir_addr(ctx->pgtbl_paddr);