[752cd8f] | 1 | /* |
---|
[6c58b6f] | 2 | * This file contains the i386ex console IO package. |
---|
[752cd8f] | 3 | * |
---|
| 4 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * All rights assigned to U.S. Government, 1994. |
---|
| 7 | * |
---|
| 8 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
| 9 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
| 10 | * notice must appear in all copies of this file and its derivatives. |
---|
| 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #define F386_INIT |
---|
| 16 | |
---|
[6c58b6f] | 17 | #include <bsp.h> |
---|
| 18 | #include <rtems/libio.h> |
---|
| 19 | |
---|
[752cd8f] | 20 | #include <stdlib.h> |
---|
| 21 | |
---|
| 22 | #include "../startup/80386ex.h" |
---|
| 23 | |
---|
| 24 | /* console_cleanup |
---|
| 25 | * |
---|
| 26 | * This routine is called at exit to clean up the console hardware. |
---|
| 27 | * |
---|
| 28 | * Input parameters: NONE |
---|
| 29 | * |
---|
| 30 | * Output parameters: NONE |
---|
| 31 | * |
---|
| 32 | * Return values: |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | void console_cleanup( void ) |
---|
| 36 | { |
---|
| 37 | register rtems_unsigned8 ignored; |
---|
| 38 | |
---|
| 39 | /* clear the read buffer */ |
---|
| 40 | |
---|
| 41 | inport_byte( RBR0, ignored ); |
---|
| 42 | |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | /* console_initialize |
---|
| 46 | * |
---|
| 47 | * This routine initializes the console IO driver. |
---|
| 48 | * |
---|
| 49 | * Input parameters: NONE |
---|
| 50 | * |
---|
| 51 | * Output parameters: NONE |
---|
| 52 | * |
---|
| 53 | * Return values: |
---|
| 54 | */ |
---|
| 55 | |
---|
| 56 | rtems_device_driver console_initialize( |
---|
| 57 | rtems_device_major_number major, |
---|
| 58 | rtems_device_minor_number minor, |
---|
[6c58b6f] | 59 | void *arg |
---|
[752cd8f] | 60 | ) |
---|
| 61 | { |
---|
[6c58b6f] | 62 | rtems_status_code status; |
---|
| 63 | |
---|
| 64 | /* |
---|
| 65 | * flush the console now and at exit. Just in case. |
---|
| 66 | */ |
---|
| 67 | |
---|
| 68 | console_cleanup(); |
---|
| 69 | |
---|
| 70 | status = rtems_io_register_name( |
---|
| 71 | "/dev/console", |
---|
| 72 | major, |
---|
| 73 | (rtems_device_minor_number) 0 |
---|
| 74 | ); |
---|
| 75 | |
---|
| 76 | if (status != RTEMS_SUCCESSFUL) |
---|
| 77 | rtems_fatal_error_occurred(status); |
---|
| 78 | |
---|
| 79 | atexit( console_cleanup ); |
---|
| 80 | |
---|
| 81 | return RTEMS_SUCCESSFUL; |
---|
[752cd8f] | 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | /* is_character_ready |
---|
| 86 | * |
---|
| 87 | * This routine returns TRUE if a character is available. |
---|
| 88 | * |
---|
| 89 | * Input parameters: NONE |
---|
| 90 | * |
---|
| 91 | * Output parameters: NONE |
---|
| 92 | * |
---|
| 93 | * Return values: |
---|
| 94 | */ |
---|
| 95 | |
---|
| 96 | rtems_boolean is_character_ready( |
---|
| 97 | char *ch |
---|
| 98 | ) |
---|
| 99 | { |
---|
| 100 | register rtems_unsigned8 status; |
---|
| 101 | |
---|
| 102 | inport_byte( LSR1, status ); |
---|
| 103 | |
---|
| 104 | if ( Is_rx_ready( status ) ) { |
---|
| 105 | inport_byte( RBR1, status ); |
---|
| 106 | *ch = status; |
---|
| 107 | return TRUE; |
---|
| 108 | } |
---|
| 109 | return FALSE; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | /* inbyte |
---|
| 113 | * |
---|
| 114 | * This routine reads a character from the UART. |
---|
| 115 | * |
---|
| 116 | * Input parameters: NONE |
---|
| 117 | * |
---|
| 118 | * Output parameters: NONE |
---|
| 119 | * |
---|
| 120 | * Return values: |
---|
| 121 | * character read from UART |
---|
| 122 | */ |
---|
| 123 | |
---|
| 124 | char inbyte( void ) |
---|
| 125 | { |
---|
| 126 | register rtems_unsigned8 status; |
---|
| 127 | char ch; |
---|
| 128 | |
---|
| 129 | do { |
---|
| 130 | inport_byte( LSR1, status ); |
---|
| 131 | } while ( !( status & 0x01 ));/* s/b while ( !( Is_rx_ready( status ) ) ); */ |
---|
| 132 | |
---|
| 133 | inport_byte( RBR1, ch ); |
---|
| 134 | |
---|
| 135 | return ch; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | /* outbyte |
---|
| 139 | * |
---|
| 140 | * This routine transmits a character out the port. It supports |
---|
| 141 | * XON/XOFF flow control. |
---|
| 142 | * |
---|
| 143 | * Input parameters: |
---|
| 144 | * ch - character to be transmitted |
---|
| 145 | * |
---|
| 146 | * Output parameters: NONE |
---|
| 147 | */ |
---|
| 148 | |
---|
| 149 | void outbyte( |
---|
| 150 | char ch |
---|
| 151 | ) |
---|
| 152 | { |
---|
| 153 | rtems_unsigned8 status; |
---|
| 154 | |
---|
| 155 | do { |
---|
| 156 | inport_byte( LSR1, status ); |
---|
| 157 | } while ( ! ( 0x40 & status ) ); /* ( Is_tx_ready( status ) ) );*/ |
---|
| 158 | |
---|
| 159 | /* |
---|
| 160 | * GDB will NOT use XON/XOFF protocol |
---|
| 161 | */ |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | #ifdef USE_XON |
---|
| 165 | |
---|
| 166 | while ( is_character_ready( &status ) == TRUE ) { |
---|
| 167 | if ( status == XOFF ) |
---|
| 168 | do { |
---|
| 169 | while ( is_character_ready( &status ) == FALSE ) ; |
---|
| 170 | } while ( status != XON ); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | #endif |
---|
| 174 | |
---|
| 175 | outport_byte( TBR1, ch ); |
---|
| 176 | |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | /* |
---|
[6c58b6f] | 180 | * Open entry point |
---|
[752cd8f] | 181 | */ |
---|
[6c58b6f] | 182 | |
---|
| 183 | rtems_device_driver console_open( |
---|
| 184 | rtems_device_major_number major, |
---|
| 185 | rtems_device_minor_number minor, |
---|
| 186 | void * arg |
---|
[752cd8f] | 187 | ) |
---|
| 188 | { |
---|
[6c58b6f] | 189 | return RTEMS_SUCCESSFUL; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | /* |
---|
| 193 | * Close entry point |
---|
| 194 | */ |
---|
| 195 | |
---|
| 196 | rtems_device_driver console_close( |
---|
| 197 | rtems_device_major_number major, |
---|
| 198 | rtems_device_minor_number minor, |
---|
| 199 | void * arg |
---|
| 200 | ) |
---|
| 201 | { |
---|
| 202 | return RTEMS_SUCCESSFUL; |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | /* |
---|
| 206 | * read bytes from the serial port. We only have stdin. |
---|
| 207 | */ |
---|
| 208 | |
---|
| 209 | rtems_device_driver console_read( |
---|
| 210 | rtems_device_major_number major, |
---|
| 211 | rtems_device_minor_number minor, |
---|
| 212 | void * arg |
---|
| 213 | ) |
---|
| 214 | { |
---|
| 215 | rtems_libio_rw_args_t *rw_args; |
---|
| 216 | char *buffer; |
---|
| 217 | int maximum; |
---|
| 218 | int count = 0; |
---|
| 219 | |
---|
| 220 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 221 | |
---|
| 222 | buffer = rw_args->buffer; |
---|
| 223 | maximum = rw_args->count; |
---|
| 224 | |
---|
| 225 | for (count = 0; count < maximum; count++) { |
---|
| 226 | buffer[ count ] = inbyte(); |
---|
| 227 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
| 228 | buffer[ count++ ] = '\n'; |
---|
| 229 | buffer[ count ] = 0; |
---|
[752cd8f] | 230 | break; |
---|
| 231 | } |
---|
| 232 | } |
---|
[6c58b6f] | 233 | |
---|
| 234 | rw_args->bytes_moved = count; |
---|
| 235 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
[752cd8f] | 236 | } |
---|
| 237 | |
---|
| 238 | /* |
---|
[6c58b6f] | 239 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
[752cd8f] | 240 | */ |
---|
[6c58b6f] | 241 | |
---|
| 242 | rtems_device_driver console_write( |
---|
| 243 | rtems_device_major_number major, |
---|
| 244 | rtems_device_minor_number minor, |
---|
| 245 | void * arg |
---|
[752cd8f] | 246 | ) |
---|
| 247 | { |
---|
[6c58b6f] | 248 | int count; |
---|
| 249 | int maximum; |
---|
| 250 | rtems_libio_rw_args_t *rw_args; |
---|
| 251 | char *buffer; |
---|
| 252 | |
---|
| 253 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 254 | |
---|
| 255 | buffer = rw_args->buffer; |
---|
| 256 | maximum = rw_args->count; |
---|
| 257 | |
---|
| 258 | for (count = 0; count < maximum; count++) { |
---|
| 259 | if ( buffer[ count ] == '\n') { |
---|
| 260 | outbyte('\r'); |
---|
[752cd8f] | 261 | } |
---|
[6c58b6f] | 262 | outbyte( buffer[ count ] ); |
---|
[752cd8f] | 263 | } |
---|
[6c58b6f] | 264 | |
---|
| 265 | rw_args->bytes_moved = maximum; |
---|
| 266 | return 0; |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | /* |
---|
| 270 | * IO Control entry point |
---|
| 271 | */ |
---|
| 272 | |
---|
| 273 | rtems_device_driver console_control( |
---|
| 274 | rtems_device_major_number major, |
---|
| 275 | rtems_device_minor_number minor, |
---|
| 276 | void * arg |
---|
| 277 | ) |
---|
| 278 | { |
---|
| 279 | return RTEMS_SUCCESSFUL; |
---|
[752cd8f] | 280 | } |
---|