public void WriteBack(ushort pageIndex, ushort frameIndex) { TlbEntry newEntry = new TlbEntry(pageIndex, frameIndex); //look for an empty entry for (int i = 0; i < EntriesPerTLB; i++) { if (_entries[i].PageIndex == null) { _entries[i] = newEntry; return; } } //swap a resident entry with a biggest counter int maxValue = 0, maxIndex = 0; for (int i = 0; i < EntriesPerTLB; i++) { if (_entries[i].Counter > maxValue) { maxValue = _entries[i].Counter; maxIndex = i; } } _entries[maxIndex] = newEntry; }
public TLB() { for (int i = 0; i < 16; i++) { _entries[i] = new TlbEntry(); } }
internal static (int index, TlbEntry entry) CreateTlbEntry(uint virtualAddress, uint physicalAddress, bool rw = true, bool supervisor = false) { var entry = physicalAddress & 0xFFFFFC00; entry |= rw ? PageTableFlags.Rw : 0; entry |= supervisor ? PageTableFlags.Supervisor : 0; var tag = TlbEntry.TagFromAddress(virtualAddress); var tlbEntry = new TlbEntry { entry = entry, tag = tag, }; var index = TlbEntry.IndexFromTag(tag); return(index, tlbEntry); }