source: rtems/c/src/lib/libbsp/powerpc/gen83xx/startup/bspstart.c @ 3c6fe2e

4.104.114.95
Last change on this file since 3c6fe2e was 3c6fe2e, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 07/14/08 at 08:46:06

added haleakala BSP contributed by Michael Hamel

  • Property mode set to 100644
File size: 6.1 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
111void bsp_calc_mem_layout()
112{
113  /*
114   * these labels (!) are defined in the linker command file
115   * or when the linker is invoked
116   * NOTE: the information(size) is the address of the object,
117   * not the object otself
118   */
119  extern unsigned char TopRamReserved;
120  extern unsigned char _WorkspaceBase[];
121
122  /*
123   * compute the memory layout:
124   * - first unused address is Workspace start
125   * - Heap starts at end of workspace
126   * - Heap ends at end of memory - reserved memory area
127   */
128  Configuration.work_space_start = _WorkspaceBase;
129
130  BSP_heap_start = ((char *)Configuration.work_space_start +
131                    rtems_configuration_get_work_space_size());
132
133#if defined(HAS_UBOOT)
134  BSP_heap_end = (uboot_bdinfo_ptr->bi_memstart
135                  + uboot_bdinfo_ptr->bi_memsize
136                  - (uint32_t)&TopRamReserved);
137#else
138  BSP_heap_end = (void *)(RAM_END - (uint32_t)&TopRamReserved);
139#endif
140
141}
142
143
144void bsp_start(void)
145{
146  ppc_cpu_id_t myCpu;
147  ppc_cpu_revision_t myCpuRevision;
148  register unsigned char* intrStack;
149
150  /*
151   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
152   * store the result in global variables so that it can be used latter...
153   */
154  myCpu             = get_ppc_cpu_type();
155  myCpuRevision = get_ppc_cpu_revision();
156  /*
157   * determine heap and workspace placement
158   */
159  bsp_calc_mem_layout();
160
161  cpu_init();
162
163  /*
164   * Initialize some SPRG registers related to irq handling
165   */
166
167  intrStack = (((unsigned char*)&intrStackPtr) - PPC_MINIMUM_STACK_FRAME_SIZE);
168
169  _write_SPRG1((unsigned int)intrStack);
170
171  /* Signal them that this BSP has fixed PR288 - eventually, this should
172   * go away
173   */
174  _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
175
176  /*
177   * this is evaluated during runtime, so it should be ok to set it
178   * before we initialize the drivers
179   */
180  BSP_bus_frequency   = BSP_CLKIN_FRQ * BSP_SYSPLL_MF / BSP_SYSPLL_CKID;
181  /*
182   *  initialize the device driver parameters
183   */
184  bsp_clicks_per_usec = (BSP_bus_frequency/1000000);
185
186  /*
187   * Install our own set of exception vectors
188   */
189
190  initialize_exceptions();
191
192  /*
193   * Enable instruction and data caches. Do not force writethrough mode.
194   */
195#if INSTRUCTION_CACHE_ENABLE
196  rtems_cache_enable_instruction();
197#endif
198#if DATA_CACHE_ENABLE
199  rtems_cache_enable_data();
200#endif
201
202  /*
203   *  Allocate the memory for the RTEMS Work Space.  This can come from
204   *  a variety of places: hard coded address, malloc'ed from outside
205   *  RTEMS world (e.g. simulator or primitive memory manager), or (as
206   *  typically done by stock BSPs) by subtracting the required amount
207   *  of work space from the last physical address on the CPU board.
208   */
209
210  /*
211   * Initalize RTEMS IRQ system
212   */
213  BSP_rtems_irq_mng_init(0);
214
215#ifdef SHOW_MORE_INIT_SETTINGS
216  printk("Exit from bspstart\n");
217#endif
218
219  }
220
221/*
222 *
223 *  _Thread_Idle_body
224 *
225 *  Replaces the one in c/src/exec/score/src/threadidlebody.c
226 *  The MSR[POW] bit is set to put the CPU into the low power mode
227 *  defined in HID0.  HID0 is set during starup in start.S.
228 *
229 */
230Thread _Thread_Idle_body(uint32_t ignored )
231  {
232
233  for(;;)
234    {
235
236    asm volatile("mfmsr 3; oris 3,3,4; sync; mtmsr 3; isync; ori 3,3,0; ori 3,3,0");
237
238    }
239
240  return 0;
241
242  }
243
Note: See TracBrowser for help on using the repository browser.