]> git.corax.cc Git - corax/commitdiff
Move architecture-independent process implementation out of the arch directory
authorMatthias Kruk <m@m10k.eu>
Fri, 27 Sep 2019 06:08:52 +0000 (15:08 +0900)
committerMatthias Kruk <m@m10k.eu>
Fri, 27 Sep 2019 06:17:53 +0000 (15:17 +0900)
kernel/arch/Makefile
kernel/arch/process.c [deleted file]
kernel/core/Makefile
kernel/core/process.c [new file with mode: 0644]
kernel/include/process.h [new file with mode: 0644]

index 8097994f4ef10cc7752e42c964aeb356256f3c10..e7e4cceed87b98fc69b0ce7310ec5dafb317dda7 100644 (file)
@@ -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 (file)
index 6b53f48..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-#include <corax/types.h>
-#include <corax/errno.h>
-#include <corax/heap.h>
-#include <arch.h>
-#include <debug.h>
-#include <process.h>
-#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);
-}
index 92db6f914015c2c9aca0e7417a20a7651d4e0875..bb68e27d2f8375385e7f5c6f2d4c38ca03e81978 100644 (file)
@@ -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 (file)
index 0000000..6b53f48
--- /dev/null
@@ -0,0 +1,87 @@
+#include <corax/types.h>
+#include <corax/errno.h>
+#include <corax/heap.h>
+#include <arch.h>
+#include <debug.h>
+#include <process.h>
+#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 (file)
index 0000000..c201180
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __PROCESS_H
+#define __PROCESS_H
+
+#include <corax/types.h>
+
+typedef struct process process_t;
+
+int process_create(process_t**, u32_t, void*);
+int process_switch(process_t*);
+
+#endif /* __PROCESS_H */