source: rtems/c/src/lib/libbsp/a29k/portsw/startup/bspstart.c @ c244a9ee

4.104.114.84.9
Last change on this file since c244a9ee was c244a9ee, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 14, 1998 at 9:32:12 PM

Stack checker extension now accounted for in confdefs.h

  • Property mode set to 100644
File size: 5.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 *  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#include <bsp.h>
24#include <rtems/libio.h>
25 
26#include <libcsupport.h>
27 
28#include <string.h>
29 
30#ifdef STACK_CHECKER_ON
31#include <stackchk.h>
32#endif
33
34#ifndef lint
35static char _sccsid[] = "@(#)bspstart.c 09/11/96     1.15\n";
36#endif
37
38/*
39 *  The original table from the application and our copy of it with
40 *  some changes.
41 */
42
43extern rtems_configuration_table Configuration;
44
45rtems_configuration_table  BSP_Configuration;
46
47rtems_cpu_table Cpu_table;
48
49char *rtems_progname;
50
51/*      Initialize whatever libc we are using
52 *      called from postdriver hook
53 */
54
55#define HEAP_BLOCK_SIZE (16 * 1024)
56
57rtems_unsigned32        heap_size = 0;
58rtems_unsigned32        heap_start;
59
60void bsp_libc_init()
61{
62    heap_size = 2 * 1024 * 1024; /* allocate a maximum of 2 megabytes for the heap */
63
64    /* allocate all remaining memory to the heap */
65    do {
66       heap_size -= HEAP_BLOCK_SIZE;
67       heap_start = _sysalloc( heap_size );
68    } while ( !heap_start );
69
70    if (!heap_start)
71       rtems_fatal_error_occurred( heap_size );
72
73    if (heap_start & (CPU_ALIGNMENT-1))
74        heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
75
76    /*
77     *  The last parameter to RTEMS_Malloc_Initialize is the "chunk"
78     *  size which a multiple of will be requested on each sbrk()
79     *  call by malloc().  A value of 0 indicates that sbrk() should
80     *  not be called to extend the heap.
81     */
82
83    RTEMS_Malloc_Initialize((void *) heap_start, heap_size, 0);
84
85    /*
86     *  Init the RTEMS libio facility to provide UNIX-like system
87     *  calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc)
88     *  Uses malloc() to get area for the iops, so must be after malloc init
89     */
90
91    rtems_libio_init();
92
93    /*
94     * Set up for the libc handling.
95     */
96
97    if (BSP_Configuration.ticks_per_timeslice > 0)
98        libc_init(1);                /* reentrant if possible */
99    else
100        libc_init(0);                /* non-reentrant */
101
102}
103
104/*
105 *  Function:   bsp_pretasking_hook
106 *  Created:    95/03/10
107 *
108 *  Description:
109 *      BSP pretasking hook.  Called just before drivers are initialized.
110 *      Used to setup libc and install any BSP extensions.
111 *
112 *  NOTES:
113 *      Must not use libc (to do io) from here, since drivers are
114 *      not yet initialized.
115 *
116 */
117 
118void
119bsp_pretasking_hook(void)
120{
121    bsp_libc_init();
122
123#ifdef STACK_CHECKER_ON
124    /*
125     *  Initialize the stack bounds checker
126     *  We can either turn it on here or from the app.
127     */
128 
129    Stack_check_Initialize();
130#endif
131 
132#ifdef RTEMS_DEBUG
133    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
134#endif
135}
136 
137
138/*
139 *  Use the shared bsp_postdriver_hook() implementation
140 */
141 
142void bsp_postdriver_hook(void);
143
144int bsp_start(
145  int argc,
146  char **argv,
147  char **environp
148)
149{
150  if ((argc > 0) && argv && argv[0])
151    rtems_progname = argv[0];
152  else
153    rtems_progname = "RTEMS";
154
155  /* set the PIA0 register wait states */
156  *(volatile unsigned32 *)0x80000020 = 0x04080000;
157
158  /*
159   *  Allocate the memory for the RTEMS Work Space.  This can come from
160   *  a variety of places: hard coded address, malloc'ed from outside
161   *  RTEMS world (e.g. simulator or primitive memory manager), or (as
162   *  typically done by stock BSPs) by subtracting the required amount
163   *  of work space from the last physical address on the CPU board.
164   */
165
166  /*
167   *  Copy the Configuration Table .. so we can change it
168   */
169
170  BSP_Configuration = Configuration;
171
172  /*
173   * Tell libio how many fd's we want and allow it to tweak config
174   */
175
176  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
177
178  /*
179   *  Need to "allocate" the memory for the RTEMS Workspace and
180   *  tell the RTEMS configuration where it is.  This memory is
181   *  not malloc'ed.  It is just "pulled from the air".
182   */
183
184  BSP_Configuration.work_space_start = _sysalloc( BSP_Configuration.work_space_size + 512 );
185  if (!BSP_Configuration.work_space_start)
186    rtems_fatal_error_occurred( BSP_Configuration.work_space_size );
187   
188  BSP_Configuration.work_space_start = (void *) ((unsigned int)((char *)BSP_Configuration.work_space_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1));
189
190  /*
191   *  initialize the CPU table for this BSP
192   */
193
194  /*
195   *  we do not use the pretasking_hook
196   */
197
198  Cpu_table.pretasking_hook = bsp_pretasking_hook;  /* init libc, etc. */
199
200  Cpu_table.predriver_hook = NULL;
201
202  Cpu_table.postdriver_hook = bsp_postdriver_hook;
203
204  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
205
206  Cpu_table.do_zero_of_workspace = TRUE;
207
208  Cpu_table.interrupt_stack_size = 4096;
209
210  Cpu_table.extra_system_initialization_stack = 0;
211
212  /*
213   *  Don't forget the other CPU Table entries.
214   */
215
216  _settrap( 109,&a29k_enable_sup);
217  _settrap( 110,&a29k_disable_sup);
218  _settrap( 111,&a29k_enable_all_sup);
219  _settrap( 112,&a29k_disable_all_sup);
220  _settrap( 106,&a29k_context_switch_sup);
221  _settrap( 107,&a29k_context_restore_sup);
222  _settrap( 108,&a29k_context_save_sup);
223  _settrap( 105,&a29k_sigdfl_sup);
224
225  /*
226   *  Start RTEMS
227   */
228
229  rtems_initialize_executive( &BSP_Configuration, &Cpu_table );
230
231  bsp_cleanup();
232
233  return 0;
234}
Note: See TracBrowser for help on using the repository browser.