Line 92... |
Line 92... |
translations then translate() performs translation otherwise phy address is
|
translations then translate() performs translation otherwise phy address is
|
equal to logical. */
|
equal to logical. */
|
static oraddr_t translate(oraddr_t laddr,int* breakpoint)
|
static oraddr_t translate(oraddr_t laddr,int* breakpoint)
|
{
|
{
|
int i;
|
int i;
|
|
int brkp;
|
|
|
/* No translation (i.e. when loading kernel into simulator) */
|
/* No translation (i.e. when loading kernel into simulator) */
|
/* PRINTF("transl_table=%x laddr=%x\n", transl_table, laddr);
|
/* PRINTF("transl_table=%x laddr=%x\n", transl_table, laddr);
|
PRINTF("laddr=%x\n", laddr);*/
|
PRINTF("laddr=%x\n", laddr);*/
|
if (transl_table == 0)
|
if (transl_table == 0)
|
return laddr;
|
return laddr;
|
|
|
/* Try to find our translation in the table. */
|
/* Try to find our translation in the table. */
|
for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
|
for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
|
if ((laddr & ~(PAGE_SIZE - 1)) == evalsim_mem32(transl_table + i)) {
|
if ((laddr & ~(PAGE_SIZE - 1)) == eval_direct32(transl_table + i,
|
setsim_mem32(transl_table + i + 8, -2); /* Page modified */
|
&brkp, 0, 0)) {
|
|
/* Page modified */
|
|
set_direct32(transl_table + i + 8, -2, &brkp, 0, 0);
|
PRINTF("found paddr=%"PRIx32"\n",
|
PRINTF("found paddr=%"PRIx32"\n",
|
evalsim_mem32(transl_table + i + 4) | (laddr & (PAGE_SIZE - 1)));
|
eval_direct32(transl_table + i + 4, &brkp, 0, 0) |
|
return (oraddr_t)evalsim_mem32(transl_table + i + 4) | (laddr & (oraddr_t)(PAGE_SIZE - 1));
|
(laddr & (PAGE_SIZE - 1)));
|
|
return (oraddr_t)eval_direct32(transl_table + i + 4, &brkp, 0, 0) |
|
|
(laddr & (oraddr_t)(PAGE_SIZE - 1));
|
}
|
}
|
|
|
/* Allocate new phy page for us. */
|
/* Allocate new phy page for us. */
|
for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
|
for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
|
if (evalsim_mem32(transl_table + i + 8) == 0) {
|
if (eval_direct32(transl_table + i + 8, &brkp, 0, 0) == 0) {
|
setsim_mem32(transl_table + i, laddr & ~(PAGE_SIZE - 1)); /* VPN */
|
/* VPN */
|
setsim_mem32(transl_table + i + 4, (i/16) * PAGE_SIZE); /* PPN */
|
set_direct32(transl_table + i, laddr & ~(PAGE_SIZE - 1), &brkp, 0, 0);
|
setsim_mem32(transl_table + i + 8, -2); /* Page modified */
|
/* PPN */
|
|
set_direct32(transl_table + i + 4, (i/16) * PAGE_SIZE, &brkp, 0, 0);
|
|
/* Page modified */
|
|
set_direct32(transl_table + i + 8, -2, &brkp, 0, 0);
|
PRINTF("newly allocated ppn=%"PRIx32"\n",
|
PRINTF("newly allocated ppn=%"PRIx32"\n",
|
evalsim_mem32(transl_table + i + 4));
|
eval_direct32(transl_table + i + 4, &brkp, 0, 0));
|
PRINTF("newly allocated .ppn=%"PRIxADDR"\n", transl_table + i + 4);
|
PRINTF("newly allocated .ppn=%"PRIxADDR"\n", transl_table + i + 4);
|
PRINTF("newly allocated ofs=%"PRIxADDR"\n", (laddr & (PAGE_SIZE - 1)));
|
PRINTF("newly allocated ofs=%"PRIxADDR"\n", (laddr & (PAGE_SIZE - 1)));
|
PRINTF("newly allocated paddr=%"PRIx32"\n",
|
PRINTF("newly allocated paddr=%"PRIx32"\n",
|
evalsim_mem32(transl_table + i + 4) | (laddr & (PAGE_SIZE - 1)));
|
eval_direct32(transl_table + i + 4, &brkp, 0, 0) |
|
return (oraddr_t)evalsim_mem32(transl_table + i + 4) | (laddr & (oraddr_t)(PAGE_SIZE - 1));
|
(laddr & (PAGE_SIZE - 1)));
|
|
return (oraddr_t)eval_direct32(transl_table + i + 4, &brkp, 0, 0) |
|
|
(laddr & (oraddr_t)(PAGE_SIZE - 1));
|
}
|
}
|
/* If we come this far then all phy memory is used and we can't find our page
|
/* If we come this far then all phy memory is used and we can't find our page
|
nor allocate new page. */
|
nor allocate new page. */
|
transl_error = 1;
|
transl_error = 1;
|
|
|