source: rtems/c/src/lib/libbsp/shared/bootcard.c @ af536c96

4.104.114.84.95
Last change on this file since af536c96 was af536c96, checked in by Joel Sherrill <joel.sherrill@…>, on 09/28/01 at 23:14:58

2001-09-28 Joel Sherrill <joel@…>

  • shared/bootcard.c, shared/main.c: Now call int c_rtems_main() not main().
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 *  A simple main which can be used on any embedded target.
3 *
4 *  This style of initialization insures that the C++ global
5 *  constructors are executed after RTEMS is initialized.
6 *
7 *  Thanks to Chris Johns <cjohns@plessey.com.au> for this idea.
8 *
9 *  COPYRIGHT (c) 1989-1999.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.OARcorp.com/rtems/license.html.
15 *
16 *  $Id$
17 */
18
19#include <bsp.h>
20
21#ifdef USE_INIT_FINI
22#include <stdlib.h> /* for atexit() */
23#endif
24
25extern void bsp_start( void );
26extern void bsp_cleanup( void );
27
28extern rtems_configuration_table  Configuration;
29extern rtems_configuration_table  BSP_Configuration;
30extern rtems_cpu_table            Cpu_table;
31
32rtems_api_configuration_table BSP_RTEMS_Configuration;
33
34#ifdef RTEMS_POSIX_API
35posix_api_configuration_table BSP_POSIX_Configuration;
36#endif
37
38/* Initialize C++ global Ctor/Dtor and initializes exception handling. */
39#if defined(USE_INIT_FINI)
40extern void _fini( void );
41#endif
42
43rtems_interrupt_level bsp_isr_level;
44
45/*
46 *  Since there is a forward reference
47 */
48
49int c_rtems_main(int argc, char **argv, char **envp);
50
51int boot_card(int argc, char **argv, char **envp)
52{
53  int    status;
54  static char  *argv_pointer = NULL;
55  static char  *envp_pointer = NULL;
56  char **argv_p = &argv_pointer;
57  char **envp_p = &envp_pointer;
58
59  /*
60   *  Set things up so c_rtems_main() is called with real pointers for
61   *  argv and envp.  If the BSP has passed us something useful, then
62   *  pass it on.  Somehow we need to eventually make this available to
63   *  a real main() in user land. :)
64   */
65
66  if ( argv )
67    argv_p = argv;
68
69  if ( envp )
70    envp_p = envp;
71
72
73  /*
74   *  Set default values for the CPU Table fields all ports must have.
75   *  These values can be overridden in bsp_start() but they are
76   *  right most of the time.
77   */
78
79  Cpu_table.pretasking_hook                 = NULL;
80  Cpu_table.predriver_hook                  = NULL;
81  Cpu_table.postdriver_hook                 = NULL;
82  Cpu_table.idle_task                       = NULL;
83  Cpu_table.do_zero_of_workspace            = TRUE;
84  Cpu_table.interrupt_stack_size            = RTEMS_MINIMUM_STACK_SIZE;
85  Cpu_table.extra_mpci_receive_server_stack = 0;
86  Cpu_table.stack_allocate_hook             = NULL;
87  Cpu_table.stack_free_hook                 = NULL;
88
89
90  /*
91   *  Copy the configuration table so we and the BSP wants to change it.
92   */
93
94  BSP_Configuration       = Configuration;
95
96  BSP_RTEMS_Configuration = *Configuration.RTEMS_api_configuration;
97  BSP_Configuration.RTEMS_api_configuration = &BSP_RTEMS_Configuration;
98
99#ifdef RTEMS_POSIX_API
100  BSP_POSIX_Configuration = *Configuration.POSIX_api_configuration;
101  BSP_Configuration.POSIX_api_configuration = &BSP_POSIX_Configuration;
102#endif
103
104  /*
105   *  The atexit hook will be before the static destructor list's entry
106   *  point.
107   */
108
109  bsp_start();
110
111  /*
112   *  Initialize RTEMS but do NOT start multitasking.
113   */
114
115  bsp_isr_level =
116    rtems_initialize_executive_early( &BSP_Configuration, &Cpu_table );
117
118  /*
119   *  Call c_rtems_main() and eventually let the first task or the real
120   *  main() invoke the global constructors if there are any.
121   */
122
123#ifdef USE_INIT_FINI
124   atexit( _fini );
125#endif
126
127  status = c_rtems_main( argc, argv_p, envp_p );
128
129  /*
130   *  Perform any BSP specific shutdown actions.
131   */
132
133  bsp_cleanup(); 
134
135  /*
136   *  Now return to the start code.
137   */
138
139  return status;
140}
Note: See TracBrowser for help on using the repository browser.