コード例 #1
0
ファイル: user_environment.c プロジェクト: Mennat-Ullah/FOS
//
// Initialize the kernel virtual memory layout for environment e.
// Given a pointer to an allocated page directory, set the e->env_pgdir and e->env_cr3 accordingly,
// and initialize the kernel portion of the new environment's address space.
// Do NOT (yet) map anything into the user portion
// of the environment's virtual address space.
//
void initialize_environment(struct Env* e, uint32* ptr_user_page_directory)
{	
	// PROJECT 2008: Your code here.
	panic("initialize_environment function is not completed yet") ;
	// [1] initialize the kernel portion of the new environment's address space.
	
	// [2] set e->env_pgdir and e->env_cr3 accordingly,	
	
	//Completes other environment initializations, (envID, status and most of registers)
	complete_environment_initialization(e);
}
コード例 #2
0
//
// Initialize the kernel virtual memory layout for environment e.
// Given a pointer to an allocated page directory, set the e->env_pgdir and e->env_cr3 accordingly,
// and initialize the kernel portion of the new environment's address space.
// Do NOT (yet) map anything into the user portion
// of the environment's virtual address space.
//
void initialize_environment(struct Env* e, uint32* ptr_user_page_directory
		, unsigned int phys_user_page_directory)
{
	//panic("initialize_environment function is not completed yet") ;
	// [1] initialize the kernel portion of the new environment's address space.
	// [2] set e->env_pgdir and e->env_cr3 accordingly,
	int i;
	e->env_page_directory = ptr_user_page_directory;
	e->env_cr3 = phys_user_page_directory;

	//[TODODONE]: copy the kernel area only (to avoid copying the currently shared objects)
	for (i = 0 ; i < PDX(USER_TOP) ; i++)
	{
		e->env_page_directory[i] = 0 ;
	}

	for (i = PDX(USER_TOP) ; i < 1024 ; i++)
	{
		e->env_page_directory[i] = ptr_page_directory[i] ;
	}

	// Allocate the page working set for both kernel and user
#if USE_KHEAP == 1
	{
		e->__uptr_pws = (struct WorkingSetElement*) USER_PAGES_WS_START;

		e->ptr_pageWorkingSet = create_user_page_WS(e->page_WS_max_size);

		unsigned int sva = (unsigned int)e->ptr_pageWorkingSet;
		uint32 nBytes = sizeof(struct WorkingSetElement) * e->page_WS_max_size;
		unsigned int dva = (unsigned int) (e->__uptr_pws);
		for(sva = (uint32)(e->ptr_pageWorkingSet); sva < ((uint32)(e->ptr_pageWorkingSet) + nBytes) ; sva+=PAGE_SIZE, dva+=PAGE_SIZE)
		{
			unsigned int pa = kheap_physical_address(sva);
			map_frame(e->env_page_directory, to_frame_info(pa), (void*)dva, PERM_USER);
		}
	}
#else
	{
		uint32 env_index = (uint32)(e-envs);
		e->__uptr_pws = (struct WorkingSetElement*)
						( ((struct Env*)(UENVS+sizeof(struct Env)*env_index))->ptr_pageWorkingSet );
	}
#endif

	//initialize environment working set
	for(i=0; i< (e->page_WS_max_size); i++)
	{
		e->ptr_pageWorkingSet[i].virtual_address = 0;
		e->ptr_pageWorkingSet[i].empty = 1;
		e->ptr_pageWorkingSet[i].time_stamp = 0 ;
	}
	e->page_last_WS_index = 0;

	for(i=0; i< __TWS_MAX_SIZE; i++)
	{
		e->__ptr_tws[i].virtual_address = 0;
		e->__ptr_tws[i].empty = 1;
		e->__ptr_tws[i].time_stamp = 0 ;
	}

	e->table_last_WS_index = 0;

	e->pageFaultsCounter=0;
	e->tableFaultsCounter=0;

	e->nModifiedPages=0;
	e->nNotModifiedPages=0;

	e->shared_free_address = USER_SHARED_MEM_START;

	//Completes other environment initializations, (envID, status and most of registers)
	complete_environment_initialization(e);
}