From: Matthias Kruk Date: Fri, 27 Sep 2019 06:08:52 +0000 (+0900) Subject: Move architecture-independent process implementation out of the arch directory X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=c3b5d65f8459a4889822fad0816f47f6450b9afa;p=corax Move architecture-independent process implementation out of the arch directory --- diff --git a/kernel/arch/Makefile b/kernel/arch/Makefile index 8097994..e7e4cce 100644 --- a/kernel/arch/Makefile +++ b/kernel/arch/Makefile @@ -1,5 +1,5 @@ OBJECTS = boot.o debug.o init.o cpu.o cpu32.o entry.o interrupt.o paging.o apic.o i8259.o task.o \ - heap.o process.o + heap.o OUTPUT = arch.o LDFLAGS += -r INCLUDES = -I../../include -I../include -I../.. diff --git a/kernel/arch/process.c b/kernel/arch/process.c deleted file mode 100644 index 6b53f48..0000000 --- a/kernel/arch/process.c +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "paging.h" -#include "cpu.h" - -struct process { - struct pagedir *p_pgdir; - struct task *p_tasks; - u32_t p_privl; -}; - -int process_create(process_t **dst, u32_t ppl, void *entry) -{ - int ret_val; - process_t *proc; - - ret_val = -ENOMEM; - proc = kmalloc(sizeof(*proc)); - - if(proc) { - void *pdbr; - void *kstack; - void *ustack; - - ret_val = pg_dir_create(&(proc->p_pgdir)); - - if(ret_val < 0) { - goto cleanup; - } - - pdbr = proc->p_pgdir->pd_base; - kstack = pg_dir_get_kstack(proc->p_pgdir); - ustack = pg_dir_get_ustack(proc->p_pgdir); - - proc->p_tasks = kmalloc(sizeof(*(proc->p_tasks))); - - if(!proc->p_tasks) { - ret_val = -ENOMEM; - goto cleanup; - } - - proc->p_privl = ppl; - - task_prepare(proc->p_tasks, (u32_t)pdbr, (u32_t)entry, - (u32_t)kstack, (u32_t)ustack + PAGE_SIZE, ppl); - - proc->p_tasks->t_sp = (u32_t)(CONFIG_KERNEL_STACK_BASE + - ((u32_t)proc->p_tasks->t_sp - (u32_t)kstack)); - } - -cleanup: - if(ret_val < 0) { - if(proc) { - if(proc->p_pgdir) { - /* cleanup pagedir */ - /* pg_dir_free(proc->p_pgdir): */ - proc->p_pgdir = NULL; - } - - if(proc->p_tasks) { - /* cleanup task */ - - kfree(proc->p_tasks); - proc->p_tasks = NULL; - } - - kfree(proc); - proc = NULL; - } - } - - *dst = proc; - return(ret_val); -} - -int process_switch(process_t *proc) -{ - int ret_val; - - ret_val = task_switch(proc->p_tasks); - - return(ret_val); -} diff --git a/kernel/core/Makefile b/kernel/core/Makefile index 92db6f9..bb68e27 100644 --- a/kernel/core/Makefile +++ b/kernel/core/Makefile @@ -1,4 +1,4 @@ -OBJECTS = main.o +OBJECTS = main.o process.o OUTPUT = core.o INCLUDES = -I../include -I../../include -I../.. CFLAGS += $(INCLUDES) diff --git a/kernel/core/process.c b/kernel/core/process.c new file mode 100644 index 0000000..6b53f48 --- /dev/null +++ b/kernel/core/process.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include +#include "paging.h" +#include "cpu.h" + +struct process { + struct pagedir *p_pgdir; + struct task *p_tasks; + u32_t p_privl; +}; + +int process_create(process_t **dst, u32_t ppl, void *entry) +{ + int ret_val; + process_t *proc; + + ret_val = -ENOMEM; + proc = kmalloc(sizeof(*proc)); + + if(proc) { + void *pdbr; + void *kstack; + void *ustack; + + ret_val = pg_dir_create(&(proc->p_pgdir)); + + if(ret_val < 0) { + goto cleanup; + } + + pdbr = proc->p_pgdir->pd_base; + kstack = pg_dir_get_kstack(proc->p_pgdir); + ustack = pg_dir_get_ustack(proc->p_pgdir); + + proc->p_tasks = kmalloc(sizeof(*(proc->p_tasks))); + + if(!proc->p_tasks) { + ret_val = -ENOMEM; + goto cleanup; + } + + proc->p_privl = ppl; + + task_prepare(proc->p_tasks, (u32_t)pdbr, (u32_t)entry, + (u32_t)kstack, (u32_t)ustack + PAGE_SIZE, ppl); + + proc->p_tasks->t_sp = (u32_t)(CONFIG_KERNEL_STACK_BASE + + ((u32_t)proc->p_tasks->t_sp - (u32_t)kstack)); + } + +cleanup: + if(ret_val < 0) { + if(proc) { + if(proc->p_pgdir) { + /* cleanup pagedir */ + /* pg_dir_free(proc->p_pgdir): */ + proc->p_pgdir = NULL; + } + + if(proc->p_tasks) { + /* cleanup task */ + + kfree(proc->p_tasks); + proc->p_tasks = NULL; + } + + kfree(proc); + proc = NULL; + } + } + + *dst = proc; + return(ret_val); +} + +int process_switch(process_t *proc) +{ + int ret_val; + + ret_val = task_switch(proc->p_tasks); + + return(ret_val); +} diff --git a/kernel/include/process.h b/kernel/include/process.h new file mode 100644 index 0000000..c201180 --- /dev/null +++ b/kernel/include/process.h @@ -0,0 +1,29 @@ +/* + * This file is part of the Corax operating system. + * Copyright (C) 2016-2019 Matthias Kruk + * + * Corax is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Corax is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Corax. If not, see . + */ + +#ifndef __PROCESS_H +#define __PROCESS_H + +#include + +typedef struct process process_t; + +int process_create(process_t**, u32_t, void*); +int process_switch(process_t*); + +#endif /* __PROCESS_H */