source: rtems/c/src/lib/libbsp/i386/pc386/console/console.c @ 5d18fb0

4.104.114.84.95
Last change on this file since 5d18fb0 was 5d18fb0, checked in by Joel Sherrill <joel.sherrill@…>, on 06/27/98 at 18:51:49

PC386 BSP enhancements from Aleksey Romanov (Quality Quorum
<qqi@…>). Unfortunately after merging these,
the pc386 will not boot using grub for for. It still does not
work using netboot for me. Here is his summary of changes:

rtems/c/src/lib/libbsp/i386/pc386/Makefile.in

Added support for new sub-directory

rtems/c/src/lib/libbsp/i386/pc386/bsp_specs

Made possible to build COFF image

rtems/c/src/lib/libbsp/i386/pc386/console/console.c

Added support for serial consoles, selectable by patching
binary image, added assert(), use _IBMPC_inch_sleep()
instaed of _IMBPC_inch()

rtems/c/src/lib/libbsp/i386/pc386/console/inch.c

Added _IMBPC_inch_sleep()

rtems/c/src/lib/libbsp/i386/pc386/console/outch.c

Oops - just formatting

rtems/c/src/lib/libbsp/i386/pc386/include/Makefile.in

Added support for new files

rtems/c/src/lib/libbsp/i386/pc386/include/bsp.h

Added support for new features

rtems/c/src/lib/libbsp/i386/pc386/include/pc386uart.h

New file: definitions for serial ports

rtems/c/src/lib/libbsp/i386/pc386/include/pcibios.h

New file: definitions for PCI BIOS

rtems/c/src/lib/libbsp/i386/pc386/pc386dev/Makefile.in

New file: makefile in new directory

rtems/c/src/lib/libbsp/i386/pc386/pc386dev/i386-stub-glue.c

New file: i386-stub interface

rtems/c/src/lib/libbsp/i386/pc386/pc386dev/i386-stub.c

New file: i386-stub itself

rtems/c/src/lib/libbsp/i386/pc386/pc386dev/pc386uart.c

New file: serial ports

rtems/c/src/lib/libbsp/i386/pc386/pc386dev/pcibios.c

New file: PCI BIOS support

rtems/c/src/lib/libbsp/i386/pc386/start/start.s

Commented out DEBUG_EARLY stuff, everything is working fine

rtems/c/src/lib/libbsp/i386/pc386/start/start16.s

Cleaned up

rtems/c/src/lib/libbsp/i386/pc386/startup/bspstart.c

Added call to console_resereve_resources

rtems/c/src/lib/libbsp/i386/pc386/startup/exit.c

Added support for serial console

rtems/c/src/lib/libbsp/i386/pc386/startup/ldsegs.s

Fixed typo in comments

rtems/c/src/lib/libbsp/i386/pc386/tools/Makefile.in

Changed to reflect cnages in code

rtems/c/src/lib/libbsp/i386/pc386/tools/bin2boot.c

Trivialized, problem - I do not know how to make patch
remove obsolete files - there are a lot of them there

rtems/c/src/lib/libbsp/i386/pc386/tools/binpatch.c

New file: utility to do binary patches

rtems/c/src/lib/libbsp/i386/pc386/wrapup/Makefile.in

Added support for new directory

rtems/make/custom/pc386.cfg

Add COFF image building

  • Property mode set to 100644
