source: rtems/c/src/lib/libbsp/powerpc/gen83xx/startup/cpuinit.c @ 3df08660

4.104.114.84.95
Last change on this file since 3df08660 was f610e83f, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 07/10/07 at 16:00:28

compilable release of virtex/gen83xx/gen5200 powerpc adaptations. Merged many different versions of new exception handling code to shared sources.

  • Property mode set to 100644
File size: 8.1 KB
Line 
1/*===============================================================*\
2| Project: RTEMS generic MPC83xx BSP                              |
3+-----------------------------------------------------------------+
4| Partially based on the code references which are named below.   |
5| Adaptions, modifications, enhancements and any recent parts of  |
6| the code are:                                                   |
7|                    Copyright (c) 2005                           |
8|                    Embedded Brains GmbH                         |
9|                    Obere Lagerstr. 30                           |
10|                    D-82178 Puchheim                             |
11|                    Germany                                      |
12|                    rtems@embedded-brains.de                     |
13+-----------------------------------------------------------------+
14| The license and distribution terms for this file may be         |
15| found in the file LICENSE in this distribution or at            |
16|                                                                 |
17| http://www.rtems.com/license/LICENSE.                           |
18|                                                                 |
19+-----------------------------------------------------------------+
20| this file contains the code to initialize the cpu               |
21\*===============================================================*/
22/***********************************************************************/
23/*                                                                     */
24/*   Module:       cpuinit.c                                           */
25/*   Date:         07/17/2003                                          */
26/*   Purpose:      RTEMS MPC5x00 C level startup code                  */
27/*                                                                     */
28/*---------------------------------------------------------------------*/
29/*                                                                     */
30/*   Description:  This file contains additional functions for         */
31/*                 initializing the MPC5x00 CPU                        */
32/*                                                                     */
33/*---------------------------------------------------------------------*/
34/*                                                                     */
35/*   Code                                                              */
36/*   References:   MPC8260ads additional CPU initialization            */
37/*   Module:       cpuinit.c                                           */
38/*   Project:      RTEMS 4.6.0pre1 / MCF8260ads BSP                    */
39/*   Version       1.1                                                 */
40/*   Date:         10/22/2002                                          */
41/*                                                                     */
42/*   Author(s) / Copyright(s):                                         */
43/*                                                                     */
44/*   Written by Jay Monkman (jmonkman@frasca.com)                      */
45/*                                                                     */
46/*---------------------------------------------------------------------*/
47/*                                                                     */
48/*   Partially based on the code references which are named above.     */
49/*   Adaptions, modifications, enhancements and any recent parts of    */
50/*   the code are under the right of                                   */
51/*                                                                     */
52/*         IPR Engineering, Dachauer Straße 38, D-80335 MÃŒnchen        */
53/*                        Copyright(C) 2003                            */
54/*                                                                     */
55/*---------------------------------------------------------------------*/
56/*                                                                     */
57/*   IPR Engineering makes no representation or warranties with        */
58/*   respect to the performance of this computer program, and          */
59/*   specifically disclaims any responsibility for any damages,        */
60/*   special or consequential, connected with the use of this program. */
61/*                                                                     */
62/*---------------------------------------------------------------------*/
63/*                                                                     */
64/*   Version history:  1.0                                             */
65/*                                                                     */
66/***********************************************************************/
67
68#include <bsp.h>
69#include <rtems/powerpc/registers.h>
70#include <mpc83xx/mpc83xx.h>
71
72#include <libcpu/mmu.h>
73#include <libcpu/spr.h>
74#include <string.h>
75
76#define USE_IMMU
77
78/* Macros for HID0 access */
79#define SET_HID0(r)   __asm__ volatile ("mtspr 0x3F0,%0\n" ::"r"(r))
80#define GET_HID0(r)   __asm__ volatile ("mfspr %0,0x3F0\n" :"=r"(r))
81
82#define DBAT_MTSPR(val,name) __MTSPR(val,name);
83#define SET_DBAT(n,uv,lv) {DBAT_MTSPR(lv,DBAT##n##L);DBAT_MTSPR(uv,DBAT##n##U);}
84#if defined(USE_IMMU )
85#define IBAT_MTSPR(val,name) __MTSPR(val,name);
86#define SET_IBAT(n,uv,lv) {IBAT_MTSPR(lv,IBAT##n##L);IBAT_MTSPR(uv,IBAT##n##U);}
87#endif
88
89void calc_dbat_regvals(BAT *bat_ptr,
90                       uint32_t base_addr,
91                       uint32_t size,
92                       boolean flg_w,
93                       boolean flg_i,
94                       boolean flg_m,
95                       boolean flg_g,
96                       boolean flg_bpp)
97{
98  uint32_t block_mask;
99  uint32_t end_addr;
100
101  /*
102   * determine block mask, that overlaps the whole block
103   */
104  end_addr = base_addr+size-1;
105  block_mask = ~0;
106  while ((end_addr & block_mask) != (base_addr & block_mask)) {
107    block_mask <<= 1;
108  }
109 
110  bat_ptr->batu.bepi  = base_addr  >> (32-15);
111  bat_ptr->batu.bl    = ~(block_mask >> (28-11));
112  bat_ptr->batu.vs    = 1;
113  bat_ptr->batu.vp    = 1;
114 
115  bat_ptr->batl.brpn  = base_addr  >> (32-15);
116  bat_ptr->batl.w  = flg_w;
117  bat_ptr->batl.i  = flg_i;
118  bat_ptr->batl.m  = flg_m;
119  bat_ptr->batl.g  = flg_g;
120  bat_ptr->batl.pp = flg_bpp;
121}
122
123void clear_mmu_regs(void)
124{
125  uint32_t i;
126  /*
127   * clear segment registers
128   */
129  for (i = 0;i < 16;i++) {
130    asm volatile(" mtsrin       %0, %1\n"::"r" (i * 0x1000),"r"(i<<(31-3)));
131  }
132  /*
133   * clear TLBs
134   */
135  for (i = 0;i < 32;i++) {
136    asm volatile(" tlbie        %0\n"::"r" (i << (31-19)));
137  }
138}
139
140void cpu_init(void)
141{
142  register unsigned long reg;
143  BAT dbat,ibat;
144
145  /*
146   * clear MMU/Segment registers
147   */
148  clear_mmu_regs();
149  /*
150   * clear caches
151   */
152  GET_HID0(reg);
153  reg |=  (HID0_ICFI | HID0_DCI);
154  SET_HID0(reg);
155  reg &= ~(HID0_ICFI | HID0_DCI);
156  SET_HID0(reg);
157 
158  /*
159   * set up IBAT registers in MMU
160   */
161  memset(&ibat,0,sizeof(ibat));
162  SET_IBAT(2,ibat.batu,ibat.batl);
163  SET_IBAT(3,ibat.batu,ibat.batl);
164  SET_IBAT(4,ibat.batu,ibat.batl);
165  SET_IBAT(5,ibat.batu,ibat.batl);
166  SET_IBAT(6,ibat.batu,ibat.batl);
167  SET_IBAT(7,ibat.batu,ibat.batl);
168
169  calc_dbat_regvals(&ibat,RAM_START,RAM_SIZE,0,0,0,0,BPP_RX);
170  SET_IBAT(0,ibat.batu,ibat.batl);
171  calc_dbat_regvals(&ibat,ROM_START,ROM_SIZE,0,0,0,0,BPP_RX);
172  SET_IBAT(1,ibat.batu,ibat.batl);
173
174  /*
175   * set up DBAT registers in MMU
176   */
177  memset(&dbat,0,sizeof(dbat));
178  SET_DBAT(3,dbat.batu,dbat.batl);
179  SET_DBAT(4,dbat.batu,dbat.batl);
180  SET_DBAT(5,dbat.batu,dbat.batl);
181  SET_DBAT(6,dbat.batu,dbat.batl);
182  SET_DBAT(7,dbat.batu,dbat.batl);
183
184  calc_dbat_regvals(&dbat,RAM_START,RAM_SIZE,1,0,1,0,BPP_RW);
185  SET_DBAT(0,dbat.batu,dbat.batl);
186
187  calc_dbat_regvals(&dbat,ROM_START,ROM_SIZE,1,0,1,0,BPP_RX);
188  SET_DBAT(1,dbat.batu,dbat.batl);
189
190  calc_dbat_regvals(&dbat,IMMRBAR,1024*1024,1,1,1,1,BPP_RW);
191  SET_DBAT(2,dbat.batu,dbat.batl);
192
193  /*
194   * enable data/instruction MMU in MSR
195   */
196  _write_MSR(_read_MSR() | MSR_DR/* | MSR_IR*/);
197
198  /*
199   * enable FPU in MSR
200   */
201  _write_MSR(_read_MSR() | MSR_FP);
202
203  /*
204   * in HID0:
205   * - enable dynamic power management
206   * - enable machine check interrupts
207   */
208  GET_HID0(reg);
209  reg |=  (HID0_EMCP | HID0_DPM) ;
210  SET_HID0(reg);
211
212  /*
213   * enable timebase clock
214   */
215  mpc83xx.syscon.spcr |= M83xx_SYSCON_SPCR_TBEN;
216}
Note: See TracBrowser for help on using the repository browser.