From 873dec41fc97224bd1704bc68de1e055cb1d711f Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Sat, 6 Mar 2004 00:25:37 +0000 Subject: [PATCH] clean code --- second/MMU040.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/second/MMU040.c b/second/MMU040.c index af336f9..5b06966 100644 --- a/second/MMU040.c +++ b/second/MMU040.c @@ -91,10 +91,9 @@ static int isTTSegment(unsigned long addr) int MMU040_logical2physicalAttr(unsigned long logicalAddr, unsigned long *physicalAddr, unsigned long *attr) { - int rootIndex; - int ptrIndex; - int pageIndex; unsigned long TC; + int rootIndex, ptrIndex, pageIndex; + unsigned long pageOffst; unsigned long rootTable, ptrTable, pageTable; unsigned long rootEntry, tableEntry, pageEntry; @@ -110,17 +109,10 @@ int MMU040_logical2physicalAttr(unsigned long logicalAddr, unsigned long *physic return 0; } - rootIndex = (logicalAddr & 0xFE000000) >> 25; - ptrIndex = (logicalAddr & 0x01FC0000) >> 18; - pageIndex = IS_8K_PAGE(TC) ? (logicalAddr & 0x0003E000) >> 13 : - (logicalAddr & 0x0003F000) >> 12; - - TRACE("root idx: %d ptr idx: %d page idx: %d\n", rootIndex, ptrIndex, - pageIndex); - MMU040_get_SRP(&rootTable); TRACE("SRP: %ld\n", rootTable); + rootIndex = (logicalAddr & 0xFE000000) >> 25; rootEntry = MMU040_read_phys(rootTable + 4 * rootIndex); TRACE("Root Entry: %08lx\n", rootEntry); @@ -130,6 +122,7 @@ int MMU040_logical2physicalAttr(unsigned long logicalAddr, unsigned long *physic } ptrTable = GET_RP_ADDR(rootEntry); + ptrIndex = (logicalAddr & 0x01FC0000) >> 18; tableEntry = MMU040_read_phys(ptrTable + 4 * ptrIndex); TRACE("table Entry: %08lx\n", tableEntry); @@ -138,15 +131,28 @@ int MMU040_logical2physicalAttr(unsigned long logicalAddr, unsigned long *physic return -1; } - pageTable = ( IS_8K_PAGE(TC) ? GET_TD_8K_ADDR(tableEntry) : - GET_TD_4K_ADDR(tableEntry) ); - pageEntry = MMU040_read_phys(pageTable + 4 * pageIndex); if (IS_8K_PAGE(TC)) - *physicalAddr = pageEntry & 0xFFFFE000; + { + pageTable = GET_TD_8K_ADDR(tableEntry); + pageIndex = (logicalAddr & 0x0003E000) >> 13; + + pageEntry = MMU040_read_phys(pageTable + 4 * pageIndex); + pageOffst = logicalAddr & 0x00001FFF; + + *physicalAddr = (pageEntry & 0xFFFFE000) + pageOffst; + } else - *physicalAddr = pageEntry & 0xFFFFF000; + { + pageTable = GET_TD_4K_ADDR(tableEntry); + pageIndex = (logicalAddr & 0x0003F000) >> 12; + + pageEntry = MMU040_read_phys(pageTable + 4 * pageIndex); + pageOffst = logicalAddr & 0x00000FFF; + + *physicalAddr = (pageEntry & 0xFFFFF000) + pageOffst; + } *attr = pageEntry & 0x000004FF;