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

4.115
Last change on this file since 24bf11e was 24bf11e, checked in by Sebastian Huber <sebastian.huber@…>, on 02/12/14 at 09:31:38

score: Add CPU counter support

Add a CPU counter interface to allow access to a free-running counter.
It is useful to measure short time intervals. This can be used for
example to enable profiling of critical low-level functions.

Add two busy wait functions rtems_counter_delay_ticks() and
rtems_counter_delay_nanoseconds() implemented via the CPU counter.

  • Property mode set to 100644
File size: 3.0 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-2008.
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
15#include <string.h>
16#include <fcntl.h>
17#include <bsp.h>
18#include <bsp/irq.h>
19#include <psim.h>
20#include <bsp/bootcard.h>
21#include <bsp/linker-symbols.h>
22#include <rtems/bspIo.h>
23#include <rtems/counter.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(SPRG1)
31
32/*  On psim, each click of the decrementer register corresponds
33 *  to 1 instruction.  By setting this to 100, we are indicating
34 *  that we are assuming it can execute 100 instructions per
35 *  microsecond.  This corresponds to sustaining 1 instruction
36 *  per cycle at 100 Mhz.  Whether this is a good guess or not
37 *  is anyone's guess.
38 */
39extern int PSIM_INSTRUCTIONS_PER_MICROSECOND[];
40
41/*
42 * PCI Bus Frequency
43 */
44unsigned int BSP_bus_frequency;
45
46/*
47 *  Driver configuration parameters
48 */
49uint32_t   bsp_clicks_per_usec;
50
51/*
52 * Memory on this board.
53 */
54uint32_t BSP_mem_size = (uint32_t)RamSize;
55
56/*
57 * Time base divisior (how many tick for 1 second).
58 */
59unsigned int BSP_time_base_divisor;
60
61extern unsigned long __rtems_end[];
62
63void BSP_panic(char *s)
64{
65  printk("%s PANIC %s\n",_RTEMS_version, s);
66  __asm__ __volatile ("sc");
67}
68
69void _BSP_Fatal_error(unsigned int v)
70{
71  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
72  __asm__ __volatile ("sc");
73}
74
75/*
76 *  bsp_start
77 *
78 *  This routine does the bulk of the system initialization.
79 */
80void bsp_start( void )
81{
82  /*
83   * Note we can not get CPU identification dynamically.
84   * PVR has to be set to PPC_PSIM (0xfffe) from the device
85   * file.
86   */
87
88  get_ppc_cpu_type();
89
90  /*
91   *  initialize the device driver parameters
92   */
93  BSP_bus_frequency        = (unsigned int)PSIM_INSTRUCTIONS_PER_MICROSECOND;
94  bsp_clicks_per_usec      = BSP_bus_frequency;
95  BSP_time_base_divisor    = 1;
96  rtems_counter_initialize_converter(bsp_clicks_per_usec * 1000000);
97
98  /*
99   * Initialize default raw exception handlers.
100   */
101  ppc_exc_initialize_with_vector_base(
102    PPC_INTERRUPT_DISABLE_MASK_DEFAULT,
103    (uintptr_t) bsp_section_work_begin,
104    rtems_configuration_get_interrupt_stack_size(),
105    (void *) 0xfff00000
106  );
107
108  /*
109   * Initalize RTEMS IRQ system
110   */
111  BSP_rtems_irq_mng_init(0);
112
113  /*
114   * Setup BATs and enable MMU
115   */
116  /* Memory */
117  setdbat(0, 0x0<<24, 0x0<<24, 2<<24, _PAGE_RW);
118  setibat(0, 0x0<<24, 0x0<<24, 2<<24,        0);
119  /* PCI    */
120  setdbat(1, 0x8<<24, 0x8<<24, 1<<24,  IO_PAGE);
121  setdbat(2, 0xc<<24, 0xc<<24, 1<<24,  IO_PAGE);
122
123  _write_MSR(_read_MSR() | MSR_DR | MSR_IR);
124  __asm__ volatile("sync; isync");
125
126}
Note: See TracBrowser for help on using the repository browser.