aboutsummaryrefslogtreecommitdiff
path: root/kernel/inc
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/inc')
-rw-r--r--kernel/inc/boot.h25
-rw-r--r--kernel/inc/fb.h10
-rw-r--r--kernel/inc/fs.h4
-rw-r--r--kernel/inc/interrupts.h1
-rw-r--r--kernel/inc/load.h1
-rw-r--r--kernel/inc/mm.h108
-rw-r--r--kernel/inc/proc.h9
7 files changed, 153 insertions, 5 deletions
diff --git a/kernel/inc/boot.h b/kernel/inc/boot.h
index 6bacc31..7f085cd 100644
--- a/kernel/inc/boot.h
+++ b/kernel/inc/boot.h
@@ -6,10 +6,33 @@
#include <def.h>
-extern struct vid_info *boot_passed;
struct vid_info {
u32 mode;
u32 *vbe;
};
+enum mmap_type {
+ MEMORY_AVAILABLE = 1,
+ MEMORY_RESERVED,
+ MEMORY_ACPI,
+ MEMORY_NVS,
+ MEMORY_DEFECT,
+ MEMORY_DISABLED
+};
+
+struct mmap_boot {
+ u32 lbase;
+ u32 hbase;
+ u32 lsize;
+ u32 hsize;
+ u32 type;
+ u32 acpi;
+};
+
+struct mem_info {
+ struct mmap_boot *start;
+ u32 *end;
+ u32 size;
+};
+
#endif
diff --git a/kernel/inc/fb.h b/kernel/inc/fb.h
new file mode 100644
index 0000000..3e7b08f
--- /dev/null
+++ b/kernel/inc/fb.h
@@ -0,0 +1,10 @@
+// MIT License, Copyright (c) 2021 Marvin Borner
+
+#ifndef FB
+#define FB
+
+#include <boot.h>
+
+void fb_install(struct vid_info *boot);
+
+#endif
diff --git a/kernel/inc/fs.h b/kernel/inc/fs.h
index 33b1afb..cd97b99 100644
--- a/kernel/inc/fs.h
+++ b/kernel/inc/fs.h
@@ -20,6 +20,7 @@ struct device {
void *data;
s32 (*read)(void *buf, u32 offset, u32 count, struct device *dev);
s32 (*write)(void *buf, u32 offset, u32 count, struct device *dev);
+ s32 (*ioctl)(u32 request, void *arg1, void *arg2, void *arg3, struct device *dev);
u8 (*ready)(void);
};
@@ -40,6 +41,8 @@ struct vfs {
void *data;
s32 (*read)(const char *path, void *buf, u32 offset, u32 count, struct device *dev);
s32 (*write)(const char *path, void *buf, u32 offset, u32 count, struct device *dev);
+ s32 (*ioctl)(const char *path, u32 request, void *arg1, void *arg2, void *arg3,
+ struct device *dev);
s32 (*stat)(const char *path, struct stat *buf, struct device *dev);
s32 (*wait)(const char *path, u32 func_ptr, struct device *dev);
u8 (*perm)(const char *path, enum vfs_perm perm, struct device *dev);
@@ -60,6 +63,7 @@ struct device *vfs_find_dev(const char *path);
s32 vfs_read(const char *path, void *buf, u32 offset, u32 count);
s32 vfs_write(const char *path, void *buf, u32 offset, u32 count);
+s32 vfs_ioctl(const char *path, u32 request, void *arg1, void *arg2, void *arg3);
s32 vfs_stat(const char *path, struct stat *buf);
s32 vfs_wait(const char *path, u32 func_ptr);
s32 vfs_poll(const char **files);
diff --git a/kernel/inc/interrupts.h b/kernel/inc/interrupts.h
index 30c91c3..fc00402 100644
--- a/kernel/inc/interrupts.h
+++ b/kernel/inc/interrupts.h
@@ -32,6 +32,7 @@ void irq_uninstall_handler(int irq);
void isr_install_handler(int isr, void (*handler)(struct regs *r));
void isr_uninstall_handler(int isr);
+void isr_panic(struct regs *r);
void interrupts_install(void);
diff --git a/kernel/inc/load.h b/kernel/inc/load.h
index 407fbeb..f493e84 100644
--- a/kernel/inc/load.h
+++ b/kernel/inc/load.h
@@ -5,7 +5,6 @@
#include <proc.h>
-void proc_load(struct proc *proc, void *data);
int bin_load(const char *path, struct proc *proc);
#endif
diff --git a/kernel/inc/mm.h b/kernel/inc/mm.h
new file mode 100644
index 0000000..d3e37f6
--- /dev/null
+++ b/kernel/inc/mm.h
@@ -0,0 +1,108 @@
+// MIT License, Copyright (c) 2021 Marvin Borner
+
+#ifndef PAGING_H
+#define PAGING_H
+
+#include <boot.h>
+#include <def.h>
+#include <interrupts.h>
+
+struct memory_range {
+ u32 base;
+ u32 size;
+};
+
+/**
+ * Physical
+ */
+
+struct memory_range physical_alloc(u32 size);
+void physical_free(struct memory_range range);
+
+/**
+ * Virtual
+ */
+
+#define PAGE_SIZE 0x1000
+#define PAGE_COUNT 1024
+#define PAGE_ALIGN(x) ((x) + PAGE_SIZE - ((x) % PAGE_SIZE))
+#define PAGE_ALIGNED(x) ((x) % PAGE_SIZE == 0)
+#define PAGE_ALIGN_UP(x) (((x) % PAGE_SIZE == 0) ? (x) : (x) + PAGE_SIZE - ((x) % PAGE_SIZE))
+#define PAGE_ALIGN_DOWN(x) ((x) - ((x) % PAGE_SIZE))
+
+union page_table_entry {
+ struct PACKED {
+ u32 present : 1;
+ u32 writable : 1;
+ u32 user : 1;
+ u32 write_through : 1;
+ u32 cache_disable : 1;
+ u32 accessed : 1;
+ u32 dirty : 1;
+ u32 attribute : 1;
+ u32 global : 1;
+ u32 available : 3;
+ u32 address : 20;
+ } bits;
+ u32 uint;
+} PACKED;
+
+struct page_table {
+ union page_table_entry entries[PAGE_COUNT];
+} PACKED;
+
+union page_dir_entry {
+ struct PACKED {
+ u32 present : 1;
+ u32 writable : 1;
+ u32 user : 1;
+ u32 write_through : 1;
+ u32 cache_disable : 1;
+ u32 accessed : 1;
+ u32 reserved : 1;
+ u32 page_size : 1;
+ u32 global : 1;
+ u32 available : 3;
+ u32 address : 20;
+ } bits;
+ u32 uint;
+} PACKED;
+
+struct page_dir {
+ union page_dir_entry entries[PAGE_COUNT];
+} PACKED;
+
+u8 virtual_present(struct page_dir *dir, u32 vaddr);
+u32 virtual_to_physical(struct page_dir *dir, u32 vaddr);
+void virtual_map(struct page_dir *dir, struct memory_range prange, u32 vaddr, u32 flags);
+struct memory_range virtual_alloc(struct page_dir *dir, struct memory_range physical_range,
+ u32 flags);
+void virtual_free(struct page_dir *dir, struct memory_range vrange);
+struct page_dir *virtual_create_dir(void);
+void virtual_destroy_dir(struct page_dir *dir);
+struct page_dir *virtual_kernel_dir(void);
+
+/**
+ * Memory wrappers
+ */
+
+#define MEMORY_NONE (0 << 0)
+#define MEMORY_USER (1 << 0)
+#define MEMORY_CLEAR (1 << 1)
+#define memory_range(base, size) ((struct memory_range){ (base), (size) })
+
+struct memory_range memory_range_from(u32 base, u32 size);
+struct memory_range memory_range_around(u32 base, u32 size);
+
+void *memory_alloc(struct page_dir *dir, u32 size, u32 flags);
+void *memory_alloc_identity(struct page_dir *dir, u32 flags);
+void memory_map_identity(struct page_dir *dir, struct memory_range prange, u32 flags);
+void memory_free(struct page_dir *dir, struct memory_range vrange);
+void memory_switch_dir(struct page_dir *dir);
+void memory_backup_dir(struct page_dir **backup);
+
+void memory_install(struct mem_info *mem_info, struct vid_info *vid_info);
+
+void page_fault_handler(struct regs *r);
+
+#endif
diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h
index 272a3ac..a44fd68 100644
--- a/kernel/inc/proc.h
+++ b/kernel/inc/proc.h
@@ -9,7 +9,7 @@
#include <stack.h>
#include <sys.h>
-#define PROC_QUANTUM 10 // Milliseconds or something // TODO
+#define PROC_QUANTUM 42 // Milliseconds or something // TODO
#define EFLAGS_ALWAYS 0x2 // Always one
#define EFLAGS_INTERRUPTS 0x200 // Enable interrupts
@@ -23,6 +23,7 @@
#define STREAM_MAX_SIZE 4096
enum stream_defaults { STREAM_IN, STREAM_OUT, STREAM_ERR, STREAM_LOG, STREAM_UNKNOWN = -1 };
+enum proc_priv { PROC_PRIV_NONE, PROC_PRIV_ROOT, PROC_PRIV_KERNEL };
enum proc_state { PROC_RUNNING, PROC_SLEEPING };
enum proc_wait_type { PROC_WAIT_DEV, PROC_WAIT_MSG };
@@ -47,9 +48,10 @@ struct stream {
struct proc {
u32 pid;
u32 entry;
- u8 super;
+ u8 priv;
char name[32];
struct stream streams[4];
+ struct page_dir *page_dir;
struct regs regs;
struct proc_wait wait; // dev_id
enum proc_state state;
@@ -67,6 +69,7 @@ void proc_yield(struct regs *r);
void proc_clear_quantum(void);
void proc_enable_waiting(u32 id, enum proc_wait_type type);
void proc_wait_for(u32 id, enum proc_wait_type type, u32 func_ptr);
-struct proc *proc_make(void);
+struct proc *proc_make(enum proc_priv priv);
+void proc_stack_push(struct proc *proc, u32 data);
#endif