Line 28... |
Line 28... |
|
|
extern int cont_run;
|
extern int cont_run;
|
|
|
/* Insn MMU */
|
/* Insn MMU */
|
|
|
|
inline unsigned long immu_simulate_tlb(unsigned long virtaddr)
|
|
{
|
|
int set, way = -1;
|
|
int i;
|
|
unsigned long tagaddr;
|
|
unsigned long vpn;
|
|
|
|
if (!(mfspr(SPR_SR) & SPR_SR_IME) || !(testsprbits(SPR_UPR, SPR_UPR_IMP)))
|
|
return virtaddr;
|
|
|
|
/* Which set to check out? */
|
|
set = (virtaddr / config.immu.pagesize) % config.immu.nsets;
|
|
tagaddr = (virtaddr / config.immu.pagesize) / config.immu.nsets;
|
|
vpn = virtaddr / config.immu.pagesize;
|
|
|
|
/* Scan all ways and try to find a matching way. */
|
|
for (i = 0; i < config.immu.nways; i++)
|
|
if ((getsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_VPN) == vpn) &&
|
|
testsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_V))
|
|
way = i;
|
|
|
|
/* Did we find our tlb entry? */
|
|
if (way >= 0) { /* Yes, we did. */
|
|
immu_stats.fetch_tlbhit++;
|
|
debug(5, "ITLB hit (virtaddr=%x).\n", virtaddr);
|
|
|
|
/* Test for page fault */
|
|
if (mfspr (SPR_SR) & SPR_SR_SUPV) {
|
|
if (!(mfspr (SPR_ITLBTR_BASE(way) + set) & SPR_ITLBTR_SWE))
|
|
except_handle(EXCEPT_IPF, virtaddr);
|
|
} else {
|
|
if (!(mfspr (SPR_ITLBTR_BASE(way) + set) & SPR_ITLBTR_UWE))
|
|
except_handle(EXCEPT_IPF, virtaddr);
|
|
}
|
|
|
|
/* Set LRUs */
|
|
for (i = 0; i < config.immu.nways; i++)
|
|
if (testsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU))
|
|
setsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU, getsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU) - 1);
|
|
setsprbits(SPR_ITLBMR_BASE(way) + set, SPR_ITLBMR_LRU, config.immu.ustates - 1);
|
|
|
|
return getsprbits(SPR_ITLBTR_BASE(way) + set, SPR_ITLBTR_PPN) * config.immu.pagesize + (virtaddr % config.immu.pagesize);
|
|
}
|
|
else { /* No, we didn't. */
|
|
int minlru = config.immu.ustates - 1;
|
|
int minway = 0;
|
|
|
|
immu_stats.fetch_tlbmiss++;
|
|
#if 0
|
|
for (i = 0; i < config.immu.nways; i++)
|
|
if (getsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU) < minlru)
|
|
minway = i;
|
|
|
|
setsprbits(SPR_ITLBMR_BASE(minway) + set, SPR_ITLBMR_VPN, vpn);
|
|
for (i = 0; i < config.immu.nways; i++)
|
|
if (testsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU))
|
|
setsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU, getsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU) - 1);
|
|
setsprbits(SPR_ITLBMR_BASE(minway) + set, SPR_ITLBMR_LRU, config.immu.ustates - 1);
|
|
setsprbits(SPR_ITLBTR_BASE(minway) + set, SPR_ITLBTR_PPN, vpn); /* 1 to 1 */
|
|
setsprbits(SPR_ITLBMR_BASE(minway) + set, SPR_ITLBMR_V, 1);
|
|
#endif
|
|
except_handle(EXCEPT_ITLBMISS, virtaddr);
|
|
/* if tlb refill implemented in HW */
|
|
/* return getsprbits(SPR_ITLBTR_BASE(minway) + set, SPR_ITLBTR_PPN) * config.immu.pagesize + (virtaddr % config.immu.pagesize); */
|
|
return 0;
|
|
}
|
|
}
|
|
|
unsigned long immu_translate(unsigned long virtaddr)
|
unsigned long immu_translate(unsigned long virtaddr)
|
{
|
{
|
unsigned long phyaddr = immu_simulate_tlb(virtaddr);
|
unsigned long phyaddr = immu_simulate_tlb(virtaddr);
|
|
|
/* printf("IMMU translate(%x) = %x\n", virtaddr, phyaddr);*/
|
/* printf("IMMU translate(%x) = %x\n", virtaddr, phyaddr);*/
|
Line 99... |
Line 167... |
}
|
}
|
}
|
}
|
printf("\n");
|
printf("\n");
|
}
|
}
|
|
|
unsigned long immu_simulate_tlb(unsigned long virtaddr)
|
|
{
|
|
int set, way = -1;
|
|
int i;
|
|
unsigned long tagaddr;
|
|
unsigned long vpn;
|
|
|
|
if (!(mfspr(SPR_SR) & SPR_SR_IME) || !(testsprbits(SPR_UPR, SPR_UPR_IMP)))
|
|
return virtaddr;
|
|
|
|
/* Which set to check out? */
|
|
set = (virtaddr / config.immu.pagesize) % config.immu.nsets;
|
|
tagaddr = (virtaddr / config.immu.pagesize) / config.immu.nsets;
|
|
vpn = virtaddr / config.immu.pagesize;
|
|
|
|
/* Scan all ways and try to find a matching way. */
|
|
for (i = 0; i < config.immu.nways; i++)
|
|
if ((getsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_VPN) == vpn) &&
|
|
testsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_V))
|
|
way = i;
|
|
|
|
/* Did we find our tlb entry? */
|
|
if (way >= 0) { /* Yes, we did. */
|
|
immu_stats.fetch_tlbhit++;
|
|
debug(5, "ITLB hit (virtaddr=%x).\n", virtaddr);
|
|
|
|
/* Set LRUs */
|
|
for (i = 0; i < config.immu.nways; i++)
|
|
if (testsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU))
|
|
setsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU, getsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU) - 1);
|
|
setsprbits(SPR_ITLBMR_BASE(way) + set, SPR_ITLBMR_LRU, config.immu.ustates - 1);
|
|
|
|
return getsprbits(SPR_ITLBTR_BASE(way) + set, SPR_ITLBTR_PPN) * config.immu.pagesize + (virtaddr % config.immu.pagesize);
|
|
}
|
|
else { /* No, we didn't. */
|
|
int minlru = config.immu.ustates - 1;
|
|
int minway = 0;
|
|
|
|
immu_stats.fetch_tlbmiss++;
|
|
#if 0
|
|
for (i = 0; i < config.immu.nways; i++)
|
|
if (getsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU) < minlru)
|
|
minway = i;
|
|
|
|
setsprbits(SPR_ITLBMR_BASE(minway) + set, SPR_ITLBMR_VPN, vpn);
|
|
for (i = 0; i < config.immu.nways; i++)
|
|
if (testsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU))
|
|
setsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU, getsprbits(SPR_ITLBMR_BASE(i) + set, SPR_ITLBMR_LRU) - 1);
|
|
setsprbits(SPR_ITLBMR_BASE(minway) + set, SPR_ITLBMR_LRU, config.immu.ustates - 1);
|
|
setsprbits(SPR_ITLBTR_BASE(minway) + set, SPR_ITLBTR_PPN, vpn); /* 1 to 1 */
|
|
setsprbits(SPR_ITLBMR_BASE(minway) + set, SPR_ITLBMR_V, 1);
|
|
#endif
|
|
except_handle(EXCEPT_ITLBMISS, virtaddr);
|
|
/* if tlb refill implemented in HW */
|
|
/* return getsprbits(SPR_ITLBTR_BASE(minway) + set, SPR_ITLBTR_PPN) * config.immu.pagesize + (virtaddr % config.immu.pagesize); */
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
No newline at end of file
|
No newline at end of file
|