summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/i386/pc386/startup/bspstart.c
blob: 0559fbe0659425f38b919c5eb9de932b8a2c976d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
 * @file
 *
 * This file contains the PC386 BSP startup package. It includes application,
 * board, and monitor specific initialization and configuration.
 */

/*
 * This file was initially written by Joel Sherrill as part of the go32 BSP.
 * It was subsequently adapted as part of the pc386 BSP by developers from
 * the NavIST Group in 1997.
 *
 * Copyright (c) 2016.
 * Chris Johns <chrisj@rtems.org>
 *
 * COPYRIGHT (c) 1989-2008, 2016.
 * On-Line Applications Research Corporation (OAR).
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 *
 * (C) Copyright 1997 -
 * - NavIST Group - Real-Time Distributed Systems and Industrial Automation
 * Instituto Superior Tecnico * Lisboa * PORTUGAL (http://pandora.ist.utl.pt)
 *
 * NavISY Disclaimer:
 * This file is provided "AS IS" without warranty of any kind, either
 * expressed or implied.
 */

#include <bsp.h>
#include <bsp/bspimpl.h>
#include <bsp/irq.h>
#include <rtems/pci.h>
#include <libcpu/cpuModel.h>

/*
 * PCI Bus Configuration
 */
rtems_pci_config_t BSP_pci_configuration = {
  (volatile unsigned char*)0,
  (volatile unsigned char*)0,
  NULL
};

/*
 * Helper to initialize the PCI Bus
 */
static void bsp_pci_initialize_helper(void)
{
#if (BSP_IS_EDISON == 0)
  const pci_config_access_functions *pci_accessors;

  pci_accessors = pci_bios_initialize();
  if (pci_accessors != NULL) {
    printk("PCI bus: using PCI BIOS interface\n");
    BSP_pci_configuration.pci_functions = pci_accessors;
    return;
  }

  pci_accessors = pci_io_initialize();
  if (pci_accessors != NULL) {
    printk("PCI bus: using PCI I/O interface\n");
    BSP_pci_configuration.pci_functions = pci_accessors;
    return;
  }

  printk("PCI bus: could not initialize PCI BIOS interface\n");
#endif
}

/*-------------------------------------------------------------------------+
|         Function: bsp_start
|      Description: Called before main is invoked.
| Global Variables: None.
|        Arguments: None.
|          Returns: Nothing.
+--------------------------------------------------------------------------*/
static void bsp_start_default( void )
{
  /*
   * Turn off watchdog
   */
#if (BSP_IS_EDISON == 1)
  volatile uint32_t *edison_wd = (volatile uint32_t *)0xff009000;
  *edison_wd = 0x11f8;
#endif

  /*
   * Calibrate variable for 1ms-loop (see timer.c)
   */
#if (BSP_IS_EDISON == 0)
  Calibrate_loop_1ms();
#endif

  /*
   * Init rtems interrupt management
   */
  rtems_irq_mngt_init();

  /*
   * Init rtems exceptions management
   */
  rtems_exception_init_mngt();

  /*
   * init PCI Bios interface...
   */
  bsp_pci_initialize_helper();

  /*
   * Probe for legacy UARTs.
   */
  legacy_uart_probe();

  /*
   * Probe for UARTs on PCI.
   */
  pci_uart_probe();

  /*
   * Parse the GDB arguments and flag a serial port as not valid. This stops
   * the console from claming the port.
   */
#if BSP_GDB_STUB
  pc386_parse_gdb_arguments();
#endif

  /*
   * Figure out where printk() and console IO is to be directed.  Do this after
   * the legacy and PCI bus probes so we have a chance for those devices to be
   * added to the set in the console driver.  In general, do it as early as
   * possible so printk() has a chance to work early on devices found via PCI
   * probe.
   */
  pc386_parse_console_arguments();

#if (BSP_IS_EDISON == 0)
  Clock_driver_install_handler();
#endif

#if BSP_ENABLE_IDE
  bsp_ide_cmdline_init();
#endif
} /* bsp_start_default */

/*
 *  By making this a weak alias for bsp_start_default, a brave soul
 *  can override the actual bsp_start routine used.
 */
void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));