source: rtems/c/src/lib/libbsp/powerpc/gen83xx/startup/bspstart.c @ 2211b75c

4.104.114.95
Last change on this file since 2211b75c was 42bf1b9, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 05/15/08 at 15:10:38

adapted gen83xx to new board

  • Property mode set to 100644
File size: 6.3 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;
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   * this is evaluated during runtime, so it should be ok to set it
192   * before we initialize the drivers
193   */
194  BSP_bus_frequency   = BSP_CLKIN_FRQ * BSP_SYSPLL_MF / BSP_SYSPLL_CKID;
195  /*
196   *  initialize the device driver parameters
197   */
198  bsp_clicks_per_usec = (BSP_bus_frequency/1000000);
199
200  /*
201   * Install our own set of exception vectors
202   */
203
204  initialize_exceptions();
205
206  /*
207   * Enable instruction and data caches. Do not force writethrough mode.
208   */
209#if INSTRUCTION_CACHE_ENABLE
210  rtems_cache_enable_instruction();
211#endif
212#if DATA_CACHE_ENABLE
213  rtems_cache_enable_data();
214#endif
215
216  /*
217   *  Allocate the memory for the RTEMS Work Space.  This can come from
218   *  a variety of places: hard coded address, malloc'ed from outside
219   *  RTEMS world (e.g. simulator or primitive memory manager), or (as
220   *  typically done by stock BSPs) by subtracting the required amount
221   *  of work space from the last physical address on the CPU board.
222   */
223
224  /*
225   * Initalize RTEMS IRQ system
226   */
227  BSP_rtems_irq_mng_init(0);
228
229#ifdef SHOW_MORE_INIT_SETTINGS
230  printk("Exit from bspstart\n");
231#endif
232
233  }
234
235/*
236 *
237 *  _Thread_Idle_body
238 *
239 *  Replaces the one in c/src/exec/score/src/threadidlebody.c
240 *  The MSR[POW] bit is set to put the CPU into the low power mode
241 *  defined in HID0.  HID0 is set during starup in start.S.
242 *
243 */
244Thread _Thread_Idle_body(uint32_t ignored )
245  {
246
247  for(;;)
248    {
249
250    asm volatile("mfmsr 3; oris 3,3,4; sync; mtmsr 3; isync; ori 3,3,0; ori 3,3,0");
251
252    }
253
254  return 0;
255
256  }
257
Note: See TracBrowser for help on using the repository browser.