[7150f00f] | 1 | /*-------------------------------------------------------------------------+ |
---|
| 2 | | console.c v1.1 - PC386 BSP - 1997/08/07 |
---|
| 3 | +--------------------------------------------------------------------------+ |
---|
| 4 | | This file contains the PC386 console I/O package. |
---|
| 5 | +--------------------------------------------------------------------------+ |
---|
| 6 | | (C) Copyright 1997 - |
---|
| 7 | | - NavIST Group - Real-Time Distributed Systems and Industrial Automation |
---|
| 8 | | |
---|
| 9 | | http://pandora.ist.utl.pt |
---|
| 10 | | |
---|
| 11 | | Instituto Superior Tecnico * Lisboa * PORTUGAL |
---|
| 12 | +--------------------------------------------------------------------------+ |
---|
| 13 | | Disclaimer: |
---|
| 14 | | |
---|
| 15 | | This file is provided "AS IS" without warranty of any kind, either |
---|
| 16 | | expressed or implied. |
---|
| 17 | +--------------------------------------------------------------------------+ |
---|
| 18 | | This code is based on: |
---|
| 19 | | console.c,v 1.4 1995/12/19 20:07:23 joel Exp - go32 BSP |
---|
| 20 | | With the following copyright notice: |
---|
| 21 | | ************************************************************************** |
---|
| 22 | | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. * |
---|
| 23 | | * On-Line Applications Research Corporation (OAR). * |
---|
| 24 | | * All rights assigned to U.S. Government, 1994. * |
---|
| 25 | | * * |
---|
| 26 | | * This material may be reproduced by or for the U.S. Government pursuant * |
---|
| 27 | | * to the copyright license under the clause at DFARS 252.227-7013. This * |
---|
| 28 | | * notice must appear in all copies of this file and its derivatives. * |
---|
| 29 | | ************************************************************************** |
---|
| 30 | +--------------------------------------------------------------------------*/ |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | #include <stdlib.h> |
---|
| 34 | |
---|
| 35 | #include <bsp.h> |
---|
| 36 | #include <irq.h> |
---|
| 37 | #include <rtems/libio.h> |
---|
| 38 | |
---|
| 39 | /*-------------------------------------------------------------------------+ |
---|
| 40 | | Constants |
---|
| 41 | +--------------------------------------------------------------------------*/ |
---|
| 42 | #define KEYBOARD_IRQ 0x01 /* Keyboard IRQ. */ |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | /*-------------------------------------------------------------------------+ |
---|
| 46 | | External Prototypes |
---|
| 47 | +--------------------------------------------------------------------------*/ |
---|
| 48 | extern rtems_isr _IBMPC_keyboard_isr(rtems_vector_number); |
---|
| 49 | /* keyboard (IRQ 0x01) Interrupt Service Routine (defined in 'inch.c') */ |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | /*-------------------------------------------------------------------------+ |
---|
| 53 | | Functions |
---|
| 54 | +--------------------------------------------------------------------------*/ |
---|
| 55 | /*-------------------------------------------------------------------------+ |
---|
| 56 | | Function: console_cleanup |
---|
| 57 | | Description: This routine is called at exit to clean up the console |
---|
| 58 | | hardware. |
---|
| 59 | | Global Variables: None. |
---|
| 60 | | Arguments: None. |
---|
| 61 | | Returns: Nothing. |
---|
| 62 | +--------------------------------------------------------------------------*/ |
---|
| 63 | void |
---|
| 64 | console_cleanup(void) |
---|
| 65 | { |
---|
| 66 | /* nothing */ |
---|
| 67 | } /* console_cleanup */ |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | /*-------------------------------------------------------------------------+ |
---|
| 71 | | Function: is_character_ready |
---|
| 72 | | Description: Check if a character is available for input, and if so |
---|
| 73 | | return it. |
---|
| 74 | | Global Variables: None. |
---|
| 75 | | Arguments: c - character read if available, otherwise unchanged. |
---|
| 76 | | Returns: TRUE if there was a character available for input, |
---|
| 77 | | FALSE otherwise. |
---|
| 78 | +--------------------------------------------------------------------------*/ |
---|
| 79 | rtems_boolean |
---|
| 80 | is_character_ready(char *c) |
---|
| 81 | { |
---|
| 82 | return (_IBMPC_chrdy(c) ? TRUE : FALSE); |
---|
| 83 | } /* is_character_ready */ |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | /*-------------------------------------------------------------------------+ |
---|
| 87 | | Function: inbyte |
---|
| 88 | | Description: Read a character from the console (keyboard). |
---|
| 89 | | Global Variables: None. |
---|
| 90 | | Arguments: None. |
---|
| 91 | | Returns: Caracter read from the console. |
---|
| 92 | +--------------------------------------------------------------------------*/ |
---|
| 93 | unsigned char |
---|
| 94 | inbyte(void) |
---|
| 95 | { |
---|
| 96 | char c = _IBMPC_inch(); |
---|
| 97 | |
---|
| 98 | /* Echo character to screen */ |
---|
| 99 | _IBMPC_outch(c); |
---|
| 100 | if (c == '\r') |
---|
| 101 | _IBMPC_outch('\n'); /* CR = CR + LF */ |
---|
| 102 | |
---|
| 103 | return c; |
---|
| 104 | } /* inbyte */ |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | /*-------------------------------------------------------------------------+ |
---|
| 108 | | Function: outbyte |
---|
| 109 | | Description: Write a character to the console (display). |
---|
| 110 | | Global Variables: None. |
---|
| 111 | | Arguments: Character to be written. |
---|
| 112 | | Returns: Nothing. |
---|
| 113 | +--------------------------------------------------------------------------*/ |
---|
| 114 | void |
---|
| 115 | outbyte(char c) |
---|
| 116 | { |
---|
| 117 | _IBMPC_outch(c); |
---|
| 118 | } /* outbyte */ |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | /*-------------------------------------------------------------------------+ |
---|
| 122 | | Console device driver INITIALIZE entry point. |
---|
| 123 | +--------------------------------------------------------------------------+ |
---|
| 124 | | Initilizes the I/O console (keyboard + VGA display) driver. |
---|
| 125 | +--------------------------------------------------------------------------*/ |
---|
| 126 | rtems_device_driver |
---|
| 127 | console_initialize(rtems_device_major_number major, |
---|
| 128 | rtems_device_minor_number minor, |
---|
| 129 | void *arg) |
---|
| 130 | { |
---|
| 131 | rtems_status_code status; |
---|
| 132 | |
---|
| 133 | /* Initialize video */ |
---|
| 134 | _IBMPC_initVideo(); |
---|
| 135 | |
---|
| 136 | /* Install keyboard interrupt handler */ |
---|
| 137 | status = PC386_installRtemsIrqHandler(KEYBOARD_IRQ, _IBMPC_keyboard_isr); |
---|
| 138 | |
---|
| 139 | if (status != RTEMS_SUCCESSFUL) |
---|
| 140 | { |
---|
| 141 | printk("Error installing keyboard interrupt handler!\n"); |
---|
| 142 | rtems_fatal_error_occurred(status); |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | status = |
---|
| 146 | rtems_io_register_name("/dev/console", major, (rtems_device_minor_number)0); |
---|
| 147 | |
---|
| 148 | if (status != RTEMS_SUCCESSFUL) |
---|
| 149 | { |
---|
| 150 | printk("Error registering console device!\n"); |
---|
| 151 | rtems_fatal_error_occurred(status); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | atexit(console_cleanup); |
---|
| 155 | |
---|
| 156 | return RTEMS_SUCCESSFUL; |
---|
| 157 | } /* console_initialize */ |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | /*-------------------------------------------------------------------------+ |
---|
| 161 | | Console device driver OPEN entry point |
---|
| 162 | +--------------------------------------------------------------------------*/ |
---|
| 163 | rtems_device_driver |
---|
| 164 | console_open(rtems_device_major_number major, |
---|
| 165 | rtems_device_minor_number minor, |
---|
| 166 | void *arg) |
---|
| 167 | { |
---|
| 168 | return RTEMS_SUCCESSFUL; |
---|
| 169 | } /* console_open */ |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | /*-------------------------------------------------------------------------+ |
---|
| 173 | | Console device driver CLOSE entry point |
---|
| 174 | +--------------------------------------------------------------------------*/ |
---|
| 175 | rtems_device_driver |
---|
| 176 | console_close(rtems_device_major_number major, |
---|
| 177 | rtems_device_minor_number minor, |
---|
| 178 | void *arg) |
---|
| 179 | { |
---|
| 180 | return RTEMS_SUCCESSFUL; |
---|
| 181 | } /* console_close */ |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | /*-------------------------------------------------------------------------+ |
---|
| 185 | | Console device driver READ entry point. |
---|
| 186 | +--------------------------------------------------------------------------+ |
---|
| 187 | | Read characters from the I/O console. We only have stdin. |
---|
| 188 | +--------------------------------------------------------------------------*/ |
---|
| 189 | rtems_device_driver |
---|
| 190 | console_read(rtems_device_major_number major, |
---|
| 191 | rtems_device_minor_number minor, |
---|
| 192 | void *arg) |
---|
| 193 | { |
---|
| 194 | rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg; |
---|
| 195 | char *buffer = rw_args->buffer; |
---|
| 196 | int count, maximum = rw_args->count; |
---|
| 197 | |
---|
| 198 | for (count = 0; count < maximum; count++) |
---|
| 199 | { |
---|
| 200 | buffer[count] = inbyte(); |
---|
| 201 | if (buffer[count] == '\n' || buffer[count] == '\r') |
---|
| 202 | { |
---|
| 203 | /* What if this goes past the end of the buffer? We're hosed. [bhc] */ |
---|
| 204 | buffer[count++] = '\n'; |
---|
| 205 | buffer[count] = '\0'; |
---|
| 206 | break; |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | rw_args->bytes_moved = count; |
---|
| 211 | return ((count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED); |
---|
| 212 | } /* console_read */ |
---|
| 213 | |
---|
| 214 | |
---|
| 215 | /*-------------------------------------------------------------------------+ |
---|
| 216 | | Console device driver WRITE entry point. |
---|
| 217 | +--------------------------------------------------------------------------+ |
---|
| 218 | | Write characters to the I/O console. Stderr and stdout are the same. |
---|
| 219 | +--------------------------------------------------------------------------*/ |
---|
| 220 | rtems_device_driver |
---|
| 221 | console_write(rtems_device_major_number major, |
---|
| 222 | rtems_device_minor_number minor, |
---|
| 223 | void * arg) |
---|
| 224 | { |
---|
| 225 | rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg; |
---|
| 226 | char *buffer = rw_args->buffer; |
---|
| 227 | int count, maximum = rw_args->count; |
---|
| 228 | |
---|
| 229 | for (count = 0; count < maximum; count++) |
---|
| 230 | { |
---|
| 231 | outbyte(buffer[count]); |
---|
| 232 | if (buffer[count] == '\n') |
---|
| 233 | outbyte('\r'); /* LF = LF + CR */ |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | rw_args->bytes_moved = maximum; |
---|
| 237 | return RTEMS_SUCCESSFUL; |
---|
| 238 | } /* console_write */ |
---|
| 239 | |
---|
| 240 | |
---|
| 241 | /*-------------------------------------------------------------------------+ |
---|
| 242 | | Console device driver CONTROL entry point |
---|
| 243 | +--------------------------------------------------------------------------*/ |
---|
| 244 | rtems_device_driver |
---|
| 245 | console_control(rtems_device_major_number major, |
---|
| 246 | rtems_device_minor_number minor, |
---|
| 247 | void *arg) |
---|
| 248 | { |
---|
| 249 | return RTEMS_SUCCESSFUL; |
---|
| 250 | } /* console_control */ |
---|