source: rtems/c/src/lib/libbsp/powerpc/virtex/startup/bspstart.c @ d046f1e

4.104.114.95
Last change on this file since d046f1e was d046f1e, checked in by Joel Sherrill <joel.sherrill@…>, on 11/28/07 at 22:02:57

2007-11-28 Joel Sherrill <joel.sherrill@…>

  • startup/bspstart.c: Now compiles and links.
  • Property mode set to 100644
File size: 7.8 KB
Line 
1/*  bsp_start()
2 *
3 *  This routine starts the application.  It includes application,
4 *  board, and monitor specific initialization and configuration.
5 *  The generic CPU dependent initialization has been performed
6 *  before this routine is invoked.
7 *
8 *  INPUT:  NONE
9 *
10 *  OUTPUT: NONE
11 *
12 *  Author:     Thomas Doerfler <td@imd.m.isar.de>
13 *              IMD Ingenieurbuero fuer Microcomputertechnik
14 *
15 *  COPYRIGHT (c) 1998 by IMD
16 *
17 *  Changes from IMD are covered by the original distributions terms.
18 *  This file has been derived from the papyrus BSP:
19 *
20 *  Author:     Andrew Bray <andy@i-cubed.co.uk>
21 *
22 *  COPYRIGHT (c) 1995 by i-cubed ltd.
23 *
24 *  To anyone who acknowledges that this file is provided "AS IS"
25 *  without any express or implied warranty:
26 *      permission to use, copy, modify, and distribute this file
27 *      for any purpose is hereby granted without fee, provided that
28 *      the above copyright notice and this notice appears in all
29 *      copies, and that the name of i-cubed limited not be used in
30 *      advertising or publicity pertaining to distribution of the
31 *      software without specific, written prior permission.
32 *      i-cubed limited makes no representations about the suitability
33 *      of this software for any purpose.
34 *
35 *  Modifications for spooling console driver and control of memory layout
36 *  with linker command file by
37 *              Thomas Doerfler <td@imd.m.isar.de>
38 *  for these modifications:
39 *  COPYRIGHT (c) 1997 by IMD, Puchheim, Germany.
40 *
41 *  To anyone who acknowledges that this file is provided "AS IS"
42 *  without any express or implied warranty:
43 *      permission to use, copy, modify, and distribute this file
44 *      for any purpose is hereby granted without fee, provided that
45 *      the above copyright notice and this notice appears in all
46 *      copies. IMD makes no representations about the suitability
47 *      of this software for any purpose.
48 *
49 *  Derived from c/src/lib/libbsp/no_cpu/no_bsp/startup/bspstart.c:
50 *
51 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
52 *  On-Line Applications Research Corporation (OAR).
53 *
54 *  Modifications for PPC405GP by Dennis Ehlin
55 *
56 *  $Id$
57 */
58#include <string.h>
59#include <fcntl.h>
60
61#include <bsp.h>
62#include <rtems/libio.h>
63#include <rtems/libcsupport.h>
64#include <bsp/irq.h>
65#include <rtems/bspIo.h>
66#include <libcpu/cpuIdent.h>
67#include <libcpu/spr.h>
68#include <rtems/powerpc/powerpc.h>
69
70SPR_RW(SPRG0)
71SPR_RW(SPRG1)
72
73#include RTEMS_XPARAMETERS_H
74#include <stdio.h>
75
76/*
77 *  The original table from the application and our copy of it with
78 *  some changes.
79 */
80
81extern rtems_configuration_table Configuration;
82
83rtems_configuration_table  BSP_Configuration;
84
85rtems_cpu_table Cpu_table;
86
87char *rtems_progname;
88
89uint32_t _heap_start;
90uint32_t _heap_end;
91uint32_t _top_of_ram;
92
93/*
94 *  Driver configuration parameters
95 */
96boolean    bsp_exceptions_in_RAM;
97uint32_t   bsp_clicks_per_usec;
98uint32_t   bsp_serial_per_sec;         /* Serial clocks per second */
99boolean    bsp_serial_external_clock;
100boolean    bsp_serial_xon_xoff;
101boolean    bsp_serial_cts_rts;
102uint32_t   bsp_serial_rate;
103uint32_t   bsp_timer_average_overhead; /* Average overhead of timer in ticks */
104uint32_t   bsp_timer_least_valid;      /* Least valid number from timer      */
105boolean    bsp_timer_internal_clock;   /* TRUE, when timer runs with CPU clk */
106
107
108/*      Initialize whatever libc we are using
109 *      called from postdriver hook
110 */
111
112void bsp_XAssertHandler(const char* file, int line);
113void bsp_postdriver_hook(void);
114void bsp_libc_init( void *, uint32_t, int );
115
116
117void bsp_XAssertHandler(const char* file, int line) {
118  printf("\n***\n*** XAssert Failed!  File: %s, Line: %d\n***\n", file, line);
119}
120
121/*
122 *
123 *  bsp_predriver_hook
124 *
125 *  Before drivers are setup.
126 */
127
128void bsp_predriver_hook(void)
129{
130 
131}
132
133/*
134 *  Function:   bsp_pretasking_hook
135 *  Created:    95/03/10
136 *
137 *  Description:
138 *      BSP pretasking hook.  Called just before drivers are initialized.
139 *      Used to setup libc and install any BSP extensions.
140 *
141 *  NOTES:
142 *      Must not use libc (to do io) from here, since drivers are
143 *      not yet initialized.
144 *
145 */
146
147void bsp_pretasking_hook(void)
148{
149
150
151    uint32_t        heap_start;
152    uint32_t        heap_size;
153    uint32_t        heap_end;
154
155    /* round up from the top of workspace to next 64k boundary, get
156     * default heapsize from linker script  */
157    heap_start = (((uint32_t)BSP_Configuration.work_space_start +
158                   BSP_Configuration.work_space_size) + 0x18000) & 0xffff0000;
159
160    heap_end = _heap_start + (uint32_t)&_HeapSize;
161
162    heap_size = (heap_end - heap_start);
163
164    _heap_start = heap_start;
165    _heap_end = heap_end;
166
167    _top_of_ram = heap_end;
168
169    bsp_libc_init((void *) heap_start, heap_size, 0); /* 64 * 1024 */
170
171/*
172  XAssertSetCallback((XAssertCallback*)bsp_XAssertHandler);
173*/
174
175#ifdef RTEMS_DEBUG
176    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
177#endif
178}
179
180/*
181 *  bsp_start
182 *
183 *  This routine does the bulk of the system initialization.
184 */
185
186
187void bsp_start( void )
188{
189  extern unsigned long *intrStackPtr;
190  register unsigned char* intrStack;
191  ppc_cpu_id_t myCpu;
192  ppc_cpu_revision_t myCpuRevision;
193
194  /*
195   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
196   * function store the result in global variables
197   * so that it can be used latter...
198   */
199  myCpu             = get_ppc_cpu_type();
200  myCpuRevision = get_ppc_cpu_revision();
201  /*
202   *  initialize the CPU table for this BSP
203   * NOTE: this must be before the exception initialization,
204   * because exception code useses some information from Cpu_table
205   */
206
207  Cpu_table.pretasking_hook = bsp_pretasking_hook;  /* init libc, etc. */
208  Cpu_table.predriver_hook  = bsp_predriver_hook;
209  Cpu_table.postdriver_hook = bsp_postdriver_hook;
210  Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY;
211
212  /* timebase register ticks/microsecond */
213  bsp_clicks_per_usec = (250000000 / 1000000);
214
215  bsp_serial_per_sec = 14625000;
216  bsp_serial_external_clock = 0;
217  bsp_timer_internal_clock  = 1;
218  bsp_serial_xon_xoff = 0;
219  bsp_serial_cts_rts = 0;
220  bsp_serial_rate = 115200;
221  bsp_timer_average_overhead = 2;
222  bsp_timer_least_valid = 3;
223  bsp_exceptions_in_RAM = TRUE;
224
225  /*
226   * Initialize some SPRG registers related to irq handling
227   */
228
229  intrStack = (((unsigned char*)&intrStackPtr) - PPC_MINIMUM_STACK_FRAME_SIZE);
230  _write_SPRG1((unsigned int)intrStack);
231  /* signal them that we have fixed PR288 - eventually, this should go away */
232  _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
233
234
235  /*
236   * Initialize default raw exception handlers.
237   * See shared/vectors/vectors_init.c
238   */
239  initialize_exceptions();
240
241  /*
242   * Install our own set of exception vectors
243   */
244  BSP_rtems_irq_mng_init(0);
245
246  /*
247   *  Allocate the memory for the RTEMS Work Space.  This can come from
248   *  a variety of places: hard coded address, malloc'ed from outside
249   *  RTEMS world (e.g. simulator or primitive memory manager), or (as
250   *  typically done by stock BSPs) by subtracting the required amount
251   *  of work space from the last physical address on the CPU board.
252   */
253
254  /*
255   *  Need to "allocate" the memory for the RTEMS Workspace and
256   *  tell the RTEMS configuration where it is.  This memory is
257   *  not malloc'ed.  It is just "pulled from the air".
258   */
259  /* FIME: plan usage of RAM better:
260     - make top of ram dynamic,
261     - make rest of ram to heap...
262     -remove RAM_END from bsp.h, this cannot be valid...
263      or must be a function call
264   */
265  {
266    extern int _end;
267
268    /* round _end up to next 64k boundary for start of workspace */
269    BSP_Configuration.work_space_start = (void *)((((uint32_t)&_end) + 0x18000) & 0xffff0000);
270  }
271
272}
273
274void BSP_ask_for_reset(void)
275{
276  printk("system stopped, press RESET");
277  while(1) {};
278}
279
280void BSP_panic(char *s)
281{
282  printk("%s PANIC %s\n",_RTEMS_version, s);
283  BSP_ask_for_reset();
284}
285
286void _BSP_Fatal_error(unsigned int v)
287{
288  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
289  BSP_ask_for_reset();
290}
291 
Note: See TracBrowser for help on using the repository browser.