kern

changeset 42:e6de3c6015cb

started implementing processes
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 24 Jul 2011 18:29:24 +0300
parents 928b0ebfff4d
children 5f6c5751ae05
files src/asmops.h src/intr.c src/proc.c src/proc.h
diffstat 4 files changed, 59 insertions(+), 8 deletions(-) [+]
line diff
     1.1 --- a/src/asmops.h	Tue Jun 14 01:19:07 2011 +0300
     1.2 +++ b/src/asmops.h	Sun Jul 24 18:29:24 2011 +0300
     1.3 @@ -1,6 +1,12 @@
     1.4  #ifndef ASMOPS_H_
     1.5  #define ASMOPS_H_
     1.6  
     1.7 +/* general purpose registers as they are pushed by pusha */
     1.8 +struct registers {
     1.9 +	uint32_t edi, esi, ebp, esp;
    1.10 +	uint32_t ebx, edx, ecx, eax;
    1.11 +} __attribute__ ((packed));
    1.12 +
    1.13  #define enable_intr() asm volatile("sti")
    1.14  #define disable_intr() asm volatile("cli")
    1.15  #define halt_cpu() asm volatile("hlt")
     2.1 --- a/src/intr.c	Tue Jun 14 01:19:07 2011 +0300
     2.2 +++ b/src/intr.c	Sun Jul 24 18:29:24 2011 +0300
     2.3 @@ -40,12 +40,13 @@
     2.4   */
     2.5  struct intr_frame {
     2.6  	/* registers pushed by pusha in intr_entry_* */
     2.7 -	uint32_t edi, esi, ebp, esp;
     2.8 -	uint32_t ebx, edx, ecx, eax;
     2.9 +	struct registers regs;
    2.10  	/* interrupt number and error code pushed in intr_entry_* */
    2.11  	uint32_t inum, err;
    2.12  	/* pushed by CPU during interrupt entry */
    2.13  	uint32_t eip, cs, eflags;
    2.14 +	/* pushed by CPU during interrupt entry from user space */
    2.15 +	uint32_t esp, ss;
    2.16  };
    2.17  
    2.18  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/proc.c	Sun Jul 24 18:29:24 2011 +0300
     3.3 @@ -0,0 +1,37 @@
     3.4 +#include "proc.h"
     3.5 +#include "tss.h"
     3.6 +
     3.7 +static struct process proc[MAX_PROC];
     3.8 +static int cur_pid;
     3.9 +
    3.10 +void init_proc(void)
    3.11 +{
    3.12 +	cur_pid = -1;
    3.13 +
    3.14 +	/* prepare the first process */
    3.15 +
    3.16 +	/* create the virtual address space for this process */
    3.17 +
    3.18 +	/* allocate a chunk of memory for the process image
    3.19 +	 * and copy the code of test_proc there.
    3.20 +	 * (should be mapped at a fixed address)
    3.21 +	 */
    3.22 +
    3.23 +	/* fill in the proc[0].ctx with the appropriate process stack
    3.24 +	 * and instruction pointers
    3.25 +	 */
    3.26 +
    3.27 +	/* switch to it by calling a function that takes the context
    3.28 +	 * of the current process, plugs the values into the interrupt
    3.29 +	 * stack, and calls iret.
    3.30 +	 * (should also set ss0/sp0 in TSS before returning)
    3.31 +	 */
    3.32 +}
    3.33 +
    3.34 +void save_context(struct intr_frame *ifrm)
    3.35 +{
    3.36 +	proc[cur_pid].ctx->regs = ifrm->regs;
    3.37 +	proc[cur_pid].ctx->instr_ptr = ifrm->eip;
    3.38 +	proc[cur_pid].ctx->stack_ptr = ifrm->esp;
    3.39 +	proc[cur_pid].ctx->flags = ifrm->eflags;
    3.40 +}
     4.1 --- a/src/proc.h	Tue Jun 14 01:19:07 2011 +0300
     4.2 +++ b/src/proc.h	Sun Jul 24 18:29:24 2011 +0300
     4.3 @@ -1,14 +1,21 @@
     4.4  #ifndef PROC_H_
     4.5  #define PROC_H_
     4.6  
     4.7 -#include "tss.h"
     4.8 +#include "asmops.h"
     4.9 +
    4.10 +#define MAX_PROC	128
    4.11 +
    4.12 +struct context {
    4.13 +	struct registers regs;
    4.14 +	uint32_t instr_ptr;
    4.15 +	uint32_t stack_ptr;
    4.16 +	uint32_t flags;
    4.17 +	/* TODO add FPU state */
    4.18 +};
    4.19 +
    4.20  
    4.21  struct process {
    4.22 -	int id;
    4.23 -
    4.24 -	struct task_state tss;
    4.25 -
    4.26 -	struct process *next;
    4.27 +	struct context ctx;
    4.28  };
    4.29  
    4.30  #endif	/* PROC_H_ */