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

4.104.114.95
Last change on this file since a725a4d7 was a725a4d7, checked in by Till Straumann <strauman@…>, on 11/30/07 at 01:23:04

2007-11-29 Till Straumann <strauman@…>

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