source: rtems/c/src/lib/libbsp/powerpc/gen83xx/startup/bspstart.c @ 67a9b24a

4.104.114.95
Last change on this file since 67a9b24a was 67a9b24a, checked in by Joel Sherrill <joel.sherrill@…>, on 05/12/08 at 18:42:36

2008-05-12 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, startup/bspstart.c: Refactored and renamed initialization routines to rtems_initialize_data_structures, rtems_initialize_before_drivers, rtems_initialize_device_drivers, and rtems_initialize_start_multitasking. This opened the sequence up so that bootcard() could provide a more robust and flexible framework which is easier to explain and understand. This also lays the groundwork for sharing the division of available memory between the RTEMS workspace and heap and the C library initialization across all BSPs.
  • Property mode set to 100644
File size: 6.2 KB
Line 
1/*===============================================================*\
2| Project: RTEMS generic MPC83xx BSP                              |
3+-----------------------------------------------------------------+
4|                    Copyright (c) 2007                           |
5|                    Embedded Brains GmbH                         |
6|                    Obere Lagerstr. 30                           |
7|                    D-82178 Puchheim                             |
8|                    Germany                                      |
9|                    rtems@embedded-brains.de                     |
10+-----------------------------------------------------------------+
11| The license and distribution terms for this file may be         |
12| found in the file LICENSE in this distribution or at            |
13|                                                                 |
14| http://www.rtems.com/license/LICENSE.                           |
15|                                                                 |
16+-----------------------------------------------------------------+
17| this file contains the BSP startup code                         |
18\*===============================================================*/
19
20/*
21 *  $Id$
22 */
23
24#include <bsp.h>
25
26#include <rtems/libio.h>
27#include <rtems/libcsupport.h>
28#include <rtems/powerpc/powerpc.h>
29#include <rtems/score/thread.h>
30
31#include <rtems/bspIo.h>
32#include <libcpu/cpuIdent.h>
33#include <libcpu/spr.h>
34#include <bsp/irq.h>
35
36#include <string.h>
37
38SPR_RW(SPRG0)
39SPR_RW(SPRG1)
40
41extern unsigned long intrStackPtr;
42static char *BSP_heap_start, *BSP_heap_end;
43
44/*
45 * constants for c_clock driver:
46 * system bus frequency (for timebase etc)
47 * and
48 * Time base divisior: scaling value:
49 * BSP_time_base_divisor = TB ticks per millisecond/BSP_bus_frequency
50 */
51unsigned int BSP_bus_frequency = BSP_CSB_CLK_FRQ;
52unsigned int BSP_time_base_divisor = 4000;  /* 4 bus clicks per TB click */
53
54/*
55 *  Driver configuration parameters
56 */
57uint32_t   bsp_clicks_per_usec;
58
59/*
60 *  Use the shared implementations of the following routines.
61 *  Look in rtems/c/src/lib/libbsp/shared/bsplibc.c.
62 */
63void bsp_libc_init( void *, uint32_t, int );
64extern void initialize_exceptions(void);
65extern void cpu_init(void);
66
67void BSP_panic(char *s)
68  {
69  printk("%s PANIC %s\n",_RTEMS_version, s);
70  /*
71   * FIXME: hang/restart system
72   */
73  __asm__ __volatile ("sc");
74  }
75
76void _BSP_Fatal_error(unsigned int v)
77  {
78  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
79  /*
80   * FIXME: hang/restart system
81   */
82  __asm__ __volatile ("sc");
83  }
84
85/*
86 *  Function:   bsp_pretasking_hook
87 *  Created:    95/03/10
88 *
89 *  Description:
90 *      BSP pretasking hook.  Called just before drivers are initialized.
91 *      Used to setup libc and install any BSP extensions.
92 *
93 *  NOTES:
94 *      Must not use libc (to do io) from here, since drivers are
95 *      not yet initialized.
96 *
97 */
98
99void
100bsp_pretasking_hook(void)
101{
102
103  /*
104   * initialize libc including the heap
105   */
106  bsp_libc_init( BSP_heap_start,
107                 BSP_heap_end - BSP_heap_start,
108                 0);
109
110
111#ifdef STACK_CHECKER_ON
112  /*
113   *  Initialize the stack bounds checker
114   *  We can either turn it on here or from the app.
115   */
116
117  Stack_check_Initialize();
118#endif
119
120#ifdef RTEMS_DEBUG
121  rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
122#endif
123}
124
125void bsp_calc_mem_layout()
126{
127  /*
128   * these labels (!) are defined in the linker command file
129   * or when the linker is invoked
130   * NOTE: the information(size) is the address of the object,
131   * not the object otself
132   */
133  extern unsigned char TopRamReserved;
134  extern unsigned char _WorkspaceBase[];
135
136  /*
137   * compute the memory layout:
138   * - first unused address is Workspace start
139   * - Heap starts at end of workspace
140   * - Heap ends at end of memory - reserved memory area
141   */
142  Configuration.work_space_start = _WorkspaceBase;
143
144  BSP_heap_start = ((char *)Configuration.work_space_start +
145                    rtems_configuration_get_work_space_size());
146
147#if defined(HAS_UBOOT)
148  BSP_heap_end = (uboot_bdinfo_ptr->bi_memstart
149                  + uboot_bdinfo_ptr->bi_memsize
150                  - (uint32_t)&TopRamReserved);
151#else
152  BSP_heap_end = (void *)(RAM_END - (uint32_t)&TopRamReserved);
153#endif
154
155}
156
157
158void bsp_start(void)
159{
160  ppc_cpu_id_t myCpu;
161  ppc_cpu_revision_t myCpuRevision;
162  register unsigned char* intrStack;
163
164  /*
165   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
166   * store the result in global variables so that it can be used latter...
167   */
168  myCpu             = get_ppc_cpu_type();
169  myCpuRevision = get_ppc_cpu_revision();
170  /*
171   * determine heap and workspace placement
172   */
173  bsp_calc_mem_layout();
174
175  cpu_init();
176
177  /*
178   * Initialize some SPRG registers related to irq handling
179   */
180
181  intrStack = (((unsigned char*)&intrStackPtr) - PPC_MINIMUM_STACK_FRAME_SIZE);
182
183  _write_SPRG1((unsigned int)intrStack);
184
185  /* Signal them that this BSP has fixed PR288 - eventually, this should
186   * go away
187   */
188  _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
189
190  /*
191   *  initialize the device driver parameters
192   */
193  bsp_clicks_per_usec        = (BSP_CSB_CLK_FRQ/1000000);
194
195  /*
196   * Install our own set of exception vectors
197   */
198
199  initialize_exceptions();
200
201  /*
202   * Enable instruction and data caches. Do not force writethrough mode.
203   */
204#if INSTRUCTION_CACHE_ENABLE
205  rtems_cache_enable_instruction();
206#endif
207#if DATA_CACHE_ENABLE
208  rtems_cache_enable_data();
209#endif
210
211  /*
212   *  Allocate the memory for the RTEMS Work Space.  This can come from
213   *  a variety of places: hard coded address, malloc'ed from outside
214   *  RTEMS world (e.g. simulator or primitive memory manager), or (as
215   *  typically done by stock BSPs) by subtracting the required amount
216   *  of work space from the last physical address on the CPU board.
217   */
218
219  /*
220   * Initalize RTEMS IRQ system
221   */
222  BSP_rtems_irq_mng_init(0);
223
224#ifdef SHOW_MORE_INIT_SETTINGS
225  printk("Exit from bspstart\n");
226#endif
227
228  }
229
230/*
231 *
232 *  _Thread_Idle_body
233 *
234 *  Replaces the one in c/src/exec/score/src/threadidlebody.c
235 *  The MSR[POW] bit is set to put the CPU into the low power mode
236 *  defined in HID0.  HID0 is set during starup in start.S.
237 *
238 */
239Thread _Thread_Idle_body(uint32_t ignored )
240  {
241
242  for(;;)
243    {
244
245    asm volatile("mfmsr 3; oris 3,3,4; sync; mtmsr 3; isync; ori 3,3,0; ori 3,3,0");
246
247    }
248
249  return 0;
250
251  }
252
Note: See TracBrowser for help on using the repository browser.