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

4.104.114.95
Last change on this file since 558bc25 was 558bc25, checked in by Joel Sherrill <joel.sherrill@…>, on 12/03/07 at 22:26:33

2007-12-03 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, startup/bspstart.c: Moved most of the remaining CPU Table fields to the Configuration Table. This included pretasking_hook, predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace, extra_mpci_receive_server_stack, stack_allocate_hook, and stack_free_hook. As a side-effect of this effort some multiprocessing code was made conditional and some style clean up occurred.
  • Property mode set to 100644
File size: 5.3 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/bat.h>
28#include <libcpu/spr.h>
29
30SPR_RW(SPRG0)
31SPR_RW(SPRG1)
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 */
67unsigned int BSP_bus_frequency;
68
69/*
70 * Time base divisior (how many tick for 1 second).
71 */
72unsigned int BSP_time_base_divisor;
73
74/*
75 *  Use the shared implementations of the following routines
76 */
77
78void bsp_postdriver_hook(void);
79void bsp_libc_init( void *, uint32_t, int );
80
81/*
82 * system init stack and soft irq stack size
83 */
84#define INIT_STACK_SIZE 0x1000
85#define INTR_STACK_SIZE CONFIGURE_INTERRUPT_STACK_MEMORY
86
87void BSP_panic(char *s)
88{
89  printk("%s PANIC %s\n",_RTEMS_version, s);
90  __asm__ __volatile ("sc");
91}
92
93void _BSP_Fatal_error(unsigned int v)
94{
95  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
96  __asm__ __volatile ("sc");
97}
98
99/*
100 *  bsp_pretasking_hook
101 *
102 *  BSP pretasking hook.  Called just before drivers are initialized.
103 *  Used to setup libc and install any BSP extensions.
104 */
105
106void bsp_pretasking_hook(void)
107{
108  extern int end;
109  uint32_t         heap_start;
110  uint32_t         heap_size;
111
112  heap_start = (uint32_t) &end;
113  if (heap_start & (CPU_ALIGNMENT-1))
114    heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
115
116  heap_size = BSP_Configuration.work_space_start - (void *)&end;
117  heap_size &= 0xfffffff0;  /* keep it as a multiple of 16 bytes */
118
119  bsp_libc_init((void *) heap_start, heap_size, 0);
120
121#ifdef RTEMS_DEBUG
122  rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
123#endif
124}
125
126/*
127 *  bsp_start
128 *
129 *  This routine does the bulk of the system initialization.
130 */
131
132void bsp_start( void )
133{
134  unsigned char     *work_space_start;
135  register uint32_t  intrStack;
136  register uint32_t *intrStackPtr;
137
138  /*
139   * Note we can not get CPU identification dynamically, so
140   * force current_ppc_cpu.
141   */
142  current_ppc_cpu = PPC_PSIM;
143
144  /*
145   * Set up our hooks
146   * Make sure libc_init is done before drivers initialized so that
147   * they can use atexit()
148   */
149
150  Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY;
151
152  BSP_bus_frequency        = (unsigned int)&PSIM_INSTRUCTIONS_PER_MICROSECOND;
153  BSP_time_base_divisor    = 1;
154
155  /*
156   *  The simulator likes the exception table to be at 0xfff00000.
157   */
158
159  bsp_exceptions_in_RAM = FALSE;
160
161  BSP_Configuration.work_space_size += 1024;
162
163  work_space_start =
164    (unsigned char *)&RAM_END - BSP_Configuration.work_space_size;
165
166  if ( work_space_start <= (unsigned char *)&end ) {
167    printk( "bspstart: Not enough RAM!!!\n" );
168    bsp_cleanup();
169  }
170
171  BSP_Configuration.work_space_start = work_space_start;
172  #if (BSP_DIRTY_MEMORY == 1)
173  {
174    memset(&end, 0xCF,  (unsigned char *)&RAM_END - (unsigned char *)&end );
175  }
176  #endif
177
178  /*
179   * Initialize the interrupt related settings
180   * SPRG1 = software managed IRQ stack
181   *
182   * This could be done latter (e.g in IRQ_INIT) but it helps to understand
183   * some settings below...
184   */
185  intrStack = ((uint32_t) __rtems_end) +
186          INIT_STACK_SIZE + INTR_STACK_SIZE - PPC_MINIMUM_STACK_FRAME_SIZE;
187
188  /* make sure it's properly aligned */
189  intrStack &= ~(CPU_STACK_ALIGNMENT-1);
190
191  /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
192  intrStackPtr = (uint32_t*) intrStack;
193  *intrStackPtr = 0;
194
195  _write_SPRG1(intrStack);
196
197  /* signal them that we have fixed PR288 - eventually, this should go away */
198  _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
199
200  /*
201   * Initialize default raw exception handlers. See vectors/vectors_init.c
202   */
203  initialize_exceptions();
204
205  /*
206   * Initalize RTEMS IRQ system
207   */
208  BSP_rtems_irq_mng_init(0);
209
210  /*
211   * Setup BATs and enable MMU
212   */
213  /* Memory */
214  setdbat(0, 0x0<<24, 0x0<<24, 1<<24, _PAGE_RW);
215  setibat(0, 0x0<<24, 0x0<<24, 1<<24,        0);
216  /* PCI    */
217  setdbat(1, 0x8<<24, 0x8<<24, 1<<24,  IO_PAGE);
218  setdbat(2, 0xc<<24, 0xc<<24, 1<<24,  IO_PAGE);
219
220  _write_MSR(_read_MSR() | MSR_DR | MSR_IR);
221  asm volatile("sync; isync");
222
223}
Note: See TracBrowser for help on using the repository browser.