Rupert Swarbrick | 299cae5 | 2020-05-05 11:11:06 +0100 | [diff] [blame] | 1 | # Copyright lowRISC contributors. |
| 2 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 5 | # This is sourced by all supported simulators. The driver scripts |
Rupert Swarbrick | 299cae5 | 2020-05-05 11:11:06 +0100 | [diff] [blame] | 6 | # (dvsim.py) need to make sure that we don't ask for an unsupported |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 7 | # dumping format (SHM with VCS, for example). The adjoining common.tcl |
| 8 | # must be sourced prior to sourcing this file. |
| 9 | |
| 10 | if {[info proc setDefault] ne "setDefault"} { |
| 11 | puts "ERROR: Please ensure that common.tcl is sourced." |
| 12 | quit |
| 13 | } |
| 14 | |
Srikrishna Iyer | 6f14afa | 2022-07-25 17:45:56 -0700 | [diff] [blame] | 15 | # A procedure that provides a wave-format-agnostic way to enable a scope (design heirarchy). |
Rupert Swarbrick | 299cae5 | 2020-05-05 11:11:06 +0100 | [diff] [blame] | 16 | # |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 17 | # In large designs, dumping waves on the entire hierarchy can significantly slow down the |
| 18 | # simulation. It is useful in that case to only dump the relevant scopes of interest during debug. |
| 19 | # |
Srikrishna Iyer | 6f14afa | 2022-07-25 17:45:56 -0700 | [diff] [blame] | 20 | # waves : The wave-format (fsdb, shm, vpd, vcd, evcd, etc). |
| 21 | # simulator : The simulator used for running the simulation (vcs, xcelium, etc). |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 22 | # scope : Design / testbench hierarchy to dump waves. Defaults to $tb_top. |
| 23 | # depth : Levels in the hierarchy to dump waves. Defaults to 0 (dump all levels). |
Srikrishna Iyer | 6f14afa | 2022-07-25 17:45:56 -0700 | [diff] [blame] | 24 | # fsdb_flags : Additional string flags passed to fsdbDumpVars. Defaults to "+all", which enables |
| 25 | # dumping of memories, MDAs, structs, unions, power, packed structs, and SVAs. |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 26 | # probe_flags : Additional string flags passed to probe command (Xcelium). Defaults to "-all". |
Srikrishna Iyer | 6f14afa | 2022-07-25 17:45:56 -0700 | [diff] [blame] | 27 | # dump_flags : Additional string flags passed to dump command (VCS). Defaults to "-aggregates", |
| 28 | # which enables dumping of structs and arrays. |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 29 | # |
Srikrishna Iyer | 6f14afa | 2022-07-25 17:45:56 -0700 | [diff] [blame] | 30 | # Depending on the need, more such technology specific flags can be added in future. |
| 31 | proc wavedumpScope {waves simulator scope {depth 0} {fsdb_flags "+all"} {probe_flags "-all"} |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 32 | {dump_flags "-aggregates"}} { |
Rupert Swarbrick | 299cae5 | 2020-05-05 11:11:06 +0100 | [diff] [blame] | 33 | |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 34 | switch $waves { |
| 35 | "none" { |
Srikrishna Iyer | 6f14afa | 2022-07-25 17:45:56 -0700 | [diff] [blame] | 36 | return |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | "fsdb" { |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 40 | if {$simulator eq "xcelium"} { |
| 41 | call fsdbDumpvars $depth $scope $fsdb_flags |
| 42 | call fsdbDumpSVA $depth $scope |
| 43 | } else { |
| 44 | fsdbDumpvars $depth $scope $fsdb_flags |
| 45 | fsdbDumpSVA $depth $scope |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | "shm" { |
| 50 | if {$depth == 0} { |
| 51 | set depth "all" |
| 52 | } |
Tung Hoang | defc214 | 2021-04-19 17:36:00 -0700 | [diff] [blame] | 53 | probe "$scope" $probe_flags -depth $depth -memories -shm |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | "vpd" { |
Srikrishna Iyer | 6f14afa | 2022-07-25 17:45:56 -0700 | [diff] [blame] | 57 | global vpd_fid |
| 58 | dump -add "$scope" -fid $vpd_fid -depth $depth $dump_flags |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | "vcd" { |
| 62 | if {$simulator eq "xcelium"} { |
| 63 | if {$depth == 0} { |
| 64 | set depth "all" |
| 65 | } |
Tung Hoang | defc214 | 2021-04-19 17:36:00 -0700 | [diff] [blame] | 66 | probe "$scope" $probe_flags -depth $depth -memories -vcd |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
| 70 | "evcd" { |
| 71 | if {$simulator eq "xcelium"} { |
| 72 | if {$depth == 0} { |
| 73 | set depth "all" |
| 74 | } |
| 75 | probe "$scope" $probe_flags -depth $depth -evcd |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | default { |
| 80 | puts "ERROR: Unknown wave format: ${waves}." |
| 81 | quit |
| 82 | } |
| 83 | } |
Srikrishna Iyer | 6f14afa | 2022-07-25 17:45:56 -0700 | [diff] [blame] | 84 | |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 85 | puts "INFO: Dumping waves in scope \"$scope:$depth\"." |
Rupert Swarbrick | 299cae5 | 2020-05-05 11:11:06 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Srikrishna Iyer | 6f14afa | 2022-07-25 17:45:56 -0700 | [diff] [blame] | 88 | # A global variable representing the file id (fid) of the waves dumped in VPD format. |
| 89 | setDefault vpd_fid 0 |
| 90 | |
| 91 | # The entry point to enable dumping waves. |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 92 | # |
Srikrishna Iyer | 6f14afa | 2022-07-25 17:45:56 -0700 | [diff] [blame] | 93 | # If waves are not enabled (i.e. $waves == "none"), we do nothing. If enabled, then first, we run |
| 94 | # the tcl command to establish the dump file. Then, we run `wavedumpScope args...` to enable dumping |
| 95 | # the required hierarchies. |
| 96 | global waves |
| 97 | global simulator |
| 98 | if {$waves ne "none"} { |
| 99 | set wavedump_db "waves.$waves" |
| 100 | puts "INFO: Dumping waves in [string toupper $waves] format to $wavedump_db." |
Rupert Swarbrick | 299cae5 | 2020-05-05 11:11:06 +0100 | [diff] [blame] | 101 | |
Srikrishna Iyer | 6f14afa | 2022-07-25 17:45:56 -0700 | [diff] [blame] | 102 | # If waves are enabled, then issue the necessary tcl commands to enable the generation of waves. |
| 103 | # To explicitly list the hierarchies to dump, use the wavedumpScope proc instead. |
| 104 | switch $waves { |
| 105 | "fsdb" { |
| 106 | if {$simulator eq "xcelium"} { |
| 107 | call fsdbDumpfile $wavedump_db |
| 108 | } else { |
| 109 | fsdbDumpfile $wavedump_db |
| 110 | } |
| 111 | } |
Srikrishna Iyer | f807f9d | 2020-11-17 01:37:52 -0800 | [diff] [blame] | 112 | |
Srikrishna Iyer | 6f14afa | 2022-07-25 17:45:56 -0700 | [diff] [blame] | 113 | "shm" { |
| 114 | checkEq simulator "xcelium" |
| 115 | database -open $wavedump_db -default -shm |
| 116 | } |
| 117 | |
| 118 | "vpd" { |
| 119 | checkEq simulator "vcs" |
| 120 | global vpd_fid |
| 121 | set vpd_fid [dump -file $wavedump_db -type VPD] |
| 122 | } |
| 123 | |
| 124 | "vcd" { |
| 125 | if {$simulator eq "xcelium"} { |
| 126 | database -open $wavedump_db -default -vcd |
| 127 | } else { |
| 128 | puts "ERROR: Simulator $simulator does not support dumping waves in VCD." |
| 129 | quit |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | "evcd" { |
| 134 | if {$simulator eq "xcelium"} { |
| 135 | database -open $wavedump_db -default -evcd |
| 136 | } else { |
| 137 | puts "ERROR: Simulator $simulator does not support dumping waves in EVCD." |
| 138 | quit |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | default { |
| 143 | puts "ERROR: Unknown wave format: ${waves}." |
| 144 | quit |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | # Decide whether to dump the entire testbench hierarchy by default. |
| 149 | # |
| 150 | # If this variable is not set externally, it is set to 1 by default here. When set to 1, it adds |
| 151 | # the entire top-level testbench instance for dumping waves. For larger designs, this may slow |
| 152 | # down the simulation. The user can if needed, set it to 0 in the external tcl script that sources |
| 153 | # this script and manually add the hierarchies of interest in there, using the wavedumpScope proc. |
| 154 | # See the adjoining sim.tcl for an example. |
| 155 | setDefault dump_tb_top 1 |
| 156 | |
| 157 | if {$dump_tb_top == 1} { |
| 158 | global tb_top |
| 159 | wavedumpScope $waves $simulator $tb_top 0 |
| 160 | } else { |
| 161 | puts "INFO: the hierarchies to be dumped are expected to be indicated externally." |
| 162 | } |
Rupert Swarbrick | 299cae5 | 2020-05-05 11:11:06 +0100 | [diff] [blame] | 163 | } |