summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/idt.c6
-rw-r--r--src/kernel/idt.h1
-rw-r--r--src/kernel/isrs.asm3
-rw-r--r--src/kernel/log.c2
-rw-r--r--src/kernel/main.c6
-rw-r--r--src/kernel/paging.c6
-rw-r--r--src/kernel/paging.h1
-rw-r--r--src/kernel/task.c3
8 files changed, 15 insertions, 13 deletions
diff --git a/src/kernel/idt.c b/src/kernel/idt.c
index 460cfb0..31d597f 100644
--- a/src/kernel/idt.c
+++ b/src/kernel/idt.c
@@ -70,9 +70,7 @@ static char sc_get_key() {
}
static void *sc_allocate_ram(uint32_t pages) {
-//switch_to_kernel_cr3();
- void *result = pd_user_allocate_anywhere_writable(active_task->page_directory, pages);
-//switch_to_task_cr3();
+ return pd_user_allocate_anywhere_writable(active_task->page_directory, pages);
}
void const *syscall_table[] = {
@@ -90,7 +88,7 @@ extern void syscall_isr;
extern void quit_isr;
extern void yield_isr;
-void register_int(uint8_t n, void *isr, uint8_t dpl) {
+static void register_int(uint8_t n, void *isr, uint8_t dpl) {
idt[n].addr_low = (uint32_t)isr & 0xffff;
idt[n].addr_high = (uint32_t)isr >> 16;
idt[n].cs = 0x10;
diff --git a/src/kernel/idt.h b/src/kernel/idt.h
index 6815de9..9971d9a 100644
--- a/src/kernel/idt.h
+++ b/src/kernel/idt.h
@@ -4,6 +4,5 @@
#include <stdint.h>
void init_idt();
-void enable_idt();
#endif \ No newline at end of file
diff --git a/src/kernel/isrs.asm b/src/kernel/isrs.asm
index 163ddbe..56f3c12 100644
--- a/src/kernel/isrs.asm
+++ b/src/kernel/isrs.asm
@@ -86,6 +86,9 @@ _before_start_task:
iret
_start_user_mode:
+ mov ax, 0x2b
+ mov ds, ax
+
push dword 0x2b
sub esp, 4
push dword 0x00000200;interrupt flag
diff --git a/src/kernel/log.c b/src/kernel/log.c
index e8695cc..bc8ff84 100644
--- a/src/kernel/log.c
+++ b/src/kernel/log.c
@@ -4,7 +4,7 @@
#define INFO_COM COM1
void init_log() {
- vga_set_color(0x2f);
+ vga_set_color(0x30);
vga_blank();
}
diff --git a/src/kernel/main.c b/src/kernel/main.c
index eb57a01..1fe8e7b 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -12,6 +12,7 @@
#include "pci.h"
#include "log.h"
#include "elf.h"
+#include "vga.h"
void reset_tree();
void tree(struct drive *d);
@@ -143,9 +144,8 @@ void main() {
logsz(nbuf);
logsz("k user memory free.\n");
-//while (1)
-// asm ("hlt");
-
init_idt();
+
+ vga_set_color(0x07);
_start_user_mode();
} \ No newline at end of file
diff --git a/src/kernel/paging.c b/src/kernel/paging.c
index b92e037..36fb8a7 100644
--- a/src/kernel/paging.c
+++ b/src/kernel/paging.c
@@ -45,7 +45,8 @@ void pd_map(void *pd, uint32_t physical_addr, uint32_t virtual_addr, bool writab
((uint32_t *)(*ptp & PE_ADDR_MASK))[(virtual_addr >> 12) % 1024] = physical_addr | PE_USER | PE_PRESENT | (PE_WRITABLE * writable);
}
-bool pd_is_mapped(void *pd, uint32_t vma) {
+__attribute__ ((pure))
+static bool pd_is_mapped(void *pd, uint32_t vma) {
uint32_t pde = ((uint32_t *)pd)[vma >> 22];
return (pde & PE_PRESENT) && (((uint32_t *)(pde & PE_ADDR_MASK))[(vma >> 12) % 1024] & PE_PRESENT);
}
@@ -85,7 +86,7 @@ void *pd_user_allocate(void *pd, uint32_t vma, uint32_t pages, bool writable) {
void *pd_user_allocate_anywhere_writable(void *pd, uint32_t pages) {
uint32_t run = 0;
for (void *vma = (void *)KERNEL_END; vma; vma += 4096) {
- if (pd_is_mapped(pd, vma))
+ if (pd_is_mapped(pd, (uint32_t)vma))
run = 0;
else if (++run == pages) {
vma -= (pages - 1) * 4096;
@@ -94,6 +95,7 @@ void *pd_user_allocate_anywhere_writable(void *pd, uint32_t pages) {
return vma;
}
}
+ return 0;
}
#define KPAGE_DIR ((uint32_t *)0x00005000)
diff --git a/src/kernel/paging.h b/src/kernel/paging.h
index 72400e8..e39b3f2 100644
--- a/src/kernel/paging.h
+++ b/src/kernel/paging.h
@@ -6,7 +6,6 @@ void init_paging();
void *new_pd();
void free_pd(void *pd);
void pd_map(void *pd, uint32_t physical_addr, uint32_t virtual_addr, bool writable);
-void switch_pd(void *pd);
void free_task_pd(void *pd);
void *new_task_pd();
diff --git a/src/kernel/task.c b/src/kernel/task.c
index 79b2f09..c8a8ac8 100644
--- a/src/kernel/task.c
+++ b/src/kernel/task.c
@@ -1,6 +1,7 @@
#include "panic.h"
#include "task.h"
#include "paging.h"
+#include "log.h"
struct tss {
struct tss *prev;
@@ -41,7 +42,7 @@ struct tss {
#define MAX_TASKS 64
-struct task_state tasks[MAX_TASKS];
+static struct task_state tasks[MAX_TASKS];
struct task_state *active_task;
void init_tasks() {