source: rtems/c/src/lib/libbsp/sh/gensh1/startup/bspstart.c @ e2a2ec60

4.104.114.84.95
Last change on this file since e2a2ec60 was e2a2ec60, checked in by Joel Sherrill <joel.sherrill@…>, on 03/21/98 at 15:37:18

Switch to using a shared main() for all of the embedded BSPs
based on the GNU tools. This usually involved correcting the
type of bsp_start(), bsp_cleanup(), adjusting the start code to
call the right start routine (the shared boot_card()), and then
removing code from bsp_start() which was performed in the new
boot_card()/main() path.

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