// ************************************************************************** // ************************************************************************** // vma <a> int P4_vmaccess(int argc, char* argv[]) { unsigned short int adr, rpt, upt; printf("\nValidate arguments..."); // ?? validate arguments adr = INTEGER(argv[1]); printf(" = %04x", getMemAdr(adr, 1)-&MEMWORD(0)); 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
// ************************************************************************** // ************************************************************************** // 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
structure() { VERT v, *head; if (progress) fprintf(stderr," getreach:\n"); getreach(); if (routerr) return; if (progress) fprintf(stderr," getflow:\n"); getflow(); if (progress) fprintf(stderr," getthen:\n"); getthen(START); head = challoc(nodenum * sizeof(*head)); for (v = 0; v < nodenum; ++v) head[v] = UNDEFINED; for (v = START; DEFINED(v); v = RSIB(v)) fixhd(v,UNDEFINED,head); /* fixhd must be called before getloop so that it gets applied to IFVX which becomes NXT(w) for UNTVX w */ if (progress) fprintf(stderr," getloop:\n"); getloop(); if (progress) fprintf(stderr," getbranch:\n"); getbranch(head); chfree(head,nodenum * sizeof(*head)); head = 0; }
void dolog(int level, const char *msg, const char *func, const char *file, int line, ...) { const bool use_colors = !DEFINED(__APPLE__) && !DEFINED(__EMSCRIPTEN__); char *msg_formatted, *full_msg; const char *format; char time_str[32] = ""; va_list args; va_start(args, line); vasprintf(&msg_formatted, msg, args); va_end(args); if (use_colors && level >= GOX_LOG_WARN) { format = "\e[33;31m%s%-60s\e[m %s (%s:%d)"; } else {
output() { VERT w; int i; brace = challoc(nodenum * sizeof(*brace)); for (i = 0; i < nodenum; ++i) brace[i] = FALSE; if (progress) fprintf(stderr,"ndbrace:\n"); for (w = START; DEFINED(w); w = RSIB(w)) ndbrace(w); if (progress) fprintf(stderr,"outrat:\n"); for (w = START; DEFINED(w); w = RSIB(w)) outrat(w,0,YESTAB); OUTSTR("END\n"); chfree(brace,nodenum * sizeof(*brace)); brace = 0; }
void dump_rpt_and_upt() { int rpt, upt; 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); } } } } }
// ************************************************************************** // ************************************************************************** // 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
// ************************************************************************** // ************************************************************************** // output page table entry void outPTE(char* s, int pte) { int pte1, pte2; char flags[10]; // read pt pte1 = memory[pte]; pte2 = memory[pte+1]; // look at appropriate flags strcpy(flags, "-----"); if (DEFINED(pte1)) flags[0] = 'F'; if (DIRTY(pte1)) flags[1] = 'D'; if (REFERENCED(pte1)) flags[2] = 'R'; if (PINNED(pte1)) flags[3] = 'P'; if (PAGED(pte2)) flags[4] = 'S'; // output pte line if(DEFINED(pte1) || DEFINED(pte2)) printf("\n%s x%04x = %04x %04x %s", s, pte, pte1, pte2, flags); if (DEFINED(pte1) || DEFINED(pte2)) printf(" Frame=%d", FRAME(pte1)); if (DEFINED(pte2)) printf(" Page=%d", SWAPPAGE(pte2)); return; } // end outPTE
getreach() /* obtain REACH(v) for each node v */ { VERT v; struct pair *pr; for (v = 0; v < nodenum; ++v) REACH(v) = UNDEFINED; number(START); for (v = START; DEFINED(v); v = RSIB(v)) { pr = exits(v); /* need to free the space for pr */ chfree(pr,sizeof(*pr)); } }
// ************************************************************************** // ************************************************************************** // display contents of UPT void displayUPT(int rptNum, int uptNum) { unsigned short int rpte, upt, upte1, upte2, uptba; rptNum &= BITS_3_0_MASK; uptNum &= BITS_4_0_MASK; // index to process <rptNum>'s rpt + <uptNum> index rpte = MEMWORD(((LC3_RPT + (rptNum<<6)) + uptNum*2)); // calculate upt's base address uptba = uptNum<<11; if (!DEFINED(rpte)) return; printf("\nUser Page Table %d", FRAME(rpte)); upt = FRAME(rpte)<<6; displayPT(upt, uptba, 1<<6); return; } // end displayUPT
static void configure_caches(cache_t* I1c, cache_t* D1c, cache_t* L2c) { #define DEFINED(L) (-1 != L.size || -1 != L.assoc || -1 != L.line_size) Int n_clos = 0; // Count how many were defined on the command line. if (DEFINED(clo_I1_cache)) { n_clos++; } if (DEFINED(clo_D1_cache)) { n_clos++; } if (DEFINED(clo_L2_cache)) { n_clos++; } // Set the cache config (using auto-detection, if supported by the // architecture) VG_(configure_caches)( I1c, D1c, L2c, (3 == n_clos) ); // Then replace with any defined on the command line. if (DEFINED(clo_I1_cache)) { *I1c = clo_I1_cache; } if (DEFINED(clo_D1_cache)) { *D1c = clo_D1_cache; } if (DEFINED(clo_L2_cache)) { *L2c = clo_L2_cache; } // Then check values and fix if not acceptable. check_cache(I1c, "I1"); check_cache(D1c, "D1"); check_cache(L2c, "L2"); if (VG_(clo_verbosity) > 1) { VG_(message)(Vg_UserMsg, "Cache configuration used:"); VG_(message)(Vg_UserMsg, " I1: %dB, %d-way, %dB lines", I1c->size, I1c->assoc, I1c->line_size); VG_(message)(Vg_UserMsg, " D1: %dB, %d-way, %dB lines", D1c->size, D1c->assoc, D1c->line_size); VG_(message)(Vg_UserMsg, " L2: %dB, %d-way, %dB lines", L2c->size, L2c->assoc, L2c->line_size); } #undef CMD_LINE_DEFINED }
static int update(gesture_t *gest, const inputs_t *inputs, int mask) { const touch_t *ts = inputs->touches; int nb_ts = 0; int i, j; for (i = 0; i < ARRAY_SIZE(inputs->touches); i++) { for (j = 0; j < ARRAY_SIZE(inputs->touches[i].down); j++) { if (ts[i].down[j]) { nb_ts++; break; } } } if (gest->type == GESTURE_DRAG) { switch (gest->state) { case GESTURE_POSSIBLE: if (nb_ts == 1 && ts[0].down[gest->button]) { vec2_copy(ts[0].pos, gest->start_pos[0]); vec2_copy(gest->start_pos[0], gest->pos); if (!rect_contains(gest->viewport, gest->pos)) { gest->state = GESTURE_FAILED; break; } gest->state = (mask & (GESTURE_CLICK | GESTURE_PINCH)) ? GESTURE_RECOGNISED : GESTURE_BEGIN; } break; case GESTURE_RECOGNISED: if (vec2_dist(gest->start_pos[0], ts[0].pos) >= g_start_dist) gest->state = GESTURE_BEGIN; if (nb_ts == 0) { gest->state = (!(mask & GESTURE_CLICK)) ? GESTURE_BEGIN : GESTURE_FAILED; } if (nb_ts > 1) gest->state = GESTURE_FAILED; break; case GESTURE_BEGIN: case GESTURE_UPDATE: vec2_copy(ts[0].pos, gest->pos); gest->state = GESTURE_UPDATE; if (!ts[0].down[gest->button]) gest->state = GESTURE_END; break; } } if (gest->type == GESTURE_CLICK) { vec2_copy(ts[0].pos, gest->pos); switch (gest->state) { case GESTURE_POSSIBLE: if (ts[0].down[gest->button]) { vec2_copy(ts[0].pos, gest->start_pos[0]); gest->state = GESTURE_RECOGNISED; } break; case GESTURE_RECOGNISED: if (!ts[0].down[gest->button]) gest->state = GESTURE_TRIGGERED; break; } } if (gest->type == GESTURE_PINCH) { switch (gest->state) { case GESTURE_POSSIBLE: if (ts[0].down[0] && ts[1].down[0]) { gest->state = GESTURE_BEGIN; vec2_copy(ts[0].pos, gest->start_pos[0]); vec2_copy(ts[1].pos, gest->start_pos[1]); gest->pinch = 1; gest->rotation = 0; vec2_mix(ts[0].pos, ts[1].pos, 0.5, gest->pos); } break; case GESTURE_BEGIN: case GESTURE_UPDATE: gest->state = GESTURE_UPDATE; gest->pinch = vec2_dist(ts[0].pos, ts[1].pos) / vec2_dist(gest->start_pos[0], gest->start_pos[1]); gest->rotation = get_angle(gest->start_pos[0], gest->start_pos[1], ts[0].pos, ts[1].pos); vec2_mix(ts[0].pos, ts[1].pos, 0.5, gest->pos); if (!ts[0].down[0] || !ts[1].down[0]) gest->state = GESTURE_END; break; } } if (gest->type == GESTURE_HOVER) { switch (gest->state) { case GESTURE_POSSIBLE: if (DEFINED(GOXEL_MOBILE)) break; //Workaround. if (nb_ts == 0) { vec2_copy(ts[0].pos, gest->pos); if (rect_contains(gest->viewport, gest->pos)) { gest->state = GESTURE_BEGIN; } } break; case GESTURE_BEGIN: case GESTURE_UPDATE: vec2_copy(ts[0].pos, gest->pos); gest->state = rect_contains(gest->viewport, gest->pos) ? GESTURE_UPDATE : GESTURE_END; break; } } return 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
int getFrame(int notme) { int frame; frame = getAvailableFrame(); if (frame >=0) return frame; // run clock int i, j, upta, frameToRemove; i = lastRpte; // i = 0x2400; // j = lastUpte; while(1){ // for(i=0x2400;i<0x3000;i+=2){ // printf("%x", i); if(DEFINED(memory[i])){ upta = FRAME(memory[i]); upta = (upta<<6); //double confirm int k; bool nothingInFrame = 1; for(k=upta;k<upta+64;k+=2){ if(DEFINED(memory[k])){ nothingInFrame = 0; break; } } if(nothingInFrame && FRAME(memory[i])!=notme){ frameToRemove = FRAME(memory[i]); lastRpte=i+2; memory[i] = CLEAR_DEFINED(memory[i]); memory[i] = CLEAR_REF(memory[i]); if(PAGED(memory[i+1]) && DIRTY(memory[i])){ memory[i+1] = accessPage(SWAPPAGE(memory[i+1]), frameToRemove, PAGE_OLD_WRITE); }else{ memory[i+1] = accessPage(0, frameToRemove, PAGE_NEW_WRITE); } memory[i+1] = SET_PAGED(memory[i+1]); memory[i] = SET_DIRTY(memory[i]); //possibly clear frame number return frameToRemove; // i can swap out this upt } // for(j=upta;j<upta+64;j+=2){ while(uptOffset < 64){ j = upta + uptOffset; if(DEFINED(memory[j])){ if(REFERENCED(memory[j])){ memory[j] = CLEAR_REF(memory[j]); }else{ //use this data frame frameToRemove = FRAME(memory[j]); lastRpte = i; memory[j] = CLEAR_DEFINED(memory[j]); memory[j] = CLEAR_REF(memory[j]); // memory[j] = SWAPPAGE(memory[j]); if(PAGED(memory[j+1]) && DIRTY(memory[j])){ memory[j+1] = accessPage(SWAPPAGE(memory[j+1]), frameToRemove, PAGE_OLD_WRITE); }else{ memory[j+1] = accessPage(0, frameToRemove, PAGE_NEW_WRITE); } memory[j+1] = SET_PAGED(memory[j+1]); uptOffset+=2; // may not need this line //need to loop through rest next time but if nothing dont remove this one return frameToRemove; } } uptOffset+=2; } uptOffset = 0; // } } i+=2; if(i==0x3000){ i=0x2400; } // } } // memory[(frameToRemove<<6)] return frame; }
int getClockFrame(int notme) { int frame; // iterate through rpts (0x2400 - LC3_RPT_END) int maxWrap = 20; for (;maxWrap; cBigHand += 2, cLittleHand = 0) { int i; int rpte1; int upta, upte1; if (cBigHand >= LC3_RPT_END) { DEBUG_STATEMENT(DEBUG_MMU,"\nClock is wrapping"); cBigHand = LC3_RPT; maxWrap--; } rpte1 = memory[cBigHand]; if (DEFINED(rpte1) && REFERENCED(rpte1)) { // clear reference DEBUG_STATEMENT(DEBUG_MMU,"\nclearing ref for rpte"); memory[cBigHand] = rpte1 = CLEAR_REF(rpte1); } else if (DEFINED(rpte1)) { // if one is non-referenced go to the user page table // scout out the upt!! note that this has not been referenced if (DEBUG_MMU) { outPTE("\nRPT entry being checked - ", cBigHand); } upta = (FRAME(rpte1)<<6); for (i = cLittleHand % 64; i < 64;i += 2, cLittleHand = i % 64) { // - iterate over userpage table upte1 = memory[upta + (i)]; if (PINNED(upte1) || FRAME(upte1) == notme) { DEBUG_STATEMENT(DEBUG_MMU,"\nupte1 frame was the notme frame (%x = %x) or pinned", FRAME(upte1), notme); if (DEBUG_MMU) { outPTE("UPT entry being checked - ", upta + i); } continue; } if (DEFINED(upte1) && REFERENCED(upte1)) { // - if entry is referenced un-reference and move on // clear reference DEBUG_STATEMENT(DEBUG_MMU,"\nclearing ref for upte %d", cLittleHand); memory[cBigHand] = rpte1 = SET_PINNED(rpte1); memory[upta + (i)] = upte1 = CLEAR_REF(upte1); } else if (DEFINED(upte1)) { // - otherwise prep it for being put into swap // we can use the frame referenced by upte1 if (DEBUG_MMU) { outPTE("UPT entry being checked - ", upta + 1); } DEBUG_STATEMENT(DEBUG_MMU,"\nUpte1 %x, Upte2 %x", upte1, memory[upta + (i + 1)]); memory[cBigHand] = rpte1 = SET_DIRTY(rpte1); frame = FRAME(upte1); swapOutFrame(upta + i); cLittleHand += 2; DEBUG_STATEMENT(DEBUG_MMU,"\nFound a data frame that can be used! (%d, %x)", frame, frame); return frame; } } cLittleHand = 0; if (!REFERENCED(rpte1) && !PINNED(rpte1) && FRAME(rpte1) != notme) { // if we only replaced or did nothing to upte entries // we can use the frame referenced by rpte1 frame = FRAME(rpte1); DEBUG_STATEMENT(DEBUG_MMU,"\nFound a upt frame that can be used! (%d, %x)", frame, frame); swapOutFrame(cBigHand); cBigHand += 2; return frame; } else { // otherwise remove the pin flag memory[cBigHand] = rpte1 = CLEAR_PINNED(rpte1); } } } // when you get the bottom start at the top again DEBUG_STATEMENT(DEBUG_MMU,"\n No valid frame found notme = %d", notme); if (DEBUG_MMU) { displayTableHierarchy(); } return -1; }
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
int getFrame(int notme) { int UPTClock; // clock for UPT int frame; frame = getAvailableFrame(); if (frame >=0) return frame; if(RPTClock == 0){ RPTClock = LC3_RPT; } int RPTBegin = RPTClock; int first = 1; int rptCount = 0; //iterate the first time through the tables while(first || RPTClock != RPTBegin){ rptCount++; first = 0; //Check and make sure the notme condition holds if(DEFINED(memory[RPTClock])){ UPTClock = (FRAME(memory[RPTClock])<<6); int UPTBegin = UPTClock; int uFirst = 1; int hadDefined = 0; int uptcount = 0; while(uFirst || UPTClock != UPTBegin){ uptcount++; uFirst = 0; if(DEFINED(memory[UPTClock])){ hadDefined = 1; } if(notme != UPTClock && DEFINED(memory[UPTClock])){ //swap out if not referenced if(!REFERENCED(memory[UPTClock])){ //if it's dirty, write it to memory int swapPage = 0; if (DIRTY(memory[UPTClock])){ if(PAGED(memory[UPTClock + 1])) swapPage = accessPage(SWAPPAGE(memory[UPTClock + 1]), FRAME(memory[UPTClock]), PAGE_OLD_WRITE); else swapPage = accessPage(0, FRAME(memory[UPTClock]), PAGE_NEW_WRITE); memory[UPTClock] = CLEAR_DIRTY(memory[UPTClock]); memory[UPTClock+1] = SET_PAGED(swapPage); pageWrites++; } //no longer in main memory--it's swapped! memory[UPTClock] = CLEAR_DEFINED(memory[UPTClock]); //increment the clock if(RPTClock + 2 < LC3_RPT_END) RPTClock += 2; else RPTClock = LC3_RPT; return FRAME(memory[UPTClock]); } memory[UPTClock] = CLEAR_REF(memory[UPTClock]); } //sanity check assert(UPTClock >= 0x3000); if(UPTClock + 2 < UPTBegin + LC3_FRAME_SIZE) UPTClock += 2; else UPTClock = UPTBegin; } if(!REFERENCED(memory[RPTClock]) && !hadDefined && notme != RPTClock){ int swapPage; if(PAGED(memory[RPTClock + 1])) swapPage = accessPage(SWAPPAGE(memory[RPTClock + 1]), FRAME(memory[RPTClock]), PAGE_OLD_WRITE); else swapPage = accessPage(0, FRAME(memory[RPTClock]), PAGE_NEW_WRITE); memory[RPTClock] = CLEAR_DIRTY(memory[RPTClock]); memory[RPTClock+1] = SET_PAGED(swapPage); pageWrites++; memory[RPTClock] = CLEAR_DEFINED(memory[RPTClock]); int rE1 = memory[RPTClock]; if(RPTClock + 2 < LC3_RPT_END) RPTClock += 2; else RPTClock = LC3_RPT; return FRAME(rE1); } //clear the reference bit memory[RPTClock] = CLEAR_REF(memory[RPTClock]); } if(RPTClock + 2 < LC3_RPT_END){ RPTClock += 2; } else{ RPTClock = LC3_RPT; } } RPTBegin = RPTClock; first = 1; while(first || RPTClock != RPTBegin){ rptCount++; first = 0; //Check and make sure the notme condition holds if(DEFINED(memory[RPTClock])){ UPTClock = (FRAME(memory[RPTClock])<<6); int UPTBegin = UPTClock; int uFirst = 1; int hadDefined = 0; int uptcount = 0; while(uFirst || UPTClock != UPTBegin){ uptcount++; uFirst = 0; if(DEFINED(memory[UPTClock])){ hadDefined = 1; } if(notme != UPTClock && DEFINED(memory[UPTClock])){ //swap out if not referenced if(!REFERENCED(memory[UPTClock])){ //if it's dirty, write it to memory int swapPage = 0; if (DIRTY(memory[UPTClock])){ if(PAGED(memory[UPTClock + 1])) swapPage = accessPage(SWAPPAGE(memory[UPTClock + 1]), FRAME(memory[UPTClock]), PAGE_OLD_WRITE); else swapPage = accessPage(0, FRAME(memory[UPTClock]), PAGE_NEW_WRITE); memory[UPTClock] = CLEAR_DIRTY(memory[UPTClock]); memory[UPTClock+1] = SET_PAGED(swapPage); pageWrites++; } //no longer in main memory--it's swapped! memory[UPTClock] = CLEAR_DEFINED(memory[UPTClock]); //increment the clock if(RPTClock + 2 < LC3_RPT_END) RPTClock += 2; else RPTClock = LC3_RPT; return FRAME(memory[UPTClock]); } memory[UPTClock] = CLEAR_REF(memory[UPTClock]); } //sanity check assert(UPTClock >= 0x3000); if(UPTClock + 2 < UPTBegin + LC3_FRAME_SIZE) UPTClock += 2; else UPTClock = UPTBegin; } if(!REFERENCED(memory[RPTClock]) && !hadDefined && notme != RPTClock){ int swapPage; if(PAGED(memory[RPTClock + 1])) swapPage = accessPage(SWAPPAGE(memory[RPTClock + 1]), FRAME(memory[RPTClock]), PAGE_OLD_WRITE); else swapPage = accessPage(0, FRAME(memory[RPTClock]), PAGE_NEW_WRITE); memory[RPTClock] = CLEAR_DIRTY(memory[RPTClock]); memory[RPTClock+1] = SET_PAGED(swapPage); pageWrites++; memory[RPTClock] = CLEAR_DEFINED(memory[RPTClock]); int rE1 = memory[RPTClock]; if(RPTClock + 2 < LC3_RPT_END) RPTClock += 2; else RPTClock = LC3_RPT; return FRAME(rE1); } //clear the reference bit memory[RPTClock] = CLEAR_REF(memory[RPTClock]); } if(RPTClock + 2 < LC3_RPT_END){ RPTClock += 2; } else{ RPTClock = LC3_RPT; } } //we should never ever be here assert(0); return -1; }
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
void single_hook_fill(pTHX_ const char *hook, const char *type, SingleHook *sth, SV *sub, U32 allowed_args) { if (!DEFINED(sub)) { sth->sub = NULL; sth->arg = NULL; } else if (SvROK(sub)) { SV *sv = SvRV(sub); switch (SvTYPE(sv)) { case SVt_PVCV: sth->sub = sv; sth->arg = NULL; break; case SVt_PVAV: { AV *in = (AV *) sv; I32 len = av_len(in); if (len < 0) Perl_croak(aTHX_ "Need at least a code reference in %s hook for " "type '%s'", hook, type); else { SV **pSV = av_fetch(in, 0, 0); if (pSV == NULL || !SvROK(*pSV) || SvTYPE(sv = SvRV(*pSV)) != SVt_PVCV) Perl_croak(aTHX_ "%s hook defined for '%s' is not " "a code reference", hook, type); else { I32 ix; AV *out; for (ix = 0; ix < len; ++ix) { pSV = av_fetch(in, ix+1, 0); if (pSV == NULL) fatal("NULL returned by av_fetch() in single_hook_fill()"); if (SvROK(*pSV) && sv_isa(*pSV, ARGTYPE_PACKAGE)) { HookArgType argtype = (HookArgType) SvIV(SvRV(*pSV)); #define CHECK_ARG_TYPE(type) \ case HOOK_ARG_ ## type: \ if ((allowed_args & SHF_ALLOW_ARG_ ## type) == 0) \ Perl_croak(aTHX_ #type " argument not allowed"); \ break switch (argtype) { CHECK_ARG_TYPE(SELF); CHECK_ARG_TYPE(TYPE); CHECK_ARG_TYPE(DATA); CHECK_ARG_TYPE(HOOK); } #undef CHECK_ARG_TYPE } } sth->sub = sv; out = newAV(); av_extend(out, len-1); for (ix = 0; ix < len; ++ix) { pSV = av_fetch(in, ix+1, 0); if (pSV == NULL) fatal("NULL returned by av_fetch() in single_hook_fill()"); SvREFCNT_inc(*pSV); if (av_store(out, ix, *pSV) == NULL) SvREFCNT_dec(*pSV); } sth->arg = (AV *) sv_2mortal((SV *) out); } } } break; default: goto not_code_or_array_ref; } } else { not_code_or_array_ref: Perl_croak(aTHX_ "%s hook defined for '%s' is not " "a code or array reference", hook, type); } }
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
int clockRunner(int notme) { //extern int curRPT; //extern TCB tcb[MAX_TASKS]; int i,j,k; int rpta, rpte1, rpte2; int upta, upte1, upte2; int victimFrame; int tupta, tupte1; //printf("\nClock running...%d\n",clockCount++); //victimEntry = 0; while (1) { //rpta = tcb[curRPT].RPT; for (i = curRPTE; i < 0x3000; i+=2) { //rpte1 = memory[rpta + i]; //rpte2 = memory[rpta + i + 1]; rpte1 = memory[i]; rpte2 = memory[i + 1]; if (DEFINED(rpte1)) { if (curUPTE == 0) { if(PINNED(rpte1)) { //memory[rpta + i] = rpte1 = CLEAR_PINNED(rpte1); memory[i] = rpte1 = CLEAR_PINNED(rpte1); } } upta = (FRAME(rpte1)<<6); for (j = curUPTE; j < 64; j+=2) { upte1 = memory[upta + j]; upte2 = memory[upta + j + 1]; if (DEFINED(upte1)) { //memory[rpta + i] = rpte1 = SET_PINNED(rpte1); memory[i] = rpte1 = SET_PINNED(rpte1); if (REFERENCED(upte1)) { memory[upta + j] = upte1 = CLEAR_REF(upte1); } else { //victimEntry = upte1; // if end of UPT, reset upte and move to next UPT //break; // because this is the victim // instead of break, do swapping and return victim frame number // immunity from notme //if (FRAME(upte1) != notme) //{ if (DIRTY(upte1)) { int page; //stat pageWrites++; if(PAGED(upte2)) { page = accessPage(SWAPPAGE(upte2),FRAME(upte1),PAGE_OLD_WRITE); } else { page = accessPage(0,FRAME(upte1),PAGE_NEW_WRITE); } upte2 = page; memory[upta + j + 1] = upte2 = SET_PAGED(upte2); } // save frame number before obliterating first word victimFrame = FRAME(upte1); //memory[upta + j] = upte1 = CLEAR_DEFINED(upte1); memory[upta + j] = upte1 = 0; curUPTE = (j + 2) % 64; //printf("\nChose a UPT victim: %d\n",victimFrame); return victimFrame; //} } } } // immunity from notme if ((FRAME(rpte1) != notme) && (!PINNED(rpte1))) { //victimEntry = rpte1; // if end of RPT, reset rpte and move to next RPT //break; // because this is the victim // instead of break, do swapping and return victim frame number //victimEntry = FRAME(rpte1); // sanity check tupta = (FRAME(rpte1)<<6); for (k = 0; k < 64; k+=2) { tupte1 = memory[tupta + k]; if (DEFINED(tupte1)) printf("\nEvicting a UPT that has defined entries!!!\n"); } //if (DIRTY(rpte1)) { int page; //stat pageWrites++; if(PAGED(rpte2)) { page = accessPage(SWAPPAGE(rpte2),FRAME(rpte1),PAGE_OLD_WRITE); } else { page = accessPage(0,FRAME(rpte1),PAGE_NEW_WRITE); } rpte2 = page; //memory[rpta + i + 1] = rpte2 = SET_PAGED(rpte2); memory[i + 1] = rpte2 = SET_PAGED(rpte2); } // save frame number before obliterating first word victimFrame = FRAME(rpte1); //memory[rpta + i] = rpte1 = CLEAR_DEFINED(rpte1); //memory[rpta + i] = rpte1 = 0; memory[i] = rpte1 = 0; //curRPTE = (i + 2) % 64; //printf("\nChose a RPT victim: %d\n",victimFrame); return victimFrame; } curUPTE = 0; } } //curRPT = (curRPT + 1) % MAX_TASKS; curRPTE = 0x2400; } }