source: rtems/c/src/lib/libbsp/powerpc/papyrus/startup/bspstart.c @ c62d36f

4.104.114.84.95
Last change on this file since c62d36f was 3652ad35, checked in by Joel Sherrill <joel.sherrill@…>, on 09/19/95 at 14:53:29

Minor bug fixes to get all targets compilable and running. The
single biggest changes were the expansion of the workspace size
macro to include other types of objects and the increase in the
minimum stack size for most CPUs.

  • Property mode set to 100644
File size: 6.6 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:     Andrew Bray <andy@i-cubed.demon.co.uk>
13 *
14 *  COPYRIGHT (c) 1995 by i-cubed ltd.
15 *
16 *  To anyone who acknowledges that this file is provided "AS IS"
17 *  without any express or implied warranty:
18 *      permission to use, copy, modify, and distribute this file
19 *      for any purpose is hereby granted without fee, provided that
20 *      the above copyright notice and this notice appears in all
21 *      copies, and that the name of i-cubed limited not be used in
22 *      advertising or publicity pertaining to distribution of the
23 *      software without specific, written prior permission.
24 *      i-cubed limited makes no representations about the suitability
25 *      of this software for any purpose.
26 *
27 *  Derived from c/src/lib/libbsp/no_cpu/no_bsp/startup/bspstart.c:
28 *
29 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
30 *  On-Line Applications Research Corporation (OAR).
31 *  All rights assigned to U.S. Government, 1994.
32 *
33 *  This material may be reproduced by or for the U.S. Government pursuant
34 *  to the copyright license under the clause at DFARS 252.227-7013.  This
35 *  notice must appear in all copies of this file and its derivatives.
36 *
37 *  bspstart.c,v 1.2 1995/05/31 16:56:29 joel Exp
38 */
39
40#include <bsp.h>
41#include <rtems/libio.h>
42 
43#include <libcsupport.h>
44 
45#include <string.h>
46#include <fcntl.h>
47 
48#ifdef STACK_CHECKER_ON
49#include <stackchk.h>
50#endif
51
52/*
53 *  The original table from the application and our copy of it with
54 *  some changes.
55 */
56
57extern rtems_configuration_table Configuration;
58
59rtems_configuration_table  BSP_Configuration;
60
61rtems_cpu_table Cpu_table;
62
63char *rtems_progname;
64
65/*      Initialize whatever libc we are using
66 *      called from postdriver hook
67 */
68
69void bsp_libc_init()
70{
71    extern int _end;
72    rtems_unsigned32        heap_start;
73
74    heap_start = (rtems_unsigned32) &_end;
75    if (heap_start & (CPU_ALIGNMENT-1))
76        heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
77
78    /*
79     *  The last parameter to RTEMS_Malloc_Initialize is the "chunk"
80     *  size which a multiple of will be requested on each sbrk()
81     *  call by malloc().  A value of 0 indicates that sbrk() should
82     *  not be called to extend the heap.
83     */
84
85    RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0);
86
87    /*
88     *  Init the RTEMS libio facility to provide UNIX-like system
89     *  calls for use by newlib (ie: provide __open, __close, etc)
90     *  Uses malloc() to get area for the iops, so must be after malloc init
91     */
92
93    rtems_libio_init();
94
95    /*
96     * Set up for the libc handling.
97     */
98
99    if (BSP_Configuration.ticks_per_timeslice > 0)
100        libc_init(1);                /* reentrant if possible */
101    else
102        libc_init(0);                /* non-reentrant */
103
104}
105
106/*
107 *  Function:   bsp_pretasking_hook
108 *  Created:    95/03/10
109 *
110 *  Description:
111 *      BSP pretasking hook.  Called just before drivers are initialized.
112 *      Used to setup libc and install any BSP extensions.
113 *
114 *  NOTES:
115 *      Must not use libc (to do io) from here, since drivers are
116 *      not yet initialized.
117 *
118 */
119 
120void
121bsp_pretasking_hook(void)
122{
123    bsp_libc_init();
124 
125#ifdef STACK_CHECKER_ON
126    /*
127     *  Initialize the stack bounds checker
128     *  We can either turn it on here or from the app.
129     */
130 
131    Stack_check_Initialize();
132#endif
133 
134#ifdef RTEMS_DEBUG
135    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
136#endif
137}
138 
139
140/*
141 * After drivers are setup, register some "filenames"
142 * and open stdin, stdout, stderr files
143 *
144 * Newlib will automatically associate the files with these
145 * (it hardcodes the numbers)
146 */
147 
148void
149bsp_postdriver_hook(void)
150{
151  int stdin_fd, stdout_fd, stderr_fd;
152 
153  if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1)
154    rtems_fatal_error_occurred('STD0');
155 
156  if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
157    rtems_fatal_error_occurred('STD1');
158 
159  if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
160    rtems_fatal_error_occurred('STD2');
161 
162  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
163    rtems_fatal_error_occurred('STIO');
164}
165
166int main(
167  int argc,
168  char **argv,
169  char **environp
170)
171{
172  if ((argc > 0) && argv && argv[0])
173    rtems_progname = argv[0];
174  else
175    rtems_progname = "RTEMS";
176
177  /*
178   *  Allocate the memory for the RTEMS Work Space.  This can come from
179   *  a variety of places: hard coded address, malloc'ed from outside
180   *  RTEMS world (e.g. simulator or primitive memory manager), or (as
181   *  typically done by stock BSPs) by subtracting the required amount
182   *  of work space from the last physical address on the CPU board.
183   */
184
185  /*
186   *  Copy the Configuration Table .. so we can change it
187   */
188
189  BSP_Configuration = Configuration;
190
191  /*
192   * Add 1 region for the RTEMS Malloc
193   */
194
195  BSP_Configuration.maximum_regions++;
196
197  /*
198   * Add 1 extension for newlib libc
199   */
200
201#ifdef RTEMS_NEWLIB
202    BSP_Configuration.maximum_extensions++;
203#endif
204
205  /*
206   * Add 1 extension for stack checker
207   */
208
209#ifdef STACK_CHECKER_ON
210    BSP_Configuration.maximum_extensions++;
211#endif
212
213  /*
214   * Tell libio how many fd's we want and allow it to tweak config
215   */
216
217  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
218
219  /*
220   *  Need to "allocate" the memory for the RTEMS Workspace and
221   *  tell the RTEMS configuration where it is.  This memory is
222   *  not malloc'ed.  It is just "pulled from the air".
223   */
224
225/*BSP_Configuration.work_space_size *= 4;*/
226
227  BSP_Configuration.work_space_start = (void *)
228      RAM_END - BSP_Configuration.work_space_size;
229
230  /*
231   *  initialize the CPU table for this BSP
232   */
233
234  Cpu_table.pretasking_hook = bsp_pretasking_hook;  /* init libc, etc. */
235
236  Cpu_table.predriver_hook = NULL;
237
238  Cpu_table.postdriver_hook = bsp_postdriver_hook;
239
240  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
241
242  Cpu_table.do_zero_of_workspace = TRUE;
243
244  Cpu_table.interrupt_stack_size = 4 * 1024;
245
246  Cpu_table.extra_system_initialization_stack = 0;
247
248  /*
249   *  Don't forget the other CPU Table entries.
250   */
251
252  Cpu_table.clicks_per_usec = 10;
253
254  Cpu_table.serial_per_sec = 10000000;
255
256  Cpu_table.serial_external_clock = 1;
257
258  Cpu_table.serial_xon_xoff = 0;
259
260  Cpu_table.serial_cts_rts = 1;
261
262  Cpu_table.serial_rate = 9600;
263
264  Cpu_table.timer_average_overhead = 2;
265
266  Cpu_table.timer_least_valid = 3;
267
268  /*
269   *  Start RTEMS
270   */
271
272  rtems_initialize_executive( &BSP_Configuration, &Cpu_table );
273
274  bsp_cleanup();
275}
Note: See TracBrowser for help on using the repository browser.