oops, bounds checking on free-running tb_cxxrtl

This commit is contained in:
Luke Wren 2021-07-18 15:20:25 +01:00
parent e95b465e26
commit ce5cc1f150
1 changed files with 14 additions and 9 deletions

View File

@ -138,7 +138,7 @@ int main(int argc, char **argv) {
#else #else
uint32_t wdata = top.p_ahblm__hwdata.get<uint32_t>(); uint32_t wdata = top.p_ahblm__hwdata.get<uint32_t>();
#endif #endif
if (bus_addr <= MEM_SIZE) { if (bus_addr <= MEM_SIZE - (1u << bus_size)) {
unsigned int n_bytes = 1u << bus_size; unsigned int n_bytes = 1u << bus_size;
// Note we are relying on hazard3's byte lane replication // Note we are relying on hazard3's byte lane replication
for (unsigned int i = 0; i < n_bytes; ++i) { for (unsigned int i = 0; i < n_bytes; ++i) {
@ -158,8 +158,8 @@ int main(int argc, char **argv) {
} }
} }
else if (bus_trans && !bus_write) { else if (bus_trans && !bus_write) {
if (bus_addr <= MEM_SIZE) {
bus_addr &= ~0x3u; bus_addr &= ~0x3u;
if (bus_addr <= MEM_SIZE - 4) {
rdata = rdata =
(uint32_t)mem[bus_addr] | (uint32_t)mem[bus_addr] |
mem[bus_addr + 1] << 8 | mem[bus_addr + 1] << 8 |
@ -171,6 +171,7 @@ int main(int argc, char **argv) {
top.p_d__hrdata.set<uint32_t>(rdata); top.p_d__hrdata.set<uint32_t>(rdata);
if (bus_trans_i) { if (bus_trans_i) {
bus_addr_i &= ~0x3u; bus_addr_i &= ~0x3u;
if (bus_addr_i <= MEM_SIZE - 4) {
top.p_i__hrdata.set<uint32_t>( top.p_i__hrdata.set<uint32_t>(
(uint32_t)mem[bus_addr_i] | (uint32_t)mem[bus_addr_i] |
mem[bus_addr_i + 1] << 8 | mem[bus_addr_i + 1] << 8 |
@ -178,6 +179,10 @@ int main(int argc, char **argv) {
mem[bus_addr_i + 3] << 24 mem[bus_addr_i + 3] << 24
); );
} }
else {
top.p_i__hrdata.set<uint32_t>(0);
}
}
#else #else
top.p_ahblm__hrdata.set<uint32_t>(rdata); top.p_ahblm__hrdata.set<uint32_t>(rdata);
#endif #endif