-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathSystem.cpp
More file actions
95 lines (77 loc) · 2.65 KB
/
Copy pathSystem.cpp
File metadata and controls
95 lines (77 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2020 Western Digital Corporation or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Hart.hpp"
#include "Core.hpp"
#include "System.hpp"
using namespace WdRiscv;
template <typename URV>
System<URV>::System(unsigned coreCount, unsigned hartsPerCore,
unsigned hartIdOffset, size_t memSize,
size_t pageSize, size_t regionSize)
: hartCount_(coreCount * hartsPerCore), hartsPerCore_(hartsPerCore)
{
cores_.resize(coreCount);
memory_ = std::make_shared<Memory>(memSize, pageSize, regionSize);
sparseMem_ = nullptr;
Memory& mem = *(memory_.get());
mem.setHartCount(hartCount_);
for (unsigned ix = 0; ix < coreCount; ++ix)
{
URV coreHartId = ix * hartIdOffset;
cores_.at(ix) = std::make_shared<CoreClass>(coreHartId, ix, hartsPerCore, mem);
// Maintain a vector of all the harts in the system. Map hart-id to index
// of hart in system.
auto core = cores_.at(ix);
for (unsigned i = 0; i < hartsPerCore; ++i)
{
auto hart = core->ithHart(i);
sysHarts_.push_back(hart);
URV hartId = coreHartId + i;
unsigned hartIx = ix*hartsPerCore + i;
hartIdToIndex_[hartId] = hartIx;
}
}
#ifdef MEM_CALLBACKS
sparseMem_ = new SparseMem();
auto readf = [this](uint64_t addr, unsigned size, uint64_t& value) -> bool {
return sparseMem_->read(addr, size, value); };
auto writef = [this](uint64_t addr, unsigned size, uint64_t value) -> bool {
return sparseMem_->write(addr, size, value); };
mem.defineReadMemoryCallback(readf);
mem.defineWriteMemoryCallback(writef);
#endif
}
template <typename URV>
System<URV>::~System()
{
delete sparseMem_;
sparseMem_ = nullptr;
}
template <typename URV>
void
System<URV>::checkUnmappedElf(bool flag)
{
if (memory_)
memory_->checkUnmappedElf(flag);
}
template <typename URV>
bool
System<URV>::writeAccessedMemory(const std::string& path) const
{
if (not sparseMem_)
return false;
return sparseMem_->writeHexFile(path);
}
template class WdRiscv::System<uint32_t>;
template class WdRiscv::System<uint64_t>;