kern

annotate 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
rev   line source
nuclear@42 1 #include "proc.h"
nuclear@42 2 #include "tss.h"
nuclear@42 3
nuclear@42 4 static struct process proc[MAX_PROC];
nuclear@42 5 static int cur_pid;
nuclear@42 6
nuclear@42 7 void init_proc(void)
nuclear@42 8 {
nuclear@42 9 cur_pid = -1;
nuclear@42 10
nuclear@42 11 /* prepare the first process */
nuclear@42 12
nuclear@42 13 /* create the virtual address space for this process */
nuclear@42 14
nuclear@42 15 /* allocate a chunk of memory for the process image
nuclear@42 16 * and copy the code of test_proc there.
nuclear@42 17 * (should be mapped at a fixed address)
nuclear@42 18 */
nuclear@42 19
nuclear@42 20 /* fill in the proc[0].ctx with the appropriate process stack
nuclear@42 21 * and instruction pointers
nuclear@42 22 */
nuclear@42 23
nuclear@42 24 /* switch to it by calling a function that takes the context
nuclear@42 25 * of the current process, plugs the values into the interrupt
nuclear@42 26 * stack, and calls iret.
nuclear@42 27 * (should also set ss0/sp0 in TSS before returning)
nuclear@42 28 */
nuclear@42 29 }
nuclear@42 30
nuclear@42 31 void save_context(struct intr_frame *ifrm)
nuclear@42 32 {
nuclear@42 33 proc[cur_pid].ctx->regs = ifrm->regs;
nuclear@42 34 proc[cur_pid].ctx->instr_ptr = ifrm->eip;
nuclear@42 35 proc[cur_pid].ctx->stack_ptr = ifrm->esp;
nuclear@42 36 proc[cur_pid].ctx->flags = ifrm->eflags;
nuclear@42 37 }