* ========== Copyright Header Begin ==========================================
* OpenSPARC T2 Processor File: options.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* The above named 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 work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* ========== Copyright Header End ============================================
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
#pragma ident "@(#)options.c 1.33 07/05/30 SMI"
uint64_t debug_bits
= 0ULL;
uint64_t debug_bits_xor
= -1ULL;
#define DEFAULT_PORT 65400
#define DEFAULT_RETRY_MAX 64
* FIXME: a better place for the following?
void (*mbox_trap
)(simcpu_t
*sp
) = NULL
;
void (*fpga_intr
)(int bit
) = NULL
;
printf("Usage: sim [-p | --port debugger-port]"
"\n\t[-P | --portmax port]"
"\n\t[-M | --no-magic-traps]"
"\n\t[-b | --buffer log-buffering-size]"
"\n\t[-l | --logfile log-file]"
"\n\t[-L | --lib-path path_to_plugins]"
"\n\t[-debug debug_bits]"
"\n\t[-debugxor debug_bits]"
"\n\t[-t | --threads threads]"
"\n\t[-q | --quantum execution_quantum]"
"\n\t[-g | --dumpconfig]"
"\n\t[--cpp-cmd preprocessor_command_name]"
"\n\t[--cpp-options preprocessor_command_options]"
printf("sim: illegal option\n");
* pre-configuration of selectable options
* before looking at command line
options
.cpp_optionsp
= "";
options
.config_filep
= NULL
;
options
.accept_port
= DEFAULT_PORT
;
options
.port_retry_max
= DEFAULT_RETRY_MAX
;
options
.specific_port
= false;
options
.flag_auto_start
= false;
options
.magic_traps
= true;
options
.analyzer
= false;
options
.buffersz
= -1; /* auto-determine */
options
.log_file
= NULL
; /* defaults to stdout */
options
.threads
= sysconf(_SC_NPROCESSORS_ONLN
);
options
.dumpconfig
= false;
/* Save Restore Defaults */
options
.save_restore
.filenamep
= Xstrdup("mem_image.axis");
options
.save_restore
.legion_format
= true;
options
.save_restore
.trigger_icount
= 0ULL;
options
.save_restore
.trap_pc
= UINT64_MAX
;
options
.save_restore
.mem_patch
.addr
= 0ULL;
options
.save_restore
.mem_patch
.val
= 0ULL;
options
.walltime
= false;
LIST_INIT(options
.libpath
, char);
const char banner_string
[] =
"## ###### ##### ## ###### ## ## \n"
"## ## ## ## ## ## ## ### ## \n"
"## ##### ## ## ## ## ## # ## \n"
"## ## ## ### ## ## ## ## # ## \n"
"## ## ## ## ## ## ## ## ### \n"
"####### ###### ##### ## ###### ## ## ";
printf("%s\n", banner_string
);
printf("Copyright 2006 Sun Microsystems, Inc. All rights reserved.\n");
extern const char datestamp
[];
const char version
[] = "0.1";
printf("Legion version %s compiled on %s\n",
PRINTF(("Legion build options:\n"));
PRINTF(("\n\t**DEBUG BUILD**\n"));
PRINTF(("\t**NON DEBUG BUILD**\n"));
PRINTF(("\tHost OS: Solaris 9\n"));
PRINTF(("\tHost CPU: sparcV9\n"));
PRINTF(("\tDEBUG enabled\n"));
PRINTF(("\tNDEBUG enabled\n"));
PRINTF(("\tENABLE_MAGIC_TRAPS enabled\n"));
PRINTF(("\tPERFORMANCE_CHECK enabled\n"));
PRINTF(("\tERROR_INJECTION enabled\n"));
PRINTF(("\tWALL_TIME (--walltime option) enabled\n"));
PRINTF(("\tCONSOLE_RESET enabled\n"));
PRINTF(("\tDEBUG_TL_RAISE enabled\n"));
PRINTF(("\tDEBUG_GL_RAISE enabled\n"));
PRINTF(("\tERROR_TRAP_GEN enabled\n"));
#if HYPERPRIVILEGED_USE_WARN
PRINTF(("\tHYPERPRIVILEGED_USE_WARN enabled\n"));
PRINTF(("\tINTERNAL_BUILD enabled\n"));
PRINTF(("\tEXTERNAL_BUILD enabled\n"));
PRINTF(("Library search paths:"));
for (o
= 0; o
< options
.libpath
.count
; o
++) {
p
= LIST_ENTRY(options
.libpath
, o
);
#define DEF_PLUGIN_DIR "./plugins"
process_opts(int argc
, char ** argv
)
/* save the input CLI for later reference */
for (i
= 0; i
< argc
; i
++) {
strlcat(inputCliLine
, argv
[i
], sizeof (inputCliLine
));
strlcat(inputCliLine
, " ", sizeof (inputCliLine
));
for (i
= 1; i
< argc
&& argv
[i
][0] == '-'; i
++) {
if (streq(p
, "h") || streq(p
, "-help")) {
if (streq(p
, "p") || streq(p
, "-port")) {
fatal("Illegal value for port number %s", argv
[i
]);
options
.accept_port
= num
;
options
.specific_port
= true;
if (streq(p
, "P") || streq(p
, "-portmax")) {
fatal("Illegal value for portmax %s", argv
[i
]);
options
.port_retry_max
= num
;
if (streq(p
, "a") || streq(p
, "-autos")) {
options
.flag_auto_start
= true;
if (streq(p
, "M") || streq(p
, "-no-magic-traps")) {
options
.magic_traps
= false;
if (streq(p
, "z") || streq(p
, "-analyzer")) {
if (streq(p
, "b") || streq(p
, "-buffer")) {
if (options
.buffersz
!= -1) {
fatal("-buffer option already set at %d"
" dont specify option twice!\n",
if (streq(p
, "l") || streq(p
, "-logfile")) {
if (options
.log_file
!= NULL
) {
fatal("-logfile option already set to %s"
" dont specify option twice!\n",
options
.log_file
= argv
[i
];
if (streq(p
, "t") || streq(p
, "-threads")) {
if (options
.threads
> sysconf(_SC_NPROCESSORS_ONLN
)) {
fprintf(stderr
, "\nUsing more threads (%d)"
" than available CPUs (%d) lowers"
" overall performance!\n\n",
sysconf(_SC_NPROCESSORS_ONLN
));
if (streq(p
, "q") || streq(p
, "-quantum")) {
num
= strtoll(argv
[i
], NULL
, 0);
if (streq(p
, "-cpp-cmd")) {
options
.cpp_cmd
= argv
[i
];
if (streq(p
, "-cpp-options")) {
options
.cpp_optionsp
= argv
[i
];
if (streq(p
, "L") || streq(p
, "-lib-path")) {
* check to see if path dir really exists here
/* FIXME: maybe we want to silently fail */
fatal("%s is not a valid library directory",
LIST_ADD_PTR(options
.libpath
, char, strp
);
if (streq(p
, "v") || streq(p
, "-verbose")) {
if (streq(p
, "s") || streq(p
, "-silent")) {
if (streq(p
, "g") || streq(p
, "-dumpconfig")) {
options
.dumpconfig
= true;
if (streq(p
, "-walltime")) {
fprintf(stderr
, "--walltime option ignored in "
fprintf(stderr
, "-debug option ignored in "
debug_bits
= strtoll(argv
[i
], NULL
, 0);
if (streq(p
, "debugxor")) {
fprintf(stderr
, "-debugxor option ignored in "
debug_bits_xor
= strtoll(argv
[i
], NULL
, 0);
fatal("Illegal option %s", p
);
* Additional cleanup for library search paths
/* retrieve the env if present */
p
= getenv("SIM_LIB_PATH");
if ((p
!= NULL
) && (*p
== '\0')) {
/* NULL env is equivalent to "." */
LIST_ADD_PTR(options
.libpath
, char, ".");
/* Process a colon separated list of directories */
for (p
= strtok_r(p
, ":", &lastp
); p
!= NULL
;
p
= strtok_r(NULL
, ":", &lastp
)) {
LIST_ADD_PTR(options
.libpath
, char, strp
);
if (is_a_dir(DEF_PLUGIN_DIR
)) {
strp
= Xstrdup(DEF_PLUGIN_DIR
);
LIST_ADD_PTR(options
.libpath
, char, strp
);
* assume any non option provided is the name
options
.config_filep
= Xstrdup(argv
[i
]);
/* no config filed specified? */
* Essentially this function attempts to consolidate
* default values with options chosen on the command line
* and check the sanity of the final result.