// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: ui_utils.cc
// 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 (C) 1991, Sun Microsystems, Inc.
#pragma ident "@(#)1.14 06/01/25 ui_utils.cc"
#include <sys/resource.h>
#include "blaze_globals.h"
#include "sim_cmd_struct.h"
#include "blaze_globals.h"
#include "ui_cmd_struct.h"
wd_thread_t
*pwd_locker
= NULL
;
time_thread_t
*ptm_locker
= NULL
;
static void * wd_thread_start (void *);
static void * time_thread_start (void *);
///////////////////////////////////////////////////
// Create Remote Interface
void *remote_lib_handle
= NULL
;
RemoteExInterface g_remote_ex_intf
;
RemoteConfig g_remote_config
;
char remote_help_str
[] = "remote [port=<port#>] [debug_on=1]";
int remote_cmd_action(void * /* usrdata */, int argc
, char **argv
)
// parse config arguments
for (int i
=1; i
<argc
; i
++)
char *name_value
= argv
[i
];
char *name
= strtok ( name_value
, " =" );
ui
->error("cannot read remote interface param name %s\n", name_value
);
char *param
= strtok ( NULL
, "\0" );
ui
->error("cannot read remote interface param value %s\n", name_value
);
value
= (int)strtol(param
, NULL
, 0);
if (strcmp ( name
, "port") == 0 )
g_remote_config
.port
= value
;
else if (strcmp ( name
, "max_connections") == 0 )
g_remote_config
.max_connections
= value
;
else if (strcmp ( name
, "debug_on") == 0 )
g_remote_config
.debug_on
= value
;
// start remote interface
g_remote_ex_intf
.create(&g_remote_config
);
// initialize remote debugger interface
int init_remote_debugger_interface (char* fname
, char* modname
, void* lib_handle
)
if (remote_lib_handle
!= 0)
ui
->error("Remote Interface was loaded already %s\n", modname
);
remote_lib_handle
= lib_handle
;
if ( remote_lib_handle
== NULL
)
ui
->error("cannot obtain a handle for Remote Interface library %s\n", fname
);
// extract lib exported interface
GetRemoteIntfFn get_interface
= (GetRemoteIntfFn
)dlsym ( remote_lib_handle
, "get_ex_remote_interface" );
if (get_interface
== NULL
)
ui
->error("cannot find remote exported interface, wrong libriry\n");
// obtain remote interface
get_interface ( &g_remote_ex_intf
);
UI_register_cmd_2("remote", remote_help_str
, remote_cmd_action
, NULL
);
// set defaults config params
g_remote_config
.port
= INTF_PORT
;
g_remote_config
.max_connections
= MAX_CONNECTIONS
;
g_remote_config
.port_step
= MAX_PORT_STEP
;
g_remote_config
.debug_on
= 0;
// update stop status for the remote client if any extern
if (g_remote_ex_intf
.update_status
)
g_remote_ex_intf
.update_status(SIGNAL_BREAKPOINT
);
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
* This routine parses thru a string. It sets wp to point to the first
* word in that string and returns a pointer to the rest of the line.
* It puts a null character after the first word.
* It eats leading white space characters. If string doesn't contain
* any text, it sets wp and the return value to point to a null character.
char* ui_parsew(char* cp
, char** wp
)
/* Eat leading white space. */
/* No words in string so return. */
/* skip over first word */
while (!isspace(*cp
) && *cp
!= '\0')
cp
++; /* skip over word */
/* Put null char after first word in string. */
/* Eat white space between first word and rest of line. */
/* Strip off any white space at end of first word. */
ui_remove_trailing_whitespace(*wp
);
/* Strip off any white space at end of line. */
ui_remove_trailing_whitespace(cp
);
///////////////////////////////////////////////////////
/* Strip off any white space or newlines at end of string. */
void ui_remove_trailing_whitespace(char* str
)
for (cp
= str
+ strlen(str
) - 1; (cp
>= str
) && (*cp
== '\n' || isspace(*cp
)); cp
--) {
// This function extracts a string from the buffer
// passed in. Returned is a freshly allocated buffer
// for the new string, which is null terminated.
// It is the caller's responsibility to eventually
// free the allocated string.
char * extract_string(char * cmd_str
)
bool_t is_quoted
= false;
// be lazy, allocate all the space for the buffer
assert(bufp
= (char*)malloc(len
+1));
ui
->error("Missing closing quote at end of string: %s\n",cmd_str
);
ui
->error("Illegal escape at end of string: %s\n",cmd_str
);
case 'n': c
= '\n'; break;
case 'r': c
= '\r'; break;
case 't': c
= '\t'; break;
case '"': c
= '"'; break;
case '\\': c
= '\\'; break;
ui
->error("Unknown escape in string: %s\n",cmd_str
);
if (is_quoted
) goto success
;
ui
->error("Quotes need to be escaped in the string: %s\n",cmd_str
);
if (!is_quoted
) goto success
;
///////////////////////////////////////////////////////
// Added new routine for BLAZE UI parsing
// returns ARGV pointer, sets *ARGC
ui_argv_argc_parse (char *cmd
, int *neval
)
int argc
= 4; /* *neval; using neval is dumb, requires user init */
char **pargv
= (char**) calloc (argc
, sizeof(char*));
char * cmdcopy
= (char*) strdup(cmd
);
int inquotes
= 0; /* flag when we're inside a " quoted string */
int backslash
= 0; /* yet another flag... */
// remove leading spaces if any
if ((*s
== '\0') || (*s
== '\n')) {
while (!isspace(*s
) || inquotes
) {
#if 0 /* not yet debugged, and needs to be before the ++s */
if (*s
== '"' && ! backslash
) inquotes
= ! inquotes
;
if (*s
== '\\') backslash
= 1;
// copy parsed arg into argv
pargv
[nargc
++] = (char*) strdup (ps
);
// re-allocate argv if we have too many args
pargv
= (char**) realloc (pargv
, sizeof(char*) * argc
);
// skip (insignificant) white-spaces between words
if ((*s
== '\0') || (*s
== '\n'))
pargv
[nargc
++] = (char*) strdup (ps
);
void ui_argv_free(int argc
, char **argv
)
///////////////////////////////////////////////////////
bool_t
redirect_stdout (int target_fd
)
int dup_fd
= dup (fileno(stdout
));
if (dup( target_fd
) <= -1) {
store_stdout_fd (dup_fd
);
///////////////////////////////////////////////////////
int dup_fd
= get_stdout_fd ();
ui
->error("STDOUT has not been redirected\n");
if (dup (dup_fd
) <= -1) {