source: rtems/bsps/powerpc/virtex4/start/bspstart.c @ 762fa62

5
Last change on this file since 762fa62 was 65f868c, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/18 at 12:17:25

Add _CPU_Counter_frequency()

Add rtems_counter_frequency() API function. Use it to initialize the
counter value converter via the new system initialization step
(RTEMS_SYSINIT_CPU_COUNTER). This decouples the counter implementation
and the counter converter. It avoids an unnecessary pull in of the
64-bit integer division from libgcc.

Update #3456.

  • Property mode set to 100644
File size: 6.4 KB
Line 
1/*
2 *  This routine starts the application.  It includes application,
3 *  board, and monitor specific initialization and configuration.
4 *  The generic CPU dependent initialization has been performed
5 *  before this routine is invoked.
6 */
7
8/*
9 *  Author:     Thomas Doerfler <td@imd.m.isar.de>
10 *              IMD Ingenieurbuero fuer Microcomputertechnik
11 *
12 *  COPYRIGHT (c) 1998 by IMD
13 *
14 *  Changes from IMD are covered by the original distributions terms.
15 *  This file has been derived from the papyrus BSP:
16 *
17 *  Author:     Andrew Bray <andy@i-cubed.co.uk>
18 *
19 *  COPYRIGHT (c) 1995 by i-cubed ltd.
20 *
21 *  To anyone who acknowledges that this file is provided "AS IS"
22 *  without any express or implied warranty:
23 *      permission to use, copy, modify, and distribute this file
24 *      for any purpose is hereby granted without fee, provided that
25 *      the above copyright notice and this notice appears in all
26 *      copies, and that the name of i-cubed limited not be used in
27 *      advertising or publicity pertaining to distribution of the
28 *      software without specific, written prior permission.
29 *      i-cubed limited makes no representations about the suitability
30 *      of this software for any purpose.
31 *
32 *  Modifications for spooling console driver and control of memory layout
33 *  with linker command file by
34 *              Thomas Doerfler <td@imd.m.isar.de>
35 *  for these modifications:
36 *  COPYRIGHT (c) 1997 by IMD, Puchheim, Germany.
37 *
38 *  To anyone who acknowledges that this file is provided "AS IS"
39 *  without any express or implied warranty:
40 *      permission to use, copy, modify, and distribute this file
41 *      for any purpose is hereby granted without fee, provided that
42 *      the above copyright notice and this notice appears in all
43 *      copies. IMD makes no representations about the suitability
44 *      of this software for any purpose.
45 *
46 *  Derived from c/src/lib/libbsp/no_cpu/no_bsp/startup/bspstart.c:
47 *
48 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
49 *  On-Line Applications Research Corporation (OAR).
50 *
51 *  Modifications for PPC405GP by Dennis Ehlin
52 *  Modifications for Virtex4 by Richard Claus <claus@slac.stanford.edu>
53 */
54#include <rtems.h>
55#include <rtems/config.h>
56#include <rtems/bspIo.h>
57#include <rtems/counter.h>
58#include <rtems/libio.h>
59#include <rtems/libcsupport.h>
60#include <rtems/sysinit.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#include <inttypes.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;
100
101
102/*
103 * Provide weak aliases so that RTEMS distribution builds
104 */
105static void _noopfun(void) {}
106
107
108void app_bsp_start(void)
109__attribute__(( weak, alias("_noopfun") ));
110
111void app_bsp_predriver_hook(void)
112__attribute__(( weak, alias("_noopfun") ));
113
114
115static char* bspMsgBuffer = (char*)MsgAreaBase;
116
117static void __bsp_outchar_to_memory(char c)
118{
119  static char* msgBuffer = (char*)MsgAreaBase;
120  *msgBuffer++ = c;
121  if (msgBuffer >= &bspMsgBuffer[(int)MsgAreaSize])  msgBuffer = bspMsgBuffer;
122  *msgBuffer   = 0x00;                /* Overwrite next location to show EOM */
123}
124
125
126void BSP_ask_for_reset(void)
127{
128  printk("\nSystem stopped, issue RESET");
129
130  for(;;);
131}
132
133uint32_t _CPU_Counter_frequency(void)
134{
135  return bsp_clicks_per_usec * 1000000;
136}
137
138/*===================================================================*/
139
140/*
141 *  BSP start routine.  Called by boot_card().
142 *
143 *  This routine does the bulk of the system initialization.
144 */
145void bsp_start(void)
146{
147  uintptr_t          intrStackStart;
148  uintptr_t          intrStackSize;
149
150  ppc_cpu_id_t       myCpu;
151  ppc_cpu_revision_t myCpuRevision;
152
153  /* Set the character output function;  The application may override this */
154  BSP_output_char = __bsp_outchar_to_memory;
155
156  printk("RTEMS %s\n", rtems_get_version_string());
157
158  /*
159   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
160   * function stores the result in global variables so that it can be used later...
161   */
162  myCpu         = get_ppc_cpu_type();
163  myCpuRevision = get_ppc_cpu_revision();
164  printk("CPU: 0x%04x,  Revision: 0x%04x = %d,  Name: %s\n",
165         myCpu, myCpuRevision, myCpuRevision, get_ppc_cpu_type_name(myCpu));
166
167  /*
168   *  Initialize the device driver parameters
169   */
170
171  /* Timebase register ticks/microsecond;  The application may override these */
172  bsp_clicks_per_usec        = 350;
173
174  /*
175   * Initialize the interrupt related settings.
176   */
177  intrStackStart = CPU_UP_ALIGN((uint32_t)__bsp_ram_start);
178  intrStackSize  = rtems_configuration_get_interrupt_stack_size();
179
180  ppc_exc_initialize(intrStackStart, intrStackSize);
181
182  /* Let the user know what parameters we were compiled with */
183  printk("                  Base/Start     End         Size\n"
184         "RAM:              %p                    %p\n"
185         "RTEMS:                           %p\n"
186         "Interrupt Stack:  0x%08x              0x%x\n"
187         "Stack:            %p             %p          %p\n"
188         "Workspace:        %p             %p\n"
189         "MsgArea:          %p             %p\n"
190         "Physical RAM                     %p\n",
191         RamBase,        RamSize,
192         __rtems_end,
193         intrStackStart,                intrStackSize,
194         __stack_base,   _stack,        StackSize,
195         WorkAreaBase,   __bsp_ram_end,
196         MsgAreaBase,    MsgAreaSize,
197         __phy_ram_end);
198
199  /*
200   * Initialize RTEMS IRQ system
201   */
202  BSP_rtems_irq_mngt_init(0);
203
204  /* Continue with application-specific initialization */
205  app_bsp_start();
206}
207
208
209/*
210 *  BSP predriver hook.  Called by boot_card() just before drivers are
211 *  initialized.  Clear out any stale interrupts here.
212 */
213static void virtex4_pre_driver_hook(void)
214{
215  app_bsp_predriver_hook();
216}
217
218RTEMS_SYSINIT_ITEM(
219  virtex4_pre_driver_hook,
220  RTEMS_SYSINIT_BSP_PRE_DRIVERS,
221  RTEMS_SYSINIT_ORDER_MIDDLE
222);
Note: See TracBrowser for help on using the repository browser.