Skip to content

Commit

Permalink
Merge branch 'main' into rv32_inst_handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
kathlenemagnus authored Dec 13, 2024
2 parents 3f7371e + 98ca826 commit 4e7d5b2
Show file tree
Hide file tree
Showing 10 changed files with 390 additions and 302 deletions.
5 changes: 4 additions & 1 deletion arch/RegisterDefnsJSON.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ namespace atlas
constexpr sparta::RegisterBase::Definition::HintsT hints = 0;
constexpr sparta::RegisterBase::Definition::RegDomainT regdomain = 0;

const bool writable = id != 0 || group_num != 0;

sparta::RegisterBase::Definition defn = {
id, name, group_num, group, group_idx,
desc, bytes, field_defns, bank_membership, aliases,
subset_of, subset_offset, initial_value, hints, regdomain};
subset_of, subset_offset, initial_value, hints, regdomain,
writable};

register_defns_.push_back(defn);
}
Expand Down
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

0 comments on commit 4e7d5b2

Please sign in to comment.