# HG changeset patch # User John Tsiombikas # Date 1311999714 -10800 # Node ID 50730d42d2d3d8eb80b3eb37e6f94ca8c33d0644 # Parent 4c9c16754b59436f5404c50ef8bfa9fbb3113e20 fuck yeah, now do priviledge levels and TSS diff -r 4c9c16754b59 -r 50730d42d2d3 src/intr-asm.S --- a/src/intr-asm.S Thu Jul 28 17:56:05 2011 +0300 +++ b/src/intr-asm.S Sat Jul 30 07:21:54 2011 +0300 @@ -70,9 +70,15 @@ intr_entry_common: pusha call dispatch_intr + jmp 0f .globl intr_ret intr_ret: + /* if called as a function from context_switch, we must + * remove the pushed return address before continuing + */ + add $4, %esp +0: /* ... we skip to here otherwise */ popa /* remove error code and intr num from stack */ add $8, %esp diff -r 4c9c16754b59 -r 50730d42d2d3 src/intr.h --- a/src/intr.h Thu Jul 28 17:56:05 2011 +0300 +++ b/src/intr.h Sat Jul 30 07:21:54 2011 +0300 @@ -24,7 +24,7 @@ uint32_t eip, cs, eflags; /* pushed by CPU during interrupt entry from user space */ uint32_t esp, ss; -}; +} __attribute__ ((packed)); diff -r 4c9c16754b59 -r 50730d42d2d3 src/proc.c --- a/src/proc.c Thu Jul 28 17:56:05 2011 +0300 +++ b/src/proc.c Sat Jul 30 07:21:54 2011 +0300 @@ -26,12 +26,13 @@ * and copy the code of test_proc there. * (should be mapped at a fixed address) */ - proc_size_pg = (test_proc_end - test_proc) / PGSIZE + 1; + /*proc_size_pg = (test_proc_end - test_proc) / PGSIZE + 1; if((img_start_pg = pgalloc(proc_size_pg, MEM_USER)) == -1) { panic("failed to allocate space for the init process image\n"); } img_start = (void*)PAGE_TO_ADDR(img_start_pg); - memcpy(img_start, test_proc, proc_size_pg * PGSIZE); + memcpy(img_start, test_proc, proc_size_pg * PGSIZE);*/ + img_start = test_proc; /* instruction pointer at the beginning of the process image */ proc[0].ctx.instr_ptr = (uint32_t)img_start; @@ -47,8 +48,8 @@ proc[0].ctx.pgtbl_paddr = clone_vm(); /* we don't need the image and the stack in this address space */ - unmap_page_range(img_start_pg, proc_size_pg); - pgfree(img_start_pg, proc_size_pg); + /*unmap_page_range(img_start_pg, proc_size_pg); + pgfree(img_start_pg, proc_size_pg);*/ unmap_page(stack_pg); pgfree(stack_pg, 1); @@ -69,6 +70,7 @@ struct intr_frame ifrm; struct context *ctx = &proc[pid].ctx; + cur_pid = pid; ifrm.inum = ifrm.err = 0; @@ -76,10 +78,19 @@ ifrm.regs = ctx->regs; ifrm.eflags = ctx->flags; + ifrm.err = 0xbadf00d; + + asm volatile ( + "pushf\n\t" + "popl %0\n\t" + : "=a" (ifrm.eflags) + ); + ifrm.eip = ctx->instr_ptr; - ifrm.cs = SEGM_KCODE; /* XXX change this when we setup the TSS */ - ifrm.esp = ctx->stack_ptr; - ifrm.ss = SEGM_KDATA; /* XXX */ + ifrm.cs = selector(SEGM_KCODE, 0); /* XXX change this when we setup the TSS */ + ifrm.esp = 0;/*ctx->stack_ptr; /* this will only be used when we switch to userspace */ + ifrm.regs.esp = ctx->stack_ptr; /* ... until then... */ + ifrm.ss = 0;/*selector(SEGM_KDATA, 0); /* XXX */ /* switch to the vm of the process */ set_pgdir_addr(ctx->pgtbl_paddr); diff -r 4c9c16754b59 -r 50730d42d2d3 src/vm.c --- a/src/vm.c Thu Jul 28 17:56:05 2011 +0300 +++ b/src/vm.c Sat Jul 30 07:21:54 2011 +0300 @@ -328,8 +328,35 @@ node = pglist[area]; while(node) { if(start >= node->start && start + num <= node->end) { - ret = node->start; - node->start += num; + ret = start; /* can do .. */ + + if(start == node->start) { + /* adjacent to the start of the range */ + node->start += num; + } else if(start + num == node->end) { + /* adjacent to the end of the range */ + node->end = start; + } else { + /* somewhere in the middle, which means we need + * to allocate a new page_range + */ + struct page_range *newnode; + + if(!(newnode = alloc_node())) { + panic("pgalloc_vrange failed to allocate new page_range while splitting a range in half... bummer\n"); + } + newnode->start = start + num; + newnode->end = node->end; + newnode->next = node->next; + + node->end = start; + node->next = newnode; + /* no need to check for null nodes at this point, there's + * certainly stuff at the begining and the end, otherwise we + * wouldn't be here. so break out of it. + */ + break; + } if(node->start == node->end) { prev->next = node->next; @@ -526,7 +553,7 @@ /* we will allocate physical pages and map them to this virtual page * as needed in the loop below. */ - free_phys_page(virt_to_phys(tblpg)); + free_phys_page(virt_to_phys((uint32_t)ntbl)); kstart_dirent = ADDR_TO_PAGE(KMEM_START) / 1024; @@ -548,10 +575,10 @@ /* kernel space */ for(i=kstart_dirent; i<1024; i++) { - ndir[i] = *PGTBL(i); + ndir[i] = pgdir[i]; } - paddr = virt_to_phys(dirpg); + paddr = virt_to_phys((uint32_t)ndir); /* unmap before freeing to avoid deallocating the physical pages */ unmap_page(dirpg);