// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: std_display_class.vr
// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// For the avoidance of doubt, and except that if any non-GPL license
// choice is available it will apply instead, Sun elects to use only
// the General Public License version 2 (GPLv2) at this time for any
// software where a choice of GPL license versions is made
// available with the language indicating that GPLv2 or any later version
// may be used, or where a choice of which version of the GPL is applied is
// otherwise unspecified.
// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
// CA 95054 USA or visit www.sun.com if you need additional information or
// ========== Copyright Header End ============================================
#include <vera_defines.vrh>
#include "std_display_defines.vri"
#include "plusArgMacros.vri"
#define STD_GET_TIME sprintf (tmp_str,"%9d: ",get_cycle())
#define STD_GET_TIME sprintf (tmp_str,"%9d: ",{get_time(HI),get_time(LO)})
// NTB does not suport get_time(HI), sighhh
// get_time(LO) returns nothing, double sighhh
#define STD_GET_TIME sprintf (tmp_str,"%8d__: ",get_cycle())
local reg[MAX_VERBOSITY-1:0] verbosity[];
local reg[MAX_VERBOSITY-1:0] default_verbosity = NORMAL_VERBOSITY;
local string context_name[];
local string vlabel[MAX_VERBOSITY];
local reg [63:0] tmpTime;
// these are not local so they can be accessed directly.
// The following plus args are "standard":
integer wait_cycle_to_kill = 5;
static reg [1:0] instanceCount;
//------------------------------------------------------------------------------
// task new. paramater passing not required...
//------------------------------------------------------------------------------
task new (integer maxErrors = 1,
integer wait_cycle_to_kill = 5,
reg[2048:0] arg_bit_str = 0;
if (instanceCount !== 2'bxx) instanceCount++;
printf("More than one instance of std_display_class.vr/StandardDisplay detected!\n");
printf("Since this class keeps error counts, we only want one. You can have as\n");
printf("many pointers as you want to the single instance though. (A=new();B=A;C=A;)\n");
error("Need to FAIL, sorry!\n");
maxwarning = maxWarnings;
wait_cycle_to_kill = wait_cycle_to_kill;
start_debug = start_debug;
if (mChkPlusarg(quiet) && !mChkPlusarg(noquiet)) {
default_verbosity = QUIET_VERBOSITY;
if (mChkPlusarg(info_all)) {
default_verbosity = INFO_VERBOSITY;
if (mChkPlusarg(debug_all)) {
default_verbosity = DEBUG_VERBOSITY;
if (mChkPlusarg(debug)) {
mGetPlusargStr(mon+,arg_bit_str);
src_str.bittostr (arg_bit_str);
parse_mon_arg_str (src_str);
if (mChkPlusarg(maxerror=)) {
mGetPlusargDec(maxerror=,maxerror);
if (mChkPlusarg(maxwarning=)) {
mGetPlusargDec(maxwarning=,maxwarning);
if (mChkPlusarg(wait_cycle_to_kill=)) {
mGetPlusargDec(wait_cycle_to_kill=,wait_cycle_to_kill);
if (mChkPlusarg(start_debug=)) {
mGetPlusargDec(start_debug=,start_debug);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
task dispmon (string context_str, integer level, string message,
string file = null, integer lineNum = 0 ) {
reg[MAX_VERBOSITY-1:0] verbosity_enabled;
if (start_debug && get_cycle() < start_debug) return;
// !context_exists(context_str)
if (! assoc_index(CHECK,verbosity,context_ndx(context_str))) {
create_context (context_str);
verbosity_enabled = verbosity[context_ndx(context_str)];
if (verbosity_enabled[level]) {
printf("%s%s%s[]: %s\n", tmp_str, vlabel[level], context_str, message);
printf("%s%s%s[%s:%0d]: %s\n", tmp_str, vlabel[level], context_str, file, lineNum, message);
if (level == MON_ERR) errors++;
else if (level == MON_WARN) warnings++;
task writemon (string context_str, integer level,
string message, string file = null, integer lineNum = 0 ) {
reg[MAX_VERBOSITY-1:0] verbosity_enabled;
if (start_debug && get_cycle() < start_debug) return;
// !context_exists(context_str)
if (! assoc_index(CHECK,verbosity,context_ndx(context_str))) {
create_context (context_str);
verbosity_enabled = verbosity[context_ndx(context_str)];
if (verbosity_enabled[level]) {
printf("%s%s%s[]: %s", tmp_str, vlabel[level], context_str, message);
printf("%s%s%s[%s:%0d]: %s", tmp_str, vlabel[level], context_str, file, lineNum, message);
if (level == MON_ERR) errors++;
if (level == MON_WARN) warnings++;
task appendmon (string context_str, integer level, string message) {
reg[MAX_VERBOSITY-1:0] verbosity_enabled;
if (!context_exists(context_str)) {
create_context (context_str);
verbosity_enabled = verbosity[context_ndx(context_str)];
if (verbosity_enabled[level]) {
//------------------------------------------------------------------------------
// function integer get_errors()
//------------------------------------------------------------------------------
function integer get_errors() {
task getCounts(var integer err, var integer warn) {
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
protected task init_vlabels() {
vlabel[MON_WARN] = "WARNING: ";
vlabel[MON_ERR] = "ERROR: ";
for (ii=1;ii<MON_INFO;ii++) {
for (ii=MON_INFO;ii<MON_NORMAL;ii++) {
for (ii=MON_NORMAL;ii<MON_WARN;ii++) {
} // end task init_vlabels
//------------------------------------------------------------------------------
// task parse_mon_arg_str
//------------------------------------------------------------------------------
protected task parse_mon_arg_str ( string src_str ) {
integer eos = 0; // end of string flag
marker[0] = "="; marker[1] = "="; marker[2] = ",";
nxt_marker = src_str.search(marker[jj]);
args[ii++] = src_str.substr(0);
args[ii++] = src_str.substr(0,nxt_marker-1); // extract the first element
src_str = src_str.substr(nxt_marker+1); // update arg string head pointer
jj = (jj+1) % 3; // update delimiter search pattern pointer
nxt_marker = src_str.search(marker[jj]); // search for next delimiter
if (!(jj==2) || (ii==0)) {
error ("Test Error -- Unmatched arguments.\n");
context_str = args[kk++];
level = args[kk++].atoi();
value = args[kk++].atoi();
if (!(context_exists(context_str))) {
create_context(context_str);
set_level (context_str, level, value);
} // end task parse_arg_str
//------------------------------------------------------------------------------
// function integer context_exists
//------------------------------------------------------------------------------
function integer context_exists ( string context_str ) {
context_exists = assoc_index(CHECK,verbosity,context_ndx(context_str));
} // end function context_exists
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
task create_context ( string context_str ) {
if ( context_exists (context_str) ) {
sprintf(tmp_str,"Context %s already exists",context_str);
dispmon ("SDC", MON_ERR, tmp_str, SCOPE);
verbosity[context_ndx(context_str)] = default_verbosity;
set_context_name (context_str);
sprintf(tmp_str, "Created Verbosity[%s] element",context_str);
dispmon ("SDC", MON_DEBUG, tmp_str, SCOPE);
} // end task create_context
//------------------------------------------------------------------------------
// task set_context_verbosity
//------------------------------------------------------------------------------
task set_context_verbosity (string context_str, reg[MAX_VERBOSITY-1:0]value = NORMAL_VERBOSITY) {
sprintf(tmp_str,"Invalid Verbosity Setting %h",value);
dispmon ("SDC", MON_ERR, tmp_str, SCOPE);
if ( !(context_exists(context_str)) ) {
sprintf(tmp_str,"Context %s does not exist",context_str);
dispmon ("SDC", MON_INFO, tmp_str, SCOPE);
create_context (context_str);
verbosity[context_ndx(context_str)] = value;
sprintf(tmp_str, "Set verbosity[%s] = %h",context_str, value);
dispmon ("SDC", MON_INFO, tmp_str, SCOPE);
} // end task set_context_verbosity
//------------------------------------------------------------------------------
// function get_verbosity
//------------------------------------------------------------------------------
function reg[MAX_VERBOSITY-1:0] get_verbosity (string context_str) {
get_verbosity = verbosity[context_ndx(context_str)];
} // end function get_verbosity
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
task set_level ( string context_str = null, integer level, integer value ) {
reg[MAX_VERBOSITY-1:0] tmp_value;
if (!(level == MON_ALWAYS)) {
tmp_value = DEBUG_VERBOSITY;
tmp_value[level] = value;
this.dispmon("SDC", MON_ERR, "Sorry, you cannot turn MON_ALWAYS messages off",SCOPE);
tmp_value = NO_VERBOSITY;
for (ii=level;ii<MAX_VERBOSITY;ii++) {
if (context_str == null) {
if (assoc_index (FIRST, verbosity, mycontext)) {
verbosity[mycontext] = (value) ? tmp_value : (verbosity[mycontext] & tmp_value);
sprintf(tmp_str, "Set verbosity[%s] = %h",get_context_name(mycontext), verbosity[mycontext]);
dispmon ("SDC", MON_INFO, tmp_str, SCOPE);
while ( assoc_index (NEXT, verbosity, mycontext) ) {
verbosity[mycontext] = (value) ? tmp_value : (verbosity[mycontext] & tmp_value);
sprintf(tmp_str, "Set verbosity[%s] = %h",get_context_name(mycontext), verbosity[mycontext]);
dispmon ("SDC", MON_INFO, tmp_str, SCOPE);
dispmon ("SDC", MON_ERR, "There are no verbosity elements.",SCOPE);
if ( !(context_exists (context_str)) ) {
sprintf(tmp_str, "The context %s does not exist",context_str);
this.dispmon("SDC",MON_INFO, tmp_str, SCOPE);
create_context (context_str);
mycontext = context_ndx(context_str);
verbosity[mycontext] = (value) ? tmp_value : (verbosity[mycontext] & tmp_value);
sprintf(tmp_str, "Set verbosity[%s] = %h",context_str, verbosity[mycontext]);
dispmon ("SDC", MON_INFO, tmp_str, SCOPE);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
task set_verbosity (reg[MAX_VERBOSITY-1:0] value = NORMAL_VERBOSITY) {
if ( assoc_index (FIRST, verbosity, mycontext) ) {
verbosity[mycontext] = value;
while ( assoc_index (NEXT, verbosity, mycontext) ) {
verbosity[mycontext] = value;
dispmon("SDC", MON_ERR, "There are no verbosity elements to set",SCOPE);
} // end task set_verbosity
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
task print_verbosity (integer level, string context_str = null) {
if (context_str == null) {
this.dispmon ("SDC",level,"Printing Current Verbosity Levels:",SCOPE);
if ( assoc_index (FIRST, verbosity, mycontext) ) {
sprintf(tmp_str, "verbosity[%s] = %h",get_context_name(mycontext), verbosity[mycontext]);
this.dispmon ( get_context_name(mycontext), level, tmp_str, SCOPE);
while ( assoc_index (NEXT, verbosity, mycontext) ) {
sprintf(tmp_str, "verbosity[%s] = %h",get_context_name(mycontext), verbosity[mycontext]);
dispmon ( get_context_name(mycontext), level, tmp_str, SCOPE);
sprintf(tmp_str, "There are no verbosity elements");
dispmon ( "SDC", MON_WARN, tmp_str, SCOPE);
if ( context_exists (context_str) ) {
sprintf(tmp_str, "verbosity[%s] = %h \n",context_str, verbosity[context_ndx(context_str)]);
dispmon (context_str, level, tmp_str, SCOPE);
sprintf(tmp_str, "Cannot print verbosity for context %s. Does not exist.",context_str);
dispmon (context_str, MON_WARN, tmp_str, SCOPE);
} // end task print_verbosity
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function integer context_ndx (string context_str) {
context_ndx = context_str.hash(MAX_HASH_VALUE);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
local task set_context_name (string context_str) {
context_name[context_ndx(context_str)] = context_str;
//------------------------------------------------------------------------------
// function get_context_name
//------------------------------------------------------------------------------
function string get_context_name (integer mycontext) {
if (assoc_index(CHECK,context_name,mycontext)) {
get_context_name = context_name[mycontext];
sprintf(tmp_str, "context name for index %d does not exist",mycontext);
dispmon ("SDC",MON_ERR, tmp_str, SCOPE);
//------------------------------------------------------------------------------
// task set_default_verbosity
//------------------------------------------------------------------------------
task set_default_verbosity (reg[MAX_VERBOSITY-1:0] value) {
this.dispmon("SDC", MON_WARN, "Cannot disable MON_ALWAYS messaging.",SCOPE);
default_verbosity = value | 1;
sprintf(tmp_str, "Setting the current default verbosity to %h",default_verbosity);
dispmon("SDC", MON_INFO, tmp_str, SCOPE);
print_default_verbosity(MON_INFO);
} // end task set_default_verbosity
//------------------------------------------------------------------------------
// function get_default_verbosity
//------------------------------------------------------------------------------
function reg[MAX_VERBOSITY-1:0] get_default_verbosity () {
get_default_verbosity = default_verbosity;
//------------------------------------------------------------------------------
// task print_default_verbosity
//------------------------------------------------------------------------------
task print_default_verbosity (integer level = MON_ALWAYS){
sprintf(tmp_str, "current default verbosity is %h",default_verbosity);
dispmon("SDC", level, tmp_str, SCOPE);
} // end task print_default_verbosity
} // end class StdDisplayClass