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 <rtems.h> |
---|
12 | #include "console.h" |
---|
13 | #include "bsp.h" |
---|
14 | |
---|
15 | #include <dpmi.h> |
---|
16 | #include <go32.h> |
---|
17 | |
---|
18 | /* console_cleanup |
---|
19 | * |
---|
20 | * This routine is called at exit to clean up the console hardware. |
---|
21 | * |
---|
22 | * Input parameters: NONE |
---|
23 | * |
---|
24 | * Output parameters: NONE |
---|
25 | * |
---|
26 | * Return values: |
---|
27 | */ |
---|
28 | |
---|
29 | void console_cleanup( void ) |
---|
30 | { |
---|
31 | /* nothing */ |
---|
32 | } |
---|
33 | |
---|
34 | /* console_initialize |
---|
35 | * |
---|
36 | * This routine initializes the console IO driver. |
---|
37 | * |
---|
38 | * Input parameters: NONE |
---|
39 | * |
---|
40 | * Output parameters: NONE |
---|
41 | * |
---|
42 | * Return values: |
---|
43 | */ |
---|
44 | |
---|
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 | |
---|
52 | |
---|
53 | rtems_device_driver console_initialize( |
---|
54 | rtems_device_major_number major, |
---|
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 | } |
---|
76 | } |
---|
77 | |
---|
78 | atexit( console_cleanup ); |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | /* is_character_ready |
---|
83 | * |
---|
84 | * This routine returns TRUE if a character is available. |
---|
85 | * |
---|
86 | * Input parameters: NONE |
---|
87 | * |
---|
88 | * Output parameters: NONE |
---|
89 | * |
---|
90 | * Return values: |
---|
91 | */ |
---|
92 | |
---|
93 | rtems_boolean is_character_ready( |
---|
94 | char *ch |
---|
95 | ) |
---|
96 | { |
---|
97 | return _IBMPC_chrdy( ch ) ? TRUE : FALSE; |
---|
98 | } |
---|
99 | |
---|
100 | /* inbyte |
---|
101 | * |
---|
102 | * This routine reads a character from the UART. |
---|
103 | * |
---|
104 | * Input parameters: NONE |
---|
105 | * |
---|
106 | * Output parameters: NONE |
---|
107 | * |
---|
108 | * Return values: |
---|
109 | * character read from UART |
---|
110 | */ |
---|
111 | |
---|
112 | char inbyte( void ) |
---|
113 | { |
---|
114 | char ch = _IBMPC_inch(); |
---|
115 | #if 1 |
---|
116 | /* Echo character to screen */ |
---|
117 | void outbyte( char ch ); |
---|
118 | outbyte( ch ); |
---|
119 | if ( ch == '\r' ) |
---|
120 | outbyte( '\n' ); |
---|
121 | #endif |
---|
122 | return ch; |
---|
123 | } |
---|
124 | |
---|
125 | /* outbyte |
---|
126 | * |
---|
127 | * This routine transmits a character out the port. |
---|
128 | * |
---|
129 | * Input parameters: |
---|
130 | * ch - character to be transmitted |
---|
131 | * |
---|
132 | * Output parameters: NONE |
---|
133 | */ |
---|
134 | |
---|
135 | void outbyte( char ch ) |
---|
136 | { |
---|
137 | _IBMPC_outch( ch ); |
---|
138 | } |
---|
139 | |
---|
140 | /* |
---|
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; |
---|
160 | } |
---|
161 | } |
---|
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'); |
---|
182 | } |
---|
183 | outbyte (*(buf + i)); |
---|
184 | } |
---|
185 | return (nbytes); |
---|
186 | } |
---|