summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-08-09 03:33:28 +0200
committerMichal Idziorek <m.i@gmx.at>2014-08-09 03:33:28 +0200
commit9776ad666f27dfcdc0a00ae10567b9be8363130f (patch)
treebe90da6a3387b3e1127815507f793fe0185b404f /kernel
parent670085f41e7706be51a1e99f44a637313b96419c (diff)
working on virtual memory manager
Diffstat (limited to 'kernel')
-rw-r--r--kernel/kernel.c5
-rw-r--r--kernel/shell.c24
-rw-r--r--kernel/vmem.c76
3 files changed, 86 insertions, 19 deletions
diff --git a/kernel/kernel.c b/kernel/kernel.c
index c3a0ff7..7dd89f7 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -25,6 +25,7 @@ void int_test_handler()
void kernel_main()
{
+
// clear console
scr_clear();
@@ -42,6 +43,10 @@ void kernel_main()
mem_init(0x7c00+0x120);
scr_put_string_nl("");
+ // we know that here the bootloader placed the mamory map!
+ vmem_init();
+ scr_put_string_nl("");
+
// init and interrupt decriptor table
int_init(0x08);
int_install();
diff --git a/kernel/shell.c b/kernel/shell.c
index ad8011b..6839ec8 100644
--- a/kernel/shell.c
+++ b/kernel/shell.c
@@ -13,12 +13,6 @@ void shell_init()
{
pos=0;
command[0]=0;
-
- scr_nextline();
- scr_put_string_nl("***********************");
- scr_put_string_nl("Fools Shell v 0.0.0.1 *");
- scr_put_string_nl("***********************");
- scr_nextline();
scr_put_string("Command> ");
}
@@ -53,36 +47,28 @@ int strcmp(char *b1, char *b2)
}
// TODO: EXECUTE LATER not inside INTERRUPT !!!
-
void shell_execute()
{
- scr_nextline();
- scr_put_string(" processing command: ");
- scr_put_string_nl(command);
+ //scr_nextline();
+ //scr_put_string(" processing command: ");
+ //scr_put_string_nl(command);
if(1==strcmp(command,"TIME"))
{
- scr_put_string_nl(" getting sys time from kernel");
- scr_put_string(" ");
scr_put_hex(timer16);
- scr_put_string_nl(" seconds passed since system start.");
+ scr_put_string(" seconds passed since system start.");
}
else if(1==strcmp(command,"INT"))
{
- scr_put_string_nl(" getting count of unhandeled interrupts");
- scr_put_string(" ");
scr_put_hex(int_unhandled);
}
else if(1==strcmp(command,"EIGHT"))
{
- scr_put_string_nl(" generating software interrupt 88");
- scr_put_string(" ");
int_generate88();
-
}
else
{
- scr_put_string_nl(" unsupported command, sorry!");
+ scr_put_string(" unsupported command, sorry!");
}
pos=0;
diff --git a/kernel/vmem.c b/kernel/vmem.c
new file mode 100644
index 0000000..d434dee
--- /dev/null
+++ b/kernel/vmem.c
@@ -0,0 +1,76 @@
+#include "kernel.h"
+
+enum PAGE_PTE_FLAGS {
+
+ I86_PTE_PRESENT = 1, //0000000000000000000000000000001
+ I86_PTE_WRITABLE = 2, //0000000000000000000000000000010
+ I86_PTE_USER = 4, //0000000000000000000000000000100
+ I86_PTE_WRITETHOUGH = 8, //0000000000000000000000000001000
+ I86_PTE_NOT_CACHEABLE = 0x10, //0000000000000000000000000010000
+ I86_PTE_ACCESSED = 0x20, //0000000000000000000000000100000
+ I86_PTE_DIRTY = 0x40, //0000000000000000000000001000000
+ I86_PTE_PAT = 0x80, //0000000000000000000000010000000
+ I86_PTE_CPU_GLOBAL = 0x100, //0000000000000000000000100000000
+ I86_PTE_LV4_GLOBAL = 0x200, //0000000000000000000001000000000
+ I86_PTE_FRAME = 0x7FFFF000 //1111111111111111111000000000000
+};
+
+enum PAGE_PDE_FLAGS {
+
+ I86_PDE_PRESENT = 1, //0000000000000000000000000000001
+ I86_PDE_WRITABLE = 2, //0000000000000000000000000000010
+ I86_PDE_USER = 4, //0000000000000000000000000000100
+ I86_PDE_PWT = 8, //0000000000000000000000000001000
+ I86_PDE_PCD = 0x10, //0000000000000000000000000010000
+ I86_PDE_ACCESSED = 0x20, //0000000000000000000000000100000
+ I86_PDE_DIRTY = 0x40, //0000000000000000000000001000000
+ I86_PDE_4MB = 0x80, //0000000000000000000000010000000
+ I86_PDE_CPU_GLOBAL = 0x100, //0000000000000000000000100000000
+ I86_PDE_LV4_GLOBAL = 0x200, //0000000000000000000001000000000
+ I86_PDE_FRAME = 0x7FFFF000 //1111111111111111111000000000000
+};
+
+//! page table entry
+typedef uint32_t pt_entry;
+
+//! a page directery entry
+typedef uint32_t pd_entry;
+
+////
+
+//! virtual address
+typedef uint32_t virtual_addr;
+
+//! i86 architecture defines 1024 entries per table--do not change
+#define PAGES_PER_TABLE 1024
+#define PAGES_PER_DIR 1024
+
+#define PAGE_DIRECTORY_INDEX(x) (((x) >> 22) & 0x3ff)
+#define PAGE_TABLE_INDEX(x) (((x) >> 12) & 0x3ff)
+#define PAGE_GET_PHYSICAL_ADDRESS(x) (*x & ~0xfff)
+
+//! page table represents 4mb address space
+#define PTABLE_ADDR_SPACE_SIZE 0x400000
+
+//! directory table represents 4gb address space
+#define DTABLE_ADDR_SPACE_SIZE 0x100000000
+
+//! page sizes are 4k
+#define PAGE_SIZE 4096
+
+//! page table
+struct ptable {
+
+ pt_entry m_entries[PAGES_PER_TABLE];
+};
+
+//! page directory
+struct pdirectory {
+
+ pd_entry m_entries[PAGES_PER_DIR];
+};
+
+void vmem_init()
+{
+ scr_put_string_nl("todo: init paging");
+}