source: rtems/c/src/lib/libbsp/i386/pc386/console/console_select.c @ 014292a1

5
Last change on this file since 014292a1 was 014292a1, checked in by Chris Johns <chrisj@…>, on 04/08/16 at 08:39:38

i386/pc386: Add support for the gdb stub to use available console drivers.

Move the gdb stub from the i386 UART code to use the libchip drivers.

Use any ports discovered during the probes.

Add gdb control to the boot command line.

Change the device naming to the full device path, not a partial path.
For example /dev/com1.

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup Console
5 *
6 * @brief pc386 console select
7 *
8 * This file contains a routine to select the console based upon a number
9 * of criteria.
10 */
11
12/*
13 *  COPYRIGHT (c) 2011-2012, 2016.
14 *  On-Line Applications Research Corporation (OAR).
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.org/license/LICENSE.
19 */
20
21#include <stdlib.h>
22#include <termios.h>
23
24#include <bsp.h>
25#include <libchip/serial.h>
26#include <rtems/libio.h>
27#include <rtems/console.h>
28#include <rtems/termiostypes.h>
29#include <bsp/bspimpl.h>
30
31#include "../../../shared/console_private.h"
32#ifdef RTEMS_RUNTIME_CONSOLE_SELECT
33  #include <crt.h>
34#endif
35
36/*
37 * Method to return true if the device associated with the
38 * minor number probs available.
39 */
40static bool bsp_Is_Available( rtems_device_minor_number minor )
41{
42  console_tbl  *cptr = Console_Port_Tbl[minor];
43
44  /*
45   * First perform the configuration dependent probe, then the
46   * device dependent probe
47   */
48  if ((!cptr->deviceProbe || cptr->deviceProbe(minor)) &&
49       cptr->pDeviceFns->deviceProbe(minor)) {
50    return true;
51  }
52  return false;
53}
54
55/*
56 * Method to return the first available device.
57 */
58static rtems_device_minor_number bsp_First_Available_Device( void )
59{
60  rtems_device_minor_number minor;
61
62  for (minor=0; minor < Console_Port_Count ; minor++) {
63    console_tbl  *cptr = Console_Port_Tbl[minor];
64
65    /*
66     * First perform the configuration dependent probe, then the
67     * device dependent probe
68     */
69
70    if ((!cptr->deviceProbe || cptr->deviceProbe(minor)) &&
71         cptr->pDeviceFns->deviceProbe(minor)) {
72      return minor;
73    }
74  }
75
76  /*
77   *  Error No devices were found.  We will want to bail here.
78   */
79  rtems_fatal_error_occurred(RTEMS_IO_ERROR);
80}
81
82static bool parse_printk_or_console(
83  const char                *param,
84  rtems_device_minor_number *minor_out
85)
86{
87  static const char         *opt;
88  const char                *option;
89  const char                *comma;
90  size_t                     length;
91  size_t                     index;
92  rtems_device_minor_number  minor;
93  console_tbl               *conscfg;
94
95  /*
96   * Check the command line for the type of mode the console is.
97   */
98  opt = bsp_cmdline_arg(param);
99  if ( !opt ) {
100    return false;
101  }
102
103  /*
104   * Fine the length, there can be more command line visible.
105   */
106  length = 0;
107  while ((opt[length] != ' ') && (opt[length] != '\0')) {
108    ++length;
109    if (length > NAME_MAX) {
110      printk("invalid option (%s): too long\n", param);
111      return false;
112    }
113  }
114
115  /*
116   * Only match up to a comma or NULL
117   */
118  index = 0;
119  while ((opt[index] != '=') && (index < length)) {
120    ++index;
121  }
122
123  if (opt[index] != '=') {
124    printk("invalid option (%s): no equals\n", param);
125    return false;
126  }
127
128  ++index;
129  option = &opt[index];
130
131  while ((opt[index] != ',') && (index < length)) {
132    ++index;
133  }
134
135  if (opt[index] == ',')
136    comma = &opt[index];
137  else
138    comma = NULL;
139
140  length = &opt[index] - option;
141
142  conscfg = console_find_console_entry( option, length, &minor );
143  if ( conscfg == NULL ) {
144    return false;
145  }
146
147  *minor_out = minor;
148  if (comma) {
149    option = comma + 1;
150    if (strncmp (option, "115200", sizeof ("115200") - 1) == 0)
151      conscfg->pDeviceParams = (void *)115200;
152    else if (strncmp (option, "57600", sizeof ("57600") - 1) == 0)
153      conscfg->pDeviceParams = (void *)57600;
154    else if (strncmp (option, "38400", sizeof ("38400") - 1) == 0)
155      conscfg->pDeviceParams = (void *)38400;
156    else if (strncmp (option, "19200", sizeof ("19200") - 1) == 0)
157      conscfg->pDeviceParams = (void *)19200;
158    else if (strncmp (option, "9600", sizeof ("9600") - 1) == 0)
159      conscfg->pDeviceParams = (void *)9600;
160    else if (strncmp (option, "4800", sizeof ("4800") - 1) == 0)
161      conscfg->pDeviceParams = (void *)4800;
162  }
163
164  return true;
165}
166
167/*
168 * Helper to retrieve device name
169 */
170static inline const char *get_name(
171  rtems_device_minor_number  minor
172)
173{
174  return Console_Port_Tbl[minor]->sDeviceName;
175}
176
177/*
178 * Parse the arguments early so the printk and console ports are
179 * set appropriately.
180 */
181void pc386_parse_console_arguments(void)
182{
183  rtems_device_minor_number minor;
184  rtems_device_minor_number minor_console = 0;
185  rtems_device_minor_number minor_printk = 0;
186
187  /*
188   * Assume that if only --console is specified, that printk() should
189   * follow that selection by default.
190   */
191  if ( parse_printk_or_console( "--console=", &minor ) ) {
192    minor_console = minor;
193    minor_printk = minor;
194  }
195
196  /*
197   * But if explicitly specified, attempt to honor it.
198   */
199  if ( parse_printk_or_console( "--printk=",  &minor ) ) {
200    minor_printk = minor;
201  }
202
203  printk( "Console: %s printk: %s\n",
204          get_name(minor_console),get_name(minor_printk) );
205
206  /*
207   * Any output after this can cause problems until termios is initialised.
208   */
209  Console_Port_Minor = minor_console;
210  BSPPrintkPort = minor_printk;
211}
212
213/*
214 *  This handles the selection of the console after the devices are
215 *  initialized.
216 */
217void bsp_console_select(void)
218{
219  #ifdef RTEMS_RUNTIME_CONSOLE_SELECT
220    /*
221     * WARNING: This code is really needed any more and should be removed.
222     *          references to COM1 and COM2 like they are wrong.
223     */
224    if ( BSP_runtime_console_select )
225      BSP_runtime_console_select(&BSPPrintkPort, &Console_Port_Minor);
226
227    /*
228     * If no video card, fall back to serial port console
229     */
230    if((Console_Port_Minor == BSP_CONSOLE_VGA)
231     && (*(unsigned char*) NB_MAX_ROW_ADDR == 0)
232     && (*(unsigned short*)NB_MAX_COL_ADDR == 0)) {
233      Console_Port_Minor = BSP_CONSOLE_COM2;
234      BSPPrintkPort      = BSP_CONSOLE_COM1;
235    }
236  #endif
237
238  /*
239   * If the device that was selected isn't available then
240   * let the user know and select the first available device.
241   */
242  if ( !bsp_Is_Available( Console_Port_Minor ) ) {
243    printk(
244      "Error finding %s setting console to first available\n",
245      get_name(Console_Port_Minor)
246    );
247    Console_Port_Minor = bsp_First_Available_Device();
248  }
249}
Note: See TracBrowser for help on using the repository browser.