diff options
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | kernel/kernel.c | 5 | ||||
| -rw-r--r-- | kernel/shell.c | 24 | ||||
| -rw-r--r-- | kernel/vmem.c | 76 |
5 files changed, 95 insertions, 22 deletions
@@ -32,6 +32,9 @@ kernel_entry.o: boot/kernel_entry.asm kernel.o: kernel/kernel.c kernel/console.h gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0 +vmem.o: kernel/vmem.c + gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0 + mem.o: kernel/mem.c gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0 @@ -50,7 +53,7 @@ timer.o: kernel/timer.c shell.o: kernel/shell.c gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0 -kernel.bin: kernel_entry.o kernel.o console.o interrupts.o keyboard.o timer.o shell.o mem.o +kernel.bin: kernel_entry.o kernel.o console.o interrupts.o keyboard.o timer.o shell.o mem.o vmem.o ld -o $@ -Ttext 0x1000 --oformat binary -melf_i386 $^ -O0 @@ -33,7 +33,10 @@ Issues * Makefile is hardcoded and contains mistakes too! * size of bitmap to track free blocks of physical memory is hardcoded to max. * physical memory manager allocator naively implemented. - +* kernel should run in high memory (~3gb) virutal mem. why? except v86 tasks? +* redesign keyboard interrupt handler (faster!) +* redesign command handling (not inside the interrupt!!!) +* implement a real shell (in user mode) MY NOTES BELOW THIS LINE @@ -140,4 +143,4 @@ REFERENCES * http://www.brokenthorn.com/Resources/OSDev17.html * http://www.jamesmolloy.co.uk/tutorial_html/9.-Multitasking.html * http://pdos.csail.mit.edu/6.828/2011/labs/lab6/ - +* http://wiki.osdev.org/Virtual_8086_Mode 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"); +} |
