# HG changeset patch # User John Tsiombikas # Date 1311521364 -10800 # Node ID e6de3c6015cb26d28900e0235e0baf8c5325bacd # Parent 928b0ebfff4ddb3222b0c73c279d93c93cb568e9 started implementing processes diff -r 928b0ebfff4d -r e6de3c6015cb src/asmops.h --- a/src/asmops.h Tue Jun 14 01:19:07 2011 +0300 +++ b/src/asmops.h Sun Jul 24 18:29:24 2011 +0300 @@ -1,6 +1,12 @@ #ifndef ASMOPS_H_ #define ASMOPS_H_ +/* general purpose registers as they are pushed by pusha */ +struct registers { + uint32_t edi, esi, ebp, esp; + uint32_t ebx, edx, ecx, eax; +} __attribute__ ((packed)); + #define enable_intr() asm volatile("sti") #define disable_intr() asm volatile("cli") #define halt_cpu() asm volatile("hlt") diff -r 928b0ebfff4d -r e6de3c6015cb src/intr.c --- a/src/intr.c Tue Jun 14 01:19:07 2011 +0300 +++ b/src/intr.c Sun Jul 24 18:29:24 2011 +0300 @@ -40,12 +40,13 @@ */ struct intr_frame { /* registers pushed by pusha in intr_entry_* */ - uint32_t edi, esi, ebp, esp; - uint32_t ebx, edx, ecx, eax; + struct registers regs; /* interrupt number and error code pushed in intr_entry_* */ uint32_t inum, err; /* pushed by CPU during interrupt entry */ uint32_t eip, cs, eflags; + /* pushed by CPU during interrupt entry from user space */ + uint32_t esp, ss; }; diff -r 928b0ebfff4d -r e6de3c6015cb src/proc.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/proc.c Sun Jul 24 18:29:24 2011 +0300 @@ -0,0 +1,37 @@ +#include "proc.h" +#include "tss.h" + +static struct process proc[MAX_PROC]; +static int cur_pid; + +void init_proc(void) +{ + cur_pid = -1; + + /* prepare the first process */ + + /* create the virtual address space for this process */ + + /* allocate a chunk of memory for the process image + * and copy the code of test_proc there. + * (should be mapped at a fixed address) + */ + + /* fill in the proc[0].ctx with the appropriate process stack + * and instruction pointers + */ + + /* switch to it by calling a function that takes the context + * of the current process, plugs the values into the interrupt + * stack, and calls iret. + * (should also set ss0/sp0 in TSS before returning) + */ +} + +void save_context(struct intr_frame *ifrm) +{ + proc[cur_pid].ctx->regs = ifrm->regs; + proc[cur_pid].ctx->instr_ptr = ifrm->eip; + proc[cur_pid].ctx->stack_ptr = ifrm->esp; + proc[cur_pid].ctx->flags = ifrm->eflags; +} diff -r 928b0ebfff4d -r e6de3c6015cb src/proc.h --- a/src/proc.h Tue Jun 14 01:19:07 2011 +0300 +++ b/src/proc.h Sun Jul 24 18:29:24 2011 +0300 @@ -1,14 +1,21 @@ #ifndef PROC_H_ #define PROC_H_ -#include "tss.h" +#include "asmops.h" + +#define MAX_PROC 128 + +struct context { + struct registers regs; + uint32_t instr_ptr; + uint32_t stack_ptr; + uint32_t flags; + /* TODO add FPU state */ +}; + struct process { - int id; - - struct task_state tss; - - struct process *next; + struct context ctx; }; #endif /* PROC_H_ */