blob: eeb76e2b2f32f02db7149d1f09c10c42e6d1176e [file] [log] [blame]
Rupert Swarbrick299cae52020-05-05 11:11:06 +01001# 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 Iyerf807f9d2020-11-17 01:37:52 -08005# This is sourced by all supported simulators. The driver scripts
Rupert Swarbrick299cae52020-05-05 11:11:06 +01006# (dvsim.py) need to make sure that we don't ask for an unsupported
Srikrishna Iyerf807f9d2020-11-17 01:37:52 -08007# dumping format (SHM with VCS, for example). The adjoining common.tcl
8# must be sourced prior to sourcing this file.
9
10if {[info proc setDefault] ne "setDefault"} {
11 puts "ERROR: Please ensure that common.tcl is sourced."
12 quit
13}
14
Srikrishna Iyer6f14afa2022-07-25 17:45:56 -070015# A procedure that provides a wave-format-agnostic way to enable a scope (design heirarchy).
Rupert Swarbrick299cae52020-05-05 11:11:06 +010016#
Srikrishna Iyerf807f9d2020-11-17 01:37:52 -080017# 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 Iyer6f14afa2022-07-25 17:45:56 -070020# waves : The wave-format (fsdb, shm, vpd, vcd, evcd, etc).
21# simulator : The simulator used for running the simulation (vcs, xcelium, etc).
Srikrishna Iyerf807f9d2020-11-17 01:37:52 -080022# 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 Iyer6f14afa2022-07-25 17:45:56 -070024# 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 Iyerf807f9d2020-11-17 01:37:52 -080026# probe_flags : Additional string flags passed to probe command (Xcelium). Defaults to "-all".
Srikrishna Iyer6f14afa2022-07-25 17:45:56 -070027# dump_flags : Additional string flags passed to dump command (VCS). Defaults to "-aggregates",
28# which enables dumping of structs and arrays.
Srikrishna Iyerf807f9d2020-11-17 01:37:52 -080029#
Srikrishna Iyer6f14afa2022-07-25 17:45:56 -070030# Depending on the need, more such technology specific flags can be added in future.
31proc wavedumpScope {waves simulator scope {depth 0} {fsdb_flags "+all"} {probe_flags "-all"}
Srikrishna Iyerf807f9d2020-11-17 01:37:52 -080032 {dump_flags "-aggregates"}} {
Rupert Swarbrick299cae52020-05-05 11:11:06 +010033
Srikrishna Iyerf807f9d2020-11-17 01:37:52 -080034 switch $waves {
35 "none" {
Srikrishna Iyer6f14afa2022-07-25 17:45:56 -070036 return
Srikrishna Iyerf807f9d2020-11-17 01:37:52 -080037 }
38
39 "fsdb" {
Srikrishna Iyerf807f9d2020-11-17 01:37:52 -080040 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 Hoangdefc2142021-04-19 17:36:00 -070053 probe "$scope" $probe_flags -depth $depth -memories -shm
Srikrishna Iyerf807f9d2020-11-17 01:37:52 -080054 }
55
56 "vpd" {
Srikrishna Iyer6f14afa2022-07-25 17:45:56 -070057 global vpd_fid
58 dump -add "$scope" -fid $vpd_fid -depth $depth $dump_flags
Srikrishna Iyerf807f9d2020-11-17 01:37:52 -080059 }
60
61 "vcd" {
62 if {$simulator eq "xcelium"} {
63 if {$depth == 0} {
64 set depth "all"
65 }
Tung Hoangdefc2142021-04-19 17:36:00 -070066 probe "$scope" $probe_flags -depth $depth -memories -vcd
Srikrishna Iyerf807f9d2020-11-17 01:37:52 -080067 }
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 Iyer6f14afa2022-07-25 17:45:56 -070084
Srikrishna Iyerf807f9d2020-11-17 01:37:52 -080085 puts "INFO: Dumping waves in scope \"$scope:$depth\"."
Rupert Swarbrick299cae52020-05-05 11:11:06 +010086}
87
Srikrishna Iyer6f14afa2022-07-25 17:45:56 -070088# A global variable representing the file id (fid) of the waves dumped in VPD format.
89setDefault vpd_fid 0
90
91# The entry point to enable dumping waves.
Srikrishna Iyerf807f9d2020-11-17 01:37:52 -080092#
Srikrishna Iyer6f14afa2022-07-25 17:45:56 -070093# 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.
96global waves
97global simulator
98if {$waves ne "none"} {
99 set wavedump_db "waves.$waves"
100 puts "INFO: Dumping waves in [string toupper $waves] format to $wavedump_db."
Rupert Swarbrick299cae52020-05-05 11:11:06 +0100101
Srikrishna Iyer6f14afa2022-07-25 17:45:56 -0700102 # 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 Iyerf807f9d2020-11-17 01:37:52 -0800112
Srikrishna Iyer6f14afa2022-07-25 17:45:56 -0700113 "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 Swarbrick299cae52020-05-05 11:11:06 +0100163}