From 6acb68797562fbfac983a408d1fc2653658e63d7 Mon Sep 17 00:00:00 2001 From: Johnny Date: Thu, 17 Aug 2023 13:24:43 +0800 Subject: [PATCH 1/2] sim: provide a signal constructor with an init_state 1. The current SignalSinkPort and SignalSourcePort have no ways to assign the init value of the state. Add a new constructor for them with the param init_state 2. After the source and sink are bound, the state at both side should be the same. Set the the state of sink to the state of source in the bind() function. Change-Id: Idde0a12aa0ddd0c9c599ef47059674fb12aa5d68 --- src/sim/signal.hh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/sim/signal.hh b/src/sim/signal.hh index 3cb3f62c0d..398da9e711 100644 --- a/src/sim/signal.hh +++ b/src/sim/signal.hh @@ -79,6 +79,7 @@ class SignalSinkPort : public Port _source = dynamic_cast *>(&peer); fatal_if(!_source, "Attempt to bind signal pin %s to " "incompatible pin %s", name(), peer.name()); + _state = _source->state(); Port::bind(peer); } void @@ -94,12 +95,21 @@ class SignalSourcePort : public Port { private: SignalSinkPort *sink = nullptr; - State _state = {}; + State _state; public: - SignalSourcePort(const std::string &_name, PortID _id=InvalidPortID) : - Port(_name, _id) - {} + SignalSourcePort(const std::string &_name, PortID _id = InvalidPortID) + : Port(_name, _id) + { + _state = {}; + } + + SignalSourcePort(const std::string &_name, PortID _id, + const State &init_state) + : SignalSourcePort(_name, _id) + { + _state = init_state; + } void set(const State &new_state) @@ -126,6 +136,6 @@ class SignalSourcePort : public Port } }; -} // namespace gem5 +} // namespace gem5 -#endif //__SIM_SIGNAL_HH__ +#endif //__SIM_SIGNAL_HH__ From 76fe71ebd0d4a56e4d59163393067026dbe6fe2e Mon Sep 17 00:00:00 2001 From: Johnny Date: Wed, 23 Aug 2023 10:13:32 +0800 Subject: [PATCH 2/2] sim: provide a signal constructor with an init_state Add more description to the code Change-Id: Iff8fb20762baa0c9d0b7e5f24fb8769d7e198b5c --- src/sim/signal.hh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sim/signal.hh b/src/sim/signal.hh index 398da9e711..b94618a9c3 100644 --- a/src/sim/signal.hh +++ b/src/sim/signal.hh @@ -79,6 +79,7 @@ class SignalSinkPort : public Port _source = dynamic_cast *>(&peer); fatal_if(!_source, "Attempt to bind signal pin %s to " "incompatible pin %s", name(), peer.name()); + // The state of sink has to match the state of source. _state = _source->state(); Port::bind(peer); } @@ -104,6 +105,7 @@ class SignalSourcePort : public Port _state = {}; } + // Give an initial value to the _state instead of using a default value. SignalSourcePort(const std::string &_name, PortID _id, const State &init_state) : SignalSourcePort(_name, _id)