// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: console.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 ============================================
bool console::get_pty(char **name
, int *sfd
, int *mfd
){
if ((*mfd
= open("/dev/ptmx", O_RDWR
|O_NDELAY
)) == -1) {
fprintf(stderr
,"get_pty: Cannot find a pseudo tty.\n");
fprintf(stderr
,"get_pty: Could not grant access to slave pseudo tty\n");
if (unlockpt(*mfd
) < 0) {
fprintf(stderr
,"get_pty: Unable to unlock pseudo tty.\n");
*name
= strdup(ptsname(*mfd
));
*sfd
= open(*name
, O_RDWR
| O_NOCTTY
);
fprintf(stderr
,"get_pty: Unable to open slave side for %d\n", *mfd
);
if (ioctl(*sfd
, I_PUSH
, "ptem") < 0) {
fprintf(stderr
,"get_pty: Ioctl I_PUSH ptem failed\n");
perror("ioctl i_push ptem");
if (ioctl(*sfd
, I_PUSH
, "ldterm") < 0) {
fprintf(stderr
,"serial: Ioctl I_PUSH ldterm failed\n");
perror("ioctl i_push ldterm");
chmod(*name
,S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
| S_IROTH
| S_IWOTH
);
ioctl(*sfd
, TCGETA
, &tty
);
tty
.c_lflag
&= ~(ICANON
|ECHO
|ECHOE
|ECHOK
|ECHONL
);
ioctl(*sfd
, TCSETA
, &tty
);
void console::term_read_ports(fd_set readfds
){
for(termMapIter
= termMap
.begin(); termMapIter
!= termMap
.end(); termMapIter
++){
if (FD_ISSET(termMapIter
->second
->mport_fd
, &readfds
)) {
while ((nbytes
= read(termMapIter
->second
->mport_fd
, &ch
, 1)) == 1){
termMapIter
->second
->cbFun(termMapIter
->second
->cbData
, buf
, termMapIter
->first
);
//return a unique port identifier and the tty name for tip connection in tty_name
int console::getTerminal(char * title
, int numScrolLines
, inputCallbk cbFun
, void * cbData
, char ** tty_name
, bool pop_win
){
console::title
= strdup(title
);
term_lines
= numScrolLines
;
if(!get_pty(&t
->tty_name
, &t
->port_fd
, &t
->mport_fd
)){
pthread_mutex_lock(&termMutex
);
termMap
[currentPortNum
++] = t
;
retVal
= currentPortNum
- 1;
pthread_mutex_unlock(&termMutex
);
t
->pop_term(display
, fn
, bg
, fg
, title
, numScrolLines
, exec
);
*tty_name
= strdup(t
->tty_name
);
void console::term_select(){
//time out every 1 second, to check if additional consoles have been added.
for(termMapIter
= termMap
.begin(); termMapIter
!= termMap
.end(); termMapIter
++)
FD_SET(termMapIter
->second
->mport_fd
, &readFd
);
n
= select(FD_SETSIZE
, &readFd
, (fd_set
*)0,(fd_set
*)0, &tval
);
default: /* input available */
void * callTermThread(void * arg
){
console
* t
= (console
*)arg
;