source: rtems/c/src/lib/libbsp/powerpc/psim/startup/bspstart.c @ 07e9642c

4.104.114.9
Last change on this file since 07e9642c was 07e9642c, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 28, 2007 at 9:44:46 PM

2007-11-28 Joel Sherrill <joel.sherrill@…>

  • startup/bspstart.c: Eliminate PowerPC specific elements from the CPU Table. They have been replaced with variables named bsp_XXX as needed.
  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
2 *  This set of routines 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 any of these are invoked.
6 *
7 *  COPYRIGHT (c) 1989-2007.
8 *  On-Line Applications Research Corporation (OAR).
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.rtems.com/license/LICENSE.
13 *
14 *  $Id$
15 */
16
17#include <string.h>
18#include <fcntl.h>
19#include <bsp.h>
20#include <bsp/irq.h>
21#include <rtems/libio.h>
22#include <rtems/libcsupport.h>
23#include <rtems/bspIo.h>
24#include <rtems/powerpc/powerpc.h>
25
26#include <libcpu/cpuIdent.h>
27#include <libcpu/spr.h>
28
29SPR_RW(SPRG0)
30SPR_RW(SPRG1)
31
32/*
33 *  Driver configuration parameters
34 */
35boolean bsp_exceptions_in_RAM;
36
37extern unsigned long __rtems_end[];
38
39void  initialize_exceptions(void);
40
41/*  On psim, each click of the decrementer register corresponds
42 *  to 1 instruction.  By setting this to 100, we are indicating
43 *  that we are assuming it can execute 100 instructions per
44 *  microsecond.  This corresponds to sustaining 1 instruction
45 *  per cycle at 100 Mhz.  Whether this is a good guess or not
46 *  is anyone's guess.
47 */
48
49extern int PSIM_INSTRUCTIONS_PER_MICROSECOND;
50
51/*
52 *  The original table from the application and our copy of it with
53 *  some changes.
54 */
55
56extern rtems_configuration_table  Configuration;
57rtems_configuration_table         BSP_Configuration;
58rtems_cpu_table                   Cpu_table;
59
60/*
61 *  Tells us where to put the workspace in case remote debugger is present.
62 */
63
64#if 0
65extern uint32_t          rdb_start;
66#endif
67
68/*
69 * PCI Bus Frequency
70 */
71unsigned int BSP_bus_frequency;
72
73/*
74 * Time base divisior (how many tick for 1 second).
75 */
76unsigned int BSP_time_base_divisor;
77
78/*
79 *  Use the shared implementations of the following routines
80 */
81
82void bsp_postdriver_hook(void);
83void bsp_libc_init( void *, uint32_t, int );
84
85/*
86 * system init stack and soft irq stack size
87 */
88#define INIT_STACK_SIZE 0x1000
89#define INTR_STACK_SIZE CONFIGURE_INTERRUPT_STACK_MEMORY
90
91void BSP_panic(char *s)
92{
93  printk("%s PANIC %s\n",_RTEMS_version, s);
94  __asm__ __volatile ("sc");
95}
96
97void _BSP_Fatal_error(unsigned int v)
98{
99  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
100  __asm__ __volatile ("sc");
101}
102
103/*
104 *  bsp_pretasking_hook
105 *
106 *  BSP pretasking hook.  Called just before drivers are initialized.
107 *  Used to setup libc and install any BSP extensions.
108 */
109
110void bsp_pretasking_hook(void)
111{
112  extern int end;
113  uint32_t         heap_start;
114  uint32_t         heap_size;
115
116  heap_start = (uint32_t) &end;
117  if (heap_start & (CPU_ALIGNMENT-1))
118    heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
119
120  heap_size = BSP_Configuration.work_space_start - (void *)&end;
121  heap_size &= 0xfffffff0;  /* keep it as a multiple of 16 bytes */
122
123  bsp_libc_init((void *) heap_start, heap_size, 0);
124
125#ifdef RTEMS_DEBUG
126  rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
127#endif
128}
129
130/*
131 *  bsp_start
132 *
133 *  This routine does the bulk of the system initialization.
134 */
135
136void bsp_start( void )
137{
138  unsigned char     *work_space_start;
139  register uint32_t  intrStack;
140  register uint32_t *intrStackPtr;
141
142  /*
143   * Note we can not get CPU identification dynamically, so
144   * force current_ppc_cpu.
145   */
146  current_ppc_cpu = PPC_PSIM;
147
148  /*
149   * Set up our hooks
150   * Make sure libc_init is done before drivers initialized so that
151   * they can use atexit()
152   */
153
154  Cpu_table.pretasking_hook = bsp_pretasking_hook;    /* init libc, etc. */
155  Cpu_table.postdriver_hook = bsp_postdriver_hook;
156
157  /*
158   *  Is this true?
159   *
160   *  PSIM does zero out memory BUT only when IT begins execution.  Thus
161   *  if we want to have a clean slate in the workspace each time we
162   *  begin execution of OUR application, then we must zero the workspace.
163   *
164   *  It is true that it takes simulated time to clear the memory.
165   */
166
167  Cpu_table.do_zero_of_workspace = FALSE;
168
169  Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY;
170
171  BSP_bus_frequency        = (unsigned int)&PSIM_INSTRUCTIONS_PER_MICROSECOND;
172  BSP_time_base_divisor    = 1;
173
174  /*
175   *  The simulator likes the exception table to be at 0xfff00000.
176   */
177
178  bsp_exceptions_in_RAM = FALSE;
179
180  BSP_Configuration.work_space_size += 1024;
181
182  work_space_start =
183    (unsigned char *)&RAM_END - BSP_Configuration.work_space_size;
184
185  if ( work_space_start <= (unsigned char *)&end ) {
186    printk( "bspstart: Not enough RAM!!!\n" );
187    bsp_cleanup();
188  }
189
190  BSP_Configuration.work_space_start = work_space_start;
191  #if defined(BSP_DIRTY_MEMORY)
192  {
193    memset(&end, 0xCF,  (unsigned char *)&RAM_END - (unsigned char *)&end );
194  }
195  #endif
196
197  /*
198   * Initialize the interrupt related settings
199   * SPRG1 = software managed IRQ stack
200   *
201   * This could be done latter (e.g in IRQ_INIT) but it helps to understand
202   * some settings below...
203   */
204  intrStack = ((uint32_t) __rtems_end) + 
205          INIT_STACK_SIZE + INTR_STACK_SIZE - PPC_MINIMUM_STACK_FRAME_SIZE;
206
207  /* make sure it's properly aligned */
208  intrStack &= ~(CPU_STACK_ALIGNMENT-1);
209
210  /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
211  intrStackPtr = (uint32_t*) intrStack;
212  *intrStackPtr = 0;
213
214  _write_SPRG1(intrStack);
215
216  /* signal them that we have fixed PR288 - eventually, this should go away */
217  _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
218
219  /*
220   * Initialize default raw exception handlers. See vectors/vectors_init.c
221   */
222  initialize_exceptions();
223
224  /*
225   * Initalize RTEMS IRQ system
226   */
227  BSP_rtems_irq_mng_init(0);
228
229}
Note: See TracBrowser for help on using the repository browser.