void mmu_addTranslation(page_virt pv, page_phys pp){ if(pp == INVALID){ printf("Proposed address is invalid...\n"); printf(" Hint: run the debugger and set a breakpoint for this line\n"); abort(); }else if(! ((!mmu_array[pv].swapped) || (mmu_array[pv].loaded))){ // Si ! (swapped => loaded) printf("Page was swapped and invalidated but not reloaded...\n"); printf(" Hint: run the debugger and set a breakpoint for this line\n"); abort(); } mmu_clearAccessedBit(pv); // Just to be sure everything is ok mmu_clearDirtyBit(pv); // Idem mprotect(ADDROF(pv),PAGESIZE,PROT_READ); mmu_array[pv].pp=pp; }
// Invalidate page... but wait until write has been done void mmu_invalidatePage(page_virt pv){ if(mmu_array[pv].swapped == FALSE){ printf("Page has not been swapped yet...\n"); printf(" Hint: run the debugger and set a breakpoint for this line\n"); exit(1); } mprotect(ADDROF(pv),PAGESIZE,PROT_NONE); mmu_array[pv].dirty=0; mmu_array[pv].pp=INVALID; mmu_array[pv].loaded=0; struct timeval delay; struct timeval now; gettimeofday(&now,NULL); timeradd(&delay,&delay_flush,&delay); timersub(&delay,&now,&delay); if(delay.tv_sec >= 0){ int UNUSED r; struct timespec s; TV2TS(delay,s); //do{ // r=nanosleep(&s,&s); // }while(r < 0 && errno == EINTR); } }
void mmu_clearAccessedBit(page_virt pv){ mprotect(ADDROF(pv),PAGESIZE,PROT_NONE); mmu_array[pv].accessed=0; }
void mmu_setAccessedBit(page_virt pv){ mprotect(ADDROF(pv),PAGESIZE,PROT_READ); mmu_array[pv].accessed=1; }
void mmu_clearDirtyBit(page_virt pv){ mprotect(ADDROF(pv),PAGESIZE,mmu_array[pv].accessed ? PROT_READ : PROT_NONE); mmu_array[pv].dirty=0; }
void mmu_setDirtyBit(page_virt pv){ mprotect(ADDROF(pv),PAGESIZE,PROT_WRITE|PROT_READ); mmu_array[pv].dirty=1; mmu_array[pv].swapped=0; }
inline constexpr L const & left(virtual_member<L, R> const &a) noexcept { return *(L const *)((ADDROF(a)) - (&((L *)ADDROF(a))->proto_member_union_start_ - ADDROF(a))); }
inline constexpr L && child(virtual_member<L, R> &&a) noexcept { return static_cast<L &&>(*(L*)((ADDROF(a)) - (&((L *)ADDROF(a))->proto_member_union_start_ - ADDROF(a)))); }