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

4.104.114.95
Last change on this file since b9f34ad was 21ca2199, checked in by Joel Sherrill <joel.sherrill@…>, on 09/13/07 at 15:01:25

2007-09-13 Joel Sherrill <joel.sherrill@…>

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