source: rtems/c/src/lib/libbsp/powerpc/virtex5/startup/bspstart.c @ b1e8a58

4.11
Last change on this file since b1e8a58 was b1e8a58, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 14, 2012 at 8:57:55 AM

bsps/powerpc: Exception initialization error is fatal

  • Property mode set to 100644
File size: 7.6 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 Virtex5 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  uintptr_t         intrStackStart = CPU_UP_ALIGN((uint32_t)__bsp_ram_start);
108  uintptr_t         intrStackSize  = rtems_configuration_get_interrupt_stack_size();
109
110  /*
111   * Initialize default raw exception handlers.
112   *
113   * This BSP does not assume anything about firmware possibly loaded in the
114   * FPGA, so the external interrupt should not be enabled in order to avoid
115   * spurious interrupts.
116   */
117  ppc_exc_initialize(PPC_INTERRUPT_DISABLE_MASK_DEFAULT & ~MSR_EE,
118                     intrStackStart,
119                     intrStackSize);
120
121  /* Install our own set of exception vectors */
122  BSP_rtems_irq_mngt_init(0);
123}
124
125
126void app_bsp_start(void)
127__attribute__(( weak, alias("_bsp_start") ));
128
129void app_bsp_pretasking_hook(void)
130__attribute__(( weak, alias("_noopfun") ));
131
132void app_bsp_predriver_hook(void)
133__attribute__(( weak, alias("_noopfun") ));
134
135
136static char* bspMsgBuffer = (char*)MsgAreaBase;
137
138static void __bsp_outchar_to_memory(char c)
139{
140  static char* msgBuffer = (char*)MsgAreaBase;
141  *msgBuffer++ = c;
142  if (msgBuffer >= &bspMsgBuffer[(int)MsgAreaSize])  msgBuffer = bspMsgBuffer;
143  *msgBuffer   = 0x00;                /* Overwrite next location to show EOM */
144}
145
146
147void BSP_ask_for_reset(void)
148{
149  printk("\nSystem stopped, issue RESET");
150  for(;;);
151}
152
153
154void BSP_panic(char *s)
155{
156  printk("\n%s PANIC %s\n", _RTEMS_version, s);
157  BSP_ask_for_reset();
158}
159
160
161void _BSP_Fatal_error(unsigned int v)
162{
163  printk("\n%s FATAL ERROR %x\n", _RTEMS_version, v);
164  BSP_ask_for_reset();
165}
166
167
168/*===================================================================*/
169
170/*
171 *  BSP start routine.  Called by boot_card().
172 *
173 *  This routine does the bulk of the system initialization.
174 */
175void bsp_start(void)
176{
177  uintptr_t          intrStackStart;
178  uintptr_t          intrStackSize;
179  ppc_cpu_id_t       myCpu;
180  ppc_cpu_revision_t myCpuRevision;
181
182  /* Set the character output function;  The application may override this */
183  BSP_output_char = __bsp_outchar_to_memory;
184
185  printk("\nWelcome to RTEMS %s\n", _RTEMS_version );
186
187  /*
188   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
189   * function stores the result in global variables so that it can be used later...
190   */
191  myCpu         = get_ppc_cpu_type();
192  myCpuRevision = get_ppc_cpu_revision();
193  printk("CPU: 0x%04x,  Revision: 0x%04x = %d,  Name: %s\n",
194         myCpu, myCpuRevision, myCpuRevision, get_ppc_cpu_type_name(myCpu));
195
196  /*
197   *  Initialize the device driver parameters
198   */
199
200  /* Timebase register ticks/microsecond;  The application may override these */
201  bsp_clicks_per_usec        = 450;
202  bsp_timer_internal_clock   = true;
203  bsp_timer_average_overhead = 2;
204  bsp_timer_least_valid      = 3;
205
206  /*
207   * Initialize the interrupt related settings.
208   */
209  intrStackStart = CPU_UP_ALIGN((uint32_t)__bsp_ram_start);
210  intrStackSize  = rtems_configuration_get_interrupt_stack_size();
211  printk("                  Base/Start     End         Size\n"
212         "RAM:              0x%08x              0x%x\n"
213         "RTEMS:                        0x%08x\n"
214         "Interrupt Stack:  0x%08x              0x%x\n"
215         "Stack:            0x%08x  0x%08x  0x%x\n"
216         "Workspace:        0x%08x  0x%08x\n"
217         "MsgArea:          0x%08x              0x%x\n"
218         "Physical RAM                  0x%08x\n",
219         (uint32_t)RamBase,                               (uint32_t)RamSize,
220         (uint32_t)__rtems_end,
221         intrStackStart,                                  intrStackSize,
222         (uint32_t)__stack_base, (uint32_t)_stack,        (uint32_t)StackSize,
223         (uint32_t)WorkAreaBase, (uint32_t)__bsp_ram_end,
224         (uint32_t)MsgAreaBase,                           (uint32_t)MsgAreaSize,
225         (uint32_t)__phy_ram_end);
226
227  /* Continue with application-specific initialization */
228  app_bsp_start();
229}
230
231
232/*
233 *  BSP pretasking hook.  Called just before drivers are initialized.
234 *  Used to setup libc and install any BSP extensions.
235 *
236 *  Must not use libc (to do io) from here, since drivers are not yet
237 *  initialized.
238 */
239
240void bsp_pretasking_hook(void)
241{
242  app_bsp_pretasking_hook();
243}
244
245
246/*
247 *  BSP predriver hook.  Called by boot_card() just before drivers are
248 *  initialized.  Clear out any stale interrupts here.
249 */
250void bsp_predriver_hook(void)
251{
252  app_bsp_predriver_hook();
253}
Note: See TracBrowser for help on using the repository browser.