gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
example.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2021 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
29 
30 #include <algorithm>
31 
32 #include "base/logging.hh"
33 
34 namespace gem5
35 {
36 namespace fastmodel
37 {
38 
39 ResetControllerExample::CorePins::CorePins(const std::string &module_name)
40  : reset(module_name + ".reset"),
41  halt(module_name + ".halt")
42 {}
43 
45  const std::string &module_name, Iris::BaseCPU *c, CorePins *p)
46  : RegisterBankLE(module_name, 0), cpu(c), pins(p),
47  nsrvbar(module_name + ".nsrvbar"),
48  rvbar(module_name + ".rvbar"),
49  reset(module_name + ".reset"),
50  halt(module_name + ".halt")
51 {
52  panic_if(cpu == nullptr, "ResetControllerExample needs a target cpu.");
53  nsrvbar.writer(
54  [this] (auto &reg, auto val)
55  {
56  cpu->setResetAddr(val, false);
57  });
58  rvbar.writer(
59  [this] (auto &reg, auto val)
60  {
61  cpu->setResetAddr(val, true);
62  });
63  reset.writer(
64  [this] (auto &reg, auto val)
65  {
66  panic_if(!pins->reset.isConnected(),
67  "%s is not connected.", pins->reset.name());
68  pins->reset.set(val);
69  });
70  halt.writer(
71  [this] (auto &reg, auto val)
72  {
73  panic_if(!pins->halt.isConnected(),
74  "%s is not connected.", pins->halt.name());
75  pins->halt.set(val);
76  });
77 
78  addRegisters({
79  nsrvbar,
80  rvbar,
81  reset,
82  halt,
83  });
84 }
85 
87  : BasicPioDevice(p, 0x20),
88  pins(p.name + ".pins"),
89  registers(p.name + ".registers", p.cpu, &pins)
90 {}
91 
92 Tick
94 {
95  pkt->makeResponse();
96  auto data = pkt->getPtr<uint8_t>();
97  auto size = pkt->getSize();
98  std::fill(data, data + size, 0);
99  return pioDelay;
100 }
101 
102 Tick
104 {
105  pkt->makeResponse();
106  size_t size = pkt->getSize();
107  if (size != 4 && size != 8) {
108  pkt->setBadAddress();
109  } else {
110  auto addr = pkt->getAddr() - pioAddr;
111  registers.write(addr, pkt->getPtr<void>(), size);
112  }
113  return pioDelay;
114 }
115 
116 Port &
117 ResetControllerExample::getPort(const std::string &if_name, PortID idx)
118 {
119  if (if_name == "reset")
120  return pins.reset;
121  else if (if_name == "halt")
122  return pins.halt;
123 
124  return BasicPioDevice::getPort(if_name, idx);
125 }
126 
127 } // namespace fastmodel
128 } // namespace gem5
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
gem5::MipsISA::fill
fill
Definition: pra_constants.hh:57
gem5::BasicPioDevice::pioAddr
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:151
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::fastmodel::ResetControllerExample::CorePins::reset
SignalSourcePort< bool > reset
Definition: example.hh:51
gem5::Iris::BaseCPU::setResetAddr
virtual void setResetAddr(Addr addr, bool secure=false)
Definition: cpu.hh:90
gem5::fastmodel::ResetControllerExample::ResetControllerExample
ResetControllerExample(const Params &)
Definition: example.cc:86
example.hh
gem5::fastmodel::ResetControllerExample::Params
FastModelResetControllerExampleParams Params
Definition: example.hh:76
gem5::Iris::BaseCPU
Definition: cpu.hh:60
gem5::Packet::setBadAddress
void setBadAddress()
Definition: packet.hh:786
gem5::SignalSourcePort::set
void set(const State &new_state)
Definition: signal.hh:105
gem5::fastmodel::ResetControllerExample::Registers::reset
Register32 reset
Definition: example.hh:65
gem5::X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:776
gem5::fastmodel::ResetControllerExample::Registers::Registers
Registers(const std::string &, Iris::BaseCPU *, CorePins *)
Definition: example.cc:44
gem5::RegisterBank::write
virtual void write(Addr addr, const void *buf, Addr bytes)
Definition: reg_bank.hh:1002
gem5::RegisterBank< ByteOrder::little >::addRegisters
void addRegisters(std::initializer_list< RegisterAdder > adders)
Definition: reg_bank.hh:913
gem5::fastmodel::ResetControllerExample::CorePins::halt
SignalSourcePort< bool > halt
Definition: example.hh:52
gem5::VegaISA::c
Bitfield< 2 > c
Definition: pagetable.hh:63
gem5::fastmodel::ResetControllerExample::Registers::cpu
Iris::BaseCPU * cpu
Definition: example.hh:60
gem5::fastmodel::ResetControllerExample::write
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: example.cc:103
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::fastmodel::ResetControllerExample::getPort
Port & getPort(const std::string &, PortID=InvalidPortID) override
Get a port with a given name and index.
Definition: example.cc:117
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::fastmodel::ResetControllerExample::registers
Registers registers
Definition: example.hh:73
gem5::statistics::reset
void reset()
Definition: statistics.cc:309
gem5::BasicPioDevice::pioDelay
Tick pioDelay
Delay that the device experinces on an access.
Definition: io_device.hh:157
gem5::MipsISA::halt
Bitfield< 26 > halt
Definition: dt_constants.hh:47
gem5::fastmodel::ResetControllerExample::CorePins::CorePins
CorePins(const std::string &)
Definition: example.cc:39
gem5::X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:92
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:214
gem5::fastmodel::ResetControllerExample::pins
CorePins pins
Definition: example.hh:72
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
gem5::Packet::makeResponse
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
Definition: packet.hh:1062
gem5::fastmodel::ResetControllerExample::read
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: example.cc:93
gem5::fastmodel::ResetControllerExample::Registers::pins
CorePins * pins
Definition: example.hh:61
gem5::RegisterBank< ByteOrder::little >
logging.hh
gem5::Packet::getAddr
Addr getAddr() const
Definition: packet.hh:807
gem5::fastmodel::ResetControllerExample::Registers::rvbar
Register64 rvbar
Definition: example.hh:64
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::BasicPioDevice
Definition: io_device.hh:147
gem5::fastmodel::ResetControllerExample::CorePins
Definition: example.hh:49
gem5::Packet::getSize
unsigned getSize() const
Definition: packet.hh:817
gem5::fastmodel::ResetControllerExample::Registers::halt
Register32 halt
Definition: example.hh:66
gem5::fastmodel::ResetControllerExample::Registers::nsrvbar
Register64 nsrvbar
Definition: example.hh:63
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::PioDevice::getPort
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: io_device.cc:67
gem5::Packet::getPtr
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1225

Generated on Sun Jul 30 2023 01:56:47 for gem5 by doxygen 1.8.17