File size: 10.5 KB
Line 
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-1998.
23| *  On-Line Applications Research Corporation (OAR).
24| *  Copyright assigned to U.S. Government, 1994.
25| *
26| *  The license and distribution terms for this file may be
27| *  found in found in the file LICENSE in this distribution or at
28| *  http://www.OARcorp.com/rtems/license.html.
29| **************************************************************************
30|
31|  $Id$
32+--------------------------------------------------------------------------*/
33
34
35#include <stdlib.h>
36#include <assert.h>
37
38#include <bsp.h>
39#include <irq.h>
40#include <rtems/libio.h>
41#include <termios.h>
42#include <pc386uart.h>
43
44int PC386ConsolePort = PC386_CONSOLE_PORT_CONSOLE;
45
46static int conSetAttr(int minor, const struct termios *);
47
48/*-------------------------------------------------------------------------+
49| Constants
50+--------------------------------------------------------------------------*/
51#define KEYBOARD_IRQ  0x01  /* Keyboard IRQ. */
52
53
54/*-------------------------------------------------------------------------+
55| External Prototypes
56+--------------------------------------------------------------------------*/
57extern rtems_isr _IBMPC_keyboard_isr(rtems_vector_number);
58       /* keyboard (IRQ 0x01) Interrupt Service Routine (defined in 'inch.c') */
59
60
61void console_reserve_resources(rtems_configuration_table *conf)
62{
63  if(PC386ConsolePort != PC386_CONSOLE_PORT_CONSOLE)
64    {
65      rtems_termios_reserve_resources(conf, 1);
66    }
67  return;
68}
69
70void __assert(const char *file, int line, const char *msg)
71{
72  printk("assert failed: %s: ", file);
73  printk("%d: ", line);
74  printk("%s\n", msg);
75
76  exit(1);
77
78  return;
79}
80
81/*-------------------------------------------------------------------------+
82| Console device driver INITIALIZE entry point.
83+--------------------------------------------------------------------------+
84| Initilizes the I/O console (keyboard + VGA display) driver.
85+--------------------------------------------------------------------------*/
86rtems_device_driver
87console_initialize(rtems_device_major_number major,
88                   rtems_device_minor_number minor,
89                   void                      *arg)
90{
91  rtems_status_code status;
92
93  /* Initialize video */
94  _IBMPC_initVideo();
95
96  if(PC386ConsolePort == PC386_CONSOLE_PORT_CONSOLE)
97    {
98
99      /* Install keyboard interrupt handler */
100      status = PC386_installRtemsIrqHandler(KEYBOARD_IRQ, _IBMPC_keyboard_isr);
101
102      if (status != RTEMS_SUCCESSFUL)
103        {
104          printk("Error installing keyboard interrupt handler!\n");
105          rtems_fatal_error_occurred(status);
106        }
107     
108      status = rtems_io_register_name("/dev/console", major, 0);
109      if (status != RTEMS_SUCCESSFUL)
110        {
111          printk("Error registering console device!\n");
112          rtems_fatal_error_occurred(status);
113        }
114      printk("Initialized console on port CONSOLE\n\n");
115    }
116  else
117    {
118      /*
119       * Set up TERMIOS
120       */
121      rtems_termios_initialize ();
122     
123      /*
124       * Do device-specific initialization
125       */
126     
127      /* 9600-8-N-1 */
128      PC386_uart_init(PC386ConsolePort, 9600, 0);
129     
130     
131      /* Set interrupt handler */
132      if(PC386ConsolePort == PC386_UART_COM1)
133        {
134          status = PC386_installRtemsIrqHandler(PC386_UART_COM1_IRQ,
135                                                PC386_uart_termios_isr_com1);
136        }
137      else
138        {
139          assert(PC386ConsolePort == PC386_UART_COM2);
140
141          status = PC386_installRtemsIrqHandler(PC386_UART_COM2_IRQ,
142                                                PC386_uart_termios_isr_com2);
143        }
144      /*
145       * Register the device
146       */
147      status = rtems_io_register_name ("/dev/console", major, 0);
148      if (status != RTEMS_SUCCESSFUL)
149        {
150          printk("Error registering console device!\n");
151          rtems_fatal_error_occurred (status);
152        }
153
154      if(PC386ConsolePort == PC386_UART_COM1)
155        {
156          printk("Initialized console on port COM1 9600-8-N-1\n\n");
157        }
158      else
159        {
160          printk("Initialized console on port COM2 9600-8-N-1\n\n");
161        }
162    }
163 
164  return RTEMS_SUCCESSFUL;
165} /* console_initialize */
166
167
168/*-------------------------------------------------------------------------+
169| Console device driver OPEN entry point
170+--------------------------------------------------------------------------*/
171rtems_device_driver
172console_open(rtems_device_major_number major,
173                rtems_device_minor_number minor,
174                void                      *arg)
175{
176  rtems_status_code              status;
177  static rtems_termios_callbacks cb =
178  {
179    NULL,                     /* firstOpen */
180    NULL,                     /* lastClose */
181    NULL,                     /* pollRead */
182    PC386_uart_termios_write_com1, /* write */
183    conSetAttr,               /* setAttributes */
184    NULL,                     /* stopRemoteTx */
185    NULL,                     /* startRemoteTx */
186    1                         /* outputUsesInterrupts */
187  };
188
189  if(PC386ConsolePort == PC386_CONSOLE_PORT_CONSOLE)
190    {
191      return RTEMS_SUCCESSFUL;
192    }
193
194  if(PC386ConsolePort == PC386_UART_COM2)
195    {
196      cb.write = PC386_uart_termios_write_com2;
197    }
198
199  status = rtems_termios_open (major, minor, arg, &cb);
200
201  if(status != RTEMS_SUCCESSFUL)
202    {
203      printk("Error openning console device\n");
204      return status;
205    }
206
207  /*
208   * Pass data area info down to driver
209   */
210  PC386_uart_termios_set(PC386ConsolePort,
211                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
212 
213  /* Enable interrupts  on channel */
214  PC386_uart_intr_ctrl(PC386ConsolePort, PC386_UART_INTR_CTRL_TERMIOS);
215
216  return RTEMS_SUCCESSFUL;
217}
218
219/*-------------------------------------------------------------------------+
220| Console device driver CLOSE entry point
221+--------------------------------------------------------------------------*/
222rtems_device_driver
223console_close(rtems_device_major_number major,
224              rtems_device_minor_number minor,
225              void                      *arg)
226{
227  if(PC386ConsolePort != PC386_CONSOLE_PORT_CONSOLE)
228    {
229      return rtems_termios_close (arg);
230    }
231
232  return RTEMS_SUCCESSFUL;
233} /* console_close */
234
235 
236/*-------------------------------------------------------------------------+
237| Console device driver READ entry point.
238+--------------------------------------------------------------------------+
239| Read characters from the I/O console. We only have stdin.
240+--------------------------------------------------------------------------*/
241rtems_device_driver
242console_read(rtems_device_major_number major,
243             rtems_device_minor_number minor,
244             void                      *arg)
245{
246  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
247  char                  *buffer  = rw_args->buffer;
248  int            count, maximum  = rw_args->count;
249
250  if(PC386ConsolePort != PC386_CONSOLE_PORT_CONSOLE)
251    {
252      return rtems_termios_read (arg);
253    }
254 
255  for (count = 0; count < maximum; count++)
256  {
257    /* Get character */
258    buffer[count] = _IBMPC_inch_sleep();
259
260    /* Echo character to screen */
261    _IBMPC_outch(buffer[count]);
262    if (buffer[count] == '\r')
263      {
264        _IBMPC_outch('\n');  /* CR = CR + LF */
265      }
266
267    if (buffer[count] == '\n' || buffer[count] == '\r')
268    {
269      /* What if this goes past the end of the buffer?  We're hosed. [bhc] */
270      buffer[count++]  = '\n';
271      buffer[count]    = '\0';
272      break;
273    }
274  }
275 
276  rw_args->bytes_moved = count;
277  return ((count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED);
278} /* console_read */
279 
280
281/*-------------------------------------------------------------------------+
282| Console device driver WRITE entry point.
283+--------------------------------------------------------------------------+
284| Write characters to the I/O console. Stderr and stdout are the same.
285+--------------------------------------------------------------------------*/
286rtems_device_driver
287console_write(rtems_device_major_number major,
288              rtems_device_minor_number minor,
289              void                    * arg)
290{
291  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
292  char                  *buffer  = rw_args->buffer;
293  int            count, maximum  = rw_args->count;
294
295  if(PC386ConsolePort != PC386_CONSOLE_PORT_CONSOLE)
296    {
297      return rtems_termios_write (arg);
298    }
299 
300  for (count = 0; count < maximum; count++)
301  {
302    _IBMPC_outch(buffer[count]);
303    if (buffer[count] == '\n')
304      _IBMPC_outch('\r');            /* LF = LF + CR */
305  }
306
307  rw_args->bytes_moved = maximum;
308  return RTEMS_SUCCESSFUL;
309} /* console_write */
310
311
312 
313/*
314 * Handle ioctl request.
315 */
316rtems_device_driver
317console_control(rtems_device_major_number major,
318                rtems_device_minor_number minor,
319                void                      * arg
320)
321{
322  if(PC386ConsolePort != PC386_CONSOLE_PORT_CONSOLE)
323    {
324      return rtems_termios_ioctl (arg);
325    }
326
327  return RTEMS_SUCCESSFUL;
328}
329
330static int
331conSetAttr(int minor, const struct termios *t)
332{
333  int baud;
334
335  switch (t->c_cflag & CBAUD)
336    {
337    case B50:   
338      baud = 50;
339      break;
340    case B75:   
341      baud = 75;       
342      break;
343    case B110: 
344      baud = 110;       
345      break;
346    case B134: 
347      baud = 134;       
348      break;
349    case B150: 
350      baud = 150;       
351      break;
352    case B200:
353      baud = 200;       
354      break;
355    case B300: 
356      baud = 300;
357      break;
358    case B600: 
359      baud = 600;       
360      break;
361    case B1200:
362      baud = 1200;
363      break;
364    case B1800:
365      baud = 1800;     
366      break;
367    case B2400:
368      baud = 2400;
369      break;
370    case B4800:
371      baud = 4800;
372      break;
373    case B9600:
374      baud = 9600;
375      break;
376    case B19200:
377      baud = 19200;
378      break;
379    case B38400:
380      baud = 38400;
381      break;
382    case B57600:       
383      baud = 57600;
384      break;
385    case B115200:
386      baud = 115200;
387      break;
388    default:
389      baud = 0;
390      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
391      return 0;
392    }
393
394  PC386_uart_set_baud(PC386ConsolePort, baud);
395
396  return 0;
397}
398
399
400
401
402
403
404
405
406
Note: See TracBrowser for help on using the repository browser.