// ************************************************************************** // ************************************************************************** // vma <a> int P4_vmaccess(int argc, char* argv[]) { unsigned short int adr, rpt, upt; adr = INTEGER(argv[1]); printf(" = %04x", getMemAdr(adr, 1)-&MEMWORD(0)); printf("\nRPTI:%d(0x%x) UPTI:%d(0x%x) OFFSET:%d(0x%x)", RPTI(adr)/2, RPTI(adr), UPTI(adr)/2, UPTI(adr), FRAMEOFFSET(adr), FRAMEOFFSET(adr)); for (rpt = 0; rpt < 64; rpt+=2) { if (MEMWORD(rpt+TASK_RPT) || MEMWORD(rpt+TASK_RPT+1)) { outPTE(" RPT =", rpt+TASK_RPT); for(upt = 0; upt < 64; upt+=2) { if (DEFINED(MEMWORD(rpt+TASK_RPT)) && (DEFINED(MEMWORD((FRAME(MEMWORD(rpt+TASK_RPT))<<6)+upt)) || PAGED(MEMWORD((FRAME(MEMWORD(rpt+TASK_RPT))<<6)+upt+1)))) { outPTE(" UPT=", (FRAME(MEMWORD(rpt+TASK_RPT))<<6)+upt); } } } } printf("\nPages = %d", nextPage); return 0; } // end P4_vmaccess
unsigned short int *getMemAdr(int va, int rwFlg) { unsigned short int pa; int rpta, rpte1, rpte2; int upta, upte1, upte2; int rptFrame, uptFrame; // turn off virtual addressing for system RAM if (va < 0x3000) return &memory[va]; #if MMU_ENABLE rpta = tcb[curTask].RPT + RPTI(va); // root page table address rpte1 = memory[rpta]; // FDRP__ffffffffff rpte2 = memory[rpta+1]; // S___pppppppppppp if (DEFINED(rpte1)) { } // rpte defined else { } // rpte undefined memory[rpta] = SET_REF(rpte1); // set rpt frame access bit upta = (FRAME(rpte1)<<6) + UPTI(va); // user page table address upte1 = memory[upta]; // FDRP__ffffffffff upte2 = memory[upta+1]; // S___pppppppppppp if (DEFINED(upte1)) { } // upte defined else { } // upte undefined memory[upta] = SET_REF(upte1); // set upt frame access bit return &memory[(FRAME(upte1)<<6) + FRAMEOFFSET(va)]; #else return &memory[va]; #endif } // end getMemAdr
// ************************************************************************** // ************************************************************************** // look at virtual memory location va void lookVM(int va) { unsigned short int rpte1, rpte2, upte1, upte2, pa; // get root page table entry rpte1 = MEMWORD(LC3_RPT + RPTI(va)); rpte2 = MEMWORD(LC3_RPT + RPTI(va) + 1); if (DEFINED(rpte1)) { upte1 = MEMWORD((FRAME(rpte1)<<6) + UPTI(va)); upte2 = MEMWORD((FRAME(rpte1)<<6) + UPTI(va) + 1); } else { // rpte undefined printf("\n RTB[Undefined]"); return; } if (DEFINED(upte1)) { pa = (FRAME(upte1)<<6) + FRAMEOFFSET(va); } else { // upte undefined printf("\n UTB[Undefined]"); return; } printf("\n RPT[0x%04x] = %04x %04x", LC3_RPT + RPTI(va), rpte1, rpte2); if (rpte1&BIT_14_MASK) printf(" D"); if (rpte1&BIT_13_MASK) printf(" R"); if (rpte1&BIT_12_MASK) printf(" P"); printf(" Frame=%d", rpte1&0x03ff); if (DEFINED(rpte2)) printf(" Page=%d", rpte2&0x0fff); printf("\n UPT[0x%04x] = %04x %04x", (FRAME(rpte1)<<6) + UPTI(va), upte1, upte2); if (upte1&BIT_14_MASK) printf(" D"); if (upte1&BIT_13_MASK) printf(" R"); if (upte1&BIT_12_MASK) printf(" P"); printf(" Frame=%d", upte1&0x03ff); if (DEFINED(upte2)) printf(" Page=%d", upte2&0x0fff); printf("\n MEM[0x%04x] = %04x", pa, MEMWORD(pa)); return; } // end lookVM
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
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
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
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