| // Copyright 2023 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #include "tests/verilator_sim/sysc_tb.h" |
| |
| #include "VKelvin.h" |
| #include "tests/verilator_sim/matcha/kelvin_if.h" |
| #include "tests/verilator_sim/kelvin/debug_if.h" |
| |
| struct Kelvin_tb : Sysc_tb { |
| sc_in<bool> io_halted; |
| sc_in<bool> io_fault; |
| |
| using Sysc_tb::Sysc_tb; // constructor |
| |
| void posedge() { |
| check(!io_fault, "io_fault"); |
| if (io_halted) sc_stop(); |
| } |
| }; |
| |
| static void Kelvin_run(const char* name, const char* bin, const bool trace) { |
| VKelvin core(name); |
| Kelvin_tb tb("Kelvin_tb", 100000000, /* random= */ false); |
| Kelvin_if mif("Kelvin_if", bin); |
| Debug_if dbg("Debug_if", &mif); |
| |
| sc_signal<bool> host_req; |
| sc_signal<bool> finish; |
| sc_signal<bool> fault; |
| sc_signal<bool> clk_freeze; |
| sc_signal<bool> ml_reset; |
| sc_signal<bool> volt_sel; |
| sc_signal<bool> debug_req; |
| sc_signal<bool> slog_valid; |
| sc_signal<sc_bv<5> > slog_addr; |
| sc_signal<sc_bv<32> > slog_data; |
| sc_signal<sc_bv<32> > pc_start; |
| sc_signal<bool> cvalid; |
| sc_signal<bool> cready; |
| sc_signal<bool> cwrite; |
| sc_signal<sc_bv<32> > caddr; |
| sc_signal<sc_bv<7> > cid; |
| sc_signal<sc_bv<256> > wdata; |
| sc_signal<sc_bv<32> > wmask; |
| sc_signal<bool> rvalid; |
| sc_signal<sc_bv<7> > rid; |
| sc_signal<sc_bv<256> > rdata; |
| |
| ml_reset = 0; |
| clk_freeze = 0; |
| pc_start = 0x00000000; |
| volt_sel = 0; |
| debug_req = 0; |
| |
| tb.io_halted(finish); |
| tb.io_fault(fault); |
| |
| core.clk_i(tb.clock); |
| core.rst_ni(tb.resetn); |
| core.ml_reset(ml_reset); |
| core.clk_freeze(clk_freeze); |
| core.pc_start(pc_start); |
| core.volt_sel(volt_sel); |
| core.finish(finish); |
| core.fault(fault); |
| core.host_req(host_req); |
| core.host_req(debug_req); |
| core.slog_valid(slog_valid); |
| core.slog_addr(slog_addr); |
| core.slog_data(slog_data); |
| |
| core.mem_cvalid(cvalid); |
| core.mem_cready(cready); |
| core.mem_cwrite(cwrite); |
| core.mem_caddr(caddr); |
| core.mem_cid(cid); |
| core.mem_wdata(wdata); |
| core.mem_wmask(wmask); |
| core.mem_rvalid(rvalid); |
| core.mem_rid(rid); |
| core.mem_rdata(rdata); |
| |
| mif.clock(tb.clock); |
| mif.reset(tb.reset); |
| mif.io_bus_cvalid(cvalid); |
| mif.io_bus_cready(cready); |
| mif.io_bus_cwrite(cwrite); |
| mif.io_bus_caddr(caddr); |
| mif.io_bus_cid(cid); |
| mif.io_bus_wdata(wdata); |
| mif.io_bus_wmask(wmask); |
| mif.io_bus_rvalid(rvalid); |
| mif.io_bus_rid(rid); |
| mif.io_bus_rdata(rdata); |
| |
| dbg.clock(tb.clock); |
| dbg.reset(tb.reset); |
| dbg.io_slog_valid(slog_valid); |
| dbg.io_slog_addr(slog_addr); |
| dbg.io_slog_data(slog_data); |
| |
| if (trace) { |
| tb.trace(core); |
| } |
| |
| tb.start(); |
| } |
| |
| int sc_main(int argc, char *argv[]) { |
| if (argc <= 1) { |
| printf("Expected binary file argument\n"); |
| return -1; |
| } |
| |
| const char* path = argv[1]; |
| Kelvin_run(Sysc_tb::get_name(argv[0]), path, false); |
| return 0; |
| } |