Mon, 15 Jan 2018 00:59:06 +0100
9 files changed,
70 insertions(+),
20 deletions(-)
M
include/cedos/process.h
→
include/cedos/sched/process.h
@@ -33,6 +33,12 @@ typedef struct __PROCESS {
//! Points to the next process struct in the list. struct __PROCESS *next; + //! Points to the processes first child process. + struct __PROCESS *child; + + //! Points to one of the processes sibling processes. + struct __PROCESS *sibling; + //! Unique number to identify the process with. PROCESS_ID id;
M
include/cedos/sched.h
→
include/cedos/sched/sched.h
@@ -6,7 +6,8 @@ #define SCHEDULER_H
#include <stdint.h> -#include "cedos/process.h" +#include "cedos/sched/process.h" + #include "cedos/mm/paging.h" /*!@@ -29,7 +30,7 @@
/*! * Executes a task. */ -PROCESS_ID sched_exec(PHYS_ADDR page_dir, VIRT_ADDR eip, uint32_t eflags); +PROCESS_ID sched_exec(PHYS_ADDR page_dir, PROCESS_MAIN *entry); /*! * Return the ID of the current process.
M
kernel/interrupts.c
→
kernel/interrupts.c
@@ -1,9 +1,11 @@
-#include "cedos/interrupts.h" #include "cedos/drivers/console.h" + +#include "cedos/sched/sched.h" + +#include "cedos/interrupts.h" #include "cedos/pic.h" #include "cedos/core.h" #include "cedos/pit.h" -#include "cedos/sched.h" #define array_sizeof(array) (sizeof(array)/sizeof(array[0])) #define NULL ((void*)0)
M
kernel/main.c
→
kernel/main.c
@@ -1,10 +1,14 @@
#include "cedos/drivers/console.h" + +#include "cedos/sched/sched.h" + +#include "cedos/mm/paging.h" + #include "cedos/interrupts.h" #include "cedos/pic.h" #include "cedos/pit.h" -#include "cedos/sched.h" -#include "cedos/mm/paging.h" #include "cedos/core.h" + #include "assert.h" int os_init(void) {@@ -49,6 +53,10 @@ }
extern uint8_t* IDT; +void task1(void); +void task2(void); +void task3(void); + void task1(void) { //outb(0xFE, 0x64); while (1) { printk("Somebody once told me\n"); hlt(); }@@ -68,9 +76,9 @@ infodump();
// create test tasks printk("Creating tasks.\n"); - sched_exec(create_empty_page_dir(), task1, get_eflags()); - sched_exec(create_empty_page_dir(), task2, get_eflags()); - sched_exec(create_empty_page_dir(), task3, get_eflags()); + sched_exec(create_empty_page_dir(), task1); + sched_exec(create_empty_page_dir(), task2); + sched_exec(create_empty_page_dir(), task3); printk("Starting scheduler.\n"); sched_start();
M
kernel/mm/paging.c
→
kernel/mm/paging.c
@@ -170,5 +170,5 @@ // dump registers to stdout
} int paging_init(void) { - install_interrupt(0x0e, page_fault_isr, 0x08, TRAP_GATE); + install_interrupt(0x0e, page_fault_isr, 0x08, INT_GATE); }
M
kernel/process.c
→
kernel/sched/process.c
@@ -1,4 +1,4 @@
-#include "cedos/process.h" +#include "cedos/sched/process.h" #define NULL ((void*)0)
M
kernel/sched.c
→
kernel/sched/sched.c
@@ -1,16 +1,22 @@
-#include "cedos/sched.h" -#include "cedos/process.h" +#include "cedos/sched/sched.h" +#include "cedos/sched/process.h" + #include "cedos/mm/paging.h" + #include "cedos/drivers/console.h" +#include "cedos/drivers/speaker.h" + #include "cedos/core.h" #include "cedos/interrupts.h" #include "cedos/pit.h" #include "cedos/pic.h" + #include "assembly.h" #include "common.h" -#include "cedos/drivers/speaker.h" #define KERNEL_PRIVATE_STACK (void*)(0xC0600000) + +#define PROCESS_STD_EFLAGS (0x00000286) PROCESS* get_slot(void) { static PROCESS free_slots[4];@@ -23,7 +29,7 @@
/*! * Executes a task. */ -PROCESS_ID sched_exec(PHYS_ADDR page_dir, VIRT_ADDR eip, uint32_t eflags) { +PROCESS_ID sched_exec(PHYS_ADDR page_dir, PROCESS_MAIN *entry) { crit_enter(); PHYS_ADDR tmp_page_dir = switch_page_dir(page_dir); PROCESS* p = get_slot();@@ -33,8 +39,8 @@ p->page_dir = page_dir;
p->eip = sched_dispatcher; p->ebp = KERNEL_PRIVATE_STACK; p->esp = KERNEL_PRIVATE_STACK - sizeof(SCHED_FRAME); - p->eflags = eflags; - p->entry = (PROCESS_MAIN*)eip; + p->eflags = PROCESS_STD_EFLAGS; + p->entry = entry; // setup stack SCHED_FRAME* frame = (SCHED_FRAME*)(p->esp);@@ -42,9 +48,9 @@ frame->eax = frame->ebx = frame->ecx = frame->edx = 0;
frame->esi = frame->edi = 0; frame->ebp = p->ebp; frame->esp = p->esp; + frame->eflags = p->eflags; frame->eip = sched_dispatcher; frame->cs = 0x8; - frame->eflags = eflags; // TODO: add file descriptors for stdin, stdout and stderr@@ -71,7 +77,7 @@ }
// select next process static int pid = 0; - pid = pid % 3 + 1; + pid = pid % 2 + 1; current_pid = pid; printk("\n### SCHEDULER: SWITCH TO TASK %i\n", pid);@@ -99,7 +105,7 @@ }
int sched_init(void) { // create idle process - sched_exec(create_empty_page_dir(), idle, get_eflags()); + sched_exec(create_empty_page_dir(), idle); return 1; }
A
kernel/sched/makefile
@@ -0,0 +1,27 @@
+.RECIPEPREFIX = > + +S_OBJECTS = $(patsubst %.s,$(LOCAL_BUILD)/%.s.o,$(wildcard *.s)) +C_OBJECTS = $(patsubst %.c,$(LOCAL_BUILD)/%.c.o,$(wildcard *.c)) +OBJECTS = $(S_OBJECTS) $(C_OBJECTS) + +LOCAL_BUILD = $(GLOBAL_BUILD)/sched + +SUBDIRS = $(wildcard */.) + +.PHONY: build +build: folder $(SUBDIRS) $(OBJECTS) +> $(GCC_PREFIX)ld $(wildcard $(LOCAL_BUILD)/*.o) -r -o $(GLOBAL_BUILD)/sched.o --oformat elf32-i386 + +.PHONY: folder +folder: +> @mkdir $(LOCAL_BUILD) 2> /dev/null; true + +.PHONY: $(SUBDIRS) +$(SUBDIRS): +> make -C $@ GLOBAL_BUILD=$(LOCAL_BUILD) build + +$(LOCAL_BUILD)/%.s.o: %.s +> $(GCC_PREFIX)as -o $@ $< + +$(LOCAL_BUILD)/%.c.o: %.c $(wildcard *.h) +> $(GCC_PREFIX)gcc -c -I$(INCLUDE_DIR) --prefix=$(GCC_PREFIX) $(GCC_OPTIONS) -o $@ $<