Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / env / niu_pli / get_plus_args.c
CommitLineData
86530b38
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: get_plus_args.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 "veriuser.h"
39#include "acc_user.h"
40
41#include <stdio.h>
42#include <string.h>
43
44/*
45 * Returning a 0 in VERILOG_ERROR is *bad*, because
46 * a zero is a legitimate number to pass in for
47 * get_plus_args_num. I've changed Verilog_error to
48 * return a -1, which in verilog is FFFF...FFFF. The
49 * user had better explicitly check the return value.
50 *
51 * The functions were designed inconsistent with each other.
52 * They both should return status and set a value just
53 * like get_plus_args_str. AMS 19-july-1996
54 */
55
56#define VERILOG_ERROR -1
57#define VERILOG_OK 1
58/* #define DEBUG_PLUS_ARGS 1 */
59#define DEBUG_PLUS_ARGS 0
60
61int util_get_plus_args_str() {
62
63/* Example use:
64
65invocation script (bosox is passed in as first argument)
66-----------------
67set basename = $1
68verilog mymodule.v +tst_file_name${basename}.tst +log_file_name${basename}.log
69 +err_file_name${basename}.err +result_file_name${basename}.result
70
71mymodule.v
72----------
73reg [32*8:1] tst_file_name; // plus argument string value
74reg [32*8:1] err_file_name; // plus argument string value
75reg [32*8:1] log_file_name; // plus argument string value
76reg [32*8:1] result_file_name; // plus argument string value
77integer plus_arg_ok; // 0 if ok, 1 if no plus argument value
78
79initial
80 begin
81 // get strings from plus argument values
82 plus_arg_ok = $util_get_plus_args_str("tst_file_name", tst_file_name);
83 plus_arg_ok = $util_get_plus_args_str("err_file_name", err_file_name);
84 plus_arg_ok = $util_get_plus_args_str("log_file_name", log_file_name);
85 plus_arg_ok = $util_get_plus_args_str("result_file_name",result_file_name);
86
87 $display("tst_file_name is %s", tst_file_name);
88 $display("err_file_name is %s", err_file_name);
89 $display("log_file_name is %s", log_file_name);
90 $display("result_file_name is %s", result_file_name);
91 end
92
93*/
94
95
96/* Input is string
97 Returning value is string.
98*/
99
100 handle wrk_out;
101 char *strArgIn;
102 int sizeOut,sizeS_in;
103 int numArgs;
104 int cnt,size;
105 char *buffer, *bufferout;
106 s_setval_value value_out;
107 s_setval_delay delay_out;
108
109 delay_out.model = accNoDelay;
110 delay_out.time.type = accRealTime;
111 delay_out.time.real = 0.0;
112 value_out.format = accHexStrVal;
113
114 acc_initialize();
115
116 numArgs = tf_nump();
117 if(numArgs !=2) {
118 tf_error("$get_plus_arg_string must have two arguments");
119 tf_putp(0,VERILOG_ERROR);
120 return(VERILOG_ERROR);
121 }
122
123/* Fetch the input register and size */
124
125 wrk_out = acc_handle_tfarg(2);
126 sizeOut = (acc_fetch_size(wrk_out)/8);
127
128/* Get the string value */
129
130 strArgIn = mc_scan_plusargs(tf_getcstringp(1));
131
132 if (strArgIn == NULL) {
133 if (DEBUG_PLUS_ARGS)
134 io_printf("get_plus_args_str(): Matching string is not found: %s.\n", tf_getcstringp(1));
135 tf_putp(0,VERILOG_ERROR);
136 return(VERILOG_ERROR);
137 }
138
139 if (strArgIn) {
140 if (DEBUG_PLUS_ARGS)
141 io_printf("get_plus_args_str(): Got string value: %s\n",strArgIn);
142 }
143 else {
144 io_printf("get_plus_args_str(): Bad input string value.\n");
145 tf_putp(0,VERILOG_ERROR);
146 return(VERILOG_ERROR);
147 }
148
149
150/* Build new string */
151
152 sizeS_in = strlen(strArgIn);
153 bufferout = (char *) malloc(sizeS_in + 1);
154 sprintf(bufferout, "%s",strArgIn);
155
156 if (sizeOut < sizeS_in) {
157 tf_error("get_plus_args_str(): Register %s is not large enough.\n",
158 acc_fetch_fullname(wrk_out));
159 tf_putp(0,VERILOG_ERROR);
160 return(VERILOG_ERROR);
161 }
162
163 size = sizeS_in*2;
164 buffer = (char *) malloc(size + 1);
165 for (cnt =0; cnt < size; cnt +=2){
166 if (cnt < size){
167 /* Convert string into HEX code */
168 sprintf(&buffer[cnt],"%x",bufferout[cnt/2]);
169 }
170 }
171
172/* Null out the rest of the register
173 else {
174 buffer[cnt] = '\0';
175 buffer[cnt +1] = '\0';
176}
177*/
178
179 /* assign buffer to the verilog register */
180
181 value_out.value.str = buffer;
182 acc_set_value(wrk_out, &value_out, &delay_out);
183 tf_putp(0,VERILOG_OK);
184 acc_close();
185
186 free(buffer);
187 free(bufferout);
188 return(VERILOG_OK);
189}
190
191int util_get_plus_args_num() {
192
193/* Example use
194
195integer num_vectors; // number of test vectors
196integer MAX_FAILURES; // max failed vectors before aborting
197
198initial
199 begin
200 // get integers from plus argument values
201 num_vectors = $util_get_plus_args_num("num_vectors");
202 MAX_FAILURES = $util_get_plus_args_num("max_failures");
203 $display("%d VECTORS IN TEST FILE.", num_vectors);
204 $display("Maximum number of failures is %d", MAX_FAILURES);
205 end
206*/
207
208 /* Input: [unsigned int which is a string |
209 * C string ]
210 * Returns: Arg. value in 32 bit integer.
211 * On error returns VERILOG_C_ERROR
212 * Action: Gets the parameter, calls 'mc_scan_plusargs'
213 * to get the arg. value.
214 *
215 */
216
217
218 int np;
219 char *cp;
220
221 np = tf_nump();
222 if ( np != 1 ) {
223 if (DEBUG_PLUS_ARGS) {
224 io_printf("get_plus_args_num(): Error: Number of args != 1.\n");
225 }
226 tf_putp(0, VERILOG_ERROR);
227 return(VERILOG_ERROR);
228 }
229
230 cp = mc_scan_plusargs(tf_getcstringp(1));
231 if (cp == NULL ) {
232 if (DEBUG_PLUS_ARGS) {
233 io_printf("get_plus_args_num(): Matching number is not found: %d\n", tf_getcstringp(1));
234 }
235 tf_putp(0, VERILOG_ERROR);
236 return(VERILOG_ERROR);
237 }
238
239 if (DEBUG_PLUS_ARGS)
240 io_printf("get_plus_args_num(): Got integer value: %d\n", atoi(cp));
241
242 tf_putp(0, atoi(cp) );
243 return(VERILOG_OK);
244}
245
246
247
248
249