aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/include
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-13 17:23:29 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-13 17:23:29 +0100
commitf67c0b7e20ef0816a2d9047fd20346e3ede98b75 (patch)
tree7e547ff85cf10777b882fe925800dad4e65e6414 /src/kernel/include
parent1ca5c37cee8a9d9c3058746da78240d8dc289a02 (diff)
downloadkogata-f67c0b7e20ef0816a2d9047fd20346e3ede98b75.tar.gz
kogata-f67c0b7e20ef0816a2d9047fd20346e3ede98b75.zip
Prepare for user memory management and usermode code
Diffstat (limited to 'src/kernel/include')
-rw-r--r--src/kernel/include/paging.h8
-rw-r--r--src/kernel/include/region.h6
-rw-r--r--src/kernel/include/thread.h6
3 files changed, 16 insertions, 4 deletions
diff --git a/src/kernel/include/paging.h b/src/kernel/include/paging.h
index d42ec52..56fa7fa 100644
--- a/src/kernel/include/paging.h
+++ b/src/kernel/include/paging.h
@@ -3,10 +3,16 @@
#include <sys.h>
#include <stdbool.h>
+// Bits in the error code for page fault
+#define PF_PRESENT_BIT (1<<0)
+#define PF_WRITE_BIT (1<<1)
+#define PF_USER_BIT (1<<2)
+#define PF_RSVD_WRITE_BIT (1<<3)
+#define PF_OPFETCH_BIT (1<<4)
+
struct page_directory;
typedef struct page_directory pagedir_t;
-
void paging_setup(void* kernel_data_end);
pagedir_t *get_current_pagedir();
diff --git a/src/kernel/include/region.h b/src/kernel/include/region.h
index 1fef582..a390e06 100644
--- a/src/kernel/include/region.h
+++ b/src/kernel/include/region.h
@@ -8,18 +8,18 @@
#include <paging.h>
struct region_info;
-typedef void (*page_fault_handler_t)(pagedir_t *pd, struct region_info *r, void* addr);
+typedef void (*kernel_pf_handler_t)(pagedir_t *pd, struct region_info *r, void* addr);
typedef struct region_info {
void* addr;
size_t size;
char* type;
- page_fault_handler_t pf;
+ kernel_pf_handler_t pf;
} region_info_t;
void region_allocator_init(void* kernel_data_end);
-void* region_alloc(size_t size, char* type, page_fault_handler_t pf); // returns 0 on error
+void* region_alloc(size_t size, char* type, kernel_pf_handler_t pf); // returns 0 on error
region_info_t *find_region(void* addr);
void region_free(void* addr);
diff --git a/src/kernel/include/thread.h b/src/kernel/include/thread.h
index b5fa50d..011067f 100644
--- a/src/kernel/include/thread.h
+++ b/src/kernel/include/thread.h
@@ -3,6 +3,7 @@
#include <sys.h>
#include <paging.h>
#include <region.h>
+#include <idt.h>
#define T_STATE_RUNNING 1
#define T_STATE_PAUSED 2
@@ -12,6 +13,8 @@
#define TASK_SWITCH_FREQUENCY 50 // in herz
+typedef void (*user_pf_handler_t)(pagedir_t *pd, registers_t *regs, void* addr);
+
typedef struct saved_context {
uint32_t *esp;
void (*eip)();
@@ -27,6 +30,8 @@ typedef struct thread {
region_info_t *stack_region;
struct process *proc; // process : L1 data structure
+ user_pf_handler_t usermem_pf_handler; // page fault in user memory
+ isr_handler_t kmem_violation_handler; // page fault in kernel memory accessed by user code (violation)
struct thread *next_in_queue;
} thread_t;
@@ -40,6 +45,7 @@ extern thread_t *current_thread;
void yield();
void pause();
+void exit();
void resume_thread(thread_t *thread, bool run_at_once);