Esempio n. 1
0
int 
main() 
{

    unsigned int i;

    if(init_hardware("etc/hardware.ini") == 0) {
	fprintf(stderr, "Error in hardware initialization\n");
        exit(EXIT_FAILURE);
    }
    
    printf("ATTENTION !\nSi l'on donne une taille de matrice très grande, le processus peut prendre un certain temps\n\n");
    printf("MATRIX_SIZE : %d\n\n", MATRIX_SIZE);
    for(i=0;i<16;i++){
	IRQVECTOR[i] = ignore;
    }

    _out(MMU_PROCESS,1);


    IRQVECTOR[MMU_IRQ] = mmuhandler;
    IRQVECTOR[SYSCALL_SWTCH_0] = switch_to_process0;
    IRQVECTOR[SYSCALL_SWTCH_1] = switch_to_process1;
    _mask(0x1001);

    if(init_swap("./swap_file")==-1){
	printf("erreur\n");
    }
    init();
    return 0;
}
Esempio n. 2
0
//adds a page to swap space, gets called with the physical memory position
size_t add_swap (void * addr) {
	//init swap if necessary
	if (swap == NULL)   //init the swap table
  		init_swap ();

	//lock the swap table
	lock_acquire(&swap_lock);

	//find a free entry in the bitmap table
	size_t free = bitmap_scan (swap_table, 0, 1, false);
	//if the swap table is full panic the kernel
	if (free == BITMAP_ERROR) PANIC ("Swaptable is full\n");

	int i;
	//get frame and the memory position and write it to swap
	for (i = 0; i< SECPP; i++)
		//write block to swap, free * SECPP is the correct block position and + i because a page has a different size, same for addr
		block_write (swap, free * SECPP + i, addr + BLOCK_SECTOR_SIZE * i);

	//set the corresponding entry in the swap_table to true
	bitmap_set (swap_table, free, true);

	//release the lock for the swap table
	lock_release(&swap_lock);

	return free;

}
Esempio n. 3
0
/**************************** core implementation ****************************/
int page_sim_init(unsigned page_size, unsigned mem_size,
                  unsigned addr_space_size, unsigned max_concurrent_operations,
                  pagesim_callback callback)
{
    if (!globals.active)
	{
		if (pthread_mutex_lock(&lib_init_end_mutex) == ERROR)
			return ERROR;
        if (check_init_constraints(page_size,
                                   mem_size,
                                   addr_space_size,
                                   max_concurrent_operations) == ERROR)
            return ERROR;
        globals.page_size = page_size;
        globals.mem_size = mem_size;
        globals.addr_space_size = addr_space_size;
        globals.act_concurrent_operations = 0;
		globals.act_queries = 0;
        globals.logger = callback;
        
        if (pthread_mutex_init(&globals.concurrent_operations_mutex, NULL) 
            == ERROR)
            return ERROR;
        if (pthread_cond_init(&globals.io_oveflow_cond, NULL) 
            == ERROR)
            return ERROR;
        if (pthread_mutex_init(&globals.logger_mutex, NULL) 
            == ERROR)
            return ERROR;
        if (pthread_mutex_init(&globals.select_mutex, NULL) 
            == ERROR)
            return ERROR;
		if (pthread_mutex_init(&globals.act_queries_mutex, NULL) 
            == ERROR)
            return ERROR;
        init_strategy_metadata();
        if (init_swap() == ERROR)
            return ERROR;
        if (init_pages() == ERROR)
            return ERROR;
        
        globals.active = true;
		if (pthread_mutex_unlock(&lib_init_end_mutex) == ERROR)
			return ERROR;
		return SUCCESS;
    }
    return ERROR;
}
Esempio n. 4
0
int main(int argc, char **argv)
{
    /* init hardware */
    if(init_hardware("hardware.ini") == 0)
    {
	    fprintf(stderr, "Error in hardware initialization\n");
	    exit(EXIT_FAILURE);
    }
    
    init_swap("swapfile");
    
    memset(vm_mapping, 0, sizeof(struct vm_mapping_s) * VM_PAGES);
    memset(pm_mapping, 0, sizeof(struct pm_mapping_s) * PM_PAGES);
    
    IRQVECTOR[MMU_IRQ] = mmuhandler;
    _mask(0x1001);

    user_process();
    
    return 0;
}