# HG changeset patch # User John Tsiombikas # Date 1311582542 -10800 # Node ID 5f6c5751ae0515f78cf9254072411bc8aa1d6a02 # Parent e6de3c6015cb26d28900e0235e0baf8c5325bacd - implemented clone_vmem diff -r e6de3c6015cb -r 5f6c5751ae05 src/asmops.h --- a/src/asmops.h Sun Jul 24 18:29:24 2011 +0300 +++ b/src/asmops.h Mon Jul 25 11:29:02 2011 +0300 @@ -1,6 +1,8 @@ #ifndef ASMOPS_H_ #define ASMOPS_H_ +#include + /* general purpose registers as they are pushed by pusha */ struct registers { uint32_t edi, esi, ebp, esp; diff -r e6de3c6015cb -r 5f6c5751ae05 src/main.c --- a/src/main.c Sun Jul 24 18:29:24 2011 +0300 +++ b/src/main.c Mon Jul 25 11:29:02 2011 +0300 @@ -10,35 +10,6 @@ #include "mem.h" #include "vm.h" -static void do_nothing(); - -/* special keys */ -enum { - LALT, RALT, - LCTRL, RCTRL, - LSHIFT, RSHIFT, - F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, - CAPSLK, NUMLK, SCRLK, SYSRQ, - ESC = 27, - INSERT, DEL, HOME, END, PGUP, PGDN, LEFT, RIGHT, UP, DOWN, - NUM_DOT, NUM_ENTER, NUM_PLUS, NUM_MINUS, NUM_MUL, NUM_DIV, - NUM_0, NUM_1, NUM_2, NUM_3, NUM_4, NUM_5, NUM_6, NUM_7, NUM_8, NUM_9, - BACKSP = 127 -}; - -/* table with rough translations from set 1 scancodes to ASCII-ish */ -static int keycodes[] = { - 0, ESC, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', /* 0 - e */ - '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* f - 1c */ - LCTRL, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', /* 1d - 29 */ - LSHIFT, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', RSHIFT, /* 2a - 36 */ - NUM_MUL, LALT, ' ', CAPSLK, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, /* 37 - 44 */ - NUMLK, SCRLK, NUM_7, NUM_8, NUM_9, NUM_MINUS, NUM_4, NUM_5, NUM_6, NUM_PLUS, /* 45 - 4e */ - NUM_1, NUM_2, NUM_3, NUM_0, NUM_DOT, SYSRQ, 0, 0, F11, F12, /* 4d - 58 */ - 0, 0, 0, 0, 0, 0, 0, /* 59 - 5f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 70 - 7f */ -}; void kmain(struct mboot_info *mbinf) { @@ -72,13 +43,6 @@ for(;;) { - char c, keypress; - do { - inb(keypress, 0x64); - } while(!(keypress & 1)); - inb(c, 0x60); - if(!(c & 0x80)) { - putchar(keycodes[(int)c]); - } + halt_cpu(); } } diff -r e6de3c6015cb -r 5f6c5751ae05 src/panic.c --- a/src/panic.c Sun Jul 24 18:29:24 2011 +0300 +++ b/src/panic.c Mon Jul 25 11:29:02 2011 +0300 @@ -3,7 +3,7 @@ #include #include "asmops.h" -struct registers { +struct all_registers { uint32_t eax, ebx, ecx, edx; uint32_t esp, ebp, esi, edi; uint32_t eflags; @@ -12,12 +12,12 @@ }; /* defined in regs.S */ -void get_regs(struct registers *regs); +void get_regs(struct all_registers *regs); void panic(const char *fmt, ...) { va_list ap; - struct registers regs; + struct all_registers regs; disable_intr(); diff -r e6de3c6015cb -r 5f6c5751ae05 src/proc.c --- a/src/proc.c Sun Jul 24 18:29:24 2011 +0300 +++ b/src/proc.c Mon Jul 25 11:29:02 2011 +0300 @@ -11,6 +11,7 @@ /* prepare the first process */ /* create the virtual address space for this process */ + proc[0].ctx.pgtbl_paddr = clone_vmem(); /* allocate a chunk of memory for the process image * and copy the code of test_proc there. @@ -28,10 +29,11 @@ */ } +/* void save_context(struct intr_frame *ifrm) { proc[cur_pid].ctx->regs = ifrm->regs; proc[cur_pid].ctx->instr_ptr = ifrm->eip; proc[cur_pid].ctx->stack_ptr = ifrm->esp; proc[cur_pid].ctx->flags = ifrm->eflags; -} +}*/ diff -r e6de3c6015cb -r 5f6c5751ae05 src/proc.h --- a/src/proc.h Sun Jul 24 18:29:24 2011 +0300 +++ b/src/proc.h Mon Jul 25 11:29:02 2011 +0300 @@ -1,6 +1,7 @@ #ifndef PROC_H_ #define PROC_H_ +#include #include "asmops.h" #define MAX_PROC 128 @@ -10,6 +11,7 @@ uint32_t instr_ptr; uint32_t stack_ptr; uint32_t flags; + uint32_t pgtbl_paddr; /* TODO add FPU state */ }; diff -r e6de3c6015cb -r 5f6c5751ae05 src/vm.c --- a/src/vm.c Sun Jul 24 18:29:24 2011 +0300 +++ b/src/vm.c Mon Jul 25 11:29:02 2011 +0300 @@ -134,9 +134,10 @@ return 0; } -void unmap_page(int vpage) +int unmap_page(int vpage) { uint32_t *pgtbl; + int res = 0; int diridx = PAGE_TO_PGTBL(vpage); int pgidx = PAGE_TO_PGTBL_PG(vpage); @@ -157,8 +158,10 @@ if(0) { err: printf("unmap_page(%d): page already not mapped\n", vpage); + res = -1; } set_intr_state(intr_state); + return res; } /* if ppg_start is -1, we allocate physical pages to map with alloc_phys_page() */ @@ -173,6 +176,18 @@ return 0; } +int unmap_page_range(int vpg_start, int pgcount) +{ + int i, res = 0; + + for(i=0; i= PAGE_COUNT) { + return -1; + } + + diridx = PAGE_TO_PGTBL(vpg); + pgidx = PAGE_TO_PGTBL_PG(vpg); if(!(pgdir[diridx] & PG_PRESENT)) { - panic("virt_to_phys(%x): page table %d not present\n", vaddr, diridx); + return -1; } pgtbl = PGTBL(diridx); if(!(pgtbl[pgidx] & PG_PRESENT)) { - panic("virt_to_phys(%x): page %d not present\n", vaddr, ADDR_TO_PAGE(vaddr)); + return -1; } pgaddr = pgtbl[pgidx] & PGENT_ADDR_MASK; - - return pgaddr | ADDR_TO_PGOFFS(vaddr); + return ADDR_TO_PAGE(pgaddr); } /* allocate a contiguous block of virtual memory pages along with @@ -266,9 +299,9 @@ disable_intr(); for(i=0; i