source: rtems/c/src/lib/libbsp/powerpc/ppcn_60x/startup/bspstart.c @ eba2e4f

4.104.114.84.95
Last change on this file since eba2e4f was eba2e4f, checked in by Joel Sherrill <joel.sherrill@…>, on 11/01/00 at 21:19:23

2000-11-01 Joel Sherrill <joel@…>

  • startup/bspstart.c: assoc.h, error.h, libio_.h, libio.h, and libcsupport.h moved from libc to lib/include/rtems and now must be referenced as <rtems/XXX.h>. Header file order was cleaned up while doing this.
  • Property mode set to 100644
File size: 6.7 KB
Line 
1/*
2 *  COPYRIGHT (c) 1998 by Radstone Technology
3 *
4 *
5 * THIS FILE IS PROVIDED TO YOU, THE USER, "AS IS", WITHOUT WARRANTY OF ANY
6 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
7 * IMPLIED WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK
8 * AS TO THE QUALITY AND PERFORMANCE OF ALL CODE IN THIS FILE IS WITH YOU.
9 *
10 * You are hereby granted permission to use, copy, modify, and distribute
11 * this file, provided that this notice, plus the above copyright notice
12 * and disclaimer, appears in all copies. Radstone Technology will provide
13 * no support for this code.
14 *
15 */
16/*  bspstart.c
17 *
18 *  This set of routines starts the application.  It includes application,
19 *  board, and monitor specific initialization and configuration.
20 *  The generic CPU dependent initialization has been performed
21 *  before any of these are invoked.
22 *
23 *  COPYRIGHT (c) 1989-1997.
24 *  On-Line Applications Research Corporation (OAR).
25 *  Copyright assigned to U.S. Government, 1994.
26 *
27 *  The license and distribution terms for this file may in
28 *  the file LICENSE in this distribution or at
29 *  http://www.OARcorp.com/rtems/license.html.
30 *
31 *  $Id:
32 */
33
34#include <string.h>
35
36#include <bsp.h>
37#include <rtems/libio.h>
38#include <rtems/libcsupport.h>
39#include <pci.h>
40
41unsigned char ucSystemType;
42unsigned char ucBoardRevMaj;
43unsigned char ucBoardRevMin;
44unsigned long ulMemorySize;
45unsigned long ulCpuBusClock;
46
47/*
48 * The bus speed is expressed in MHz
49 */
50static unsigned long ulBusSpeed[] = {
51        56250000,
52        60000000,
53        64300000,
54        66666667,
55        75000000,
56        83333333,
57        100000000,
58        66666667
59};
60
61/*
62 *  The original table from the application and our copy of it with
63 *  some changes.
64 */
65 
66extern rtems_configuration_table  Configuration;
67rtems_configuration_table         BSP_Configuration;
68
69rtems_cpu_table   Cpu_table;
70rtems_unsigned32  bsp_isr_level;
71
72static int stdin_fd, stdout_fd, stderr_fd;
73
74/*
75 * End of RTEMs image imported from linker
76 */
77extern int end;
78
79/*
80 *  Use the shared implementations of the following routines
81 */
82
83void bsp_postdriver_hook(void);
84void bsp_libc_init( void *, unsigned32, int );
85
86/*
87 *  bsp_pretasking_hook
88 *
89 *  BSP pretasking hook.  Called just before drivers are initialized.
90 *  Used to setup libc and install any BSP extensions.
91 */
92
93void bsp_pretasking_hook(void)
94{
95        rtems_unsigned32 heap_start;
96        rtems_unsigned32 heap_size;
97
98        heap_start = (rtems_unsigned32) &end;
99        if (heap_start & (CPU_ALIGNMENT-1))
100          heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
101
102        heap_size = BSP_Configuration.work_space_start - (void *)&end;
103        heap_size &= 0xfffffff0;  /* keep it as a multiple of 16 bytes */
104
105        bsp_libc_init((void *) heap_start, heap_size, 0);
106
107        /*
108         * Initialise RTC hooks based on system type
109         */
110        InitializeRTC();
111
112        /*
113         * Initialise NvRAM hooks based on system type
114         */
115        InitializeNvRAM();
116
117        /*
118         * Initialise the PCI bus(ses)
119         */
120        InitializePCI();
121
122        /*
123         * Initialize the Universe PCI-VME bridge
124         */
125        InitializeUniverse();
126
127
128#ifdef RTEMS_DEBUG
129  rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
130#endif
131
132}
133
134/*
135 *  bsp_std_close
136 *
137 *  Simple routine to close all standard IO streams.
138 */
139
140void bsp_std_close( void )
141{
142        close(stdin_fd);
143        close(stdout_fd);
144        close(stderr_fd);
145}
146 
147
148/*
149 *  bsp_predriver_hook
150 *
151 *  Before drivers are setup.
152 */
153void bsp_predriver_hook(void)
154{
155  /* bsp_spurious_initialize; ??*/
156  initialize_external_exception_vector();
157}
158
159/*
160 *  bsp_start
161 *
162 *  This routine does the bulk of the system initialization.
163 */
164
165void bsp_start( void )
166{
167        unsigned char *work_space_start;
168        unsigned char ucBoardRev, ucMothMemType, ucEquipPres1, ucEquipPres2;
169        unsigned16      usPVR=0;
170        unsigned8       ucTempl, ucTemph;
171        unsigned8       ucBanksPresent;
172        unsigned8       ucSimmPresent;
173        unsigned32      ulCurBank, ulTopBank;
174
175        /*
176         * Determine system type
177         */
178        inport_byte(&((PPLANARREGISTERS)0)->MotherboardMemoryType, ucMothMemType);
179        inport_byte(&((PPLANARREGISTERS)0)->SimmPresent, ucSimmPresent);
180
181        inport_byte(&((PPLANARREGISTERS)0)->EquipmentPresent1, ucEquipPres1);
182        inport_byte(&((PPLANARREGISTERS)0)->EquipmentPresent2, ucEquipPres2);
183        ucSystemType=((ucMothMemType&0x03)<<1) | ((ucEquipPres1&0x80)>>7);
184        ucSystemType^=7;
185
186        /*
187         * Determine board revision for use by rev. specific code
188         */
189        inport_byte(&((PPLANARREGISTERS)0)->BoardRevision, ucBoardRev);
190        ucBoardRevMaj=ucBoardRev>>5;
191        ucBoardRevMin=ucBoardRev&0x1f;
192
193        /*
194         * Determine the memory size by reading the end address for top
195         * assigned bank in the memory controller
196         */
197        (void)PCIConfigRead8(0,0,0,0xa0, &ucBanksPresent);
198        for(ulCurBank=0;ulCurBank<8;ulCurBank++)
199        {
200                if((ucBanksPresent>>ulCurBank)&0x01)
201                {
202                        ulTopBank=ulCurBank;
203                }
204        }
205
206        (void)PCIConfigRead8(0,0,0,0x90+ulTopBank, &ucTempl);
207        (void)PCIConfigRead8(0,0,0,0x98+ulTopBank, &ucTemph);
208        ulMemorySize=(ucTempl+(ucTemph<<8)+1)<<20;
209#if PPCN_60X_USE_DINK
210        ulMemorySize=0x01fe0000;
211#endif
212
213        /*
214         * Determine processor bus clock
215         */
216        asm volatile ("mfpvr %0" : "=r" ((usPVR)) : "0" ((usPVR)));
217
218        /*
219         * Determine processor internal clock
220         */
221        if(ucSystemType==SYS_TYPE_PPC4)
222        {
223                if(((ucBoardRevMaj==1) && (ucBoardRevMin==0)) ||
224                   ((ucSimmPresent&0x40)==0))
225                {
226                        /*
227                         * Rev. 1A is always 66MHz
228                         */
229                        ulCpuBusClock=66666667;
230                }
231                else
232                {
233                        ulCpuBusClock=83333333;
234                }
235        }
236        else if((((usPVR>>16)==MPC603e) && (ucSystemType!=SYS_TYPE_PPC1)) ||
237                ((usPVR>>16)==MPC603ev) ||
238                ((usPVR>>16)==MPC604e))
239        {
240                ulCpuBusClock=ulBusSpeed[(ucEquipPres2&0x1c)>>2];
241        }
242        else
243        {
244                if(((ucSystemType>SYS_TYPE_PPC1) || (ucBoardRevMaj>=5)) &&
245                   (ucEquipPres1&0x08))
246                {
247                        /*
248                         * 66 MHz bus clock for 005 if indicated
249                         */
250                        ulCpuBusClock=66666667;
251                }
252                else
253                {
254                        /*
255                         * 33 MHz bus clock for 004 always
256                         */
257                        ulCpuBusClock=33333333;
258                }
259        }
260
261
262  /*
263   *  Allocate the memory for the RTEMS Work Space.  This can come from
264   *  a variety of places: hard coded address, malloc'ed from outside
265   *  RTEMS world (e.g. simulator or primitive memory manager), or (as
266   *  typically done by stock BSPs) by subtracting the required amount
267   *  of work space from the last physical address on the CPU board.
268   */
269
270  work_space_start =
271    (unsigned char *)ulMemorySize - BSP_Configuration.work_space_size;
272
273  if ( work_space_start <= (unsigned char *)&end ) {
274    DEBUG_puts( "bspstart: Not enough RAM!!!\n" );
275    bsp_cleanup();
276  }
277
278  BSP_Configuration.work_space_start = work_space_start;
279
280  /*
281   *  initialize the CPU table for this BSP
282   */
283
284  Cpu_table.exceptions_in_RAM = TRUE;
285  Cpu_table.pretasking_hook = bsp_pretasking_hook;    /* init libc, etc. */
286  Cpu_table.predriver_hook = bsp_predriver_hook;
287  Cpu_table.postdriver_hook = bsp_postdriver_hook;
288  Cpu_table.do_zero_of_workspace = TRUE;
289  Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY;
290  Cpu_table.clicks_per_usec = ulCpuBusClock/4000000;
291
292
293}
294
Note: See TracBrowser for help on using the repository browser.