Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SV32 translation test with basic PageTableWalk #20

Merged
merged 13 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_library(atlascore
Execute.cpp
AtlasExtractor.cpp
AtlasInst.cpp
PageTableWalker.cpp
observers/Observer.cpp
observers/CoSimObserver.cpp
observers/InstructionLogger.cpp
Expand Down
119 changes: 103 additions & 16 deletions core/PageTable.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#include <map>
#include <iostream>
#include "../include/AtlasTypes.hpp"
Expand All @@ -10,25 +12,110 @@ namespace atlas
private:
const uint16_t max_entries;
const uint32_t baseAddressOfpageTable;
bool isValidIndex(uint32_t idx);
size_t size();
uint16_t getMaxNumEntries(MMUMode mode) const;

bool isValidIndex(uint32_t idx)
{
uint32_t pte_size = (Mode == MMUMode::SV32) ? sizeof(RV32) : sizeof(RV64);
return ((idx >= baseAddressOfpageTable)
&& (idx < ((max_entries * pte_size) + baseAddressOfpageTable)));
}

size_t size() const { return pageTable.size(); }

uint16_t getMaxNumEntries() const
{
if (Mode == MMUMode::SV32)
return PT_ENTRIES_SV32;
else if (Mode == MMUMode::SV39)
return PT_ENTRIES_SV39;
return 0;
}

public:
std::map<uint32_t, PageTableEntry<Mode>>
pageTable; // uint32_t will be able to accomodate all the types of indexes(VPNs) for
// addressing the PTE

PageTable(uint32_t baseAddr);
void addEntry(uint32_t index, PageTableEntry<Mode> entry);
PageTableEntry<Mode> getEntry(uint32_t index);
void removeEntry(uint32_t index);
void print(std::ostream & os);
bool contains(uint32_t index);
pageTable; // uint32_t accommodates all types of VPNs for addressing the PTE

PageTable(uint32_t baseAddr) :
max_entries(getMaxNumEntries()),
baseAddressOfpageTable(baseAddr)
{
}

void addEntry(uint32_t index, PageTableEntry<Mode> entry)
{
if (size() <= max_entries && isValidIndex(index))
{
auto it = pageTable.find(index);
if (it != pageTable.end())
{
it->second = entry; // Update the existing entry
}
else
{
pageTable.insert({index, entry}); // Insert the new entry
}
}
else
{
throw std::runtime_error(
"Page table has reached its maximum capacity or index is out of bounds!");
}
}

PageTableEntry<Mode> getEntry(uint32_t index)
{
if (isValidIndex(index))
{
auto it = pageTable.find(index);
if (it != pageTable.end())
{
return it->second;
}
else
{
throw std::out_of_range("Index not found in the page table");
}
}
else
{
throw std::out_of_range("Invalid index");
}
}

void removeEntry(uint32_t index)
{
if (isValidIndex(index))
{
auto it = pageTable.find(index);
if (it != pageTable.end())
{
pageTable.erase(it);
}
else
{
throw std::out_of_range("Index not found in the page table");
}
}
else
{
throw std::out_of_range("Invalid index");
}
}

bool contains(uint32_t index) const { return pageTable.find(index) != pageTable.end(); }

void print(std::ostream & os) const
{
for (const auto & [index, entry] : pageTable)
{
os << "Index: " << index << " | PTE: " << entry.getPTE() << std::endl;
}
}
};

template <MMUMode Mode>
std::ostream & operator<<(std::ostream & os, const PageTable<Mode> & pt);
template <MMUMode Mode> std::ostream & operator<<(std::ostream & os, const PageTable<Mode> & pt)
{
pt.print(os);
return os;
}
} // namespace atlas

#include "PageTable.tpp"
109 changes: 0 additions & 109 deletions core/PageTable.tpp

This file was deleted.

Loading