コード例 #1
0
/*
 * void init_paging()
 * 	 Description: Initializes page directories, tables and control registers
 *   Inputs: none
 *   Return Value: none
 */
void init_paging()
{
	// Set up program page (physical) address array
	uint32_t i;
	for(i = 0; i < NUM_PD; i++)
	{
		PGRM_PAGE[i] = PAGE1 + i * PAGE_SIZE;
	}

	// Initialize the Page directory
	init_PD();

	// Initialize the video page table
	init_VIDEO_PT();

	// Set PSE bit in CR4
	set_PSE();

	// Set PG bit in CR0
	set_PG();

	// Set PGE bit in CR4
	set_PGE();

	INVLPG(VIDEO_MEM);
	INVLPG(KERNEL_MEM);

	//test_paging();

}
コード例 #2
0
ファイル: vmm_sim.c プロジェクト: pwlong/two_handed_eraser
int main(int argc, char *argv[]){
	
	FILE *fp;								// stimulus file handle
	char filename[50] = "stim.txt";			// stimulus file name, can be overwritten on cmdline
	 // if filename given on commandline use it otherwise use default filename
	if (argc == 2)	{strcpy(filename, argv[1]);}
	else			{strcpy(filename, "stim.txt");}
	
	int opt = 0;
	
	// parse the cmdline
	while ((opt = getopt(argc, argv, "i:p:")) != -1) {
		switch(opt) {
			case 'i':	strcpy(filename, optarg); break;
			case 'p':	available_pf = (u32) strtol(optarg,NULL,10);
						validate_pf_number(available_pf);
						break;
			case '?': 
						if (optopt == 'i'){
							printf("USAGE: -i <filename>\n\n");
							return -1;
						} else if (optopt == 'p') {
							printf("USAGE: -p <numpages>\n\n");
							return -1;
						} else {
							printf("Valid switches are:\n");
							printf("\t -i <input_filename>\n\t -p <numpages>\n\n");
							return -1;
						break;
						}
		}
	}
	
	// open the input file
	fp = fopen (filename,"r");
	if (NULL == fp){
		fprintf (stderr, "Failed to open input file. This is fatal!\n");
		exit(0);
	}
	//call function to allocate memory to PD
	init_PD();
	
	// loop through input file an feed commands to sim
	do {
		get_command(fp);
		if (strcmp(cmd, "-v") == MATCH) {
			printf("VMM Simulator Ver 0.1\n"); 
			exit(-1);
		}
		else if (strcmp(cmd, "w") == MATCH || strcmp(cmd, "r") == MATCH ) {
			// update read/wrote/access statistics
			num_accesses ++;
			if (strcmp(cmd, "w") == MATCH) {num_writes ++;}
			else                           {num_reads ++;}
			
			parse_addr(addr);
			if ( t_flag == 1 ){
				printf(" %s 0x%08X\n", cmd, addr);
			}
			if (is_PT_present(working_addr.PD_index) == 1) {
			    //check the user page present
				if(is_UP_present(working_addr.PD_index, working_addr.PT_index) == 1)
				{
					total_cycles += 20;               //if the address exist, it considers memory access
					//printf("get here few time\n");
				}
				else  //the PT exists but not the user page
				{
				   if (available_pf == used_pf)       // no pf avail then evict one page
						evict_page();
				   create_user_page(working_addr.PD_index, working_addr.PT_index,cmd);
				}
			}
			else   // new PT and UP need to created
			{	
			    while (available_pf < (used_pf + 2))   // create 2 avail pf
					evict_page();
					
			    create_page_table(working_addr.PD_index, cmd);
			    create_user_page(working_addr.PD_index, working_addr.PT_index, cmd);
			}   
		}
		if (d_flag == 1){dump_vmm();}	
		
	} while (strcmp (cmd, "EOF"));
	
	num_physical_frames = 1 + num_PT + num_UP;
	print_outputs();
	
}