source: rtems/c/src/lib/libbsp/powerpc/dmv177/startup/bspstart.c @ a38b9f8

4.104.114.84.95
Last change on this file since a38b9f8 was c932d85, checked in by Joel Sherrill <joel.sherrill@…>, on 05/30/98 at 10:09:14

New files -- from rtems-LM-980406 which was based on an RTEMS from 12/97.
This was called the dmv170 BSP in that source tree but since the DMV171
is now obsolete, we have transitioned to the DMV177 and have no intention
of checking compatibility with any other models.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*  bspstart.c
2 *
3 *  This set of routines 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 any of these are invoked.
7 *
8 *  Called by RTEMS::RTEMS constructor in rtems-ctor.cc
9 *
10 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994, 1997.
11 *  On-Line Applications Research Corporation (OAR).
12 *  All rights assigned to U.S. Government, 1994.
13 *
14 *  $Id$
15 */
16
17#include <bsp.h>
18#include <rtems/libio.h>
19
20#include <libcsupport.h>
21
22#include <string.h>
23#include <fcntl.h>
24
25#ifdef STACK_CHECKER_ON
26#include <stackchk.h>
27#endif
28
29/*
30 *  The original table from the application and our copy of it with
31 *  some changes.
32 */
33 
34extern rtems_configuration_table  Configuration;
35rtems_configuration_table         BSP_Configuration;
36rtems_cpu_table                   Cpu_table;
37rtems_unsigned32                  bsp_isr_level;
38
39/*  PAGE
40 *
41 *  bsp_libc_init
42 *
43 *  Initialize whatever libc we are using called from bsp_postdriver_hook.
44 *
45 *  Input parameters: NONE
46 *
47 *  Output parameters:  NONE
48 *
49 *  Return values: NONE
50 * 
51 */
52
53void bsp_libc_init(void)
54{
55  extern int end;
56  rtems_unsigned32 heap_start;
57  rtems_unsigned32 heap_size;
58
59  heap_start = (rtems_unsigned32) &end;
60  if (heap_start & (CPU_ALIGNMENT-1))
61    heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
62
63  heap_size = BSP_Configuration.work_space_start - (void *)&end;
64  heap_size &= 0xfffffff0;  /* keep it as a multiple of 16 bytes */
65
66  RTEMS_Malloc_Initialize((void *) heap_start, heap_size, 0);
67
68  /*
69   *  Init the RTEMS libio facility to provide UNIX-like system
70   *  calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc)
71   *  Uses malloc() to get area for the iops, so must be after malloc init
72   */
73 
74  rtems_libio_init();
75 
76  /*
77   * Set up for the libc handling.
78   */
79 
80  if (BSP_Configuration.ticks_per_timeslice > 0)
81    libc_init(1);                /* reentrant if possible */
82  else
83    libc_init(0);                /* non-reentrant */
84
85}
86
87
88/*  PAGE
89 *
90 *  bsp_pretasking_hook
91 *
92 *  BSP pretasking hook.  Called just before drivers are initialized.
93 *  Used to setup libc and install any BSP extensions.
94 *
95 *  Input parameters: NONE
96 *
97 *  Output parameters:  NONE
98 *
99 *  Return values: NONE
100 * 
101 */
102
103void bsp_pretasking_hook(void)
104{
105  bsp_libc_init();
106
107#ifdef STACK_CHECKER_ON
108  /*
109   *  Initialize the stack bounds checker
110   *  We can either turn it on here or from the app.
111   */
112
113  Stack_check_Initialize();
114#endif
115
116#ifdef RTEMS_DEBUG
117  rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
118#endif
119
120}
121
122/*  PAGE
123 *
124 *  bsp_predriver_hook
125 *
126 *  Initialization before drivers are setup.
127 *  Input parameters: NONE
128 *
129 *  Output parameters:  NONE
130 *
131 *  Return values: NONE
132 */
133
134void bsp_predriver_hook(void)
135{
136  initialize_external_exception_vector();
137}
138
139/*  PAGE
140 *
141 *  bsp_postdriver_hook
142 *
143 *  After drivers are setup, register some "filenames"
144 *  and open stdin, stdout, stderr files
145 *
146 *  Newlib will automatically associate the files with these
147 *  (it hardcodes the numbers)
148 *
149 *  Input parameters: NONE
150 *
151 *  Output parameters:  NONE
152 *
153 *  Return values: NONE
154 * 
155 */
156 
157void bsp_postdriver_hook(void)
158{
159  int stdin_fd, stdout_fd, stderr_fd;
160  int error_code;
161 
162  error_code = 'S' << 24 | 'T' << 16;
163 
164  if ((stdin_fd = __rtems_open("/dev/console", O_RDONLY, 0)) == -1)
165    rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' );
166 
167  if ((stdout_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)
168    rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' );
169 
170  if ((stderr_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)
171    rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' );
172 
173  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
174    rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' );
175}
176
177/*  PAGE
178 *
179 *  bsp_start
180 *
181 *  This routine does the bulk of the system initialization.
182 *
183 *  Input parameters: NONE
184 *
185 *  Output parameters:  NONE
186 *
187 *  Return values: NONE
188 * 
189 */
190
191void bsp_start( void )
192{
193  unsigned char *work_space_start;
194  unsigned int  msr_value = 0x2030;
195
196  /*
197   * Set BSP to initial value. Note: This value is a guess
198   * check how the real board comes up. This is critical to
199   * getting the source to work with the debugger.
200   */
201  _CPU_MSR_SET( msr_value );
202   
203  /*
204   * Set up our hooks
205   * Make sure libc_init is done before drivers initialized so that
206   * they can use atexit()
207   */
208
209  Cpu_table.exceptions_in_RAM = TRUE;
210
211  Cpu_table.pretasking_hook = bsp_pretasking_hook;    /* init libc, etc. */
212
213  Cpu_table.predriver_hook = bsp_predriver_hook;
214
215  Cpu_table.postdriver_hook = bsp_postdriver_hook;
216
217  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
218
219  Cpu_table.clicks_per_usec = 66 / 4; /* XXX get from linkcmds */
220
221
222  /*
223   *  SIS does zero out memory BUT only when IT begins execution.  Thus
224   *  if we want to have a clean slate in the workspace each time we
225   *  begin execution of OUR application, then we must zero the workspace.
226   */
227
228  Cpu_table.do_zero_of_workspace = TRUE;
229
230  /*
231   *  This should be enough interrupt stack.
232   */
233
234  Cpu_table.interrupt_stack_size = (12 * 1024);
235
236  /*
237   *  DMV170 does not support MP configurations so there is really no way
238   *  to check this out.
239   */
240
241  Cpu_table.extra_mpci_receive_server_stack = 0;
242
243  /*
244   *  Copy the table and allocate memory for the RTEMS Workspace
245   */
246
247  BSP_Configuration = Configuration;
248
249#if defined(RTEMS_POSIX_API)
250  BSP_Configuration.work_space_size *= 3;
251#endif
252
253  work_space_start =
254    (unsigned char *)&RAM_END - BSP_Configuration.work_space_size;
255
256  if ( work_space_start <= (unsigned char *)&end ) {
257    DEBUG_puts( "bspstart: Not enough RAM!!!\n" );
258    bsp_cleanup();
259  }
260
261  BSP_Configuration.work_space_start = work_space_start;
262
263  /*
264   * Add 1 region for RTEMS Malloc
265   */
266
267  BSP_Configuration.RTEMS_api_configuration->maximum_regions++;
268
269  /*
270   *  Account for the console's resources
271   */
272
273  console_reserve_resources( &BSP_Configuration );
274
275#ifdef RTEMS_NEWLIB
276  /*
277   * Add 1 extension for newlib libc
278   */
279
280  BSP_Configuration.maximum_extensions++;
281#endif
282
283#ifdef STACK_CHECKER_ON
284  /*
285   * Add 1 extension for stack checker
286   */
287
288  BSP_Configuration.maximum_extensions++;
289#endif
290
291  /*
292   * Add 1 extension for MPCI_fatal
293   */
294
295  if (BSP_Configuration.User_multiprocessing_table)
296    BSP_Configuration.maximum_extensions++;
297
298  /*
299   *  Initialize RTEMS. main() will finish it up and start multitasking.
300   */
301
302  rtems_libio_config( &BSP_Configuration, BSP_LIBIO_MAX_FDS );
303 
304  bsp_isr_level = rtems_initialize_executive_early(
305     &BSP_Configuration,
306     &Cpu_table
307  );
308}
309
310
311
312
Note: See TracBrowser for help on using the repository browser.