1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * This file contains the termios TTY driver for the i386 |
---|
5 | * vga. |
---|
6 | * |
---|
7 | * COPYRIGHT (c) 1989-2011. |
---|
8 | * On-Line Applications Research Corporation (OAR). |
---|
9 | * |
---|
10 | * Redistribution and use in source and binary forms, with or without |
---|
11 | * modification, are permitted provided that the following conditions |
---|
12 | * are met: |
---|
13 | * 1. Redistributions of source code must retain the above copyright |
---|
14 | * notice, this list of conditions and the following disclaimer. |
---|
15 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
16 | * notice, this list of conditions and the following disclaimer in the |
---|
17 | * documentation and/or other materials provided with the distribution. |
---|
18 | * |
---|
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
29 | * POSSIBILITY OF SUCH DAMAGE. |
---|
30 | */ |
---|
31 | |
---|
32 | #include <rtems.h> |
---|
33 | #include <rtems/libio.h> |
---|
34 | #include <stdlib.h> |
---|
35 | #include <libchip/serial.h> |
---|
36 | #include <rtems/vgacons.h> |
---|
37 | #include <rtems/keyboard.h> |
---|
38 | #include <libchip/sersupp.h> |
---|
39 | #include <bsp/irq.h> |
---|
40 | #include <bsp.h> |
---|
41 | #include <crt.h> |
---|
42 | #include <assert.h> |
---|
43 | #include <rtems/keyboard.h> |
---|
44 | |
---|
45 | #define VGACONS_STATIC static |
---|
46 | |
---|
47 | /* |
---|
48 | * vgacons_init |
---|
49 | * |
---|
50 | * This function initializes the VGA console to a quiecsent state. |
---|
51 | */ |
---|
52 | VGACONS_STATIC void vgacons_init(int minor) |
---|
53 | { |
---|
54 | /* |
---|
55 | * Note: We do not initialize the KBD interface here since |
---|
56 | * it was initialized regardless of whether the |
---|
57 | * vga is available or not. Therefore it is initialized |
---|
58 | * in bsp_start. |
---|
59 | */ |
---|
60 | } |
---|
61 | |
---|
62 | /* |
---|
63 | * vgacons_open |
---|
64 | * |
---|
65 | * This function opens a port for communication. |
---|
66 | * |
---|
67 | * Default state is 9600 baud, 8 bits, No parity, and 1 stop bit. |
---|
68 | */ |
---|
69 | VGACONS_STATIC int vgacons_open( |
---|
70 | int major, |
---|
71 | int minor, |
---|
72 | void *arg |
---|
73 | ) |
---|
74 | { |
---|
75 | return RTEMS_SUCCESSFUL; |
---|
76 | } |
---|
77 | |
---|
78 | /* |
---|
79 | * vgacons_close |
---|
80 | * |
---|
81 | * This function shuts down the requested port. |
---|
82 | */ |
---|
83 | VGACONS_STATIC int vgacons_close( |
---|
84 | int major, |
---|
85 | int minor, |
---|
86 | void *arg |
---|
87 | ) |
---|
88 | { |
---|
89 | return(RTEMS_SUCCESSFUL); |
---|
90 | } |
---|
91 | |
---|
92 | /* |
---|
93 | * vgacons_write_polled |
---|
94 | * |
---|
95 | * This routine polls out the requested character. |
---|
96 | */ |
---|
97 | VGACONS_STATIC void vgacons_write_polled( |
---|
98 | int minor, |
---|
99 | char c |
---|
100 | ) |
---|
101 | { |
---|
102 | _IBMPC_outch( c ); |
---|
103 | if( c == '\n') |
---|
104 | _IBMPC_outch( '\r' ); /* LF = LF + CR */ |
---|
105 | } |
---|
106 | |
---|
107 | /* |
---|
108 | * vgacons_write_support_polled |
---|
109 | * |
---|
110 | * Console Termios output entry point when using polled output. |
---|
111 | * |
---|
112 | */ |
---|
113 | VGACONS_STATIC ssize_t vgacons_write_support_polled( |
---|
114 | int minor, |
---|
115 | const char *buf, |
---|
116 | size_t len |
---|
117 | ) |
---|
118 | { |
---|
119 | int nwrite = 0; |
---|
120 | |
---|
121 | /* |
---|
122 | * poll each byte in the string out of the port. |
---|
123 | */ |
---|
124 | while (nwrite < len) { |
---|
125 | vgacons_write_polled(minor, *buf++); |
---|
126 | nwrite++; |
---|
127 | } |
---|
128 | |
---|
129 | /* |
---|
130 | * return the number of bytes written. |
---|
131 | */ |
---|
132 | return nwrite; |
---|
133 | } |
---|
134 | |
---|
135 | /* |
---|
136 | * vgacons_inbyte_nonblocking_polled |
---|
137 | * |
---|
138 | * Console Termios polling input entry point. |
---|
139 | */ |
---|
140 | VGACONS_STATIC int vgacons_inbyte_nonblocking_polled( |
---|
141 | int minor |
---|
142 | ) |
---|
143 | { |
---|
144 | if( rtems_kbpoll() ) { |
---|
145 | int c = getch(); |
---|
146 | return c; |
---|
147 | } |
---|
148 | |
---|
149 | return -1; |
---|
150 | } |
---|
151 | |
---|
152 | /* |
---|
153 | * vgacons_set_attributes |
---|
154 | * |
---|
155 | * This function sets the UART channel to reflect the requested termios |
---|
156 | * port settings. |
---|
157 | */ |
---|
158 | VGACONS_STATIC int vgacons_set_attributes( |
---|
159 | int minor, |
---|
160 | const struct termios *t |
---|
161 | ) |
---|
162 | { |
---|
163 | return 0; |
---|
164 | } |
---|
165 | |
---|
166 | bool vgacons_probe( |
---|
167 | int minor |
---|
168 | ) |
---|
169 | { |
---|
170 | rtems_status_code status; |
---|
171 | static bool firstTime = true; |
---|
172 | |
---|
173 | /* |
---|
174 | * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578#c16 |
---|
175 | */ |
---|
176 | const uint8_t* volatile nb_max_row = (const uint8_t*) NB_MAX_ROW_ADDR; |
---|
177 | const uint16_t* volatile nb_max_col = (const uint16_t*) NB_MAX_COL_ADDR; |
---|
178 | if ((*nb_max_row == 0) && (*nb_max_col == 0)) { |
---|
179 | return false; |
---|
180 | } |
---|
181 | |
---|
182 | /* |
---|
183 | * If there is a video card, let's assume there is also a keyboard. |
---|
184 | * The means that we need the ISR installed in case someone wants to |
---|
185 | * use the Keyboard or PS2 Mouse. With Microwindows, the console |
---|
186 | * can be COM1 and you can still use the mouse/VGA for graphics. |
---|
187 | */ |
---|
188 | if ( firstTime ) { |
---|
189 | status = rtems_interrupt_handler_install( |
---|
190 | BSP_KEYBOARD, |
---|
191 | "vgacons", |
---|
192 | RTEMS_INTERRUPT_UNIQUE, |
---|
193 | keyboard_interrupt, |
---|
194 | NULL |
---|
195 | ); |
---|
196 | assert(status == RTEMS_SUCCESSFUL); |
---|
197 | } |
---|
198 | firstTime = false; |
---|
199 | |
---|
200 | return true; |
---|
201 | } |
---|
202 | |
---|
203 | const console_fns vgacons_fns = |
---|
204 | { |
---|
205 | libchip_serial_default_probe, /* deviceProbe */ |
---|
206 | vgacons_open, /* deviceFirstOpen */ |
---|
207 | vgacons_close, /* deviceLastClose */ |
---|
208 | vgacons_inbyte_nonblocking_polled, /* deviceRead */ |
---|
209 | vgacons_write_support_polled, /* deviceWrite */ |
---|
210 | vgacons_init, /* deviceInitialize */ |
---|
211 | vgacons_write_polled, /* deviceWritePolled */ |
---|
212 | vgacons_set_attributes, /* deviceSetAttributes */ |
---|
213 | FALSE, /* deviceOutputUsesInterrupts */ |
---|
214 | }; |
---|