1 static char _[] = "@(#)io.c 5.22 93/10/26 14:50:43, Srini, AMD.";
2 /******************************************************************************
3 * Copyright 1991 Advanced Micro Devices, Inc.
5 * This software is the property of Advanced Micro Devices, Inc (AMD) which
6 * specifically grants the user the right to modify, use and distribute this
7 * software provided this notice is not removed or altered. All other rights
10 * AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
11 * SOFTWARE. IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL
12 * DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR
13 * USE OF THIS SOFTWARE.
15 * So that all may benefit from your experience, please report any problems
16 * or suggestions about this software to the 29K Technical Support Center at
17 * 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131 in the UK, or
18 * 0031-11-1129 in Japan, toll free. The direct dial number is 512-462-4118.
20 * Advanced Micro Devices, Inc.
21 * 29K Support Products
23 * 5900 E. Ben White Blvd.
26 *****************************************************************************
27 * Engineer: Srini Subramanian.
28 *****************************************************************************
29 * This file contains the I/O related routines.
30 *****************************************************************************
38 #include <sys/ioctl.h>
45 /* Function declarations */
47 INT32 Mini_io_setup PARAMS((void));
48 INT32 Mini_io_reset PARAMS((void));
49 int getkey PARAMS((void));
50 INT32 Mini_poll_kbd PARAMS((char *cmd_buffer, int size, int mode));
51 int cmd_io PARAMS ((char *cmd_buffer, char c));
52 int channel0_io PARAMS ((char c));
57 setbuf(stdout, 0); /* stdout unbuffered */
64 /* Nothing special for now */
69 ** This function is used to perform all host I/O. It
70 ** calls the functions cmd_io() or hif_io() as appropriate
71 ** Note that there are eight pobible I/O "modes". These
72 ** are all possible combination of:
74 ** - Host / Target I/O
75 ** - HIF / non-HIF I/O
76 ** - Command file / keyboard I/O
81 Mini_poll_kbd(cmd_buffer, size, blockmode)
90 io_config.cmd_ready = FALSE;
91 if (blockmode) { /* BLOCK until a command is typed (line buffered) */
92 while (gets(cmd_buffer) == NULL); /* no characters in stdin */
93 io_config.cmd_ready = TRUE;
94 } else { /* NONBLOCk return immediately if there is no command pending */
96 ch = (unsigned char) getche();
97 *(cmd_buffer+indx) = ch;
99 if (ch == (unsigned char) 13) { /* \r, insert \n */
100 putchar(10); /* line feed */
101 *(cmd_buffer+indx) = '\0';
102 io_config.cmd_ready = TRUE;
104 } else if (ch == (unsigned char) 8) { /* backspace */
106 } else if (ch == (unsigned char) 127) { /* delete */
121 io_config.cmd_ready = FALSE;
123 if (blockmode) { /* block mode read */
126 ioctl(fileno(stdin), FIOSNBIO, &i); /* set blocking read */
128 ioctl(fileno(stdin), FIONBIO, &i); /* set blocking read */
130 } else { /* nonblocking read */
131 /* for now only read from stdin */
134 ioctl(fileno(stdin), FIOSNBIO, &i); /* set non blocking read */
136 ioctl(fileno(stdin), FIONBIO, &i); /* set non blocking read */
140 /* Now read from stdin. */
141 result = read( 0, cmd_buffer, BUFSIZ );
146 cmd_buffer[result] = '\0';
147 io_config.cmd_ready = TRUE;
154 ioctl(fileno(stdin), FIOSNBIO, &i); /* clear non-blocking read */
156 ioctl(fileno(stdin), FIONBIO, &i); /* clear non-blocking read */