Example #1
0
//uint64_t exception_stack;
void start(uint32_t* modulep, void* physbase, void* physfree)
{
	uint64_t address = (uint64_t)(&idt);
        uint16_t size_idt = (uint16_t)(sizeof(idt));
	int my_variable = 0;
//        int i = 922222895;
	//int i =0;
        struct smap_t {
                uint64_t base, length;
                uint32_t type;
        }__attribute__((packed)) *smap;
	struct process *newproc1,*newproc2,*newproc3;
        cls();
//        while(--i>0);
        while(modulep[0] != 0x9001) modulep += modulep[1]+2;
        for(smap = (struct smap_t*)(modulep+2); smap < (struct smap_t*)((char*)modulep+modulep[1]+2*4); ++smap) {
                if (smap->type == 1 /* memory */ && smap->length != 0) {
                   kprintf("Available Physical Memory [%x-%x]\n", smap->base, smap->base + smap->length);
                }
        }
        kprintf("tarfs in [%p:%p]\n", &_binary_tarfs_start, &_binary_tarfs_end);
        set_all_handlers();
        setup_idtr(address,size_idt);
	npages_determine(134205440);
	set_consts((uint64_t)physbase,(uint64_t)physfree);
	mm_init();
	loadcr3(katopa((uint64_t)pml4e),(uint64_t)physbase,(uint64_t)physfree);
	my_variable++;
	newproc1 = (struct process*)process_setup((uint64_t)physbase,(uint64_t)physfree,"bin/newhello");
	curproc_count++;
	newproc2 = process_setup((uint64_t)physbase,(uint64_t)physfree,"bin/sacrifice");
	curproc_count++;
	newproc3 = process_setup((uint64_t)physbase,(uint64_t)physfree,"bin/pragathi");
	proc_status(newproc1);
	proc_status(newproc2);
	proc_status(newproc3);	
	cur_proc = newproc1;
	/*while(i<10000)
	{
	kmalloc(30);
	i++;
	}*/
	exception_stack = page_alloc();
	first_sched();
        while(1){}

}
Example #2
0
void copy_on_write_handler(uint64_t faultAddr)
{
	uint64_t * pte=NULL;
    struct page* newPage=NULL;
	struct page* faultPage=NULL;;
	void * buffer = kmalloc(PAGE_SIZE);
	pte = pml4Walk(current_pcb->pml4, faultAddr);
	
	//printf("In COW HANDLER\n");

	if(*pte & BIT_COW)
	{
		
		faultPage = getStrPtrFromPA((void *)(*pte));
		if(faultPage->ref_count==2)//Allocate new writeable page and map it
		{
			//Important: Copy bytes from faulting page to temp buffer
			memcpy(buffer, alignDown((void *)faultAddr), PAGE_SIZE);	
			page_remove(current_pcb->pml4, (void *)faultAddr);
			
			newPage=page_alloc();
			page_insert(current_pcb->pml4, (void *)faultAddr, newPage, BIT_PRESENT | BIT_RW | BIT_USER);	
			//Invalidate tlb?, included in page_remove
			loadcr3(current_pcb->cr3);

			//Copy back bytes from temp buffer
			memcpy(alignDown((void *)faultAddr), buffer, PAGE_SIZE);

			//printf("Inserted new page %x on COW fault on page ref=2\n", getPA(newPage));
			
		}
		else
		{
			//Make page rightable
			*pte = (*pte & ~BIT_COW) | BIT_RW;
			//printf("Made page writeable on COW fault, page ref=1\n");
				
		}		
	}	


}