page_table.cc (2800:18a615ca6e19) | page_table.cc (2809:9cb5fba079ed) |
---|---|
1/* 2 * Copyright (c) 2003 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 40 unchanged lines hidden (view full) --- 49using namespace std; 50using namespace TheISA; 51 52PageTable::PageTable(System *_system, Addr _pageSize) 53 : pageSize(_pageSize), offsetMask(mask(floorLog2(_pageSize))), 54 system(_system) 55{ 56 assert(isPowerOf2(pageSize)); | 1/* 2 * Copyright (c) 2003 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 40 unchanged lines hidden (view full) --- 49using namespace std; 50using namespace TheISA; 51 52PageTable::PageTable(System *_system, Addr _pageSize) 53 : pageSize(_pageSize), offsetMask(mask(floorLog2(_pageSize))), 54 system(_system) 55{ 56 assert(isPowerOf2(pageSize)); |
57 pTableCache[0].vaddr = 0; 58 pTableCache[1].vaddr = 0; 59 pTableCache[2].vaddr = 0; |
|
57} 58 59PageTable::~PageTable() 60{ 61} 62 63Fault 64PageTable::page_check(Addr addr, int size) const --- 25 unchanged lines hidden (view full) --- 90 91void 92PageTable::allocate(Addr vaddr, int size) 93{ 94 // starting address must be page aligned 95 assert(pageOffset(vaddr) == 0); 96 97 for (; size > 0; size -= pageSize, vaddr += pageSize) { | 60} 61 62PageTable::~PageTable() 63{ 64} 65 66Fault 67PageTable::page_check(Addr addr, int size) const --- 25 unchanged lines hidden (view full) --- 93 94void 95PageTable::allocate(Addr vaddr, int size) 96{ 97 // starting address must be page aligned 98 assert(pageOffset(vaddr) == 0); 99 100 for (; size > 0; size -= pageSize, vaddr += pageSize) { |
98 std::map<Addr,Addr>::iterator iter = pTable.find(vaddr); | 101 m5::hash_map<Addr,Addr>::iterator iter = pTable.find(vaddr); |
99 100 if (iter != pTable.end()) { 101 // already mapped 102 fatal("PageTable::allocate: address 0x%x already mapped", vaddr); 103 } 104 105 pTable[vaddr] = system->new_page(); | 102 103 if (iter != pTable.end()) { 104 // already mapped 105 fatal("PageTable::allocate: address 0x%x already mapped", vaddr); 106 } 107 108 pTable[vaddr] = system->new_page(); |
109 pTableCache[2].paddr = pTableCache[1].paddr; 110 pTableCache[2].vaddr = pTableCache[1].vaddr; 111 pTableCache[1].paddr = pTableCache[0].paddr; 112 pTableCache[1].vaddr = pTableCache[0].vaddr; 113 pTableCache[0].paddr = pTable[vaddr]; 114 pTableCache[0].vaddr = vaddr; |
|
106 } 107} 108 109 110 111bool 112PageTable::translate(Addr vaddr, Addr &paddr) 113{ 114 Addr page_addr = pageAlign(vaddr); | 115 } 116} 117 118 119 120bool 121PageTable::translate(Addr vaddr, Addr &paddr) 122{ 123 Addr page_addr = pageAlign(vaddr); |
115 std::map<Addr,Addr>::iterator iter = pTable.find(page_addr); | 124 paddr = 0; |
116 | 125 |
126 if (pTableCache[0].vaddr == vaddr) { 127 paddr = pTableCache[0].paddr; 128 return true; 129 } 130 if (pTableCache[1].vaddr == vaddr) { 131 paddr = pTableCache[1].paddr; 132 return true; 133 } 134 if (pTableCache[2].vaddr == vaddr) { 135 paddr = pTableCache[2].paddr; 136 return true; 137 } 138 139 m5::hash_map<Addr,Addr>::iterator iter = pTable.find(page_addr); 140 |
|
117 if (iter == pTable.end()) { 118 return false; 119 } 120 121 paddr = iter->second + pageOffset(vaddr); 122 return true; 123} 124 --- 13 unchanged lines hidden --- | 141 if (iter == pTable.end()) { 142 return false; 143 } 144 145 paddr = iter->second + pageOffset(vaddr); 146 return true; 147} 148 --- 13 unchanged lines hidden --- |