]> git.corax.cc Git - corax/commitdiff
Separate the architecture dependent and independent parts of the kernel more cleanly:
authorMatthias Kruk <m@m10k.eu>
Fri, 27 Sep 2019 06:18:59 +0000 (15:18 +0900)
committerMatthias Kruk <m@m10k.eu>
Fri, 27 Sep 2019 06:18:59 +0000 (15:18 +0900)
 - Add pg_dir_get_pdbr() function
 - Make definitions, types, and functions necessary for other parts of the
   kernel visible to them by moving them into the kernel/include/arch.h header

kernel/arch/paging.c
kernel/arch/paging.h
kernel/core/process.c
kernel/include/arch.h

index 222df81d3f8f375af40468c595c578aa48e8715e..bbe2c792fa05f001bc774fe0a2d3183148f27a62 100644 (file)
@@ -21,6 +21,7 @@
 #include <corax/heap.h>
 #include <multiboot.h>
 #include <debug.h>
+#include <arch.h>
 #include "cpu.h"
 #include "paging.h"
 #include "heap.h"
@@ -878,3 +879,8 @@ static int _pg_dir_add_region(pg_dir_t *pd, void *base, u32_t size,
 
        return(ret_val);
 }
+
+void* pg_dir_get_pdbr(pg_dir_t *pd)
+{
+       return(pd->pd_base);
+}
index da4a6e4253076b0fd73daa4ca63bb79cbfe66845..248a01efb46c4d28838f5447d6fd62b01f07a3fe 100644 (file)
@@ -43,8 +43,6 @@ struct region {
        u32_t reg_flags;
 };
 
-typedef struct pagedir pg_dir_t;
-
 struct pagedir {
        void  *pd_base;
        u32_t pd_flags;
@@ -96,11 +94,4 @@ void* pg_frame_alloc_start(void);
 void* pg_frame_alloc_end(void);
 void  pg_frame_free(void*);
 
-int   pg_dir_create(pg_dir_t**);
-int   pg_dir_map(pg_dir_t*, const void*, const void*, const u32_t, const u32_t);
-int   pg_dir_unmap(pg_dir_t*, const void*, const u32_t);
-
-void* pg_dir_get_kstack(pg_dir_t*);
-void* pg_dir_get_ustack(pg_dir_t*);
-
 #endif /* __PAGING_H */
index 6b53f48455643bac80f00f2a586674baec433007..fb0b75c2b277f9c26b30db92fbe57dab12d9d901 100644 (file)
@@ -1,11 +1,10 @@
+#include <config.h>
 #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;
@@ -32,7 +31,7 @@ int process_create(process_t **dst, u32_t ppl, void *entry)
                        goto cleanup;
                }
 
-               pdbr = proc->p_pgdir->pd_base;
+               pdbr = pg_dir_get_pdbr(proc->p_pgdir);
                kstack = pg_dir_get_kstack(proc->p_pgdir);
                ustack = pg_dir_get_ustack(proc->p_pgdir);
 
index dacad3c0fa7c8106a277c08ea91e025f85b74029..e77593eb418764af441aa3c8a7a17a7b84881670 100644 (file)
@@ -37,4 +37,41 @@ u32_t   cpu_set_pstate(int pstate);
 int     task_prepare(struct task*, u32_t cr3, u32_t eip, u32_t esp0, u32_t esp, u32_t priv);
 int     task_switch(struct task*);
 
+/*
+ * Definitions, types, and prototypes related to paging
+ */
+
+#define ALIGNED(_v, _a) (!((_v) & (((_a) - 1))))
+#define ALIGN(_v, _a)   (ALIGNED((_v), (_a)) ? (_v) : (((_v) & ~((_a) - 1)) + (_a)))
+
+#define PDPT_ALIGN          32
+#define PAGE_ALIGN          0x1000
+#define ARCH_ALIGN          sizeof(void*)
+
+#define PAGE_SIZE           0x1000
+#define PAGE_SIZE_BIG       0x200000
+#define PAGE_SIZE_LARGE     0x400000
+#define PAGE_SIZE_HUGE      0x40000000
+
+#define PAGE_ATTR_PRESENT           (1 << 0)
+#define PAGE_ATTR_WRITABLE          (1 << 1)
+#define PAGE_ATTR_USER              (1 << 2)
+#define PAGE_ATTR_WRITE_THRU        (1 << 3)
+#define PAGE_ATTR_CACHE_DISABLE     (1 << 4)
+#define PAGE_ATTR_ACCESSED          (1 << 5)
+#define PAGE_ATTR_DIRTY             (1 << 6)
+#define PAGE_ATTR_SIZE              (1 << 7)
+#define PAGE_ATTR_GLOBAL            (1 << 8)
+#define PAGE_ATTR_NO_EXEC           0 /* (1 << 63) */
+
+typedef struct pagedir pg_dir_t;
+
+int     pg_dir_create(pg_dir_t**);
+int     pg_dir_map(pg_dir_t*, const void*, const void*, const u32_t, const u32_t);
+int     pg_dir_unmap(pg_dir_t*, const void*, const u32_t);
+void*   pg_dir_get_pdbr(pg_dir_t*);
+
+void*   pg_dir_get_kstack(pg_dir_t*);
+void*   pg_dir_get_ustack(pg_dir_t*);
+
 #endif /* __ARCH_H */