diff options
author | Gabe Black <gabeblack@google.com> | 2019-08-16 23:12:11 -0700 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2019-08-27 22:17:57 +0000 |
commit | 51d46ef4c69173cad68e35142715c04a5b882983 (patch) | |
tree | 1bf72452de145fec75c253c61ca594e6bf8970d1 /src/sim/port.hh | |
parent | 2a566b4fa7fbd805746d598d0ffc096c2710cef9 (diff) | |
download | gem5-51d46ef4c69173cad68e35142715c04a5b882983.tar.xz |
sim: Add a takeOverFrom method to the base Port class.
This makes it easier, safer, and less verbose to swap out ports when
a CPU takes over for another CPU, for instance.
Change-Id: Ice08e4dcb4b04dc66b1841331092a78b4f6f5a96
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20233
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/sim/port.hh')
-rw-r--r-- | src/sim/port.hh | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/sim/port.hh b/src/sim/port.hh index ee4b548a5..111417263 100644 --- a/src/sim/port.hh +++ b/src/sim/port.hh @@ -126,6 +126,25 @@ class Port /** Is this port currently connected to a peer? */ bool isConnected() const { return _connected; } + + /** A utility function to make it easier to swap out ports. */ + void + takeOverFrom(Port *old) + { + assert(old); + assert(old->isConnected()); + assert(!isConnected()); + Port &peer = old->getPeer(); + assert(peer.isConnected()); + + // Disconnect the original binding. + old->unbind(); + peer.unbind(); + + // Connect the new binding. + peer.bind(*this); + bind(peer); + } }; #endif //__SIM_PORT_HH__ |