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

5
Last change on this file since 20d7093a was 20d7093a, checked in by Sebastian Huber <sebastian.huber@…>, on 12/09/15 at 10:21:12

bsps/virtex*: Use default bsp_pretasking_hook()

Update #2408.

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