Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / env / common / vera / classes / std_display_class.vr
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: std_display_class.vr
4// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
5// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
6//
7// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8//
9// This program is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; version 2 of the License.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21//
22// For the avoidance of doubt, and except that if any non-GPL license
23// choice is available it will apply instead, Sun elects to use only
24// the General Public License version 2 (GPLv2) at this time for any
25// software where a choice of GPL license versions is made
26// available with the language indicating that GPLv2 or any later version
27// may be used, or where a choice of which version of the GPL is applied is
28// otherwise unspecified.
29//
30// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
31// CA 95054 USA or visit www.sun.com if you need additional information or
32// have any questions.
33//
34// ========== Copyright Header End ============================================
35#include <vera_defines.vrh>
36#include "std_display_defines.vri"
37#include "plusArgMacros.vri"
38
39
40#ifdef DISPLAY_CYCLES
41#define STD_GET_TIME sprintf (tmp_str,"%9d: ",get_cycle())
42#else
43#define STD_GET_TIME sprintf (tmp_str,"%9d: ",{get_time(HI),get_time(LO)})
44#endif
45
46#ifdef NTB
47// NTB does not suport get_time(HI), sighhh
48// get_time(LO) returns nothing, double sighhh
49#define STD_GET_TIME sprintf (tmp_str,"%8d__: ",get_cycle())
50#endif
51
52
53class StandardDisplay {
54
55 local reg[MAX_VERBOSITY-1:0] verbosity[];
56 local reg[MAX_VERBOSITY-1:0] default_verbosity = NORMAL_VERBOSITY;
57 local string context_name[];
58 local string vlabel[MAX_VERBOSITY];
59 local reg [63:0] tmpTime;
60
61 // these are not local so they can be accessed directly.
62 integer errors = 0;
63 integer warnings = 0;
64 integer info_all = 0;
65 // The following plus args are "standard":
66 integer maxerror = 1;
67 integer maxwarning = 5;
68 integer wait_cycle_to_kill = 5;
69 integer debug = 0;
70 integer debug_all = 0;
71 integer info = 0;
72 integer start_debug = 0;
73 integer quiet = 0;
74
75 static reg [1:0] instanceCount;
76
77 //------------------------------------------------------------------------------
78 // task new. paramater passing not required...
79 //------------------------------------------------------------------------------
80 task new (integer maxErrors = 1,
81 integer errorCnt = 0,
82 integer maxWarnings = 5,
83 integer wait_cycle_to_kill = 5,
84 integer start_debug = 0)
85 {
86
87 reg[2048:0] arg_bit_str = 0;
88 string src_str;
89
90 if (instanceCount !== 2'bxx) instanceCount++;
91 else instanceCount = 1;
92
93 // sanity check
94 if (instanceCount > 1) {
95 printf("More than one instance of std_display_class.vr/StandardDisplay detected!\n");
96 printf("Since this class keeps error counts, we only want one. You can have as\n");
97 printf("many pointers as you want to the single instance though. (A=new();B=A;C=A;)\n");
98 error("Need to FAIL, sorry!\n");
99 }
100
101 maxerror = maxErrors;
102 errors = errorCnt;
103 maxwarning = maxWarnings;
104 wait_cycle_to_kill = wait_cycle_to_kill;
105 start_debug = start_debug;
106
107 init_vlabels();
108
109
110 if (mChkPlusarg(quiet) && !mChkPlusarg(noquiet)) {
111 default_verbosity = QUIET_VERBOSITY;
112 quiet = 1;
113 info_all = 0;
114 info = 0;
115 debug_all = 0;
116 debug = 0;
117 }
118
119 if (mChkPlusarg(info_all)) {
120 default_verbosity = INFO_VERBOSITY;
121 quiet = 0;
122 info_all = 1;
123 info = 1;
124 debug_all = 0;
125 debug = 0;
126 }
127
128 if (mChkPlusarg(debug_all)) {
129 default_verbosity = DEBUG_VERBOSITY;
130 quiet = 0;
131 info_all = 1;
132 info = 1;
133 debug_all = 1;
134 debug = 1;
135 }
136
137 if (mChkPlusarg(info)) {
138 quiet = 0;
139 info = 1;
140 debug = 0;
141 }
142
143 if (mChkPlusarg(debug)) {
144 quiet = 0;
145 info = 1;
146 debug = 1;
147 }
148
149 if (mChkPlusarg(mon+)) {
150 mGetPlusargStr(mon+,arg_bit_str);
151 src_str.bittostr (arg_bit_str);
152 parse_mon_arg_str (src_str);
153 }
154
155 if (mChkPlusarg(maxerror=)) {
156 mGetPlusargDec(maxerror=,maxerror);
157 }
158 if (mChkPlusarg(maxwarning=)) {
159 mGetPlusargDec(maxwarning=,maxwarning);
160 }
161 if (mChkPlusarg(wait_cycle_to_kill=)) {
162 mGetPlusargDec(wait_cycle_to_kill=,wait_cycle_to_kill);
163 }
164 if (mChkPlusarg(start_debug=)) {
165 mGetPlusargDec(start_debug=,start_debug);
166 }
167
168 } // end task new
169
170 //------------------------------------------------------------------------------
171 // task dispmon
172 //------------------------------------------------------------------------------
173
174 task dispmon (string context_str, integer level, string message,
175 string file = null, integer lineNum = 0 ) {
176
177 reg[MAX_VERBOSITY-1:0] verbosity_enabled;
178 string tmp_str;
179
180
181 if (level == MON_DEBUG)
182 if (start_debug && get_cycle() < start_debug) return;
183
184
185 // !context_exists(context_str)
186 if (! assoc_index(CHECK,verbosity,context_ndx(context_str))) {
187 create_context (context_str);
188 }
189
190 verbosity_enabled = verbosity[context_ndx(context_str)];
191
192 if (verbosity_enabled[level]) {
193
194 STD_GET_TIME;
195 if (file == null) {
196 printf("%s%s%s[]: %s\n", tmp_str, vlabel[level], context_str, message);
197 }
198 else {
199 printf("%s%s%s[%s:%0d]: %s\n", tmp_str, vlabel[level], context_str, file, lineNum, message);
200 }
201
202 if (level == MON_ERR) errors++;
203 else if (level == MON_WARN) warnings++;
204 }
205
206 } // end task dispmon
207
208
209 task writemon (string context_str, integer level,
210 string message, string file = null, integer lineNum = 0 ) {
211
212 reg[MAX_VERBOSITY-1:0] verbosity_enabled;
213 string tmp_str;
214
215
216 if (level == MON_DEBUG)
217 if (start_debug && get_cycle() < start_debug) return;
218
219 // !context_exists(context_str)
220 if (! assoc_index(CHECK,verbosity,context_ndx(context_str))) {
221 create_context (context_str);
222 }
223
224 verbosity_enabled = verbosity[context_ndx(context_str)];
225
226 if (verbosity_enabled[level]) {
227
228 STD_GET_TIME;
229 if (file == null) {
230 printf("%s%s%s[]: %s", tmp_str, vlabel[level], context_str, message);
231 }
232 else {
233 printf("%s%s%s[%s:%0d]: %s", tmp_str, vlabel[level], context_str, file, lineNum, message);
234 }
235
236 if (level == MON_ERR) errors++;
237 if (level == MON_WARN) warnings++;
238 }
239
240 } // end task writemon
241
242
243 task appendmon (string context_str, integer level, string message) {
244
245 reg[MAX_VERBOSITY-1:0] verbosity_enabled;
246 string tmp_str;
247
248 if (!context_exists(context_str)) {
249 create_context (context_str);
250 }
251
252 verbosity_enabled = verbosity[context_ndx(context_str)];
253
254 if (verbosity_enabled[level]) {
255 printf("%s",message);
256 }
257
258 } // end task appendmon
259
260
261 //------------------------------------------------------------------------------
262 // function integer get_errors()
263 //------------------------------------------------------------------------------
264 function integer get_errors() {
265 get_errors = errors;
266 }
267
268 task getCounts(var integer err, var integer warn) {
269 err = errors;
270 warn = warnings;
271 }
272
273 //------------------------------------------------------------------------------
274 // task init_vlabels
275 //------------------------------------------------------------------------------
276
277 protected task init_vlabels() {
278 integer ii;
279
280 vlabel[MON_ALWAYS] = "";
281 vlabel[MON_WARN] = "WARNING: ";
282 vlabel[MON_ERR] = "ERROR: ";
283
284 for (ii=1;ii<MON_INFO;ii++) {
285 vlabel[ii] = "DBG: ";
286 }
287 for (ii=MON_INFO;ii<MON_NORMAL;ii++) {
288 vlabel[ii] = "INFO: ";
289 }
290 for (ii=MON_NORMAL;ii<MON_WARN;ii++) {
291 vlabel[ii] = "";
292 }
293 } // end task init_vlabels
294
295
296
297 //------------------------------------------------------------------------------
298 // task parse_mon_arg_str
299 //------------------------------------------------------------------------------
300
301 protected task parse_mon_arg_str ( string src_str ) {
302
303 integer eos = 0; // end of string flag
304 integer ii = 0;
305 integer jj = 0;
306 integer kk = 0;
307 integer nxt_marker;
308 integer level;
309 integer value;
310 string marker[3];
311 string args[];
312 string context_str;
313
314 marker[0] = "="; marker[1] = "="; marker[2] = ",";
315
316 while (!eos) {
317 nxt_marker = src_str.search(marker[jj]);
318 if (nxt_marker == -1) {
319 args[ii++] = src_str.substr(0);
320 eos = 1;
321 }
322 else {
323 args[ii++] = src_str.substr(0,nxt_marker-1); // extract the first element
324 src_str = src_str.substr(nxt_marker+1); // update arg string head pointer
325 jj = (jj+1) % 3; // update delimiter search pattern pointer
326 nxt_marker = src_str.search(marker[jj]); // search for next delimiter
327 }
328 } // end while loop
329
330 if (!(jj==2) || (ii==0)) {
331 error ("Test Error -- Unmatched arguments.\n");
332 }
333
334 while (kk < ii) {
335 context_str = args[kk++];
336 level = args[kk++].atoi();
337 value = args[kk++].atoi();
338
339 if (!(context_exists(context_str))) {
340 create_context(context_str);
341 }
342
343 set_level (context_str, level, value);
344 } // end while
345
346 } // end task parse_arg_str
347
348
349 //------------------------------------------------------------------------------
350 // function integer context_exists
351 //------------------------------------------------------------------------------
352
353 function integer context_exists ( string context_str ) {
354 context_exists = assoc_index(CHECK,verbosity,context_ndx(context_str));
355 } // end function context_exists
356
357
358 //------------------------------------------------------------------------------
359 // task create_context
360 //------------------------------------------------------------------------------
361
362 task create_context ( string context_str ) {
363
364 string tmp_str;
365
366 if ( context_exists (context_str) ) {
367 sprintf(tmp_str,"Context %s already exists",context_str);
368 dispmon ("SDC", MON_ERR, tmp_str, SCOPE);
369 }
370 else {
371 verbosity[context_ndx(context_str)] = default_verbosity;
372 set_context_name (context_str);
373 sprintf(tmp_str, "Created Verbosity[%s] element",context_str);
374 dispmon ("SDC", MON_DEBUG, tmp_str, SCOPE);
375 }
376 } // end task create_context
377
378
379 //------------------------------------------------------------------------------
380 // task set_context_verbosity
381 //------------------------------------------------------------------------------
382
383 task set_context_verbosity (string context_str, reg[MAX_VERBOSITY-1:0]value = NORMAL_VERBOSITY) {
384
385 string tmp_str;
386
387
388 if (value[0] == 0) {
389 sprintf(tmp_str,"Invalid Verbosity Setting %h",value);
390 dispmon ("SDC", MON_ERR, tmp_str, SCOPE);
391 }
392
393 if ( !(context_exists(context_str)) ) {
394 sprintf(tmp_str,"Context %s does not exist",context_str);
395 dispmon ("SDC", MON_INFO, tmp_str, SCOPE);
396 create_context (context_str);
397 }
398
399 verbosity[context_ndx(context_str)] = value;
400
401 sprintf(tmp_str, "Set verbosity[%s] = %h",context_str, value);
402 dispmon ("SDC", MON_INFO, tmp_str, SCOPE);
403
404 } // end task set_context_verbosity
405
406
407 //------------------------------------------------------------------------------
408 // function get_verbosity
409 //------------------------------------------------------------------------------
410
411 function reg[MAX_VERBOSITY-1:0] get_verbosity (string context_str) {
412
413 get_verbosity = verbosity[context_ndx(context_str)];
414
415 } // end function get_verbosity
416
417
418 //------------------------------------------------------------------------------
419 // task set_level
420 //------------------------------------------------------------------------------
421
422 task set_level ( string context_str = null, integer level, integer value ) {
423
424 reg[MAX_VERBOSITY-1:0] tmp_value;
425 string tmp_str;
426 integer mycontext;
427 integer ii;
428
429 if (value == 0) {
430 if (!(level == MON_ALWAYS)) {
431 tmp_value = DEBUG_VERBOSITY;
432 tmp_value[level] = value;
433 }
434 else {
435 this.dispmon("SDC", MON_ERR, "Sorry, you cannot turn MON_ALWAYS messages off",SCOPE);
436 }
437 }
438 else {
439 tmp_value = NO_VERBOSITY;
440 for (ii=level;ii<MAX_VERBOSITY;ii++) {
441 tmp_value[ii] = value;
442 }
443 }
444
445 if (context_str == null) {
446 if (assoc_index (FIRST, verbosity, mycontext)) {
447 verbosity[mycontext] = (value) ? tmp_value : (verbosity[mycontext] & tmp_value);
448 sprintf(tmp_str, "Set verbosity[%s] = %h",get_context_name(mycontext), verbosity[mycontext]);
449 dispmon ("SDC", MON_INFO, tmp_str, SCOPE);
450 while ( assoc_index (NEXT, verbosity, mycontext) ) {
451 verbosity[mycontext] = (value) ? tmp_value : (verbosity[mycontext] & tmp_value);
452 sprintf(tmp_str, "Set verbosity[%s] = %h",get_context_name(mycontext), verbosity[mycontext]);
453 dispmon ("SDC", MON_INFO, tmp_str, SCOPE);
454 }
455 }
456 else {
457 dispmon ("SDC", MON_ERR, "There are no verbosity elements.",SCOPE);
458 }
459 }
460 else {
461 if ( !(context_exists (context_str)) ) {
462 sprintf(tmp_str, "The context %s does not exist",context_str);
463 this.dispmon("SDC",MON_INFO, tmp_str, SCOPE);
464 create_context (context_str);
465 }
466
467 mycontext = context_ndx(context_str);
468 verbosity[mycontext] = (value) ? tmp_value : (verbosity[mycontext] & tmp_value);
469 sprintf(tmp_str, "Set verbosity[%s] = %h",context_str, verbosity[mycontext]);
470 dispmon ("SDC", MON_INFO, tmp_str, SCOPE);
471 }
472 } // end task set_level
473
474
475 //------------------------------------------------------------------------------
476 // task set_verbosity
477 //------------------------------------------------------------------------------
478
479 task set_verbosity (reg[MAX_VERBOSITY-1:0] value = NORMAL_VERBOSITY) {
480 integer mycontext;
481
482 if ( assoc_index (FIRST, verbosity, mycontext) ) {
483 verbosity[mycontext] = value;
484 while ( assoc_index (NEXT, verbosity, mycontext) ) {
485 verbosity[mycontext] = value;
486 }
487 }
488 else {
489 dispmon("SDC", MON_ERR, "There are no verbosity elements to set",SCOPE);
490 }
491
492 } // end task set_verbosity
493
494
495 //------------------------------------------------------------------------------
496 // task print_verbosity
497 //------------------------------------------------------------------------------
498
499 task print_verbosity (integer level, string context_str = null) {
500
501 integer mycontext;
502 string tmp_str;
503
504 if (context_str == null) {
505 this.dispmon ("SDC",level,"Printing Current Verbosity Levels:",SCOPE);
506 if ( assoc_index (FIRST, verbosity, mycontext) ) {
507 sprintf(tmp_str, "verbosity[%s] = %h",get_context_name(mycontext), verbosity[mycontext]);
508 this.dispmon ( get_context_name(mycontext), level, tmp_str, SCOPE);
509 while ( assoc_index (NEXT, verbosity, mycontext) ) {
510 sprintf(tmp_str, "verbosity[%s] = %h",get_context_name(mycontext), verbosity[mycontext]);
511 dispmon ( get_context_name(mycontext), level, tmp_str, SCOPE);
512 }
513 }
514 else {
515 sprintf(tmp_str, "There are no verbosity elements");
516 dispmon ( "SDC", MON_WARN, tmp_str, SCOPE);
517 }
518 }
519 else {
520 if ( context_exists (context_str) ) {
521 sprintf(tmp_str, "verbosity[%s] = %h \n",context_str, verbosity[context_ndx(context_str)]);
522 dispmon (context_str, level, tmp_str, SCOPE);
523 }
524 else {
525 sprintf(tmp_str, "Cannot print verbosity for context %s. Does not exist.",context_str);
526 dispmon (context_str, MON_WARN, tmp_str, SCOPE);
527 }
528 }
529 } // end task print_verbosity
530
531
532 //------------------------------------------------------------------------------
533 // function context_ndx
534 //------------------------------------------------------------------------------
535
536 function integer context_ndx (string context_str) {
537 context_ndx = context_str.hash(MAX_HASH_VALUE);
538 }
539
540
541 //------------------------------------------------------------------------------
542 // task set_context_name
543 //------------------------------------------------------------------------------
544
545 local task set_context_name (string context_str) {
546 context_name[context_ndx(context_str)] = context_str;
547 }
548
549
550 //------------------------------------------------------------------------------
551 // function get_context_name
552 //------------------------------------------------------------------------------
553
554 function string get_context_name (integer mycontext) {
555
556 string tmp_str;
557
558 if (assoc_index(CHECK,context_name,mycontext)) {
559 get_context_name = context_name[mycontext];
560 }
561 else {
562 sprintf(tmp_str, "context name for index %d does not exist",mycontext);
563 dispmon ("SDC",MON_ERR, tmp_str, SCOPE);
564 }
565 }
566
567
568 //------------------------------------------------------------------------------
569 // task set_default_verbosity
570 //------------------------------------------------------------------------------
571
572 task set_default_verbosity (reg[MAX_VERBOSITY-1:0] value) {
573
574 string tmp_str;
575
576 if (value[0] == 0) {
577 this.dispmon("SDC", MON_WARN, "Cannot disable MON_ALWAYS messaging.",SCOPE);
578 }
579
580 default_verbosity = value | 1;
581 sprintf(tmp_str, "Setting the current default verbosity to %h",default_verbosity);
582 dispmon("SDC", MON_INFO, tmp_str, SCOPE);
583 print_default_verbosity(MON_INFO);
584
585 } // end task set_default_verbosity
586
587
588 //------------------------------------------------------------------------------
589 // function get_default_verbosity
590 //------------------------------------------------------------------------------
591
592 function reg[MAX_VERBOSITY-1:0] get_default_verbosity () {
593 get_default_verbosity = default_verbosity;
594 }
595
596
597 //------------------------------------------------------------------------------
598 // task print_default_verbosity
599 //------------------------------------------------------------------------------
600
601 task print_default_verbosity (integer level = MON_ALWAYS){
602
603 string tmp_str;
604
605 sprintf(tmp_str, "current default verbosity is %h",default_verbosity);
606 dispmon("SDC", level, tmp_str, SCOPE);
607
608 } // end task print_default_verbosity
609
610
611} // end class StdDisplayClass