OpenASIP 2.2
Loading...
Searching...
No Matches
ProcessorWrapperBlock.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2015 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/*
25 * @file ProcessorWrapperBlock.cc
26 *
27 * Implementation/Declaration of ProcessorWrapperBlock class.
28 *
29 * Created on: 7.9.2015
30 * @author Henry Linjam�ki 2015 (henry.linjamaki-no.spam-tut.fi)
31 * @note rating: red
32 */
33
35
36#include "Netlist.hh"
37#include "NetlistTools.hh"
38#include "NetlistFactories.hh"
39#include "NetlistPort.hh"
40#include "NetlistPortGroup.hh"
43#include "GlobalPackage.hh"
44#include "MemoryBusInterface.hh"
45
46#include "FileSystem.hh"
47#include "MathTools.hh"
48#include "ControlUnit.hh"
49#include "InverterBlock.hh"
50
51namespace ProGe {
52
54 const ProGeContext& context, const BaseNetlistBlock& processorBlock)
55 : BaseNetlistBlock("proc", ""),
56 context_(context),
57 coreBlock_(processorBlock.shallowCopy()) {
58 assert(processorBlock.portCount() > 0);
60
61 // Wrapper interface //
64 NetlistPort* coreLocked = new OutPort("locked", "1");
65 addPort(coreLocked);
66
67 // Instantiate core //
69
70 // Memory instantiations and connections //
71 for (size_t i = 0; i < coreBlock_->portGroupCount(); i++) {
72 const NetlistPortGroup& portGrp = coreBlock_->portGroup(i);
73 SignalGroupType type = portGrp.assignedSignalGroup().type();
75 addInstructionMemory(portGrp);
76 } else if (type == SignalGroupType::BITMASKED_SRAM_PORT) {
77 auto dmemIf = dynamic_cast<const MemoryBusInterface*>(&portGrp);
78 assert(dmemIf != nullptr);
79 addDataMemory(*dmemIf);
80 } else if (type == SignalGroupType::BYTEMASKED_SRAM_PORT) {
81 auto dmemIf = dynamic_cast<const MemoryBusInterface*>(&portGrp);
82 assert(dmemIf != nullptr);
83 addDataMemory2(*dmemIf);
84 }
85 }
86
89 connectLockStatus(*coreLocked);
90
91 // Package holding instruction bus constants
92 std::set<std::string> procPackages{context.globalPackage().name()};
93
94 // Other packages possibly holding constants used in core ports.
95 for (size_t i = 0; i < processorBlock.packageCount(); i++) {
96 procPackages.insert(processorBlock.package(i));
97 }
98
99 for (auto packageStr : procPackages) {
100 addPackage(packageStr);
101 }
102
103 addPackage(context.coreEntityName() + "_params");
104
105 // Handle unknown ports
107}
108
110
111void
113 const Path& targetBaseDir, HDL targetLang) const {
115 targetBaseDir / std::string("tb"), targetLang);
116 BaseNetlistBlock::write(targetBaseDir, targetLang);
117}
118
119void
121 const NetlistPortGroup& coreImemPort) {
122 using SigT = SignalType;
123 bool isRISCV = context_.adf().isRISCVMachine();
124
125 const int imemWidthInMaus = (context_.adf().isRISCVMachine()) ? 4 : 1;
126 const int unusedBits = std::ceil(std::log2(imemWidthInMaus));
127
128 std::string addrWidth = context_.globalPackage().fetchBlockAddressWidth();
129 if (isRISCV) {
130 const int unusedBits = std::ceil(std::log2(imemWidthInMaus));
131 addrWidth = context_.globalPackage().fetchBlockAddressWidth() + "-" +
132 std::to_string(unusedBits);
133 }
134
137 "tb/imem_init.img", true);
138 addSubBlock(imemBlock, "imem0");
139 // todo: use core id instead of counter value.
140 std::string accessTrace = std::string("core") +
142 "_imem_access_trace.dump";
143 imemBlock->setAccessTraceFile(accessTrace);
144
145 if (isRISCV) {
146 // With RISC-V the two lower bits are unused
147 const int realAddrWidth = MathTools::requiredBits(
150 imemBlock->memoryPort(), coreImemPort,
151 {{SigT::READ_DATA, SigT::FETCHBLOCK},
152 {SigT::READ_WRITE_REQUEST, SigT::READ_REQUEST}});
154 imemBlock->memoryPort().portBySignal(SigT::ADDRESS),
155 coreImemPort.portBySignal(SigT::ADDRESS), 0, unusedBits,
156 realAddrWidth - unusedBits);
157 } else {
158 netlist().connect(
159 imemBlock->memoryPort(), coreImemPort,
160 {{SigT::ADDRESS, SigT::ADDRESS},
161 {SigT::READ_DATA, SigT::FETCHBLOCK},
162 {SigT::READ_WRITE_REQUEST, SigT::READ_REQUEST}});
163 }
164
165 imemBlock->memoryPort()
166 .portBySignal(SigT::WRITE_BITMASK)
167 .setToStatic(StaticSignal::VCC);
168 imemBlock->memoryPort()
169 .portBySignal(SigT::WRITEMODE)
170 .setToStatic(StaticSignal::VCC);
171 imemBlock->memoryPort()
172 .portBySignal(SigT::WRITE_DATA)
173 .setToStatic(StaticSignal::GND);
174 coreImemPort.portBySignal(SigT::READ_REQUEST_READY)
175 .setToStatic(StaticSignal::GND); // Active low
176}
177
178void
179ProcessorWrapperBlock::addDataMemory(const MemoryBusInterface& coreDmemPort) {
180 using SigT = SignalType;
181
182 const NetlistPort& addrPort = coreDmemPort.portBySignal(SigT::ADDRESS);
183 const NetlistPort& dataPort = coreDmemPort.portBySignal(SigT::WRITE_DATA);
184
186 addrPort.widthFormula(), dataPort.widthFormula(),
187 TCEString("tb/dmem_") + coreDmemPort.addressSpace() + "_init.img",
188 /* isForSmulation = */ true);
189 addSubBlock(dmemBlock, TCEString("dmem_") + coreDmemPort.addressSpace());
190
191 if (!netlist().connect(dmemBlock->memoryPort(), coreDmemPort)) {
194 "Could not connect two port groups together.");
195 }
196}
197
198void
199ProcessorWrapperBlock::addDataMemory2(
200 const MemoryBusInterface& coreDmemPort) {
201 using SigT = SignalType;
202
203 const NetlistPort& addrPort = coreDmemPort.portBySignal(SigT::AADDR);
204 const NetlistPort& dataPort = coreDmemPort.portBySignal(SigT::RDATA);
205
208 addrPort.widthFormula(), dataPort.widthFormula(),
209 TCEString("tb/dmem_") + coreDmemPort.addressSpace() + "_init.img",
210 /* isForSmulation = */ true);
211 addSubBlock(dmemBlock, TCEString("dmem_") + coreDmemPort.addressSpace());
212
213 if (!netlist().connect(dmemBlock->memoryPort(), coreDmemPort)) {
216 "Could not connect two port groups together.");
217 }
218}
219
220void
221ProcessorWrapperBlock::connectLockStatus(
222 const NetlistPort& topLockStatusPort) {
223 assert(
224 coreBlock_->port("locked") != nullptr &&
225 "Could not found lock status port.");
226 if (!netlist().connect(*coreBlock_->port("locked"), topLockStatusPort)) {
229 "Could not connect \"locked\" signal to the toplevel");
230 }
231}
232
233/**
234 * Handles unconnected ports of the top-level TTA processor by connecting
235 * them to the toplevel
236 */
237void
238ProcessorWrapperBlock::handleUnconnectedPorts() {
239 for (size_t i = 0; i < coreBlock_->portCount(); i++) {
240 const NetlistPort& port =
241 ((const BaseNetlistBlock*)coreBlock_)->port(i);
242 if (!netlist().isPortConnected(port) && !port.hasStaticValue()) {
243 NetlistPort* topPort = port.clone();
244 addPort(topPort);
245 netlist().connect(*topPort, port);
246 }
247 }
248}
249
250} /* namespace ProGe */
#define assert(condition)
#define THROW_EXCEPTION(exceptionType, message)
Exception wrapper macro that automatically includes file name, line number and function name where th...
Definition Exception.hh:39
static std::string toString(const T &source)
static int requiredBits(unsigned long int number)
virtual size_t packageCount() const
void addSubBlock(BaseNetlistBlock *subBlock, const std::string &instanceName="")
NetlistPort * addPort(NetlistPort *port)
virtual size_t portGroupCount() const
virtual const std::string & package(size_t idx) const
virtual const NetlistPortGroup & portGroup(size_t index) const
virtual void write(const Path &targetBaseDir, HDL targetLang=VHDL) const override
virtual size_t portCount() const
void addPackage(const std::string &packageName)
virtual void writeSelf(const Path &targetBaseDir, HDL targetLang=VHDL) const
virtual const Netlist & netlist() const
const std::string name() const
const std::string fetchBlockAddressWidth() const
const std::string fetchBlockDataWidth() const
SignalGroup assignedSignalGroup() const
const NetlistPort & portBySignal(SignalType type) const
virtual NetlistPort * clone(bool asMirrored=false) const
bool hasStaticValue() const
std::string widthFormula() const
bool connect(const NetlistPort &port1, const NetlistPort &port2, int port1FirstBit, int port2FirstBit, int width=1)
Definition Netlist.cc:83
Convenience class for output ports.
static NetlistPort * resetPort(Direction direction=IN)
static NetlistPort * clockPort(Direction direction=IN)
const std::string & coreEntityName() const
const TTAMachine::Machine & adf() const
const GlobalPackage & globalPackage() const
BaseNetlistBlock * coreBlock_
The target TTA processor.
virtual void write(const Path &targetBaseDir, HDL targetLang=VHDL) const override
void addInstructionMemory(const NetlistPortGroup &)
void addDataMemory2(const MemoryBusInterface &)
void addDataMemory(const MemoryBusInterface &)
void connectLockStatus(const NetlistPort &topPCInitPort)
SignalGroupType type() const
const NetlistPortGroup & memoryPort() const
void setAccessTraceFile(const std::string filename)
virtual ULongWord end() const
virtual AddressSpace * addressSpace() const
virtual ControlUnit * controlUnit() const
Definition Machine.cc:345
bool isRISCVMachine() const
Definition Machine.cc:1057
Definition FUGen.hh:54
@ BYTEMASKED_SRAM_PORT
Signal group type for one port SRAM having read and write capability and bitmask for writing with sep...
@ BITMASKED_SRAM_PORT
Signal group type for one port SRAM having read and write capability and bitmask for writing.
@ INSTRUCTION_LINE
Signal group type for serial TTA instruction bus.
HDL
HDLs supported by ProGe.
Definition ProGeTypes.hh:40