// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: term_redirect.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) 2001 Sun Microsystems, Inc.
#pragma ident "@(#)1.6 07/11/19 term_redirect.cc"
// This file contains an implementation of console I/O
#include "blaze_globals.h"
////////////////////////////////////////////////
typedef struct term_redirect_t
char current_string
[MAXCURSTR
];
char unix_command
[MAXCURSTR
];
volatile bool_t unix_command_sent
;
bool_t unix_command_nready
;
static TermRedirect
*ptrd
= NULL
;
void * console_input_start (void *);
////////////////////////////////////////////////
char *term_redirect_get_file ()
return ptrd
->script_name
;
////////////////////////////////////////////////
void * console_input_start (void *arg
)
ui
->verbose("console input interceptor started ... \n");
mutex_lock (&ptrd
->trd_lock
);
cond_wait(&ptrd
->trd_cond
, &ptrd
->trd_lock
);
ptrd
->unix_command
[idx
= strlen(ptrd
->unix_command
)] = 0xD;
ptrd
->unix_command
[idx
+ 1] = 0x0;
term_fake_input ((uint8_t *)ptrd
->unix_command
, idx
+ 1, 0);
mutex_unlock (&ptrd
->trd_lock
);
mutex_lock (&ptrd
->uc_lock
);
ptrd
->unix_command_sent
= TRUE
;
mutex_unlock (&ptrd
->uc_lock
);
////////////////////////////////////////////////
void init_term_redirect (char *fname
)
FILE *fp
= fopen (fname
, "r");
ui
->error("file not found <%s> \n", fname
);
ptrd
= (TermRedirect
*) calloc (1, sizeof(TermRedirect
));
ptrd
->script_name
= (char*)strdup(fname
);
while (ptrd
->pstr
= fgets(ptrd
->str
, MAXCTXT
- 2, ptrd
->fp
)) {
if ((ptrd
->ptail
= get_substr_until (ptrd
->str
, ptrd
->pattern
, ':')) != NULL
) {
mutex_init(&ptrd
->trd_lock
, USYNC_THREAD
, (void*)NULL
);
mutex_init(&ptrd
->uc_lock
, USYNC_THREAD
, (void*)NULL
);
cond_init(&ptrd
->trd_cond
, USYNC_THREAD
, (void *)NULL
);
thr_create(NULL
, NULL
, console_input_start
, (void*)ptrd
, THR_BOUND
, &tid
);
////////////////////////////////////////////////
void term_redirect_add (uint8_t c
)
if ((ptrd
->pstr
== NULL
)) {
ui
->verbose("Console script is processed; return to terminal \n");
if ((c
== 0xD) || (c
== 0xA) || (c
== 0) || (ptrd
->idx
>= MAXCURSTR
- 2)) {
ptrd
->current_string
[0] = '\0';
ptrd
->current_string
[ptrd
->idx
++] = c
;
ptrd
->current_string
[ptrd
->idx
] = '\0';
if ( strstr ((const char *)ptrd
->current_string
, (const char *)ptrd
->pattern
)) {
if (!ptrd
->unix_command_nready
) {
if (get_quoted_substr (ptrd
->ptail
, ptrd
->unix_command
)) {
mutex_lock (&ptrd
->trd_lock
);
cond_signal(&ptrd
->trd_cond
);
mutex_unlock (&ptrd
->trd_lock
);
ptrd
->unix_command_nready
= TRUE
;
if (!ptrd
->unix_command_sent
) {
ptrd
->unix_command_nready
= FALSE
;
ptrd
->unix_command_sent
= FALSE
;
while (ptrd
->pstr
= fgets (ptrd
->str
, MAXCTXT
- 2, ptrd
->fp
)) {
if ((ptrd
->ptail
= get_substr_until (ptrd
->str
, ptrd
->pattern
, ':')) != NULL
) {
if (ptrd
->unix_command_nready
) {
ptrd
->unix_command_nready
= FALSE
;
ptrd
->unix_command_sent
= FALSE
;
while (ptrd
->pstr
= fgets (ptrd
->str
, MAXCTXT
- 2, ptrd
->fp
)) {
if ((ptrd
->ptail
= get_substr_until (ptrd
->str
, ptrd
->pattern
, ':')) != NULL
) {
////////////////////////////////////////////////