kern

diff src/proc.c @ 42:e6de3c6015cb

started implementing processes
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 24 Jul 2011 18:29:24 +0300
parents
children 5f6c5751ae05
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/proc.c	Sun Jul 24 18:29:24 2011 +0300
     1.3 @@ -0,0 +1,37 @@
     1.4 +#include "proc.h"
     1.5 +#include "tss.h"
     1.6 +
     1.7 +static struct process proc[MAX_PROC];
     1.8 +static int cur_pid;
     1.9 +
    1.10 +void init_proc(void)
    1.11 +{
    1.12 +	cur_pid = -1;
    1.13 +
    1.14 +	/* prepare the first process */
    1.15 +
    1.16 +	/* create the virtual address space for this process */
    1.17 +
    1.18 +	/* allocate a chunk of memory for the process image
    1.19 +	 * and copy the code of test_proc there.
    1.20 +	 * (should be mapped at a fixed address)
    1.21 +	 */
    1.22 +
    1.23 +	/* fill in the proc[0].ctx with the appropriate process stack
    1.24 +	 * and instruction pointers
    1.25 +	 */
    1.26 +
    1.27 +	/* switch to it by calling a function that takes the context
    1.28 +	 * of the current process, plugs the values into the interrupt
    1.29 +	 * stack, and calls iret.
    1.30 +	 * (should also set ss0/sp0 in TSS before returning)
    1.31 +	 */
    1.32 +}
    1.33 +
    1.34 +void save_context(struct intr_frame *ifrm)
    1.35 +{
    1.36 +	proc[cur_pid].ctx->regs = ifrm->regs;
    1.37 +	proc[cur_pid].ctx->instr_ptr = ifrm->eip;
    1.38 +	proc[cur_pid].ctx->stack_ptr = ifrm->esp;
    1.39 +	proc[cur_pid].ctx->flags = ifrm->eflags;
    1.40 +}