source: rtems/c/src/lib/libbsp/i386/pc386/console/console.c @ 1c5ebc5

4.104.11
Last change on this file since 1c5ebc5 was 1c5ebc5, checked in by Chris Johns <chrisj@…>, on Apr 28, 2009 at 6:20:35 AM

2009-04-28 Chris Johns <chrisj@…>

  • Makefile.am: Add bspcmdline.c.
  • include/bsp.h: Add boot command line interfaces.
  • start/start.c: Save the multiboot command line. Pass the command line to boot_card.
  • start/start.S: Update for boot_card command line change.
  • startup/bspstart.c: Initialise the command line.
  • startup/bspcmdline.c: New.
  • console/console.c, ide/idecfg.c: Add boot command line support.
  • Property mode set to 100644
File size: 14.1 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-1999.
23| *  On-Line Applications Research Corporation (OAR).
24| *
25| *  The license and distribution terms for this file may be
26| *  found in found in the file LICENSE in this distribution or at
27| *  http://www.rtems.com/license/LICENSE.
28| **************************************************************************
29|
30|  $Id$
31+--------------------------------------------------------------------------*/
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <assert.h>
36#include <unistd.h>
37
38#include <bsp.h>
39#include <bsp/irq.h>
40#include <rtems/libio.h>
41#include <termios.h>
42#include <uart.h>
43#include <libcpu/cpuModel.h>
44
45#include <rtems/mw_uid.h>
46#include "mouse_parser.h"
47
48/*
49 * Possible value for console input/output :
50 *      BSP_CONSOLE_PORT_CONSOLE
51 *      BSP_UART_COM1
52 *      BSP_UART_COM2
53 *
54 * Note:
55 *   1. Currently BSPPrintkPort, cannot be assigned to COM2,
56 *      it will be fixed soon.
57 *
58 *   2. If both BSPConsolePort and BSPPrintkport are assigned
59 *      to same serial device it does not work that great
60 */
61
62#if (USE_COM1_AS_CONSOLE == 1)
63int BSPConsolePort = BSP_UART_COM1;
64int BSPPrintkPort  = BSP_UART_COM1;
65#else
66int BSPConsolePort = BSP_CONSOLE_PORT_CONSOLE;
67int BSPPrintkPort  = BSP_CONSOLE_PORT_CONSOLE;
68#endif
69
70int BSPBaseBaud    = 115200;
71
72extern BSP_polling_getchar_function_type BSP_poll_char;
73extern int getch( void );
74extern void kbd_init( void );
75
76/*-------------------------------------------------------------------------+
77| External Prototypes
78+--------------------------------------------------------------------------*/
79extern void keyboard_interrupt(void );
80extern void keyboard_interrupt_wrapper(void *);
81extern char BSP_wait_polled_input(void);
82extern void _IBMPC_initVideo(void);
83
84static int  conSetAttr(int minor, const struct termios *);
85static void isr_on(const rtems_irq_connect_data *);
86static void isr_off(const rtems_irq_connect_data *);
87static int  isr_is_on(const rtems_irq_connect_data *);
88
89extern int rtems_kbpoll( void );
90
91static rtems_irq_connect_data console_isr_data = {BSP_KEYBOARD,
92                                                  keyboard_interrupt_wrapper,
93                                                  0,
94                                                  isr_on,
95                                                  isr_off,
96                                                  isr_is_on};
97
98static void
99isr_on(const rtems_irq_connect_data *unused)
100{
101  return;
102}
103
104static void
105isr_off(const rtems_irq_connect_data *unused)
106{
107  return;
108}
109
110static int
111isr_is_on(const rtems_irq_connect_data *irq)
112{
113  return BSP_irq_enabled_at_i8259s(irq->name);
114}
115
116extern int  rtems_kbpoll( void );
117
118static int
119ibmpc_console_write(int minor, const char *buf, int len)
120{
121  int count;
122  for (count = 0; count < len; count++)
123  {
124    _IBMPC_outch( buf[ count ] );
125    if( buf[ count ] == '\n')
126      _IBMPC_outch( '\r' );            /* LF = LF + CR */
127  }
128  return 0;
129}
130
131int kbd_poll_read( int minor )
132{
133  if( rtems_kbpoll() )
134  {
135     int c = getch();
136     return c;
137  }
138  return -1;
139}
140
141/*-------------------------------------------------------------------------+
142| Console device driver INITIALIZE entry point.
143+--------------------------------------------------------------------------+
144| Initilizes the I/O console (keyboard + VGA display) driver.
145+--------------------------------------------------------------------------*/
146rtems_device_driver
147console_initialize(rtems_device_major_number major,
148                   rtems_device_minor_number minor,
149                   void                      *arg)
150{
151  rtems_status_code status;
152  const char* mode;
153 
154  /*
155   * Check the command line for the type of mode
156   * the consol is.
157   */
158  mode = bsp_cmdline_arg ("--console=");
159
160  if (mode)
161  {
162    mode += sizeof ("--console=") - 1;
163    if (strncmp (mode, "console", sizeof ("console") - 1) == 0)
164    {
165      BSPConsolePort = BSP_CONSOLE_PORT_CONSOLE;
166      BSPPrintkPort  = BSP_CONSOLE_PORT_CONSOLE;
167    }
168    else if (strncmp (mode, "com1", sizeof ("com1") - 1) == 0)
169    {
170      BSPConsolePort = BSP_UART_COM1;
171      BSPPrintkPort  = BSP_UART_COM1;
172    }
173    else if (strncmp (mode, "com2", sizeof ("com2") - 1) == 0)
174    {
175      BSPConsolePort = BSP_UART_COM2;
176      BSPPrintkPort  = BSP_UART_COM2;
177    }
178  }
179 
180  /* Initialize the KBD interface */
181  kbd_init();
182
183  /*
184   * Set up TERMIOS
185   */
186  rtems_termios_initialize ();
187
188#ifdef RTEMS_RUNTIME_CONSOLE_SELECT
189  /*
190   * If no video card, fall back to serial port console
191   */
192#include <crt.h>
193  if((BSPConsolePort == BSP_CONSOLE_PORT_CONSOLE)
194   && (*(unsigned char*) NB_MAX_ROW_ADDR == 0)
195   && (*(unsigned short*)NB_MAX_COL_ADDR == 0)) {
196    BSPConsolePort = BSP_UART_COM2;
197    BSPPrintkPort  = BSP_UART_COM1;
198  }
199#endif
200
201  /*
202   *  The video was initialized in the start.s code and does not need
203   *  to be reinitialized.
204   */
205
206  if(BSPConsolePort == BSP_CONSOLE_PORT_CONSOLE)
207    {
208      /* Install keyboard interrupt handler */
209      status = BSP_install_rtems_irq_handler(&console_isr_data);
210
211    if (!status)
212        {
213          printk("Error installing keyboard interrupt handler!\n");
214          rtems_fatal_error_occurred(status);
215        }
216
217      status = rtems_io_register_name("/dev/console", major, 0);
218      if (status != RTEMS_SUCCESSFUL)
219        {
220          printk("Error registering console device!\n");
221          rtems_fatal_error_occurred(status);
222        }
223      printk("Initialized console on port CONSOLE\n\n");
224    }
225  else
226    {
227      /*
228       * Do device-specific initialization
229       */
230      /* 9600-8-N-1 */
231      BSP_uart_init(BSPConsolePort, 9600, CHR_8_BITS, 0, 0, 0);
232
233      /* Set interrupt handler */
234      if(BSPConsolePort == BSP_UART_COM1)
235        {
236             console_isr_data.name = BSP_UART_COM1_IRQ;
237        console_isr_data.hdl  = BSP_uart_termios_isr_com1;
238
239        }
240      else
241           {
242          assert(BSPConsolePort == BSP_UART_COM2);
243          console_isr_data.name = BSP_UART_COM2_IRQ;
244          console_isr_data.hdl  = BSP_uart_termios_isr_com2;
245        }
246      status = BSP_install_rtems_irq_handler(&console_isr_data);
247
248      if (!status){
249          printk("Error installing serial console interrupt handler!\n");
250          rtems_fatal_error_occurred(status);
251      }
252      /*
253       * Register the device
254       */
255      status = rtems_io_register_name ("/dev/console", major, 0);
256      if (status != RTEMS_SUCCESSFUL)
257        {
258          printk("Error registering console device!\n");
259          rtems_fatal_error_occurred (status);
260        }
261
262      if(BSPConsolePort == BSP_UART_COM1)
263        {
264          printk("Initialized console on port COM1 9600-8-N-1\n\n");
265        }
266      else
267        {
268          printk("Initialized console on port COM2 9600-8-N-1\n\n");
269        }
270
271      if(BSPPrintkPort == BSP_UART_COM1)
272        {
273          printk("Warning : This will be the last message on console\n");
274
275          /*
276           * FIXME: cast below defeats the very idea of having
277           * function pointer types defined
278           */
279          BSP_output_char = (BSP_output_char_function_type)
280                              BSP_output_char_via_serial;
281          BSP_poll_char   = (BSP_polling_getchar_function_type)
282                              BSP_poll_char_via_serial;
283        }
284      else if(BSPPrintkPort != BSP_CONSOLE_PORT_CONSOLE)
285        {
286           printk("illegal assignement of printk channel");
287         rtems_fatal_error_occurred (status);
288        }
289
290    }
291  return RTEMS_SUCCESSFUL;
292} /* console_initialize */
293
294static int console_open_count = 0;
295
296static int console_last_close(int major, int minor, void *arg)
297{
298  BSP_remove_rtems_irq_handler (&console_isr_data);
299
300  return 0;
301}
302
303static int ser_console_first_open(int major, int minor, void *arg)
304{
305  /*
306   * Pass data area info down to driver
307   */
308  BSP_uart_termios_set(BSPConsolePort,
309                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
310
311  /* Enable interrupts  on channel */
312  BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS);
313
314  return 0;
315}
316
317/*-------------------------------------------------------------------------+
318| Console device driver OPEN entry point
319+--------------------------------------------------------------------------*/
320rtems_device_driver
321console_open(rtems_device_major_number major,
322                rtems_device_minor_number minor,
323                void                      *arg)
324{
325  rtems_status_code              status;
326  static rtems_termios_callbacks cb =
327  {
328    NULL,                     /* firstOpen */
329    console_last_close,       /* lastClose */
330    NULL,          /* pollRead */
331    BSP_uart_termios_write_com1, /* write */
332    conSetAttr,               /* setAttributes */
333    NULL,                     /* stopRemoteTx */
334    NULL,                     /* startRemoteTx */
335    1                         /* outputUsesInterrupts */
336  };
337
338  if(BSPConsolePort == BSP_CONSOLE_PORT_CONSOLE)
339    {
340
341      /* Let's set the routines for termios to poll the
342       * Kbd queue for data
343       */
344      cb.pollRead = kbd_poll_read;
345      cb.outputUsesInterrupts = 0;
346      /* write the "echo" if it is on */
347      cb.write = ibmpc_console_write;
348
349      cb.setAttributes = NULL;
350      ++console_open_count;
351      status = rtems_termios_open (major, minor, arg, &cb);
352      if(status != RTEMS_SUCCESSFUL)
353      {
354         printk("Error openning console device\n");
355      }
356      return status;
357    }
358
359  if(BSPConsolePort == BSP_UART_COM2)
360    {
361      cb.write = BSP_uart_termios_write_com2;
362    }
363
364  cb.firstOpen = ser_console_first_open;
365
366  status = rtems_termios_open (major, minor, arg, &cb);
367
368  if(status != RTEMS_SUCCESSFUL)
369    {
370      printk("Error openning console device\n");
371      return status;
372    }
373
374  return RTEMS_SUCCESSFUL;
375}
376
377/*-------------------------------------------------------------------------+
378| Console device driver CLOSE entry point
379+--------------------------------------------------------------------------*/
380rtems_device_driver
381console_close(rtems_device_major_number major,
382              rtems_device_minor_number minor,
383              void                      *arg)
384{
385   return rtems_termios_close (arg);
386} /* console_close */
387
388/*-------------------------------------------------------------------------+
389| Console device driver READ entry point.
390+--------------------------------------------------------------------------+
391| Read characters from the I/O console. We only have stdin.
392+--------------------------------------------------------------------------*/
393rtems_device_driver
394console_read(rtems_device_major_number major,
395             rtems_device_minor_number minor,
396             void                      *arg)
397{
398 return rtems_termios_read( arg );
399} /* console_read */
400
401/*-------------------------------------------------------------------------+
402| Console device driver WRITE entry point.
403+--------------------------------------------------------------------------+
404| Write characters to the I/O console. Stderr and stdout are the same.
405+--------------------------------------------------------------------------*/
406rtems_device_driver
407console_write(rtems_device_major_number major,
408              rtems_device_minor_number minor,
409              void                    * arg)
410{
411  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
412  char                  *buffer  = rw_args->buffer;
413  int                    maximum  = rw_args->count;
414
415  if(BSPConsolePort != BSP_CONSOLE_PORT_CONSOLE)
416    {
417      return rtems_termios_write (arg);
418    }
419
420  /* write data to VGA */
421  ibmpc_console_write( minor, buffer, maximum );
422  rw_args->bytes_moved = maximum;
423  return RTEMS_SUCCESSFUL;
424} /* console_write */
425
426extern int vt_ioctl( unsigned int cmd, unsigned long arg);
427
428/*
429 * Handle ioctl request.
430 */
431rtems_device_driver
432console_control(rtems_device_major_number major,
433                rtems_device_minor_number minor,
434                void                      * arg
435)
436{
437        rtems_libio_ioctl_args_t *args = arg;
438        switch (args->command)
439        {
440           default:
441      if( vt_ioctl( args->command, (unsigned long)args->buffer ) != 0 )
442          return rtems_termios_ioctl (arg);
443                break;
444
445      case MW_UID_REGISTER_DEVICE:
446      printk( "SerialMouse: reg=%s\n", args->buffer );
447      register_kbd_msg_queue( args->buffer, 0 );
448                break;
449
450      case MW_UID_UNREGISTER_DEVICE:
451      unregister_kbd_msg_queue( 0 );
452                break;
453   }
454        args->ioctl_return = 0;
455   return RTEMS_SUCCESSFUL;
456}
457
458static int
459conSetAttr(int minor, const struct termios *t)
460{
461  unsigned long baud, databits, parity, stopbits;
462
463  baud = termios_baud_to_number(t->c_cflag & CBAUD);
464  if ( baud > 115200 )
465    rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
466
467  if (t->c_cflag & PARENB) {
468    /* Parity is enabled */
469    if (t->c_cflag & PARODD) {
470      /* Parity is odd */
471      parity = PEN;
472    }
473    else {
474      /* Parity is even */
475      parity = PEN | EPS;
476    }
477  }
478  else {
479    /* No parity */
480    parity = 0;
481  }
482
483  switch (t->c_cflag & CSIZE) {
484    case CS5: databits = CHR_5_BITS; break;
485    case CS6: databits = CHR_6_BITS; break;
486    case CS7: databits = CHR_7_BITS; break;
487    default: /* just to avoid warnings -- all cases are covered. */
488    case CS8: databits = CHR_8_BITS; break;
489   }
490
491  if (t->c_cflag & CSTOPB) {
492    /* 2 stop bits */
493    stopbits = STB;
494  }
495  else {
496    /* 1 stop bit */
497    stopbits = 0;
498  }
499
500  BSP_uart_set_attributes(BSPConsolePort, baud, databits, parity, stopbits);
501
502  return 0;
503}
504
505void keyboard_interrupt_wrapper(void *unused){
506  keyboard_interrupt();
507}
508
509/*
510 * BSP initialization
511 */
512
513BSP_output_char_function_type BSP_output_char =
514                       (BSP_output_char_function_type) _IBMPC_outch;
515
516BSP_polling_getchar_function_type BSP_poll_char = BSP_wait_polled_input;
Note: See TracBrowser for help on using the repository browser.