source: rtems/c/src/lib/libbsp/mips/p4000/startup/bspstart.c @ 60b791ad

4.104.114.84.95
Last change on this file since 60b791ad was 60b791ad, checked in by Joel Sherrill <joel.sherrill@…>, on 02/17/98 at 23:46:28

updated copyright to 1998

  • Property mode set to 100644
File size: 6.0 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 *  COPYRIGHT (c) 1989-1998.
13 *  On-Line Applications Research Corporation (OAR).
14 *  Copyright assigned to U.S. Government, 1994.
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.OARcorp.com/rtems/license.html.
19 *
20 *  $Id$
21 */
22
23/*
24 *  Rather than deleting this, it is commented out to (hopefully) help
25 *  the submitter send updates.
26 *
27 *  static char _sccsid[] = "@(#)bspstart.c 06/11/96     1.2\n";
28 */
29
30
31#include <bsp.h>
32#include <rtems/libio.h>
33 
34#include <libcsupport.h>
35 
36#include <string.h>
37#include <fcntl.h>
38 
39#ifdef STACK_CHECKER_ON
40#include <stackchk.h>
41#endif
42
43/*
44 *  The original table from the application and our copy of it with
45 *  some changes.
46 */
47
48extern rtems_configuration_table Configuration;
49
50rtems_configuration_table  BSP_Configuration;
51
52rtems_cpu_table Cpu_table;
53
54char *rtems_progname;
55
56/*      Initialize whatever libc we are using
57 *      called from postdriver hook
58 */
59
60#define LIBC_HEAP_SIZE (64 * 1024)
61
62void bsp_libc_init()
63{
64    extern int end;
65    rtems_unsigned32        heap_start;
66
67    heap_start = (rtems_unsigned32) &end;
68    if (heap_start & (CPU_ALIGNMENT-1))
69        heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
70
71    /*
72     *  The last parameter to RTEMS_Malloc_Initialize is the "chunk"
73     *  size which a multiple of will be requested on each sbrk()
74     *  call by malloc().  A value of 0 indicates that sbrk() should
75     *  not be called to extend the heap.
76     */
77
78    RTEMS_Malloc_Initialize((void *) heap_start, LIBC_HEAP_SIZE, 0);
79
80    /*
81     *  Init the RTEMS libio facility to provide UNIX-like system
82     *  calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc)
83     *  Uses malloc() to get area for the iops, so must be after malloc init
84     */
85
86    rtems_libio_init();
87
88    /*
89     * Set up for the libc handling.
90     */
91
92    if (BSP_Configuration.ticks_per_timeslice > 0)
93        libc_init(1);                /* reentrant if possible */
94    else
95        libc_init(0);                /* non-reentrant */
96}
97
98/*
99 *  Function:   bsp_pretasking_hook
100 *  Created:    95/03/10
101 *
102 *  Description:
103 *      BSP pretasking hook.  Called just before drivers are initialized.
104 *      Used to setup libc and install any BSP extensions.
105 *
106 *  NOTES:
107 *      Must not use libc (to do io) from here, since drivers are
108 *      not yet initialized.
109 *
110 */
111 
112void
113bsp_pretasking_hook(void)
114{
115    bsp_libc_init();
116 
117#ifdef STACK_CHECKER_ON
118    /*
119     *  Initialize the stack bounds checker
120     *  We can either turn it on here or from the app.
121     */
122 
123    Stack_check_Initialize();
124#endif
125 
126#ifdef RTEMS_DEBUG
127    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
128#endif
129}
130 
131
132/*
133 * After drivers are setup, register some "filenames"
134 * and open stdin, stdout, stderr files
135 *
136 * Newlib will automatically associate the files with these
137 * (it hardcodes the numbers)
138 */
139 
140void
141bsp_postdriver_hook(void)
142{
143  int stdin_fd, stdout_fd, stderr_fd;
144  int error_code;
145 
146  error_code = 'S' << 24 | 'T' << 16;
147 
148  if ((stdin_fd = __rtems_open("/dev/console", O_RDONLY, 0)) == -1)
149    rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' );
150 
151  if ((stdout_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)
152    rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' );
153 
154  if ((stderr_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)
155    rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' );
156 
157  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
158    rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' );
159}
160
161
162extern int end; /* defined by linker */
163
164int bsp_start(
165  int argc,
166  char **argv,
167  char **environp
168)
169{
170  if ((argc > 0) && argv && argv[0])
171    rtems_progname = argv[0];
172  else
173    rtems_progname = "RTEMS";
174
175  /*
176   *  Allocate the memory for the RTEMS Work Space.  This can come from
177   *  a variety of places: hard coded address, malloc'ed from outside
178   *  RTEMS world (e.g. simulator or primitive memory manager), or (as
179   *  typically done by stock BSPs) by subtracting the required amount
180   *  of work space from the last physical address on the CPU board.
181   */
182
183  /*
184   *  Copy the Configuration Table .. so we can change it
185   */
186
187  BSP_Configuration = Configuration;
188
189  /*
190   * Add 1 region for the RTEMS Malloc
191   */
192
193  BSP_Configuration.RTEMS_api_configuration->maximum_regions++;
194
195  /*
196   * Add 1 extension for newlib libc
197   */
198
199#ifdef RTEMS_NEWLIB
200    BSP_Configuration.maximum_extensions++;
201#endif
202
203  /*
204   * Add 1 extension for newlib libc
205   */
206
207#ifdef RTEMS_NEWLIB
208    BSP_Configuration.maximum_extensions++;
209#endif
210
211#ifdef STACK_CHECKER_ON
212    /*
213     * Add 1 extension for stack checker
214     */
215 
216    BSP_Configuration.maximum_extensions++;
217#endif
218
219  /*
220   * Tell libio how many fd's we want and allow it to tweak config
221   */
222
223  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
224
225  /*
226   *  Need to "allocate" the memory for the RTEMS Workspace and
227   *  tell the RTEMS configuration where it is.  This memory is
228   *  not malloc'ed.  It is just "pulled from the air".
229   */
230
231  BSP_Configuration.work_space_start = (void *)((unsigned64)((&end) + LIBC_HEAP_SIZE + 0x2000) & ~0x7);
232
233  /*
234   *  initialize the CPU table for this BSP
235   */
236
237  /*
238   *  we do not use the pretasking_hook
239   */
240
241  Cpu_table.pretasking_hook = bsp_pretasking_hook;  /* init libc, etc. */
242
243  Cpu_table.predriver_hook = NULL;
244
245  Cpu_table.postdriver_hook = bsp_postdriver_hook;
246
247  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
248
249  Cpu_table.do_zero_of_workspace = TRUE;
250
251  Cpu_table.interrupt_stack_size = 4096;
252
253  Cpu_table.extra_mpci_receive_server_stack = 0;
254
255  /*
256   *  Don't forget the other CPU Table entries.
257   */
258
259  /*
260   *  Start RTEMS
261   */
262
263  rtems_initialize_executive( &BSP_Configuration, &Cpu_table );
264
265  bsp_cleanup();
266
267  return 0;
268}
Note: See TracBrowser for help on using the repository browser.