Skip to content

Commit

Permalink
Adding bus stubbing support
Browse files Browse the repository at this point in the history
  • Loading branch information
janweinstock committed May 23, 2023
1 parent 3d244eb commit 84ed09a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
33 changes: 33 additions & 0 deletions include/vcml/models/generic/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ class bus : public component

void map_default(size_t target, u64 offset = 0);

void stub(const range& addr, tlm_response_status rs = TLM_OK_RESPONSE);
void stub(u64 lo, u64 hi, tlm_response_status rs = TLM_OK_RESPONSE);

template <typename SOURCE>
void stub(SOURCE& s, const range& addr,
tlm_response_status rs = TLM_OK_RESPONSE);
template <typename SOURCE>
void stub(SOURCE& s, u64 lo, u64 hi,
tlm_response_status rs = TLM_OK_RESPONSE);

template <typename SOURCE>
size_t bind(SOURCE& s);

Expand Down Expand Up @@ -134,6 +144,29 @@ inline void bus::map(size_t target, u64 lo, u64 hi, u64 offset, size_t src) {
map(target, range(lo, hi), offset, src);
}

inline void bus::stub(const range& addr, tlm_response_status rs) {
size_t target_port = out.next_index();
out[target_port].stub(rs);
map(target_port, addr);
}

inline void bus::stub(u64 lo, u64 hi, tlm_response_status rs) {
stub(range(lo, hi), rs);
}

template <typename SOURCE>
inline void bus::stub(SOURCE& s, const range& addr, tlm_response_status rs) {
size_t source_port = bind(s);
size_t target_port = out.next_index();
out[target_port].stub(rs);
map(target_port, addr, 0, source_port);
}

template <typename SOURCE>
inline void bus::stub(SOURCE& s, u64 lo, u64 hi, tlm_response_status rs) {
stub(s, range(lo, hi), rs);
}

template <typename SOURCE>
size_t bus::bind(SOURCE& source) {
size_t port = find_source_port(source);
Expand Down
2 changes: 2 additions & 0 deletions include/vcml/protocols/tlm_sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class tlm_initiator_socket
template <unsigned int WIDTH>
void bind(tlm::tlm_base_target_socket_b<WIDTH>& other);

bool is_stubbed() const { return m_stub != nullptr; }
void stub(tlm_response_status resp = TLM_ADDRESS_ERROR_RESPONSE);
};

Expand Down Expand Up @@ -297,6 +298,7 @@ class tlm_target_socket : public simple_target_socket<tlm_target_socket>
template <unsigned int WIDTH>
tlm::tlm_target_socket<WIDTH>& adapt();

bool is_stubbed() const { return m_stub != nullptr; }
void stub();

bool in_transaction() const;
Expand Down
10 changes: 7 additions & 3 deletions src/vcml/models/generic/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ size_t bus::find_source_port(sc_object& peer) const {

const char* bus::target_peer_name(size_t port) const {
auto it = m_target_peers.find(port);
if (it == m_target_peers.end())
return out[port].name();
return it->second->name();
if (it != m_target_peers.end())
return it->second->name();

auto& socket = out[port];
if (socket.is_stubbed())
return "stubbed";
return out[port].name();
}

const char* bus::source_peer_name(size_t port) const {
Expand Down
12 changes: 12 additions & 0 deletions test/models/generic_bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class bus_harness : public test_base

bus.bind(out1, mem1.in, 0xa000, 0xbfff);
bus.bind(out2, mem2.in, 0xc000, 0xdfff);

bus.stub(0xe000, 0xe7ff);
bus.stub(out2, 0xe800, 0xefff);
}

virtual void run_test() override {
Expand Down Expand Up @@ -157,6 +160,15 @@ class bus_harness : public test_base
bus.lenient = false;
EXPECT_AE(out1.writew<u32>(0xc000, data));

EXPECT_OK(out1.readw<u32>(0xe000, data))
<< "cannot read from stubbed address area";
EXPECT_OK(out1.writew<u32>(0xe0f0, data))
<< "cannot write to stubbed address range";
EXPECT_AE(out1.readw<u32>(0xe800, data))
<< "unexpected data from privately stubbed area";
EXPECT_OK(out2.readw<u32>(0xe800, data))
<< "cannot read from privately stubbed area";

bus.execute("mmap", std::cout);
std::cout << std::endl;
}
Expand Down

0 comments on commit 84ed09a

Please sign in to comment.