source: rtems/c/src/lib/libbsp/i386/pc386/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: 7.1 KB
Line 
1/*-------------------------------------------------------------------------+
2| bspstart.c v1.1 - PC386 BSP - 1997/08/07
3+--------------------------------------------------------------------------+
4| This file contains the PC386 BSP startup package. It includes application,
5| board, and monitor specific initialization and configuration. The generic CPU
6| dependent initialization has been performed before this routine is invoked.
7+--------------------------------------------------------------------------+
8| (C) Copyright 1997 -
9| - NavIST Group - Real-Time Distributed Systems and Industrial Automation
10|
11| http://pandora.ist.utl.pt
12|
13| Instituto Superior Tecnico * Lisboa * PORTUGAL
14+--------------------------------------------------------------------------+
15| Disclaimer:
16|
17| This file is provided "AS IS" without warranty of any kind, either
18| expressed or implied.
19+--------------------------------------------------------------------------+
20| This code is based on:
21|   bspstart.c,v 1.8 1996/05/28 13:12:40 joel Exp - go32 BSP
22| With the following copyright notice:
23| **************************************************************************
24| *  COPYRIGHT (c) 1989-1998.
25| *  On-Line Applications Research Corporation (OAR).
26| *  Copyright assigned to U.S. Government, 1994.
27| *
28| *  The license and distribution terms for this file may be
29| *  found in found in the file LICENSE in this distribution or at
30| *  http://www.OARcorp.com/rtems/license.html.
31| **************************************************************************
32|
33|  $Id$
34+--------------------------------------------------------------------------*/
35
36
37#include <bsp.h>
38#include <libcsupport.h>
39#include <rtems/libio.h>
40 
41#ifdef STACK_CHECKER_ON
42#include <stackchk.h>
43#endif
44
45/*-------------------------------------------------------------------------+
46| Global Variables
47+--------------------------------------------------------------------------*/
48#ifdef RTEMS_SMALL_MEMORY
49extern rtems_unsigned32 _end;           /* End of BSS. Defined in 'linkcmds'. */
50
51rtems_unsigned32 rtemsFreeMemStart = (rtems_unsigned32)&_end;
52                         /* Address of start of free memory - should be updated
53                            after creating new partitions or regions.         */
54#else
55rtems_unsigned32 rtemsFreeMemStart = RAM_START;
56                                             /* RAM_START defined in 'bsp.h'. */
57#endif /* RTEMS_SMALL_MEMORY */
58
59/* The original BSP configuration table from the application and our copy of it
60   with some changes. */
61
62extern rtems_configuration_table  Configuration;
63       rtems_configuration_table  BSP_Configuration;
64
65rtems_cpu_table Cpu_table;                     /* CPU configuration table.    */
66char            *rtems_progname;               /* Program name - from main(). */
67
68
69/*-------------------------------------------------------------------------+
70| External Prototypes
71+--------------------------------------------------------------------------*/
72extern void _exit(int);  /* define in exit.c */
73
74/*-------------------------------------------------------------------------+
75|         Function: bsp_libc_init
76|      Description: Initialize whatever libc we are using. Called from
77|                   pretasking hook.
78| Global Variables: rtemsFreeMemStart.
79|        Arguments: None.
80|          Returns: Nothing.
81+--------------------------------------------------------------------------*/
82static void
83bsp_libc_init(void)
84{
85  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
86    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
87
88  RTEMS_Malloc_Initialize((void *)rtemsFreeMemStart, HEAP_SIZE << 10, 0);
89  rtemsFreeMemStart += HEAP_SIZE << 10;           /* HEAP_SIZE is in KBytes */
90
91  /* Init the RTEMS libio facility to provide UNIX-like system calls for use by
92     newlib (ie: provide __rtems_open, __rtems_close, etc). Uses malloc()
93     to get area for the iops, so must be after malloc initialization. */
94
95  rtems_libio_init();
96
97  /* Set up for the libc handling. */
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} /* bsp_libc_init */
104
105 
106/*-------------------------------------------------------------------------+
107|         Function: bsp_pretasking_hook
108|      Description: BSP pretasking hook.  Called just before drivers are
109|                   initialized. Used to setup libc and install any BSP
110|                   extensions. NOTE: Must not use libc (to do io) from here,
111|                   since drivers are not yet initialized.
112| Global Variables: None.
113|        Arguments: None.
114|          Returns: Nothing.
115+--------------------------------------------------------------------------*/
116void
117bsp_pretasking_hook(void)
118{
119  bsp_libc_init();
120
121#ifdef STACK_CHECKER_ON
122  /* Initialize the stack bounds checker. We can either turn it on here or from
123     the app. */
124   
125  Stack_check_Initialize();
126
127#endif /* STACK_CHECKER_ON */
128 
129#ifdef RTEMS_DEBUG
130
131  rtems_debug_enable(RTEMS_DEBUG_ALL_MASK);
132
133#endif /* RTEMS_DEBUG */
134} /* bsp_pretasking_hook */
135 
136
137/*
138 *  Use the shared bsp_postdriver_hook() implementation
139 */
140 
141void bsp_postdriver_hook(void);
142
143
144/*-------------------------------------------------------------------------+
145|         Function: bsp_start
146|      Description: Called before main is invoked.
147| Global Variables: None.
148|        Arguments: None.
149|          Returns: Nothing.
150+--------------------------------------------------------------------------*/
151void bsp_start( void )
152{
153  /* If we don't have command line arguments set default program name. */
154
155  Cpu_table.pretasking_hook         = bsp_pretasking_hook; /* init libc, etc. */
156  Cpu_table.predriver_hook          = NULL;                /* use system's    */
157  Cpu_table.postdriver_hook         = bsp_postdriver_hook;
158  Cpu_table.idle_task               = NULL;
159                                          /* do not override system IDLE task */
160  Cpu_table.do_zero_of_workspace    = TRUE;
161  Cpu_table.interrupt_table_segment = get_ds();
162  Cpu_table.interrupt_table_offset  = (void *)Interrupt_descriptor_table;
163  Cpu_table.interrupt_stack_size    = 4096;
164  Cpu_table.extra_mpci_receive_server_stack = 0;
165
166  /* Copy user's table and make necessary adjustments.              */
167
168  BSP_Configuration = Configuration;
169
170  /* Place RTEMS workspace at top of physical RAM (RAM_END defined in 'bsp.h' */
171
172  BSP_Configuration.work_space_start =
173                          (void *)(RAM_END - BSP_Configuration.work_space_size);
174
175  /* Tell libio how many fd's we want and allow it to tweak config. */
176
177  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
178
179#if 0
180  rtems_initialize_executive(&BSP_Configuration, &Cpu_table);
181  /* does not return */
182
183  /*-------------------------------------------------------------------------+
184  | We only return here if the executive has finished. This happens when the
185  | task has called exit(). We will then call _exit() which is part of the bsp.
186  +--------------------------------------------------------------------------*/
187
188  for (;;)
189    _exit(0);
190
191  /* no cleanup necessary for PC386 */
192
193  return 0;
194#endif
195} /* bsp_start */
Note: See TracBrowser for help on using the repository browser.