Ejemplo n.º 1
0
unsigned short int *getMemAdr(int va, int rwFlg)
{
	unsigned short int pa;
	int rpta, rpte1, rpte2;
	int upta, upte1, upte2;
	int rptFrame, uptFrame;
    memAccess += 2;

//	rpta = 0x2400 + RPTI(va);
    rpta = tcb[curTask].RPT + RPTI(va);
	rpte1 = memory[rpta];
	rpte2 = memory[rpta+1];

	// turn off virtual addressing for system RAM
	if (va < 0x3000) return &memory[va];
#if MMU_ENABLE
	if (DEFINED(rpte1))
	{
//        printf("\nUPT frame already defined");
		// defined
        memHits++;
	}
	else
	{
		// fault
        memPageFaults++;
		rptFrame = getFrame(-1);
		rpte1 = SET_DEFINED(rptFrame);
		if (PAGED(rpte2))
		{
            //upt is in swap and we need to read it back in
			accessPage(SWAPPAGE(rpte2), rptFrame, PAGE_READ);
		}
		else
		{
            //initialize the upt memory
            memset(&memory[(rptFrame<<6)], 0, 128);
		}
	}


	memory[rpta] = rpte1 = SET_REF(rpte1);
	memory[rpta+1] = rpte2;

	upta = (FRAME(rpte1)<<6) + UPTI(va);
	upte1 = memory[upta];
	upte2 = memory[upta+1];

	if (DEFINED(upte1))
	{
		// defined
        memHits++;
	}
	else
	{
		// fault
        memPageFaults++;
		uptFrame = getFrame(FRAME(memory[rpta]));
        memory[rpta] = rpte1 = SET_REF(SET_DIRTY(rpte1));
        upte1 = SET_DEFINED(uptFrame);

        if (PAGED(upte2))
		{
            //get the data frame from swap
			accessPage(SWAPPAGE(upte2), uptFrame, PAGE_READ);
		}
		else
		{
            //we don't need to do anything
            //but we could initialize the mem to 0xf025 which is lc-3 halt instruction
            memset(&memory[(uptFrame<<6)], 0xf025, 128);
		}
	}

    if (rwFlg) {
        upte1 = SET_DIRTY(upte1);
    }

    memory[upta] = SET_REF(upte1);
	memory[upta+1] = upte2;

	return &memory[(FRAME(upte1)<<6) + FRAMEOFFSET(va)];
#else
	return &memory[va];
#endif
} // end getMemAdr
Ejemplo n.º 2
0
unsigned short int *getMemAdr(int va, int rwFlg)
{
	unsigned short int pa;
	int rpta, rpte1, rpte2;
	int upta, upte1, upte2;
	int rptFrame, uptFrame;
	extern TCB tcb[MAX_TASKS];
	extern int curTask;

	//stat
	memAccess++;

	rpta = tcb[curTask].RPT + RPTI(va);	// 0x2400 + RPTI(va);
	rpte1 = memory[rpta];
	rpte2 = memory[rpta+1];

	// turn off virtual addressing for system RAM
	if (va < 0x3000) return &memory[va];
#if MMU_ENABLE
	if (DEFINED(rpte1))
	{
		// defined
		//stat
		memHits++;
		if (rwFlg)
			rpte1 = SET_DIRTY(rpte1);
	}
	else
	{
		// fault
		//stat
		memPageFaults++;

		rptFrame = getFrame(-1);
		rpte1 = SET_DEFINED(rptFrame);
		if (PAGED(rpte2))
		{
			accessPage(SWAPPAGE(rpte2), rptFrame, PAGE_READ);
			//stat
			pageReads++;
			//clean
			if (rwFlg)
				rpte1 = SET_DIRTY(rpte1);
			else
				rpte1 = CLEAR_DIRTY(rpte1);
		}
		else
		{
			memset(&memory[(rptFrame<<6)], 0, 128);
			//dirty
			rpte1 = SET_DIRTY(rpte1);
		}
	}

	
	rpte1 = SET_PINNED(rpte1);
	memory[rpta] = rpte1 = SET_REF(rpte1);
	memory[rpta+1] = rpte2;

	upta = (FRAME(rpte1)<<6) + UPTI(va);
	upte1 = memory[upta];
	upte2 = memory[upta+1];

	//stat
	memAccess++;

	if (DEFINED(upte1))
	{
		// defined
		//stat
		memHits++;
		if (rwFlg)
			upte1 = SET_DIRTY(upte1);
	}
	else
	{
		// fault
		//stat
		memPageFaults++;

		uptFrame = getFrame(FRAME(memory[rpta]));
		upte1 = SET_DEFINED(uptFrame);
		if (PAGED(upte2))
		{
			accessPage(SWAPPAGE(upte2), uptFrame, PAGE_READ);
			//stat
			pageReads++;
			//clean unless being written to
			if (rwFlg)
				upte1 = SET_DIRTY(upte1);
			else
				upte1 = CLEAR_DIRTY(upte1);
		}
		else
		{
			//dirty
			upte1 = SET_DIRTY(upte1);
		}
	}

	rpte1 = SET_PINNED(rpte1);
	memory[rpta] = rpte1;
	memory[upta] = upte1 = SET_REF(upte1);
	memory[upta+1] = upte2;


	return &memory[(FRAME(upte1)<<6) + FRAMEOFFSET(va)];
#else
	return &memory[va];
#endif
} // end getMemAdr
Ejemplo n.º 3
0
unsigned short int *getMemAdr(int va, int rwFlg)
{
	unsigned short int pa;
	int rpta, rpte1, rpte2;
	int upta, upte1, upte2;
	int rptFrame, uptFrame;


	rpta = tcb[curTask].RPT + RPTI(va);
	rpte1 = memory[rpta];
	rpte2 = memory[rpta+1];

	// turn off virtual addressing for system RAM
	if (va < 0x3000) return &memory[va];


#if MMU_ENABLE
	if (DEFINED(rpte1))
	{
		memHits++;
	}
	else
	{
		// fault
		memPageFaults++;
		rptFrame = getFrame(-1);
		assert(rptFrame >= 192);
		rpte1 = SET_DEFINED(rptFrame);
		if (PAGED(rpte2))
		{
			accessPage(SWAPPAGE(rpte2), rptFrame, PAGE_READ);
			pageReads++;
		}
		else
		{
			rpte1 = SET_DIRTY(rpte1); rpte2 = 0;
			memset(&memory[(rptFrame<<6)], 0, 128);
		}
	}


	memory[rpta] = rpte1 = SET_REF(rpte1);
	memory[rpta+1] = rpte2;

	upta = (FRAME(rpte1)<<6) + UPTI(va);
	upte1 = memory[upta];
	upte2 = memory[upta+1];

	if (DEFINED(upte1))
	{
		memHits++;
	}
	else
	{
		// fault
		memPageFaults++;
		uptFrame = getFrame(FRAME(memory[rpta]));
		assert(uptFrame >= 192);
		upte1 = SET_DEFINED(uptFrame);
		if (PAGED(upte2))
		{
			accessPage(SWAPPAGE(upte2), uptFrame, PAGE_READ);
			pageReads++;
		}
		else
		{
			upte1 = SET_DIRTY(upte1); upte2 = 0;
		}
	}

	if(rwFlg != 0){
		upte1 = SET_DIRTY(upte1);
	}

	memory[upta] = SET_REF(upte1);
	memory[upta+1] = upte2;

	memAccess = memHits + memPageFaults;
	return &memory[(FRAME(upte1)<<6) + FRAMEOFFSET(va)];
#else
	pa = va;
#endif
	return &memory[pa];
} // end getMemAdr
Ejemplo n.º 4
0
unsigned short int *getMemAdr(int va, int rwFlg)
{
	unsigned short int pa;
	int rpta, rpte1, rpte2;
	int upta, upte1, upte2;
	int rptFrame, uptFrame;

	rpta = 0x2400 + RPTI(va) + 0x40*curTask; // address of the root page table
	rpte1 = memory[rpta];		// get a word
	rpte2 = memory[rpta+1];		// get another word

	// turn off virtual addressing for system RAM
	if (va < 0x3000) return &memory[va];
#if MMU_ENABLE

	// printf("using memory Management\n");

	if (DEFINED(rpte1))
	{
		memHits++;
		// defined
	}
	else
	{
		memPageFaults++;
		// fault
		rptFrame = getFrame(-1);
		rpte1 = SET_DEFINED(rptFrame); // setting the frame bit in the user page table
		rpte1 = SET_DIRTY(rpte1);
		if (PAGED(rpte2)) // it exists in swap space
		{
			accessPage(SWAPPAGE(rpte2), rptFrame, PAGE_READ);
		}
		else
		{
			memset(&memory[(rptFrame<<6)], 0, 128); //sets 128 bytes to 0 why is it 128? why bitshift by 6?
		}
	}


	memory[rpta] = rpte1 = SET_REF(rpte1); // sets the referenced bit in the root page table
	memory[rpta+1] = rpte2;

	upta = (FRAME(rpte1)<<6) + UPTI(va);
	upte1 = memory[upta];
	upte2 = memory[upta+1];

	if (DEFINED(upte1))
	{
		memHits++;
		// defined
	}
	else
	{
		memPageFaults++;
		// fault
		uptFrame = getFrame(FRAME(memory[rpta]));
		upte1 = SET_DEFINED(uptFrame);
		upte1 = SET_DIRTY(upte1);
		if (PAGED(upte2))
		{
			accessPage(SWAPPAGE(upte2), uptFrame, PAGE_READ);
		}
		else
		{
			memset(&memory[(uptFrame<<6)], 0, 128); //sets 128 bytes to 0 why is it 128? why bitshift by 6?
		}
	}

	if(rwFlg){
		memory[rpta] = SET_DIRTY(memory[rpta]);
	}else{

	}

	memory[upta] = SET_REF(upte1);
	memory[upta+1] = upte2;

	return &memory[(FRAME(upte1)<<6) + FRAMEOFFSET(va)];
#else
	return &memory[va];
#endif
} // end getMemAdr