kern

diff src/proc.c @ 52:fa65b4f45366

picking this up again, let's fix it
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 07 Aug 2011 06:42:00 +0300
parents b1e8c8251884
children 23abbeea4d5f
line diff
     1.1 --- a/src/proc.c	Mon Aug 01 06:45:29 2011 +0300
     1.2 +++ b/src/proc.c	Sun Aug 07 06:42:00 2011 +0300
     1.3 @@ -1,4 +1,6 @@
     1.4 +#include <stdio.h>
     1.5  #include <string.h>
     1.6 +#include <assert.h>
     1.7  #include "proc.h"
     1.8  #include "tss.h"
     1.9  #include "vm.h"
    1.10 @@ -8,6 +10,7 @@
    1.11  #include "syscall.h"
    1.12  #include "sched.h"
    1.13  
    1.14 +#define	FLAGS_INTR_BIT	9
    1.15  
    1.16  /* defined in test_proc.S */
    1.17  void test_proc(void);
    1.18 @@ -39,6 +42,8 @@
    1.19  	img_start = (void*)PAGE_TO_ADDR(img_start_pg);
    1.20  	memcpy(img_start, test_proc, proc_size_pg * PGSIZE);
    1.21  
    1.22 +	printf("copied init process at: %x\n", (unsigned int)img_start);
    1.23 +
    1.24  	/* instruction pointer at the beginning of the process image */
    1.25  	proc[1].ctx.instr_ptr = (uint32_t)img_start;
    1.26  
    1.27 @@ -49,6 +54,9 @@
    1.28  	}
    1.29  	proc[1].ctx.stack_ptr = PAGE_TO_ADDR(stack_pg) + PGSIZE;
    1.30  
    1.31 +	proc[1].stack_end = KMEM_START;
    1.32 +	proc[1].stack_start = KMEM_START - PGSIZE;
    1.33 +
    1.34  	/* create the virtual address space for this process */
    1.35  	proc[1].ctx.pgtbl_paddr = clone_vm();
    1.36  
    1.37 @@ -60,7 +68,7 @@
    1.38  	pgfree(stack_pg, 1);
    1.39  
    1.40  	/* add it to the scheduler queues */
    1.41 -	//add_proc(1, STATE_RUNNING);
    1.42 +	add_proc(1, STATE_RUNNING);
    1.43  
    1.44  	/* switch to the initial process, this never returns */
    1.45  	context_switch(1);
    1.46 @@ -69,26 +77,33 @@
    1.47  
    1.48  void context_switch(int pid)
    1.49  {
    1.50 +	struct context *ctx;
    1.51  	struct intr_frame ifrm;
    1.52 -	struct context *ctx = &proc[pid].ctx;
    1.53 +	struct intr_frame *cur_frame = get_intr_frame();
    1.54  
    1.55 +	assert(0);
    1.56  
    1.57 +	if(cur_pid == pid) {
    1.58 +		assert(cur_frame);
    1.59 +		intr_ret(*cur_frame);
    1.60 +	}
    1.61 +
    1.62 +	ctx = &proc[pid].ctx;
    1.63  	cur_pid = pid;
    1.64  
    1.65  	ifrm.inum = ifrm.err = 0;
    1.66  
    1.67  	ifrm.regs = ctx->regs;
    1.68 -	ifrm.eflags = ctx->flags | (1 << 9);
    1.69 +	ifrm.eflags = ctx->flags | (1 << FLAGS_INTR_BIT);
    1.70  
    1.71  	ifrm.eip = ctx->instr_ptr;
    1.72  	ifrm.cs = selector(SEGM_KCODE, 0);	/* XXX change this when we setup the TSS */
    1.73 -	ifrm.esp = 0;/*ctx->stack_ptr;			/* this will only be used when we switch to userspace */
    1.74 -	ifrm.regs.esp = ctx->stack_ptr;		/* ... until then... */
    1.75 -	ifrm.ss = 0;/*selector(SEGM_KDATA, 0);	/* XXX */
    1.76 +	/*ifrm.regs.esp = ctx->stack_ptr;*/		/* ... until then... */
    1.77 +	ifrm.esp = ctx->stack_ptr;			/* this will only be used when we switch to userspace */
    1.78 +	ifrm.ss = selector(SEGM_KDATA, 0);
    1.79  
    1.80  	/* switch to the vm of the process */
    1.81  	set_pgdir_addr(ctx->pgtbl_paddr);
    1.82 -
    1.83  	intr_ret(ifrm);
    1.84  }
    1.85