Last active
January 18, 2018 08:49
-
-
Save Yeaseen/6a89fa5627af5b6eee567f12f255485f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
void AddrSpace::loadIntoFreePage(int vpn){ | |
int physicalPageNo=memoryManager->AllocPage(); | |
pageTable[vpn].physicalPage = physicalPageNo; | |
pageTable[vpn].valid = true; | |
bzero(&machine -> mainMemory[(pageTable[vpn].physicalPage) * PageSize], PageSize); | |
if(noffH.code.size>0) | |
{ | |
printf("code size== %d \n",noffH.code.size); | |
unsigned int codeNumPages; | |
codeNumPages=divRoundUp(noffH.code.size,PageSize); | |
//printf("Code page nUm= %d \n", codeNumPages); | |
unsigned int initPageNum=noffH.code.virtualAddr/PageSize; | |
//printf("initPageNum== %d \n",initPageNum); | |
unsigned int lastPageNum=(noffH.code.virtualAddr+noffH.code.size)/ PageSize; | |
//printf("lastPageNum== %d\n",lastPageNum); | |
if( (vpn >= initPageNum) && (vpn <= lastPageNum) ){ | |
//printf("noffH.code.virtualAddr== %d\n", noffH.code.virtualAddr); | |
//printf("vpn*PageSize==%d \n",vpn*PageSize); | |
if(noffH.code.virtualAddr>= vpn*PageSize){ | |
unsigned int initOffset=PageSize - (noffH.code.virtualAddr % PageSize); | |
printf("starting from vpn in Code= %d\n",(pageTable[vpn].physicalPage*PageSize)+ | |
(noffH.code.virtualAddr % PageSize)); | |
printf("initOffset== %d \n",initOffset); | |
printf("code file init==%d \n",noffH.code.inFileAddr); | |
executable->ReadAt(&(machine->mainMemory[(pageTable[vpn].physicalPage*PageSize)+ | |
(noffH.code.virtualAddr % PageSize)]), | |
initOffset,noffH.code.inFileAddr); | |
} | |
else if((noffH.code.virtualAddr+noffH.code.size) < (vpn+1)*PageSize){ | |
//printf("else if\n"); | |
unsigned int extra=(noffH.code.virtualAddr+noffH.code.size)-vpn*PageSize; | |
executable->ReadAt(&(machine->mainMemory[(pageTable[vpn].physicalPage*PageSize)]), | |
extra,noffH.code.inFileAddr+((vpn*PageSize)-noffH.code.virtualAddr)); | |
} | |
else | |
{ | |
//printf("else \n"); | |
executable->ReadAt(&(machine->mainMemory[(pageTable[vpn].physicalPage*PageSize)]), | |
PageSize,noffH.code.inFileAddr+((vpn*PageSize)-noffH.code.virtualAddr)); | |
} | |
} | |
} | |
if(noffH.initData.size>0){ | |
printf("Data Size== %d \n",noffH.initData.size); | |
unsigned int dataNumPages; | |
dataNumPages=divRoundUp(noffH.initData.size,PageSize); | |
printf("Code page nUm= %d \n", dataNumPages); | |
unsigned int initDataPageNum=noffH.initData.virtualAddr/PageSize; | |
printf("initDataPageNum== %d \n",initDataPageNum); | |
unsigned int lastDataPageNum=(noffH.initData.virtualAddr+noffH.initData.size)/ PageSize; | |
if(vpn>=initDataPageNum && vpn <= lastDataPageNum){ | |
if(noffH.initData.virtualAddr>= vpn*PageSize){ | |
unsigned int initDataOffset=PageSize - (noffH.initData.virtualAddr % PageSize); | |
printf("starting from vpn for Data= %d\n",(pageTable[vpn].physicalPage*PageSize)+ | |
(noffH.initData.virtualAddr % PageSize)); | |
printf("initDataOffset== %d \n",initDataOffset); | |
printf("Data file init==%d \n",noffH.initData.inFileAddr); | |
executable->ReadAt(&(machine->mainMemory[(pageTable[vpn].physicalPage*PageSize)+ | |
(noffH.initData.virtualAddr % PageSize)]), | |
initDataOffset,noffH.initData.inFileAddr); | |
} | |
else if((noffH.initData.virtualAddr+noffH.initData.size) < (vpn+1)*PageSize){ | |
//printf("else if\n"); | |
unsigned int extra=(noffH.initData.virtualAddr+noffH.initData.size)-vpn*PageSize; | |
executable->ReadAt(&(machine->mainMemory[(pageTable[vpn].physicalPage*PageSize)]), | |
extra,noffH.initData.inFileAddr+((vpn*PageSize)-noffH.initData.virtualAddr)); | |
} | |
else | |
{ | |
//printf("else \n"); | |
executable->ReadAt(&(machine->mainMemory[(pageTable[vpn].physicalPage*PageSize)]), | |
PageSize,noffH.initData.inFileAddr+((vpn*PageSize)-noffH.initData.virtualAddr)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment