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

4.115
Last change on this file since 655bd39 was 655bd39, checked in by Ric Claus <claus@…>, on 11/30/12 at 23:58:32

Virtex5 BSP: Various updates and improvements.

This BSP now uses the MPC6xx clock driver instead of a modified PPC403 clock
driver. Support for the MMU has been added, but is not enabled by default.

  • Property mode set to 100644
File size: 7.9 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#include <rtems.h>
58#include <rtems/config.h>
59#include <rtems/bspIo.h>
60#include <rtems/libio.h>
61#include <rtems/libcsupport.h>
62
63#include <libcpu/cpuIdent.h>
64#include <libcpu/spr.h>
65
66#include <bsp.h>
67#include <bsp/vectors.h>
68#include <bsp/bootcard.h>
69#include <bsp/irq.h>
70
71#include <string.h>
72#include <fcntl.h>
73
74#define DO_DOWN_ALIGN(x,a) ((x) & ~((a)-1))
75
76#define DO_UP_ALIGN(x,a)   DO_DOWN_ALIGN(((x) + (a) - 1 ),a)
77
78#define CPU_DOWN_ALIGN(x)  DO_DOWN_ALIGN(x, CPU_ALIGNMENT)
79#define CPU_UP_ALIGN(x)    DO_UP_ALIGN(x, CPU_ALIGNMENT)
80
81
82/* Defined in linkcmds linker script */
83LINKER_SYMBOL(RamBase);
84LINKER_SYMBOL(RamSize);
85LINKER_SYMBOL(__bsp_ram_start);
86LINKER_SYMBOL(__bsp_ram_end);
87LINKER_SYMBOL(__rtems_end);
88LINKER_SYMBOL(_stack);
89LINKER_SYMBOL(StackSize);
90LINKER_SYMBOL(__stack_base);
91LINKER_SYMBOL(WorkAreaBase);
92LINKER_SYMBOL(MsgAreaBase);
93LINKER_SYMBOL(MsgAreaSize);
94LINKER_SYMBOL(__phy_ram_end);
95LINKER_SYMBOL(bsp_exc_vector_base);
96
97
98/* Expected by clock.c */
99uint32_t    bsp_clicks_per_usec;
100bool        bsp_timer_internal_clock;   /* true, when timer runs with CPU clk */
101uint32_t    bsp_timer_least_valid;
102uint32_t    bsp_timer_average_overhead;
103
104/*
105 * Bus Frequency
106 */
107unsigned int BSP_bus_frequency;
108/*
109 * processor clock frequency
110 */
111unsigned int BSP_processor_frequency;
112
113/*
114 * Time base divisior (bus freq / TB clock)
115 */
116unsigned int BSP_time_base_divisor;
117
118/*
119 * Provide weak aliases so that RTEMS distribution builds
120 */
121static void _noopfun(void) {}
122
123
124void app_bsp_start(void)
125__attribute__(( weak, alias("_noopfun") ));
126
127void app_bsp_pretasking_hook(void)
128__attribute__(( weak, alias("_noopfun") ));
129
130void app_bsp_predriver_hook(void)
131__attribute__(( weak, alias("_noopfun") ));
132
133
134static char* bspMsgBuffer = (char*)MsgAreaBase;
135
136static void __bsp_outchar_to_memory(char c)
137{
138  static char* msgBuffer = (char*)MsgAreaBase;
139  *msgBuffer++ = c;
140  if (msgBuffer >= &bspMsgBuffer[(int)MsgAreaSize])  msgBuffer = bspMsgBuffer;
141  *msgBuffer   = 0x00;                /* Overwrite next location to show EOM */
142}
143
144
145void BSP_ask_for_reset(void)
146{
147  printk("\nSystem stopped, issue RESET");
148
149  for(;;);
150}
151
152
153void BSP_panic(char *s)
154{
155  rtems_interrupt_level level;
156
157  rtems_interrupt_disable(level);
158
159  printk("\n%s PANIC %s\n", rtems_get_version_string(), s);
160
161  BSP_ask_for_reset();
162}
163
164
165void _BSP_Fatal_error(unsigned int v)
166{
167  rtems_interrupt_level level;
168
169  rtems_interrupt_disable(level);
170
171  printk("\n%s FATAL ERROR %x\n", rtems_get_version_string(), v);
172
173  BSP_ask_for_reset();
174}
175
176
177/*===================================================================*/
178
179/*
180 *  BSP start routine.  Called by boot_card().
181 *
182 *  This routine does the bulk of the system initialization.
183 */
184void bsp_start(void)
185{
186  uintptr_t          intrStackStart;
187  uintptr_t          intrStackSize;
188
189  ppc_cpu_id_t       myCpu;
190  ppc_cpu_revision_t myCpuRevision;
191
192  /* Set the character output function;  The application may override this */
193  BSP_output_char = __bsp_outchar_to_memory;
194
195  printk("RTEMS %s\n", rtems_get_version_string());
196
197  /*
198   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
199   * function stores the result in global variables so that it can be used later...
200   */
201  myCpu         = get_ppc_cpu_type();
202  myCpuRevision = get_ppc_cpu_revision();
203  printk("CPU: 0x%04x,  Revision: 0x%04x = %d,  Name: %s\n",
204         myCpu, myCpuRevision, myCpuRevision, get_ppc_cpu_type_name(myCpu));
205
206  /*
207   *  Initialize the device driver parameters
208   */
209
210  /* For mpc6xx clock driver: */
211  BSP_bus_frequency       = 465000000;
212  BSP_processor_frequency = 465000000;  /* Measured with a DPM 440 2012/8/13 */
213  BSP_time_base_divisor   = 1000;
214
215  /* Timebase register ticks/microsecond;  The application may override these */
216  bsp_clicks_per_usec        = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
217  bsp_timer_internal_clock   = true;
218  bsp_timer_average_overhead = 2;
219  bsp_timer_least_valid      = 3;
220
221  /*
222   * Initialize the interrupt related settings.
223   */
224  intrStackStart = CPU_UP_ALIGN((uint32_t)__bsp_ram_start);
225  intrStackSize  = rtems_configuration_get_interrupt_stack_size();
226
227  ppc_exc_initialize(PPC_INTERRUPT_DISABLE_MASK_DEFAULT,
228                     intrStackStart,
229                     intrStackSize);
230
231  /* Let the user know what parameters we were compiled with */
232  printk("                  Base/Start     End         Size\n"
233         "RAM:              0x%08x              0x%x\n"
234         "RTEMS:                        0x%08x\n"
235         "Interrupt Stack:  0x%08x              0x%x\n"
236         "Stack:            0x%08x  0x%08x  0x%x\n"
237         "Workspace:        0x%08x  0x%08x\n"
238         "MsgArea:          0x%08x              0x%x\n"
239         "Physical RAM                  0x%08x\n",
240         (uint32_t)RamBase,                               (uint32_t)RamSize,
241         (uint32_t)__rtems_end,
242         intrStackStart,                                  intrStackSize,
243         (uint32_t)__stack_base, (uint32_t)_stack,        (uint32_t)StackSize,
244         (uint32_t)WorkAreaBase, (uint32_t)__bsp_ram_end,
245         (uint32_t)MsgAreaBase,                           (uint32_t)MsgAreaSize,
246         (uint32_t)__phy_ram_end);
247
248  /*
249   * Initialize RTEMS IRQ system
250   */
251  BSP_rtems_irq_mngt_init(0);
252
253  /* Continue with application-specific initialization */
254  app_bsp_start();
255}
256
257
258/*
259 *  BSP pretasking hook.  Called just before drivers are initialized.
260 *  Used to setup libc and install any BSP extensions.
261 *
262 *  Must not use libc (to do io) from here, since drivers are not yet
263 *  initialized.
264 */
265
266void bsp_pretasking_hook(void)
267{
268  app_bsp_pretasking_hook();
269}
270
271
272/*
273 *  BSP predriver hook.  Called by boot_card() just before drivers are
274 *  initialized.  Clear out any stale interrupts here.
275 */
276void bsp_predriver_hook(void)
277{
278  app_bsp_predriver_hook();
279}
Note: See TracBrowser for help on using the repository browser.