source: rtems/c/src/lib/libbsp/powerpc/virtex4/startup/bspstart.c @ 16a8616

4.115
Last change on this file since 16a8616 was 16a8616, checked in by Ric Claus <claus@…>, on 03/30/12 at 15:03:43

Add Virtex4 and Virtex5 BSPs

This commit covers at least PR2020, 2022, and 2023. This
patch adds all of the code for both BSPs, modifications
to libcpu/powerpc for the ppc440, and some updates to the
BSPs from follow up review and testing.

These BSPs should be good baselines for future development.
The configurations used by Ric are custom and have a non-standard
NIC. They also do not have a UART. Thus the current console
driver just prints to a RAM buffer.

The NIC and UART support are left for future work. When the UART
support is added, moving the existing "to RAM" console driver to
a shared location is likely desirable because boards with no debug
UART port are commonly deployed. This would let printk() go to RAM.

  • Property mode set to 100644
File size: 7.8 KB
Line 
1/*  bsp_start()
2 *
3 *  This routine starts the application.  It includes application,
4 *  board, and monitor specific initialization and configuration.
5 *  The generic CPU dependent initialization has been performed
6 *  before this routine is invoked.
7 *
8 *  INPUT:  NONE
9 *
10 *  OUTPUT: NONE
11 *
12 *  Author:     Thomas Doerfler <td@imd.m.isar.de>
13 *              IMD Ingenieurbuero fuer Microcomputertechnik
14 *
15 *  COPYRIGHT (c) 1998 by IMD
16 *
17 *  Changes from IMD are covered by the original distributions terms.
18 *  This file has been derived from the papyrus BSP:
19 *
20 *  Author:     Andrew Bray <andy@i-cubed.co.uk>
21 *
22 *  COPYRIGHT (c) 1995 by i-cubed ltd.
23 *
24 *  To anyone who acknowledges that this file is provided "AS IS"
25 *  without any express or implied warranty:
26 *      permission to use, copy, modify, and distribute this file
27 *      for any purpose is hereby granted without fee, provided that
28 *      the above copyright notice and this notice appears in all
29 *      copies, and that the name of i-cubed limited not be used in
30 *      advertising or publicity pertaining to distribution of the
31 *      software without specific, written prior permission.
32 *      i-cubed limited makes no representations about the suitability
33 *      of this software for any purpose.
34 *
35 *  Modifications for spooling console driver and control of memory layout
36 *  with linker command file by
37 *              Thomas Doerfler <td@imd.m.isar.de>
38 *  for these modifications:
39 *  COPYRIGHT (c) 1997 by IMD, Puchheim, Germany.
40 *
41 *  To anyone who acknowledges that this file is provided "AS IS"
42 *  without any express or implied warranty:
43 *      permission to use, copy, modify, and distribute this file
44 *      for any purpose is hereby granted without fee, provided that
45 *      the above copyright notice and this notice appears in all
46 *      copies. IMD makes no representations about the suitability
47 *      of this software for any purpose.
48 *
49 *  Derived from c/src/lib/libbsp/no_cpu/no_bsp/startup/bspstart.c:
50 *
51 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
52 *  On-Line Applications Research Corporation (OAR).
53 *
54 *  Modifications for PPC405GP by Dennis Ehlin
55 *  Modifications for Virtex4 by Richard Claus <claus@slac.stanford.edu>
56 */
57
58#include <string.h>
59#include <fcntl.h>
60
61#include <bsp.h>
62#include <bsp/irq.h>
63#include <bsp/vectors.h>
64#include <rtems/bspIo.h>
65#include <rtems/libio.h>
66#include <rtems/libcsupport.h>
67#include <rtems/sptables.h>             /* for RTEMS_VERSION */
68#include <libcpu/cpuIdent.h>
69#include <libcpu/spr.h>
70
71#define DO_DOWN_ALIGN(x,a) ((x) & ~((a)-1))
72
73#define DO_UP_ALIGN(x,a)   DO_DOWN_ALIGN(((x) + (a) - 1 ),a)
74
75#define CPU_DOWN_ALIGN(x)  DO_DOWN_ALIGN(x, CPU_ALIGNMENT)
76#define CPU_UP_ALIGN(x)    DO_UP_ALIGN(x, CPU_ALIGNMENT)
77
78
79/* Expected by clock.c */
80uint32_t    bsp_clicks_per_usec;
81bool        bsp_timer_internal_clock;   /* true, when timer runs with CPU clk */
82uint32_t    bsp_timer_least_valid;
83uint32_t    bsp_timer_average_overhead;
84
85
86/* Defined in linkcmds linker script */
87LINKER_SYMBOL(RamBase);
88LINKER_SYMBOL(RamSize);
89LINKER_SYMBOL(__bsp_ram_start);
90LINKER_SYMBOL(__bsp_ram_end);
91LINKER_SYMBOL(__rtems_end);
92LINKER_SYMBOL(_stack);
93LINKER_SYMBOL(StackSize);
94LINKER_SYMBOL(__stack_base);
95LINKER_SYMBOL(WorkAreaBase);
96LINKER_SYMBOL(MsgAreaBase);
97LINKER_SYMBOL(MsgAreaSize);
98LINKER_SYMBOL(__phy_ram_end);
99
100
101/*
102 * Provide weak aliases so that RTEMS distribution builds
103 */
104static void _noopfun(void) {}
105static void _bsp_start(void)
106{
107  rtems_status_code sc             = RTEMS_SUCCESSFUL;
108  uintptr_t         intrStackStart = CPU_UP_ALIGN((uint32_t)__bsp_ram_start);
109  uintptr_t         intrStackSize  = rtems_configuration_get_interrupt_stack_size();
110
111  /*
112   * Initialize default raw exception handlers.
113   *
114   * This BSP does not assume anything about firmware possibly loaded in the
115   * FPGA, so the external interrupt should not be enabled in order to avoid
116   * spurious interrupts.
117   */
118  sc = ppc_exc_initialize(PPC_INTERRUPT_DISABLE_MASK_DEFAULT & ~MSR_EE,
119                          intrStackStart,
120                          intrStackSize);
121  if (sc != RTEMS_SUCCESSFUL)  BSP_panic("Cannot initialize exceptions");
122
123  /* Install our own set of exception vectors */
124  BSP_rtems_irq_mngt_init(0);
125}
126
127
128void app_bsp_start(void)
129__attribute__(( weak, alias("_bsp_start") ));
130
131void app_bsp_pretasking_hook(void)
132__attribute__(( weak, alias("_noopfun") ));
133
134void app_bsp_predriver_hook(void)
135__attribute__(( weak, alias("_noopfun") ));
136
137
138static char* bspMsgBuffer = (char*)MsgAreaBase;
139
140static void __bsp_outchar_to_memory(char c)
141{
142  static char* msgBuffer = (char*)MsgAreaBase;
143  *msgBuffer++ = c;
144  if (msgBuffer >= &bspMsgBuffer[(int)MsgAreaSize])  msgBuffer = bspMsgBuffer;
145  *msgBuffer   = 0x00;                /* Overwrite next location to show EOM */
146}
147
148
149void BSP_ask_for_reset(void)
150{
151  printk("\nSystem stopped, issue RESET");
152  for(;;);
153}
154
155
156void BSP_panic(char *s)
157{
158  printk("\n%s PANIC %s\n", _RTEMS_version, s);
159  BSP_ask_for_reset();
160}
161
162
163void _BSP_Fatal_error(unsigned int v)
164{
165  printk("\n%s FATAL ERROR %x\n", _RTEMS_version, v);
166  BSP_ask_for_reset();
167}
168
169
170/*===================================================================*/
171
172/*
173 *  BSP start routine.  Called by boot_card().
174 *
175 *  This routine does the bulk of the system initialization.
176 */
177void bsp_start(void)
178{
179  uintptr_t          intrStackStart;
180  uintptr_t          intrStackSize;
181  ppc_cpu_id_t       myCpu;
182  ppc_cpu_revision_t myCpuRevision;
183
184  /* Set the character output function;  The application may override this */
185  BSP_output_char = __bsp_outchar_to_memory;
186
187  printk("\nWelcome to RTEMS %s\n", _RTEMS_version );
188
189  /*
190   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
191   * function stores the result in global variables so that it can be used later...
192   */
193  myCpu         = get_ppc_cpu_type();
194  myCpuRevision = get_ppc_cpu_revision();
195  printk("CPU: 0x%04x,  Revision: 0x%04x = %d,  Name: %s\n",
196         myCpu, myCpuRevision, myCpuRevision, get_ppc_cpu_type_name(myCpu));
197
198  /*
199   *  Initialize the device driver parameters
200   */
201
202  /* Timebase register ticks/microsecond;  The application may override these */
203  bsp_clicks_per_usec        = 350;
204  bsp_timer_internal_clock   = true;
205  bsp_timer_average_overhead = 2;
206  bsp_timer_least_valid      = 3;
207
208  /*
209   * Initialize the interrupt related settings.
210   */
211  intrStackStart = CPU_UP_ALIGN((uint32_t)__bsp_ram_start);
212  intrStackSize  = rtems_configuration_get_interrupt_stack_size();
213  printk("                  Base/Start     End         Size\n"
214         "RAM:              0x%08x              0x%x\n"
215         "RTEMS:                        0x%08x\n"
216         "Interrupt Stack:  0x%08x              0x%x\n"
217         "Stack:            0x%08x  0x%08x  0x%x\n"
218         "Workspace:        0x%08x  0x%08x\n"
219         "MsgArea:          0x%08x              0x%x\n"
220         "Physical RAM                  0x%08x\n",
221         (uint32_t)RamBase,                               (uint32_t)RamSize,
222         (uint32_t)__rtems_end,
223         intrStackStart,                                  intrStackSize,
224         (uint32_t)__stack_base, (uint32_t)_stack,        (uint32_t)StackSize,
225         (uint32_t)WorkAreaBase, (uint32_t)__bsp_ram_end,
226         (uint32_t)MsgAreaBase,                           (uint32_t)MsgAreaSize,
227         (uint32_t)__phy_ram_end);
228
229  /* Continue with application-specific initialization */
230  app_bsp_start();
231}
232
233
234/*
235 *  BSP pretasking hook.  Called just before drivers are initialized.
236 *  Used to setup libc and install any BSP extensions.
237 *
238 *  Must not use libc (to do io) from here, since drivers are not yet
239 *  initialized.
240 */
241
242void bsp_pretasking_hook(void)
243{
244  app_bsp_pretasking_hook();
245}
246
247
248/*
249 *  BSP predriver hook.  Called by boot_card() just before drivers are
250 *  initialized.  Clear out any stale interrupts here.
251 */
252void bsp_predriver_hook(void)
253{
254  app_bsp_predriver_hook();
255}
Note: See TracBrowser for help on using the repository browser.