Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: options.c | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | /* | |
24 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved. | |
25 | * Use is subject to license terms. | |
26 | */ | |
27 | ||
28 | #pragma ident "@(#)options.c 1.33 07/05/30 SMI" | |
29 | ||
30 | #include <stdlib.h> | |
31 | #include <stdio.h> | |
32 | #include <unistd.h> | |
33 | #include <string.h> | |
34 | ||
35 | #include "basics.h" | |
36 | #include "allocate.h" | |
37 | #include "fatal.h" | |
38 | #include "list.h" | |
39 | #include "options.h" | |
40 | #include "strutil.h" | |
41 | #include "fileutil.h" | |
42 | ||
43 | options_t options; | |
44 | ||
45 | ||
46 | #ifndef NDEBUG | |
47 | uint64_t debug_bits = 0ULL; | |
48 | uint64_t debug_bits_xor = -1ULL; | |
49 | #endif | |
50 | ||
51 | ||
52 | ||
53 | #define DEFAULT_PORT 65400 | |
54 | #define DEFAULT_RETRY_MAX 64 | |
55 | ||
56 | /* | |
57 | * FIXME: a better place for the following? | |
58 | */ | |
59 | void (*mbox_trap)(simcpu_t *sp) = NULL; | |
60 | void (*fpga_intr)(int bit) = NULL; | |
61 | ||
62 | void | |
63 | help() | |
64 | { | |
65 | printf("Usage: sim [-p | --port debugger-port]" | |
66 | "\n\t[-P | --portmax port]" | |
67 | "\n\t[-a | --autos]" | |
68 | "\n\t[-M | --no-magic-traps]" | |
69 | "\n\t[-z | --analyzer]" | |
70 | "\n\t[-b | --buffer log-buffering-size]" | |
71 | "\n\t[-l | --logfile log-file]" | |
72 | "\n\t[-L | --lib-path path_to_plugins]" | |
73 | "\n\t[-debug debug_bits]" | |
74 | "\n\t[-debugxor debug_bits]" | |
75 | "\n\t[-t | --threads threads]" | |
76 | "\n\t[-q | --quantum execution_quantum]" | |
77 | "\n\t[-h | --help]" | |
78 | "\n\t[--walltime]" | |
79 | "\n\t[-g | --dumpconfig]" | |
80 | "\n\t[-v | --verbose]" | |
81 | "\n\t[-s | --silent]" | |
82 | "\n\t[--cpp-cmd preprocessor_command_name]" | |
83 | "\n\t[--cpp-options preprocessor_command_options]" | |
84 | "\n\tconfig_file\n"); | |
85 | ||
86 | } | |
87 | ||
88 | void | |
89 | usage() | |
90 | { | |
91 | printf("sim: illegal option\n"); | |
92 | help(); | |
93 | } | |
94 | ||
95 | /* | |
96 | * pre-configuration of selectable options | |
97 | * before looking at command line | |
98 | */ | |
99 | ||
100 | static void | |
101 | init_options() | |
102 | { | |
103 | options.cpp_cmd = "cpp"; | |
104 | options.cpp_optionsp = ""; | |
105 | options.config_filep = NULL; | |
106 | options.accept_port = DEFAULT_PORT; | |
107 | options.port_retry_max = DEFAULT_RETRY_MAX; | |
108 | options.specific_port = false; | |
109 | options.flag_auto_start = false; | |
110 | options.magic_traps = true; | |
111 | options.analyzer = false; | |
112 | options.buffersz = -1; /* auto-determine */ | |
113 | options.log_file = NULL; /* defaults to stdout */ | |
114 | options.threads = sysconf(_SC_NPROCESSORS_ONLN); | |
115 | options.quantum = 0; | |
116 | options.dumpconfig = false; | |
117 | ||
118 | /* Save Restore Defaults */ | |
119 | options.save_restore.filenamep = Xstrdup("mem_image.axis"); | |
120 | options.save_restore.legion_format = true; | |
121 | options.save_restore.trigger_icount = 0ULL; | |
122 | options.save_restore.trap_pc = UINT64_MAX; | |
123 | options.save_restore.mem_patch.addr = 0ULL; | |
124 | options.save_restore.mem_patch.val = 0ULL; | |
125 | ||
126 | #if VERBOSE | |
127 | options.verbose = true; | |
128 | #else | |
129 | options.verbose = false; | |
130 | #endif | |
131 | options.walltime = false; | |
132 | ||
133 | LIST_INIT(options.libpath, char); | |
134 | } | |
135 | ||
136 | void | |
137 | banner_print(void) | |
138 | { | |
139 | const char banner_string[] = | |
140 | "## \n" | |
141 | "## ###### ##### ## ###### ## ## \n" | |
142 | "## ## ## ## ## ## ## ### ## \n" | |
143 | "## ##### ## ## ## ## ## # ## \n" | |
144 | "## ## ## ### ## ## ## ## # ## \n" | |
145 | "## ## ## ## ## ## ## ## ### \n" | |
146 | "####### ###### ##### ## ###### ## ## "; | |
147 | ||
148 | ||
149 | printf("%s\n", banner_string); | |
150 | printf("Copyright 2006 Sun Microsystems, Inc. All rights reserved.\n"); | |
151 | version_print(); | |
152 | ||
153 | } | |
154 | ||
155 | void | |
156 | version_print() | |
157 | { | |
158 | int o; | |
159 | extern const char datestamp[]; | |
160 | const char version[] = "0.1"; | |
161 | ||
162 | printf("Legion version %s compiled on %s\n", | |
163 | version, datestamp); | |
164 | ||
165 | PRINTF(("Legion build options:\n")); | |
166 | ||
167 | #if DEBUG_BUILD | |
168 | PRINTF(("\n\t**DEBUG BUILD**\n")); | |
169 | #endif | |
170 | ||
171 | #if NON_DEBUG_BUILD | |
172 | PRINTF(("\t**NON DEBUG BUILD**\n")); | |
173 | #endif | |
174 | ||
175 | #if HOST_OS_SOLARIS9 | |
176 | PRINTF(("\tHost OS: Solaris 9\n")); | |
177 | #endif | |
178 | ||
179 | #if HOST_CPU_SPARC_V9 | |
180 | PRINTF(("\tHost CPU: sparcV9\n")); | |
181 | #endif | |
182 | ||
183 | #if DEBUG | |
184 | PRINTF(("\tDEBUG enabled\n")); | |
185 | #endif | |
186 | ||
187 | #if NDEBUG | |
188 | PRINTF(("\tNDEBUG enabled\n")); | |
189 | #endif | |
190 | ||
191 | #if ENABLE_MAGIC_TRAPS | |
192 | PRINTF(("\tENABLE_MAGIC_TRAPS enabled\n")); | |
193 | #endif | |
194 | ||
195 | #if PERFORMANCE_CHECK | |
196 | PRINTF(("\tPERFORMANCE_CHECK enabled\n")); | |
197 | #endif | |
198 | ||
199 | #if ERROR_INJECTION | |
200 | PRINTF(("\tERROR_INJECTION enabled\n")); | |
201 | #endif | |
202 | ||
203 | #if WALL_TIME | |
204 | PRINTF(("\tWALL_TIME (--walltime option) enabled\n")); | |
205 | #endif | |
206 | ||
207 | #if CONSOLE_RESET | |
208 | PRINTF(("\tCONSOLE_RESET enabled\n")); | |
209 | #endif | |
210 | ||
211 | #if DEBUG_TL_RAISE | |
212 | PRINTF(("\tDEBUG_TL_RAISE enabled\n")); | |
213 | #endif | |
214 | ||
215 | #if DEBUG_GL_RAISE | |
216 | PRINTF(("\tDEBUG_GL_RAISE enabled\n")); | |
217 | #endif | |
218 | ||
219 | #if ERROR_TRAP_GEN | |
220 | PRINTF(("\tERROR_TRAP_GEN enabled\n")); | |
221 | #endif | |
222 | ||
223 | #if HYPERPRIVILEGED_USE_WARN | |
224 | PRINTF(("\tHYPERPRIVILEGED_USE_WARN enabled\n")); | |
225 | #endif | |
226 | ||
227 | #if INTERNAL_BUILD | |
228 | PRINTF(("\tINTERNAL_BUILD enabled\n")); | |
229 | #else | |
230 | PRINTF(("\tEXTERNAL_BUILD enabled\n")); | |
231 | #endif | |
232 | ||
233 | PRINTF(("\n")); | |
234 | ||
235 | PRINTF(("Library search paths:")); | |
236 | for (o = 0; o < options.libpath.count; o++) { | |
237 | char *p; | |
238 | p = LIST_ENTRY(options.libpath, o); | |
239 | PRINTF((" %s", p)); | |
240 | } | |
241 | PRINTF(("\n")); | |
242 | } | |
243 | ||
244 | #define DEF_PLUGIN_DIR "./plugins" | |
245 | ||
246 | clibuf_t inputCliLine; | |
247 | ||
248 | ||
249 | bool_t | |
250 | process_opts(int argc, char ** argv) | |
251 | { | |
252 | int i; | |
253 | char *p; | |
254 | char *lastp = NULL; | |
255 | char *strp; | |
256 | ||
257 | /* save the input CLI for later reference */ | |
258 | inputCliLine[0] = '\0'; | |
259 | for (i = 0; i < argc; i++) { | |
260 | strlcat(inputCliLine, argv[i], sizeof (inputCliLine)); | |
261 | strlcat(inputCliLine, " ", sizeof (inputCliLine)); | |
262 | } | |
263 | ||
264 | init_options(); | |
265 | ||
266 | for (i = 1; i < argc && argv[i][0] == '-'; i++) { | |
267 | char *p; | |
268 | ||
269 | p = &(argv[i][1]); | |
270 | ||
271 | if (streq(p, "h") || streq(p, "-help")) { | |
272 | version_print(); | |
273 | help(); | |
274 | exit(0); | |
275 | } else | |
276 | if (streq(p, "p") || streq(p, "-port")) { | |
277 | int num; | |
278 | if (++i >= argc) { | |
279 | usage(); | |
280 | exit(1); | |
281 | } | |
282 | num = atol(argv[i]); | |
283 | if (num == 0) { | |
284 | usage(); | |
285 | fatal("Illegal value for port number %s", argv[i]); | |
286 | } | |
287 | options.accept_port = num; | |
288 | options.specific_port = true; | |
289 | } else | |
290 | if (streq(p, "P") || streq(p, "-portmax")) { | |
291 | int num; | |
292 | if (++i >= argc) { | |
293 | usage(); | |
294 | exit(1); | |
295 | } | |
296 | num = atol(argv[i]); | |
297 | if (num == 0) { | |
298 | usage(); | |
299 | fatal("Illegal value for portmax %s", argv[i]); | |
300 | } | |
301 | options.port_retry_max = num; | |
302 | } else | |
303 | if (streq(p, "a") || streq(p, "-autos")) { | |
304 | options.flag_auto_start = true; | |
305 | } else | |
306 | if (streq(p, "M") || streq(p, "-no-magic-traps")) { | |
307 | options.magic_traps = false; | |
308 | } else | |
309 | if (streq(p, "z") || streq(p, "-analyzer")) { | |
310 | options.analyzer = true; | |
311 | } else | |
312 | if (streq(p, "b") || streq(p, "-buffer")) { | |
313 | int num; | |
314 | if (++i >= argc) { | |
315 | usage(); | |
316 | exit(1); | |
317 | } | |
318 | if (options.buffersz != -1) { | |
319 | usage(); | |
320 | fatal("-buffer option already set at %d" | |
321 | " dont specify option twice!\n", | |
322 | options.buffersz); | |
323 | } | |
324 | num = atol(argv[i]); | |
325 | options.buffersz = num; | |
326 | } else | |
327 | if (streq(p, "l") || streq(p, "-logfile")) { | |
328 | if (++i >= argc) { | |
329 | usage(); | |
330 | exit(1); | |
331 | } | |
332 | if (options.log_file != NULL) { | |
333 | usage(); | |
334 | fatal("-logfile option already set to %s" | |
335 | " dont specify option twice!\n", | |
336 | options.log_file); | |
337 | } | |
338 | options.log_file = argv[i]; | |
339 | } else | |
340 | if (streq(p, "t") || streq(p, "-threads")) { | |
341 | int num; | |
342 | if (++i >= argc) { | |
343 | usage(); | |
344 | exit(1); | |
345 | } | |
346 | num = atol(argv[i]); | |
347 | options.threads = num; | |
348 | if (options.threads > sysconf(_SC_NPROCESSORS_ONLN)) { | |
349 | fprintf(stderr, "\nUsing more threads (%d)" | |
350 | " than available CPUs (%d) lowers" | |
351 | " overall performance!\n\n", | |
352 | options.threads, | |
353 | sysconf(_SC_NPROCESSORS_ONLN)); | |
354 | } | |
355 | } else | |
356 | if (streq(p, "q") || streq(p, "-quantum")) { | |
357 | uint32_t num; | |
358 | if (++i >= argc) { | |
359 | usage(); | |
360 | exit(1); | |
361 | } | |
362 | num = strtoll(argv[i], NULL, 0); | |
363 | options.quantum = num; | |
364 | } else | |
365 | if (streq(p, "-cpp-cmd")) { | |
366 | uint32_t num; | |
367 | if (++i >= argc) { | |
368 | usage(); | |
369 | exit(1); | |
370 | } | |
371 | options.cpp_cmd = argv[i]; | |
372 | } else | |
373 | if (streq(p, "-cpp-options")) { | |
374 | uint32_t num; | |
375 | if (++i >= argc) { | |
376 | usage(); | |
377 | exit(1); | |
378 | } | |
379 | options.cpp_optionsp = argv[i]; | |
380 | } else | |
381 | if (streq(p, "L") || streq(p, "-lib-path")) { | |
382 | char *namep; | |
383 | ||
384 | if (++i >= argc) { | |
385 | usage(); | |
386 | exit(1); | |
387 | } | |
388 | namep = argv[i]; | |
389 | ||
390 | /* | |
391 | * check to see if path dir really exists here | |
392 | */ | |
393 | /* FIXME: maybe we want to silently fail */ | |
394 | if (!is_a_dir(namep)) { | |
395 | usage(); | |
396 | fatal("%s is not a valid library directory", | |
397 | namep); | |
398 | } | |
399 | ||
400 | strp = Xstrdup(namep); | |
401 | LIST_ADD_PTR(options.libpath, char, strp); | |
402 | } else | |
403 | if (streq(p, "v") || streq(p, "-verbose")) { | |
404 | options.verbose = true; | |
405 | } else | |
406 | if (streq(p, "s") || streq(p, "-silent")) { | |
407 | options.verbose = false; | |
408 | } else | |
409 | if (streq(p, "g") || streq(p, "-dumpconfig")) { | |
410 | options.dumpconfig = true; | |
411 | } else | |
412 | if (streq(p, "-walltime")) { | |
413 | #if WALL_TIME | |
414 | options.walltime = true; | |
415 | #else /* WALL_TIME */ | |
416 | fprintf(stderr, "--walltime option ignored in " | |
417 | "!WALL_TIME build\n"); | |
418 | #endif /* WALL_TIME */ | |
419 | } else | |
420 | if (streq(p, "debug")) { | |
421 | if (++i >= argc) { | |
422 | usage(); | |
423 | exit(1); | |
424 | } | |
425 | #ifdef NDEBUG | |
426 | fprintf(stderr, "-debug option ignored in " | |
427 | "NDEBUG build\n"); | |
428 | #else /* NDEBUG */ | |
429 | debug_bits = strtoll(argv[i], NULL, 0); | |
430 | #endif /* NDEBUG */ | |
431 | } else | |
432 | if (streq(p, "debugxor")) { | |
433 | if (++i >= argc) { | |
434 | usage(); | |
435 | exit(1); | |
436 | } | |
437 | #ifdef NDEBUG | |
438 | fprintf(stderr, "-debugxor option ignored in " | |
439 | "NDEBUG build\n"); | |
440 | #else /* NDEBUG */ | |
441 | debug_bits_xor = strtoll(argv[i], NULL, 0); | |
442 | #endif /* NDEBUG */ | |
443 | } else | |
444 | { | |
445 | usage(); | |
446 | fatal("Illegal option %s", p); | |
447 | } | |
448 | } | |
449 | ||
450 | ||
451 | /* | |
452 | * Additional cleanup for library search paths | |
453 | */ | |
454 | ||
455 | /* retrieve the env if present */ | |
456 | p = getenv("SIM_LIB_PATH"); | |
457 | ||
458 | if ((p != NULL) && (*p == '\0')) { | |
459 | /* NULL env is equivalent to "." */ | |
460 | LIST_ADD_PTR(options.libpath, char, "."); | |
461 | } else { | |
462 | /* Process a colon separated list of directories */ | |
463 | for (p = strtok_r(p, ":", &lastp); p != NULL; | |
464 | p = strtok_r(NULL, ":", &lastp)) { | |
465 | if (is_a_dir(p)) { | |
466 | strp = Xstrdup(p); | |
467 | LIST_ADD_PTR(options.libpath, char, strp); | |
468 | } | |
469 | } | |
470 | } | |
471 | ||
472 | /* | |
473 | * | |
474 | */ | |
475 | if (is_a_dir(DEF_PLUGIN_DIR)) { | |
476 | strp = Xstrdup(DEF_PLUGIN_DIR); | |
477 | LIST_ADD_PTR(options.libpath, char, strp); | |
478 | } | |
479 | ||
480 | /* | |
481 | * assume any non option provided is the name | |
482 | * of a config file | |
483 | */ | |
484 | ||
485 | if (i == argc-1) { | |
486 | options.config_filep = Xstrdup(argv[i]); | |
487 | } else { | |
488 | /* no config filed specified? */ | |
489 | usage(); | |
490 | exit(1); | |
491 | } | |
492 | ||
493 | ||
494 | return (false); | |
495 | } | |
496 | ||
497 | ||
498 | ||
499 | /* | |
500 | * Essentially this function attempts to consolidate | |
501 | * default values with options chosen on the command line | |
502 | * and check the sanity of the final result. | |
503 | */ | |
504 | ||
505 | void | |
506 | consolidate(void) | |
507 | { | |
508 | } |