Skip to content

Commit

Permalink
Integrate printer
Browse files Browse the repository at this point in the history
  • Loading branch information
thommythomaso committed Sep 26, 2023
1 parent 02d35b6 commit 4254cf6
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 138 deletions.
1 change: 0 additions & 1 deletion cheshire.mk
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ CHS_BOOTROM_ALL += $(CHS_ROOT)/hw/bootrom/cheshire_bootrom.sv $(CHS_ROOT)/hw/boo
$(CHS_ROOT)/target/sim/vsim/compile.cheshire_soc.tcl: Bender.yml
$(BENDER) script vsim -t sim -t cv64a6_imafdcsclic_sv39 -t test -t cva6 -t rtl --vlog-arg="$(VLOG_ARGS)" > $@
echo 'vlog "$(CURDIR)/$(CHS_ROOT)/target/sim/src/elfloader.cpp" -ccflags "-std=c++11"' >> $@
echo 'vlog "$(CURDIR)/$(CHS_ROOT)/target/sim/src/cfg_format.c"' >> $@

$(CHS_ROOT)/target/sim/models:
mkdir -p $@
Expand Down
128 changes: 128 additions & 0 deletions hw/cheshire_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -604,4 +604,132 @@ package cheshire_pkg;
default: '0
};


////////////////////////////
// Configuration Printer //
////////////////////////////

function automatic string format_config (
string cfg_str,
int unsigned int_hex_split,
int unsigned param_name_width
);

// determine length of the string
automatic int unsigned cfg_len = cfg_str.len();

// temp variables
automatic string cfg_item = "";
automatic bit array_active = 0;
automatic bit unnamed_array = 0;
automatic bit was_closed = 0;
automatic int unsigned unnamed_idx = 0;
automatic string padding = "";

// overwrite closing bracket to terminate config string
cfg_str.putc(cfg_len-1, ",");

// parse each character individually, start from index 2 to omit the "'{"
for (int i = 2; i < cfg_len; i++) begin
// go through the characters individually. The default case is to accumulate them in the
// `cfg_item` buffer.

// colon denotes the separation between named value and value
// Goal: print the padded key of a named value
if (cfg_str[i] == ":") begin

// decide if we are in array mode: print an indentation
if (array_active) begin
for (int p = 0; p < param_name_width - cfg_item.len() - 4; p++) begin
padding = {padding, " "};
end
format_config = {format_config, $sformatf(" %s:%s", cfg_item, padding)};
// print no indentation
end else begin
for (int p = 0; p < param_name_width - cfg_item.len(); p++) begin
padding = {padding, " "};
end
format_config = {format_config, $sformatf("%s:%s", cfg_item, padding)};
end

// reset accumulator and padding
padding = "";
cfg_item = "";

// we found a named key: we thus don't have an array of unnamed values
if (array_active) begin
unnamed_array = 0;
end

// comma: finishes an entry. We print the value. In the case of unnamed values we add an
// increasing key.
end else if (cfg_str[i] == ",") begin
automatic longint unsigned value = cfg_item.atoi();
automatic string unnamed_idx_str = $sformatf("%-0d", unnamed_idx);
automatic string padding = "";

// we print the unnamed array index and the corresponding padding
if (array_active & unnamed_array) begin
for (int p = 0; p < param_name_width - unnamed_idx_str.len() - 4; p++) begin
padding = {padding, " "};
end
format_config = {format_config, $sformatf(" %s:%s", unnamed_idx_str, padding)};
end

// we print a value: use a defined threshold to differentiate between unsigned and
// hex values
if (value < int_hex_split) begin
format_config = {format_config, $sformatf(" %d", value)};
end else begin
// some hex formatting increasing legibility
automatic string hex_val = $sformatf("%h", value);
format_config = {format_config, "0x"};
for (int h = 0; h < hex_val.len(); h++) begin
if (h % 4 == 0 && h > 0) begin
format_config = {format_config, "_"};
end
format_config = {format_config, $sformatf("%s", hex_val[h])};
end
end

// reset accumulator and padding
padding = "";
cfg_item = "";

// array bookkeeping
unnamed_idx = unnamed_idx + 1;
if (was_closed) begin
was_closed = 0;
array_active = 0;
end

// finish entry
format_config = {format_config, "\n"};

// space: ignore
end else if (cfg_str[i] == " ") begin
continue;

// ': ignore
end else if (cfg_str[i] == "'") begin
continue;

// }: close the bracket
end else if (cfg_str[i] == "}") begin
was_closed = 1;

// {: begin array
end else if (cfg_str[i] == "{") begin
array_active = 1;
unnamed_array = 1;
unnamed_idx = 0;
format_config = {format_config, "\n"};

// default: append char to accumulator
end else begin
cfg_item = {cfg_item, cfg_str[i]};
end
end
endfunction

endpackage
121 changes: 0 additions & 121 deletions target/sim/src/cfg_format.c

This file was deleted.

28 changes: 27 additions & 1 deletion target/sim/src/fixture_cheshire_soc.sv
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

module fixture_cheshire_soc #(
/// The selected simulation configuration from the `tb_cheshire_pkg`.
parameter int unsigned SelectedCfg = 32'd0
parameter int unsigned SelectedCfg = 32'd0,
/// Print the Cheshire config at launch
parameter bit PrintCfg = 1'b0
);

`include "cheshire/typedef.svh"
Expand All @@ -18,6 +20,30 @@ module fixture_cheshire_soc #(

localparam cheshire_cfg_t DutCfg = TbCheshireConfigs[SelectedCfg];

// print the configs
initial begin
if (PrintCfg) begin : gen_print_cfg
$display("\n\nAXI In Config");
$display("----------------------------------------------");
$display("%s", format_config($sformatf("%p", gen_axi_in(DutCfg)), 4096, 24));
$display("\n\nAXI Out Config");
$display("----------------------------------------------");
$display("%s", format_config($sformatf("%p", gen_axi_out(DutCfg)), 4096, 24));
$display("\n\nRegbus In Config");
$display("----------------------------------------------");
$display("%s", format_config($sformatf("%p", gen_reg_out(DutCfg)), 4096, 24));
$display("\n\nCVA6 ID Map");
$display("----------------------------------------------");
$display("%s", format_config($sformatf("%p", gen_cva6_id_map(DutCfg)), 4096, 24));
$display("\n\nCVA6 Config");
$display("----------------------------------------------");
$display("%s", format_config($sformatf("%p", gen_cva6_cfg(DutCfg)), 4096, 24));
$display("\n\nCheshire Config");
$display("----------------------------------------------");
$display("%s", format_config($sformatf("%p", DutCfg), 4096, 24));
end
end

`CHESHIRE_TYPEDEF_ALL(, DutCfg)


Expand Down
Loading

0 comments on commit 4254cf6

Please sign in to comment.