1 | /* |
---|
2 | * This file contains the go32 console IO package. |
---|
3 | * |
---|
4 | * $Id$ |
---|
5 | */ |
---|
6 | |
---|
7 | #define IBMPC_INIT |
---|
8 | |
---|
9 | #include <stdlib.h> |
---|
10 | |
---|
11 | #include <bsp.h> |
---|
12 | #include <rtems/libio.h> |
---|
13 | |
---|
14 | #include <dpmi.h> |
---|
15 | #include <go32.h> |
---|
16 | |
---|
17 | /* console_cleanup |
---|
18 | * |
---|
19 | * This routine is called at exit to clean up the console hardware. |
---|
20 | * |
---|
21 | * Input parameters: NONE |
---|
22 | * |
---|
23 | * Output parameters: NONE |
---|
24 | * |
---|
25 | * Return values: |
---|
26 | */ |
---|
27 | |
---|
28 | void console_cleanup( void ) |
---|
29 | { |
---|
30 | /* nothing */ |
---|
31 | } |
---|
32 | |
---|
33 | /* console_initialize |
---|
34 | * |
---|
35 | * This routine initializes the console IO driver. |
---|
36 | * |
---|
37 | * Input parameters: NONE |
---|
38 | * |
---|
39 | * Output parameters: NONE |
---|
40 | * |
---|
41 | * Return values: |
---|
42 | */ |
---|
43 | |
---|
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 | |
---|
53 | rtems_device_driver console_initialize( |
---|
54 | rtems_device_major_number major, |
---|
55 | rtems_device_minor_number minor, |
---|
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 ); |
---|
78 | } |
---|
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; |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | /* is_character_ready |
---|
97 | * |
---|
98 | * This routine returns TRUE if a character is available. |
---|
99 | * |
---|
100 | * Input parameters: NONE |
---|
101 | * |
---|
102 | * Output parameters: NONE |
---|
103 | * |
---|
104 | * Return values: |
---|
105 | */ |
---|
106 | |
---|
107 | rtems_boolean is_character_ready( |
---|
108 | char *ch |
---|
109 | ) |
---|
110 | { |
---|
111 | return _IBMPC_chrdy( ch ) ? TRUE : FALSE; |
---|
112 | } |
---|
113 | |
---|
114 | /* inbyte |
---|
115 | * |
---|
116 | * This routine reads a character from the UART. |
---|
117 | * |
---|
118 | * Input parameters: NONE |
---|
119 | * |
---|
120 | * Output parameters: NONE |
---|
121 | * |
---|
122 | * Return values: |
---|
123 | * character read from UART |
---|
124 | */ |
---|
125 | |
---|
126 | char inbyte( void ) |
---|
127 | { |
---|
128 | char ch = _IBMPC_inch(); |
---|
129 | #if 1 |
---|
130 | /* Echo character to screen */ |
---|
131 | void outbyte( char ch ); |
---|
132 | outbyte( ch ); |
---|
133 | if ( ch == '\r' ) |
---|
134 | outbyte( '\n' ); |
---|
135 | #endif |
---|
136 | return ch; |
---|
137 | } |
---|
138 | |
---|
139 | /* outbyte |
---|
140 | * |
---|
141 | * This routine transmits a character out the port. |
---|
142 | * |
---|
143 | * Input parameters: |
---|
144 | * ch - character to be transmitted |
---|
145 | * |
---|
146 | * Output parameters: NONE |
---|
147 | */ |
---|
148 | |
---|
149 | void outbyte( char ch ) |
---|
150 | { |
---|
151 | _IBMPC_outch( ch ); |
---|
152 | } |
---|
153 | |
---|
154 | /* |
---|
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; |
---|
207 | } |
---|
208 | } |
---|
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'); |
---|
237 | } |
---|
238 | outbyte( buffer[ count ] ); |
---|
239 | } |
---|
240 | |
---|
241 | rw_args->bytes_moved = maximum; |
---|
242 | return 0; |
---|
243 | } |
---|
244 | |
---|
245 | /* |
---|
246 | * IO Control entry point |
---|
247 | */ |
---|
248 | |
---|
249 | rtems_device_driver console_control( |
---|
250 | rtems_device_major_number major, |
---|
251 | rtems_device_minor_number minor, |
---|
252 | void * arg |
---|
253 | ) |
---|
254 | { |
---|
255 | return RTEMS_SUCCESSFUL; |
---|
256 | } |
---|
257 | |
---|