Changeset 3a4ae6c in rtems for c/src/lib/libbsp/i386/go32/console
- Timestamp:
- 09/11/95 19:35:39 (28 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- ced11f99
- Parents:
- 5072b07
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
c/src/lib/libbsp/i386/go32/console/console.c
r5072b07 r3a4ae6c 9 9 #include <stdlib.h> 10 10 11 #include <rtems.h> 12 #include "console.h" 13 #include "bsp.h" 11 #include <bsp.h> 12 #include <rtems/libio.h> 14 13 15 14 #include <dpmi.h> … … 43 42 */ 44 43 45 /* Set this if console I/O should use go32 (DOS) read/write calls. */ 46 /* Otherwise, direct hardware accesses will be used. */ 47 int _IBMPC_Use_Go32_IO = 0; 48 49 static rtems_isr_entry old_keyboard_isr = NULL; 50 extern void _IBMPC_keyboard_isr( rtems_unsigned32 interrupt ); 51 44 /* Set this if console I/O should use go32 (DOS) read/write calls. */ 45 /* Otherwise, direct hardware accesses will be used. */ 46 47 int _IBMPC_Use_Go32_IO = 0; 48 49 static rtems_isr_entry old_keyboard_isr = NULL; 50 51 extern void _IBMPC_keyboard_isr( rtems_unsigned32 interrupt ); 52 52 53 53 rtems_device_driver console_initialize( 54 54 rtems_device_major_number major, 55 55 rtems_device_minor_number minor, 56 void *arg, 57 rtems_id self, 58 rtems_unsigned32 *status 59 ) 60 { 61 if ( _IBMPC_Use_Go32_IO ) { 62 /* Nothing. We let DOS and go32 do all the work. */ 63 } else { 64 /* Grap the keyboard interrupt so DOS doesn't steal our */ 65 /* keystrokes. */ 66 rtems_status_code status; 67 status = rtems_interrupt_catch( _IBMPC_keyboard_isr, 9, 68 &old_keyboard_isr ); 69 if ( status ) { 70 int write( int, void *, int ); 71 void exit( int ); 72 char msg[] = "error initializing keyboard\n"; 73 write( 2, msg, sizeof msg - 1 ); 74 exit( 1 ); 75 } 56 void *arg 57 ) 58 { 59 rtems_status_code status; 60 61 if ( _IBMPC_Use_Go32_IO ) { 62 /* Nothing. We let DOS and go32 do all the work. */ 63 } else { 64 /* Grap the keyboard interrupt so DOS doesn't steal our */ 65 /* keystrokes. */ 66 rtems_status_code status; 67 68 status = 69 rtems_interrupt_catch( _IBMPC_keyboard_isr, 9, &old_keyboard_isr ); 70 71 if ( status ) { 72 int write( int, void *, int ); 73 void exit( int ); 74 75 char msg[] = "error initializing keyboard\n"; 76 write( 2, msg, sizeof msg - 1 ); 77 exit( 1 ); 76 78 } 77 78 atexit( console_cleanup ); 79 } 80 81 status = rtems_io_register_name( 82 "/dev/console", 83 major, 84 (rtems_device_minor_number) 0 85 ); 86 87 if (status != RTEMS_SUCCESSFUL) 88 rtems_fatal_error_occurred(status); 89 90 atexit( console_cleanup ); 91 92 return RTEMS_SUCCESSFUL; 79 93 } 80 94 … … 118 132 outbyte( ch ); 119 133 if ( ch == '\r' ) 120 134 outbyte( '\n' ); 121 135 #endif 122 136 return ch; … … 139 153 140 154 /* 141 * __read -- read bytes from the console. Ignore fd, since 142 * we only have stdin. 143 */ 144 145 int __read( 146 int fd, 147 char *buf, 148 int nbytes 149 ) 150 { 151 int i = 0; 152 153 for ( i = 0; i < nbytes; i++ ) { 154 buf[i] = inbyte(); 155 if ( buf[i] == '\r' ) { 156 /* What if this goes past the end of the buffer? We're hosed. [bhc] */ 157 buf[i++] = '\n'; 158 buf[i] = '\0'; 159 break; 155 * Open entry point 156 */ 157 158 rtems_device_driver console_open( 159 rtems_device_major_number major, 160 rtems_device_minor_number minor, 161 void * arg 162 ) 163 { 164 return RTEMS_SUCCESSFUL; 165 } 166 167 /* 168 * Close entry point 169 */ 170 171 rtems_device_driver console_close( 172 rtems_device_major_number major, 173 rtems_device_minor_number minor, 174 void * arg 175 ) 176 { 177 return RTEMS_SUCCESSFUL; 178 } 179 180 /* 181 * read bytes from the serial port. We only have stdin. 182 */ 183 184 rtems_device_driver console_read( 185 rtems_device_major_number major, 186 rtems_device_minor_number minor, 187 void * arg 188 ) 189 { 190 rtems_libio_rw_args_t *rw_args; 191 char *buffer; 192 int maximum; 193 int count = 0; 194 195 rw_args = (rtems_libio_rw_args_t *) arg; 196 197 buffer = rw_args->buffer; 198 maximum = rw_args->count; 199 200 for (count = 0; count < maximum; count++) { 201 buffer[ count ] = inbyte(); 202 if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { 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; 160 207 } 161 208 } 162 return i; 163 } 164 165 /* 166 * __write -- write bytes to the console. Ignore fd, since 167 * stdout and stderr are the same. Since we have no filesystem, 168 * open will only return an error. 169 */ 170 171 int __write( 172 int fd, 173 char *buf, 174 int nbytes 175 ) 176 { 177 int i; 178 179 for (i = 0; i < nbytes; i++) { 180 if (*(buf + i) == '\n') { 181 outbyte ('\r'); 209 210 rw_args->bytes_moved = count; 211 return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; 212 } 213 214 /* 215 * write bytes to the serial port. Stdout and stderr are the same. 216 */ 217 218 rtems_device_driver console_write( 219 rtems_device_major_number major, 220 rtems_device_minor_number minor, 221 void * arg 222 ) 223 { 224 int count; 225 int maximum; 226 rtems_libio_rw_args_t *rw_args; 227 char *buffer; 228 229 rw_args = (rtems_libio_rw_args_t *) arg; 230 231 buffer = rw_args->buffer; 232 maximum = rw_args->count; 233 234 for (count = 0; count < maximum; count++) { 235 if ( buffer[ count ] == '\n') { 236 outbyte('\r'); 182 237 } 183 outbyte (*(buf + i));238 outbyte( buffer[ count ] ); 184 239 } 185 return (nbytes); 186 } 240 return maximum; 241 } 242 243 /* 244 * IO Control entry point 245 */ 246 247 rtems_device_driver console_control( 248 rtems_device_major_number major, 249 rtems_device_minor_number minor, 250 void * arg 251 ) 252 { 253 return RTEMS_SUCCESSFUL; 254 } 255
Note: See TracChangeset
for help on using the changeset viewer.