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

5
Last change on this file since c4ccf26c was c4ccf26c, checked in by Sebastian Huber <sebastian.huber@…>, on 04/17/18 at 04:57:46

bsps: Convert all bsp_predriver_hook()

Use RTEMS_SYSINIT_ITEM() instead.

Update #2408.

  • Property mode set to 100644
File size: 6.9 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#include <rtems/sysinit.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#include <inttypes.h>
74
75#define DO_DOWN_ALIGN(x,a) ((x) & ~((a)-1))
76
77#define DO_UP_ALIGN(x,a)   DO_DOWN_ALIGN(((x) + (a) - 1 ),a)
78
79#define CPU_DOWN_ALIGN(x)  DO_DOWN_ALIGN(x, CPU_ALIGNMENT)
80#define CPU_UP_ALIGN(x)    DO_UP_ALIGN(x, CPU_ALIGNMENT)
81
82
83/* Defined in linkcmds linker script */
84LINKER_SYMBOL(RamBase);
85LINKER_SYMBOL(RamSize);
86LINKER_SYMBOL(__bsp_ram_start);
87LINKER_SYMBOL(__bsp_ram_end);
88LINKER_SYMBOL(__rtems_end);
89LINKER_SYMBOL(_stack);
90LINKER_SYMBOL(StackSize);
91LINKER_SYMBOL(__stack_base);
92LINKER_SYMBOL(WorkAreaBase);
93LINKER_SYMBOL(MsgAreaBase);
94LINKER_SYMBOL(MsgAreaSize);
95LINKER_SYMBOL(__phy_ram_end);
96LINKER_SYMBOL(bsp_exc_vector_base);
97
98
99/* Expected by clock.c */
100uint32_t    bsp_clicks_per_usec;
101
102/*
103 * Bus Frequency
104 */
105unsigned int BSP_bus_frequency;
106/*
107 * processor clock frequency
108 */
109unsigned int BSP_processor_frequency;
110
111/*
112 * Time base divisior (bus freq / TB clock)
113 */
114unsigned int BSP_time_base_divisor;
115
116/*
117 * Provide weak aliases so that RTEMS distribution builds
118 */
119static void _noopfun(void) {}
120
121
122void app_bsp_start(void)
123__attribute__(( weak, alias("_noopfun") ));
124
125void app_bsp_predriver_hook(void)
126__attribute__(( weak, alias("_noopfun") ));
127
128
129static char* bspMsgBuffer = (char*)MsgAreaBase;
130
131static void __bsp_outchar_to_memory(char c)
132{
133  static char* msgBuffer = (char*)MsgAreaBase;
134  *msgBuffer++ = c;
135  if (msgBuffer >= &bspMsgBuffer[(int)MsgAreaSize])  msgBuffer = bspMsgBuffer;
136  *msgBuffer   = 0x00;                /* Overwrite next location to show EOM */
137}
138
139
140void BSP_ask_for_reset(void)
141{
142  printk("\nSystem stopped, issue RESET");
143
144  for(;;);
145}
146
147
148/*===================================================================*/
149
150/*
151 *  BSP start routine.  Called by boot_card().
152 *
153 *  This routine does the bulk of the system initialization.
154 */
155void bsp_start(void)
156{
157  uintptr_t          intrStackStart;
158  uintptr_t          intrStackSize;
159
160  ppc_cpu_id_t       myCpu;
161  ppc_cpu_revision_t myCpuRevision;
162
163  /* Set the character output function;  The application may override this */
164  BSP_output_char = __bsp_outchar_to_memory;
165
166  printk("RTEMS %s\n", rtems_get_version_string());
167
168  /*
169   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
170   * function stores the result in global variables so that it can be used later...
171   */
172  myCpu         = get_ppc_cpu_type();
173  myCpuRevision = get_ppc_cpu_revision();
174  printk("CPU: 0x%04x,  Revision: 0x%04x = %d,  Name: %s\n",
175         myCpu, myCpuRevision, myCpuRevision, get_ppc_cpu_type_name(myCpu));
176
177  /*
178   *  Initialize the device driver parameters
179   */
180
181  /* For mpc6xx clock driver: */
182  BSP_bus_frequency       = 465000000;
183  BSP_processor_frequency = 465000000;  /* Measured with a DPM 440 2012/8/13 */
184  BSP_time_base_divisor   = 1000;
185
186  /* Timebase register ticks/microsecond;  The application may override these */
187  bsp_clicks_per_usec        = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
188  rtems_counter_initialize_converter(
189    BSP_bus_frequency / (BSP_time_base_divisor / 1000)
190  );
191
192  /*
193   * Initialize the interrupt related settings.
194   */
195  intrStackStart = CPU_UP_ALIGN((uint32_t)__bsp_ram_start);
196  intrStackSize  = rtems_configuration_get_interrupt_stack_size();
197
198  ppc_exc_initialize(intrStackStart, intrStackSize);
199
200  /* Let the user know what parameters we were compiled with */
201  printk("                  Base/Start     End         Size\n"
202         "RAM:              %p                    %p\n"
203         "RTEMS:                           %p\n"
204         "Interrupt Stack:  0x%08x              0x%x\n"
205         "Stack:            %p             %p          %p\n"
206         "Workspace:        %p             %p\n"
207         "MsgArea:          %p             %p\n"
208         "Physical RAM                     %p\n",
209         RamBase,        RamSize,
210         __rtems_end,
211         intrStackStart,                intrStackSize,
212         __stack_base,   _stack,        StackSize,
213         WorkAreaBase,   __bsp_ram_end,
214         MsgAreaBase,    MsgAreaSize,
215         __phy_ram_end);
216
217  /*
218   * Initialize RTEMS IRQ system
219   */
220  BSP_rtems_irq_mngt_init(0);
221
222  /* Continue with application-specific initialization */
223  app_bsp_start();
224}
225
226
227/*
228 *  BSP predriver hook.  Called by boot_card() just before drivers are
229 *  initialized.  Clear out any stale interrupts here.
230 */
231static void virtex5_pre_driver_hook(void)
232{
233  app_bsp_predriver_hook();
234}
235
236RTEMS_SYSINIT_ITEM(
237  virtex5_pre_driver_hook,
238  RTEMS_SYSINIT_BSP_PRE_DRIVERS,
239  RTEMS_SYSINIT_ORDER_MIDDLE
240);
Note: See TracBrowser for help on using the repository browser.