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

4.104.114.84.95
Last change on this file since 71f4beb was 9b64c2d5, checked in by Joel Sherrill <joel.sherrill@…>, on 04/15/98 at 00:10:03

Per suggestion from Eric Norum, went from one initial extension set
to multiple. This lets the stack check extension be installed
at system initialization time and avoids the BSP having to
even know about its existence.

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