Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / env / common / pli / bwutility / c / src / mon_pli.c
CommitLineData
86530b38
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: mon_pli.c
5* Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
6* 4150 Network Circle, Santa Clara, California 95054, U.S.A.
7*
8* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9*
10* This program is free software; you can redistribute it and/or modify
11* it under the terms of the GNU General Public License as published by
12* the Free Software Foundation; version 2 of the License.
13*
14* This program is distributed in the hope that it will be useful,
15* but WITHOUT ANY WARRANTY; without even the implied warranty of
16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17* GNU General Public License for more details.
18*
19* You should have received a copy of the GNU General Public License
20* along with this program; if not, write to the Free Software
21* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22*
23* For the avoidance of doubt, and except that if any non-GPL license
24* choice is available it will apply instead, Sun elects to use only
25* the General Public License version 2 (GPLv2) at this time for any
26* software where a choice of GPL license versions is made
27* available with the language indicating that GPLv2 or any later version
28* may be used, or where a choice of which version of the GPL is applied is
29* otherwise unspecified.
30*
31* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
32* CA 95054 USA or visit www.sun.com if you need additional information or
33* have any questions.
34*
35*
36* ========== Copyright Header End ============================================
37*/
38#include "vcsuser.h"
39#include "acc_user.h"
40#include "malloc.h"
41#include "string.h"
42#include "ctype.h" /* for toupper */
43#include "stdio.h" /* for sscanf.h */
44#include <stdlib.h>
45
46#define MAX_STRING_LEN 1000
47#define ARG0 0
48#define ARG1 1
49#define ARG2 2
50
51
52static char mon_name_buf[64];
53static char *mon_inst_path[128];
54static int mon_level[128];
55static int mon_path_num;
56
57static char *diserr_arr[64];
58static char *diswarn_arr[64];
59static int diserr_num;
60static int diswarn_num;
61static int monInit_done = 0 ;
62static int error_disable = 0 ;
63
64char format_buffer[4096];
65
66static void
67get_time (int *ms, int *us, int *ns, int *ps)
68{
69 unsigned long long llx, lly;
70 int time_lo, time_hi;
71
72 time_lo = tf_getlongtime (&time_hi);
73 llx = time_lo; llx = (llx << 32) >> 32;
74 lly = time_hi; lly = (lly << 32);
75 lly |= llx;
76
77 *ps = lly % 1000; lly /= 1000;
78 *ns = lly % 1000; lly /= 1000;
79 *us = lly % 1000; lly /= 1000;
80 *ms = lly;
81}
82
83/*
84 * format function
85 */
86char *format(char *mipname)
87{
88 int num_args, cur_arg, len;
89 char *fmt_str, *ptr, c;
90
91 num_args = tf_nump();
92 cur_arg = 3;
93 len = sprintf (format_buffer, " ");
94 fmt_str = tf_getcstringp(ARG2);
95
96 ptr = format_buffer + len;
97 while (1) {
98 c = *fmt_str++;
99 if (c == 0) break;
100 if (c == '%') {
101 c = *fmt_str++;
102 switch (c) {
103 case 'b':
104 len = sprintf (ptr, "%s", tf_strgetp(cur_arg, 'b'));
105 ptr = ptr + len;
106 cur_arg++;
107 break;
108
109 case 'o':
110 len = sprintf (ptr, "%s", tf_strgetp(cur_arg, 'o'));
111 ptr = ptr + len;
112 cur_arg++;
113 break;
114
115 case 'd':
116 len = sprintf (ptr, "%s", tf_strgetp(cur_arg, 'd'));
117 ptr = ptr + len;
118 cur_arg++;
119 break;
120
121 case 'h':
122 len = sprintf (ptr, "%s", tf_strgetp(cur_arg, 'h'));
123 ptr = ptr + len;
124 cur_arg++;
125 break;
126
127 case 'e':
128 len = sprintf (ptr, "%e", tf_getrealp(cur_arg));
129 ptr = ptr + len;
130 cur_arg++;
131 break;
132
133 case 'f':
134 len = sprintf (ptr, "%e", tf_getrealp(cur_arg));
135 ptr = ptr + len;
136 cur_arg++;
137 break;
138
139 case 't':
140 len = sprintf (ptr, "%d", tf_gettime());
141 ptr = ptr + len;
142 break;
143
144 case 's':
145 len = sprintf (ptr, "%s", tf_strgetp(cur_arg, 'e'));
146 ptr = ptr + len;
147 cur_arg++;
148 break;
149
150 case 'm':
151 len = sprintf (ptr, "%s", mipname);
152 ptr = ptr + len;
153 break;
154
155 case '%':
156 *ptr++ = '%';
157 break;
158 }
159 }
160 else {
161 *ptr++ = c;
162 }
163 }
164 *ptr++ = '\0';
165 return format_buffer;
166}
167
168
169/*
170 * string match function
171 */
172int strmatch (char* s0, char* s1)
173{
174 char *p0;
175
176 p0 = strstr (s1, s0);
177 if (p0 == NULL) return 1;
178 else return 0;
179}
180
181
182/************************************************************************/
183/* $monInit check routine */
184/************************************************************************/
185void monInit_check(int data, int reason)
186{
187 char *string, *ptr;
188
189 if (monInit_done) return ;
190 monInit_done = 1 ;
191
192 /*
193 * plus args for info.
194 * +mon0=cpu0:25 +mon1=ccx:35
195 */
196
197 mon_path_num = 0;
198 while (1) {
199 sprintf (mon_name_buf, "mon%d=\0", mon_path_num);
200 string = mc_scan_plusargs(mon_name_buf);
201 if (string != 0) {
202 strcpy(mon_name_buf, string);
203 ptr = strtok (mon_name_buf, ":");
204 if (ptr == 0) {
205 tf_error("Syntax error in mon%i plus arg (instance path)\n", mon_path_num);
206 tf_dofinish();
207 return;
208 }
209 mon_inst_path[mon_path_num] = strdup (ptr);
210 ptr = strtok (NULL, ":");
211 if (ptr == 0) {
212 tf_error("Syntax error in mon%i plus arg (level)\n", mon_path_num);
213 tf_dofinish();
214 return;
215 }
216 mon_level[mon_path_num] = atoi (ptr);
217 }
218 else {
219 break;
220 }
221 mon_path_num++;
222 }
223
224 /*
225 * plus args for diserr.
226 * +diserr=uce:cer:xyz
227 */
228 diserr_num = 0;
229 string = mc_scan_plusargs("diserr=");
230 if (string != 0) {
231 ptr = strtok (string, ":");
232 if (ptr == 0) {
233 tf_error("Syntax error in diserr plus arg\n");
234 tf_dofinish();
235 return;
236 }
237 while (1) {
238 diserr_arr[diserr_num] = strdup (ptr);
239 diserr_num++;
240 ptr = strtok (NULL, ":");
241 if (ptr == 0) break;
242 }
243 }
244
245 /*
246 * plus args for diswarn.
247 * +diswarn=mem0:mem3
248 */
249 diswarn_num = 0;
250 string = mc_scan_plusargs("diswarn=");
251 if (string != 0) {
252 ptr = strtok (string, ":");
253 if (ptr == 0) {
254 tf_error("Syntax error in diswarn plus arg\n");
255 tf_dofinish();
256 return;
257 }
258 while (1) {
259 diswarn_arr[diswarn_num] = strdup (ptr);
260 diswarn_num++;
261 ptr = strtok (NULL, ":");
262 if (ptr == 0) break;
263 }
264 }
265}
266
267/************************************************************************/
268/* $monInit call routine */
269/************************************************************************/
270
271void monInit_call(int data, int reason)
272{
273 return;
274}
275
276
277
278// /************************************************************************/
279// /* $info check routine */
280// /************************************************************************/
281// void info_check(int data, int reason)
282// {
283// return;
284// }
285//
286// /************************************************************************/
287// /* $info call routine */
288// /************************************************************************/
289//
290// void infow_call(int data, int reason)
291// {
292// char *ptr_mipname;
293// int i, level;
294//
295// int ms, us, ns, ps;
296// get_time (&ms, &us, &ns, &ps);
297//
298// ptr_mipname = tf_mipname();
299//
300// /* Requires at least two arguments */
301// if (tf_nump() < ARG2) {
302// tf_error("$info requires at least two arguments, info-level and format-string");
303// tf_dofinish();
304// return;
305// }
306//
307// /* First argument to $info() must be a value */
308// if (tf_typep(ARG1) != tf_readonly) {
309// tf_error("First argument to $info must be a value");
310// tf_dofinish();
311// }
312//
313// /* Second argument to $info() must be a string */
314// if (tf_typep(ARG2) != tf_string) {
315// tf_error("Second argument to $info must be a formating string");
316// tf_dofinish();
317// }
318//
319// level = tf_getp(ARG1);
320// if (level == 0) {
321// io_printf ("%05d.%03d.%03d.%03d: INFO (%d): %s:%s", ms,us,ns,ps, level, ptr_mipname, format(ptr_mipname));
322// }
323// else {
324// for (i = 0; i < mon_path_num; i++) {
325// if ((level <= mon_level[i]) &&
326// (strmatch (mon_inst_path[i], ptr_mipname) == 0)
327// ) {
328// io_printf ("%05d.%03d.%03d.%03d: INFO (%d): %s:%s", ms,us,ns,ps, level, ptr_mipname, format(ptr_mipname));
329// }
330// }
331// }
332// return;
333// }
334//
335// void info_call(int data, int reason)
336// {
337// char *ptr_mipname;
338// int i, level;
339//
340// int ms, us, ns, ps;
341// get_time (&ms, &us, &ns, &ps);
342//
343// ptr_mipname = tf_mipname();
344//
345// /* Requires at least two arguments */
346// if (tf_nump() < ARG2) {
347// tf_error("$info requires at least two arguments, info-level and format-string");
348// tf_dofinish();
349// return;
350// }
351//
352// /* First argument to $info() must be a value */
353// if (tf_typep(ARG1) != tf_readonly) {
354// tf_error("First argument to $info must be a value");
355// tf_dofinish();
356// }
357//
358// /* Second argument to $info() must be a string */
359// if (tf_typep(ARG2) != tf_string) {
360// tf_error("Second argument to $info must be a formating string");
361// tf_dofinish();
362// }
363//
364// level = tf_getp(ARG1);
365//
366// if (level == 0) {
367// io_printf ("%05d.%03d.%03d.%03d: INFO(%d): %s:%s\n", ms,us,ns,ps, level, ptr_mipname, format(ptr_mipname));
368// }
369// else {
370// for (i = 0; i < mon_path_num; i++) {
371// if ((level <= mon_level[i]) &&
372// (strmatch (mon_inst_path[i], ptr_mipname) == 0)
373// ) {
374// io_printf ("%05d.%03d.%03d.%03d: INFO(%d): %s:%s\n", ms,us,ns,ps, level, ptr_mipname, format(ptr_mipname));
375// }
376// }
377// }
378// return;
379// }
380
381
382
383/************************************************************************/
384/* $error check routine */
385/************************************************************************/
386void error_check(int data, int reason)
387{
388 return;
389}
390
391/************************************************************************/
392/* $error call routine */
393/************************************************************************/
394
395void error_call(int data, int reason)
396{
397 char *ptr_mipname;
398 char *ptr;
399 int i;
400
401 int ms, us, ns, ps;
402
403 get_time (&ms, &us, &ns, &ps);
404
405 ptr_mipname = tf_mipname();
406
407 /* Requires at least two arguments */
408 if (tf_nump() < ARG2) {
409 tf_error("$error requires at least two arguments, error-disable-tag, and format-string");
410 tf_dofinish();
411 return;
412 }
413
414 /* First argument to $error() must be a string */
415 if (tf_typep(ARG1) != tf_string) {
416 tf_error("First argument to $error must be a value");
417 tf_dofinish();
418 }
419
420 /* Second argument to $error() must be a string */
421 if (tf_typep(ARG2) != tf_string) {
422 tf_error("Second argument to $error must be a formating string");
423 tf_dofinish();
424 }
425
426 for (i = 0; i < diserr_num; i++) {
427 ptr = strchr(diserr_arr[i], '.');
428 if (ptr == NULL) {
429 if (strcmp (tf_getcstringp(ARG1), diserr_arr[i]) == 0) {
430 io_printf ("%05d.%03d.%03d.%03d: ERROR: %s:%s\n", ms,us,ns,ps, ptr_mipname, format(ptr_mipname));
431 return;
432 }
433 }
434 else {
435 sprintf (format_buffer, "%s.%s\0", tf_getcstringp(ARG1), ptr_mipname);
436 if (strcmp (format_buffer, diserr_arr[i]) == 0) {
437 io_printf ("%05d.%03d.%03d.%03d: ERROR: %s:%s\n", ms,us,ns,ps, ptr_mipname, format(ptr_mipname));
438 return;
439 }
440 }
441 }
442 io_printf ("%05d.%03d.%03d.%03d: ERROR: %s:%s\n", ms,us,ns,ps, ptr_mipname, format(ptr_mipname));
443 if (!error_disable) tf_dofinish();
444
445 return;
446}
447
448
449
450// /************************************************************************/
451// /* $warn check routine */
452// /************************************************************************/
453// void warn_check(int data, int reason)
454// {
455// return;
456// }
457//
458// /************************************************************************/
459// /* $warn call routine */
460// /************************************************************************/
461//
462// void warn_call(int data, int reason)
463// {
464// char *ptr_mipname;
465// int i;
466//
467// int ms, us, ns, ps;
468// get_time (&ms, &us, &ns, &ps);
469//
470// ptr_mipname = tf_mipname();
471//
472// /* Requires at least two arguments */
473// if (tf_nump() < ARG2) {
474// tf_error("$warn requires at least two arguments, warn-disable-tag, and format-string");
475// tf_dofinish();
476// return;
477// }
478//
479// /* First argument to $warn() must be a string */
480// if (tf_typep(ARG1) != tf_string) {
481// tf_error("First argument to $warn must be a value");
482// tf_dofinish();
483// }
484//
485// /* Second argument to $warn() must be a string */
486// if (tf_typep(ARG2) != tf_string) {
487// tf_error("Second argument to $warn must be a formating string");
488// tf_dofinish();
489// }
490//
491// for (i = 0; i < diswarn_num; i++) {
492// if (strcmp (tf_getcstringp(ARG1), diswarn_arr[i]) == 0) return;
493// }
494// io_printf ("%05d.%03d.%03d.%03d: WARN: %s:%s\n", ms,us,ns,ps, ptr_mipname, format(ptr_mipname));
495//
496// return;
497// }
498//
499//
500//
501// /************************************************************************/
502// /* disable exit on error during runtime */
503// /************************************************************************/
504//
505// void monErrorDisable_call ()
506// {
507// error_disable = 1 ;
508// }
509//
510// /************************************************************************/
511// /* enable exit on error during runtime */
512// /************************************************************************/
513//
514// void monErrorEnable_call ()
515// {
516// error_disable = 0 ;
517// }
518
519