gem5  v22.1.0.0
sc_signal.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2018 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 
28 #include <sstream>
29 
34 
35 namespace sc_gem5
36 {
37 
39  sc_core::sc_prim_channel(name), _changeStamp(~0ULL),
40  _gem5WriterPort(nullptr)
41 {}
42 
44 
45 const sc_core::sc_event &
47 {
48  return valueChangedEvent();
49 }
50 
51 const sc_core::sc_event &
53 {
54  return _valueChangedEvent;
55 }
56 
57 bool
59 {
60  return _changeStamp == getChangeStamp();
61 }
62 
63 void
65 {
68 }
69 
70 void
72 {
75 }
76 
77 void
79 {
82 }
83 
84 namespace
85 {
86 
87 void
88 reportSignalError(ScSignalBase *sig, sc_core::sc_object *first,
89  sc_core::sc_object *second, bool delta_conflict=false)
90 {
91  std::ostringstream ss;
92  ss << "\n signal " << "`" << sig->name() << "' (" << sig->kind() << ")";
93  ss << "\n first driver `" << first->name() << "' (" <<
94  first->kind() << ")";
95  ss << "\n second driver `" << second->name() << "' (" <<
96  second->kind() << ")";
97  if (delta_conflict) {
98  ss << "\n conflicting write in delta cycle " <<
100  }
102  ss.str().c_str());
103 }
104 
105 } // anonymous namespace
106 
108  sig(_sig), firstPort(nullptr), proc(nullptr), writeStamp(~0ULL)
109 {}
110 
111 void
113  std::string iface_type_name, std::string out_name)
114 {
115  if (iface_type_name == out_name) {
116  if (firstPort)
117  reportSignalError(sig, firstPort, &port);
118  firstPort = &port;
119  }
120 }
121 
122 void
124 {
125  Process *p = scheduler.current();
126  if (!p)
127  return;
128  uint64_t stamp = getChangeStamp();
129  if (proc && proc != p)
130  reportSignalError(sig, proc, p);
131  proc = p;
132  writeStamp = stamp;
133 }
134 
136  sig(_sig), proc(nullptr), writeStamp(~0ULL)
137 {}
138 
139 void
141  std::string iface_type_name, std::string out_name)
142 {
143  return;
144 }
145 
146 void
148 {
149  Process *p = scheduler.current();
150  if (!p)
151  return;
152  uint64_t stamp = getChangeStamp();
153  if (writeStamp == stamp && proc && proc != p)
154  reportSignalError(sig, proc, p, writeStamp == stamp);
155  proc = p;
156  writeStamp = stamp;
157 }
158 
160  ScSignalBase(_name), _posStamp(~0ULL), _negStamp(~0ULL)
161 {}
162 
163 const sc_core::sc_event &
165 {
166  return _posedgeEvent;
167 }
168 
169 const sc_core::sc_event &
171 {
172  return _negedgeEvent;
173 }
174 
175 bool
177 {
178  return _posStamp == getChangeStamp();
179 }
180 
181 bool
183 {
184  return _negStamp == getChangeStamp();
185 }
186 
187 void
189 {
190  r->update();
191 }
192 
193 void
195 {
196  for (auto r: _resets)
197  _signalReset(r);
198 }
199 
200 } // namespace sc_gem5
const char * name() const
Definition: sc_object.cc:44
virtual const char * kind() const
Definition: sc_object.hh:56
InternalScEvent _negedgeEvent
Definition: sc_signal.hh:93
InternalScEvent _posedgeEvent
Definition: sc_signal.hh:92
const sc_core::sc_event & negedgeEvent() const
Definition: sc_signal.cc:170
ScSignalBaseBinary(const char *_name)
Definition: sc_signal.cc:159
const sc_core::sc_event & posedgeEvent() const
Definition: sc_signal.cc:164
std::vector< sc_gem5::Reset * > _resets
Definition: sc_signal.hh:82
virtual const char * kind() const
Definition: sc_signal.hh:57
InternalScEvent _valueChangedEvent
Definition: sc_signal.hh:72
const sc_core::sc_event & valueChangedEvent() const
Definition: sc_signal.cc:52
bool event() const
Definition: sc_signal.cc:58
virtual ~ScSignalBase()
Definition: sc_signal.cc:43
const sc_core::sc_event & defaultEvent() const
Definition: sc_signal.cc:46
ScSignalBase(const char *_name)
Definition: sc_signal.cc:38
Process * current()
Definition: scheduler.hh:185
Bitfield< 5 > r
Definition: pagetable.hh:60
Bitfield< 54 > p
Definition: pagetable.hh:70
sc_dt::uint64 sc_delta_count()
Definition: sc_main.cc:135
const char SC_ID_MORE_THAN_ONE_SIGNAL_DRIVER_[]
Definition: messages.cc:52
const sc_time SC_ZERO_TIME
Definition: sc_time.cc:290
uint64_t getChangeStamp()
Definition: sc_prim.cc:37
Scheduler scheduler
Definition: scheduler.cc:494
#define SC_REPORT_ERROR(msg_type, msg)
const std::string & name()
Definition: trace.cc:49
std::stringstream ss
Definition: trace.test.cc:45

Generated on Wed Dec 21 2022 10:22:40 for gem5 by doxygen 1.9.1