ia64/xen-unstable

changeset 755:af6bbf7bf2ab

bitkeeper revision 1.452.1.1 (3f6dc14baJxoz4mfHsRuNF95VdTfSA)

miniterm.c, README, Makefile:
new file
author kaf24@scramble.cl.cam.ac.uk
date Sun Sep 21 15:18:35 2003 +0000 (2003-09-21)
parents 016b73aec103
children 2cd0c489ef41
files .rootkeys tools/misc/miniterm/Makefile tools/misc/miniterm/README tools/misc/miniterm/miniterm.c
line diff
     1.1 --- a/.rootkeys	Sat Sep 20 21:48:30 2003 +0000
     1.2 +++ b/.rootkeys	Sun Sep 21 15:18:35 2003 +0000
     1.3 @@ -142,6 +142,9 @@ 3eb781fd8oRfPgH7qTh7xvgmwD6NgA tools/int
     1.4  3eb781fd0Eo9K1jEFCSAVzO51i_ngg tools/internal/xi_stop.c
     1.5  3f108ae2to5nHRRXfvUK7oxgjcW_yA tools/internal/xi_usage.c
     1.6  3eb781fd7211MZsLxJSiuy7W4KnJXg tools/internal/xi_vifinit
     1.7 +3f6dc136ZKOjd8PIqLbFBl_v-rnkGg tools/misc/miniterm/Makefile
     1.8 +3f6dc140C8tAeBfroAF24VrmCS4v_w tools/misc/miniterm/README
     1.9 +3f6dc142IHaf6XIcAYGmhV9nNSIHFQ tools/misc/miniterm/miniterm.c
    1.10  3f1668d4-FUY6Enc7MB3GcwUtfJ5HA tools/misc/mkdevnodes
    1.11  3f5ef5a2ir1kVAthS14Dc5QIRCEFWg tools/misc/xen-clone
    1.12  3f5ef5a2dTZP0nnsFoeq2jRf3mWDDg tools/misc/xen-clone.README
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/misc/miniterm/Makefile	Sun Sep 21 15:18:35 2003 +0000
     2.3 @@ -0,0 +1,7 @@
     2.4 +CC      = gcc
     2.5 +CFLAGS  = -O3 -march=i686 -Wall
     2.6 +
     2.7 +all: miniterm
     2.8 +
     2.9 +clean:
    2.10 +	rm -f *.o miniterm *~
    2.11 \ No newline at end of file
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/misc/miniterm/README	Sun Sep 21 15:18:35 2003 +0000
     3.3 @@ -0,0 +1,13 @@
     3.4 +This is a modified version of the miniterm program distributed as part
     3.5 +of the Linux Programmer's Guide (LPG) by Sven Goldt.
     3.6 +
     3.7 +It is intended to be used as a dumb raw terminal for debugging Xen
     3.8 +machines over the serial line.
     3.9 +
    3.10 +By default it will connect to COM1 (/dev/ttyS0) at 115200 baud.
    3.11 +These options can be modified as follows:
    3.12 + miniterm [-b<baudrate>] [-d<devicename>]
    3.13 +
    3.14 +'ctrl-b' quits miniterm.
    3.15 +
    3.16 + -- Keir Fraser (21/9/2003)
    3.17 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/misc/miniterm/miniterm.c	Sun Sep 21 15:18:35 2003 +0000
     4.3 @@ -0,0 +1,182 @@
     4.4 +/******************************************************************************
     4.5 + * miniterm.c
     4.6 + * 
     4.7 + * Adapted from the example program distributed with the Linux Programmer's
     4.8 + * Guide (LPG). This has been robustified and tweaked to work as a debugging 
     4.9 + * terminal for Xen-based machines.
    4.10 + * 
    4.11 + * Modifications are released under GPL and copyright (c) 2003, K A Fraser
    4.12 + * The original copyright message and license is fully intact below.
    4.13 + */
    4.14 +
    4.15 +/*
    4.16 + *  AUTHOR: Sven Goldt (goldt@math.tu-berlin.de)
    4.17 + *
    4.18 + *  This program is free software; you can redistribute it and/or
    4.19 + *  modify it under the terms of the GNU General Public License
    4.20 + *  as published by the Free Software Foundation; either version 2
    4.21 + *  of the License, or (at your option) any later version.
    4.22 + *
    4.23 + *  This program is distributed in the hope that it will be useful,
    4.24 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.25 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.26 + *  GNU General Public License for more details.
    4.27 + *
    4.28 + */
    4.29 +
    4.30 +#include <termios.h>
    4.31 +#include <stdio.h>
    4.32 +#include <stdlib.h>
    4.33 +#include <unistd.h>
    4.34 +#include <fcntl.h>
    4.35 +#include <sys/signal.h>
    4.36 +#include <sys/types.h>
    4.37 +#include <sys/wait.h>
    4.38 +
    4.39 +#define DEFAULT_BAUDRATE   115200
    4.40 +#define DEFAULT_SERDEVICE  "/dev/ttyS0"
    4.41 +#define ENDMINITERM        2  /* ctrl-b to quit miniterm */
    4.42 +
    4.43 +volatile int stop = 0;
    4.44 +
    4.45 +void child_handler(int s)
    4.46 +{
    4.47 +    stop = 1;
    4.48 +}
    4.49 +
    4.50 +int cook_baud(int baud)
    4.51 +{
    4.52 +    int cooked_baud = 0;
    4.53 +    switch ( baud )
    4.54 +    {
    4.55 +    case     50: cooked_baud =     B50; break;
    4.56 +    case     75: cooked_baud =     B75; break;
    4.57 +    case    110: cooked_baud =    B110; break;
    4.58 +    case    134: cooked_baud =    B134; break;
    4.59 +    case    150: cooked_baud =    B150; break;
    4.60 +    case    200: cooked_baud =    B200; break;
    4.61 +    case    300: cooked_baud =    B300; break;
    4.62 +    case    600: cooked_baud =    B600; break;
    4.63 +    case   1200: cooked_baud =   B1200; break;
    4.64 +    case   1800: cooked_baud =   B1800; break;
    4.65 +    case   2400: cooked_baud =   B2400; break;
    4.66 +    case   4800: cooked_baud =   B4800; break;
    4.67 +    case   9600: cooked_baud =   B9600; break;
    4.68 +    case  19200: cooked_baud =  B19200; break;
    4.69 +    case  38400: cooked_baud =  B38400; break;
    4.70 +    case  57600: cooked_baud =  B57600; break;
    4.71 +    case 115200: cooked_baud = B115200; break;
    4.72 +    }
    4.73 +    return cooked_baud;
    4.74 +}
    4.75 +
    4.76 +int main(int argc, char **argv)
    4.77 +{
    4.78 +    int              fd, c, cooked_baud = cook_baud(DEFAULT_BAUDRATE);
    4.79 +    char            *sername = DEFAULT_SERDEVICE;
    4.80 +    struct termios   oldsertio, newsertio, oldstdtio, newstdtio;
    4.81 +    struct sigaction sa;
    4.82 + 
    4.83 +    while ( --argc != 0 )
    4.84 +    {
    4.85 +        char *p = argv[argc];
    4.86 +        if ( *p++ != '-' )
    4.87 +            goto usage;
    4.88 +        if ( *p == 'b' )
    4.89 +        {
    4.90 +            p++;
    4.91 +            if ( (cooked_baud = cook_baud(atoi(p))) == 0 )
    4.92 +            {
    4.93 +                fprintf(stderr, "Bad baud rate '%d'\n", atoi(p));
    4.94 +                goto usage;
    4.95 +            }
    4.96 +        }
    4.97 +        else if ( *p == 'd' )
    4.98 +        {
    4.99 +            sername = ++p;
   4.100 +            if ( *sername == '\0' )
   4.101 +                goto usage;
   4.102 +        }
   4.103 +        else
   4.104 +            goto usage;
   4.105 +    }
   4.106 +
   4.107 +    /* Not a controlling tty: CTRL-C shouldn't kill us. */
   4.108 +    fd = open(sername, O_RDWR | O_NOCTTY);
   4.109 +    if ( fd < 0 )
   4.110 +    {
   4.111 +        perror(sername); 
   4.112 +        exit(-1);
   4.113 +    }
   4.114 + 
   4.115 +    tcgetattr(fd, &oldsertio); /* save current modem settings */
   4.116 + 
   4.117 +    /*
   4.118 +     * 8 data, no parity, 1 stop bit. Ignore modem control lines. Enable 
   4.119 +     * receive. Set appropriate baud rate. NO HARDWARE FLOW CONTROL!
   4.120 +     */
   4.121 +    newsertio.c_cflag = cooked_baud | CS8 | CLOCAL | CREAD;
   4.122 +
   4.123 +    /* Raw input. Ignore errors and breaks. */
   4.124 +    newsertio.c_iflag = IGNBRK | IGNPAR;
   4.125 +
   4.126 +    /* Raw output. */
   4.127 +    newsertio.c_oflag = 0; 
   4.128 +
   4.129 +    /* No echo and no signals. */
   4.130 +    newsertio.c_lflag = 0;
   4.131 + 
   4.132 +    /* blocking read until 1 char arrives */
   4.133 +    newsertio.c_cc[VMIN]=1;
   4.134 +    newsertio.c_cc[VTIME]=0;
   4.135 + 
   4.136 +    /* now clean the modem line and activate the settings for modem */
   4.137 +    tcflush(fd, TCIFLUSH);
   4.138 +    tcsetattr(fd,TCSANOW,&newsertio);
   4.139 + 
   4.140 +    /* next stop echo and buffering for stdin */
   4.141 +    tcgetattr(0,&oldstdtio);
   4.142 +    tcgetattr(0,&newstdtio); /* get working stdtio */
   4.143 +    newstdtio.c_lflag &= ~(ICANON | ECHO);
   4.144 +    tcsetattr(0,TCSANOW,&newstdtio);
   4.145 +
   4.146 +    /* Terminal settings done: now enter the main I/O loops. */
   4.147 +    switch ( fork() )
   4.148 +    {
   4.149 +    case 0:
   4.150 +        close(1); /* stdout not needed */
   4.151 +        for ( c = getchar(); c != ENDMINITERM ; c = getchar() ) 
   4.152 +            write(fd,&c,1);
   4.153 +        tcsetattr(fd,TCSANOW,&oldsertio);
   4.154 +        tcsetattr(0,TCSANOW,&oldstdtio);
   4.155 +        close(fd);
   4.156 +        exit(0); /* will send a SIGCHLD to the parent */
   4.157 +        break;
   4.158 +    case -1:
   4.159 +        perror("fork");
   4.160 +        tcsetattr(fd,TCSANOW,&oldsertio);
   4.161 +        close(fd);
   4.162 +        exit(-1);
   4.163 +    default:
   4.164 +        printf("** ctrl-b quits miniterm **\n");
   4.165 +        close(0); /* stdin not needed */
   4.166 +        sa.sa_handler = child_handler;
   4.167 +        sa.sa_flags = 0;
   4.168 +        sigaction(SIGCHLD,&sa,NULL); /* handle dying child */
   4.169 +        while ( !stop )
   4.170 +        {
   4.171 +            read(fd,&c,1); /* modem */
   4.172 +            write(1,&c,1); /* stdout */
   4.173 +        }
   4.174 +        wait(NULL); /* wait for child to die or it will become a zombie */
   4.175 +        break;
   4.176 +    }
   4.177 +
   4.178 +    return 0;
   4.179 +
   4.180 + usage:
   4.181 +    printf("miniterm [-b<baudrate>] [-d<devicename>]\n");
   4.182 +    printf("Default baud rate: %d\n", DEFAULT_BAUDRATE);
   4.183 +    printf("Default device: %s\n", DEFAULT_SERDEVICE);
   4.184 +    return 1;
   4.185 +}