1 |
786 |
skrzyp |
//=======================================================================
|
2 |
|
|
//
|
3 |
|
|
// invokemain.cxx
|
4 |
|
|
//
|
5 |
|
|
// Support for startup of ISO C environment
|
6 |
|
|
//
|
7 |
|
|
//========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): jlarmour
|
43 |
|
|
// Contributors:
|
44 |
|
|
// Date: 2000-04-30
|
45 |
|
|
// Purpose: Provide entry point for thread which then calls main()
|
46 |
|
|
// Description: cyg_libc_invoke_main() is used as the entry point for
|
47 |
|
|
// the thread object that is created to call the
|
48 |
|
|
// user-supplied main() function. It sets up the arguments
|
49 |
|
|
// (if any) and invokes exit() if main() returns
|
50 |
|
|
// Usage:
|
51 |
|
|
//
|
52 |
|
|
//####DESCRIPTIONEND####
|
53 |
|
|
//
|
54 |
|
|
//========================================================================
|
55 |
|
|
|
56 |
|
|
// CONFIGURATION
|
57 |
|
|
|
58 |
|
|
#include <pkgconf/libc_startup.h> // Configuration header
|
59 |
|
|
#include <pkgconf/isoinfra.h>
|
60 |
|
|
|
61 |
|
|
// INCLUDES
|
62 |
|
|
|
63 |
|
|
#include <cyg/infra/cyg_type.h> // Common type definitions and support
|
64 |
|
|
#include <cyg/infra/cyg_trac.h> // Common tracing support
|
65 |
|
|
#include <cyg/infra/cyg_ass.h> // Common assertion support
|
66 |
|
|
#include <stdlib.h> // exit()
|
67 |
|
|
|
68 |
|
|
// EXTERNS
|
69 |
|
|
|
70 |
|
|
externC cyg_bool cyg_hal_stop_constructors;
|
71 |
|
|
|
72 |
|
|
// FUNCTION PROTOTYPES
|
73 |
|
|
|
74 |
|
|
externC int
|
75 |
|
|
main( int argc, char *argv[] );
|
76 |
|
|
|
77 |
|
|
externC void
|
78 |
|
|
cyg_hal_invoke_constructors(void);
|
79 |
|
|
|
80 |
|
|
externC void
|
81 |
|
|
pthread_exit( void *value_ptr );
|
82 |
|
|
|
83 |
|
|
// STATICS
|
84 |
|
|
|
85 |
|
|
#ifdef CYGSEM_LIBC_INVOKE_DEFAULT_STATIC_CONSTRUCTORS
|
86 |
|
|
class cyg_libc_dummy_constructor_class {
|
87 |
|
|
public:
|
88 |
|
|
cyg_libc_dummy_constructor_class(void) { ++cyg_hal_stop_constructors; }
|
89 |
|
|
};
|
90 |
|
|
|
91 |
|
|
static cyg_libc_dummy_constructor_class cyg_libc_dummy_constructor_obj
|
92 |
|
|
CYGBLD_ATTRIB_INIT_PRI(CYG_INIT_PREDEFAULT);
|
93 |
|
|
#endif
|
94 |
|
|
|
95 |
|
|
// FUNCTIONS
|
96 |
|
|
|
97 |
|
|
externC void
|
98 |
|
|
cyg_libc_invoke_main( CYG_ADDRWORD )
|
99 |
|
|
{
|
100 |
|
|
CYG_REPORT_FUNCNAME( "cyg_libc_invoke_main" );
|
101 |
|
|
CYG_REPORT_FUNCARG1( "argument is %s", "ignored" );
|
102 |
|
|
|
103 |
|
|
#ifdef CYGSEM_LIBC_INVOKE_DEFAULT_STATIC_CONSTRUCTORS
|
104 |
|
|
// finish invoking constructors that weren't called by default
|
105 |
|
|
cyg_hal_invoke_constructors();
|
106 |
|
|
#endif
|
107 |
|
|
|
108 |
|
|
// argv[argc] must be NULL according to the ISO C standard 5.1.2.2.1
|
109 |
|
|
char *temp_argv[] = CYGDAT_LIBC_ARGUMENTS ;
|
110 |
|
|
int rc;
|
111 |
|
|
|
112 |
|
|
rc = main( (sizeof(temp_argv)/sizeof(char *)) - 1, &temp_argv[0] );
|
113 |
|
|
|
114 |
|
|
CYG_TRACE1( true, "main() has returned with code %d. Calling exit()",
|
115 |
|
|
rc );
|
116 |
|
|
|
117 |
|
|
#ifdef CYGINT_ISO_PTHREAD_IMPL
|
118 |
|
|
// It is up to pthread_exit() to call exit() if needed
|
119 |
|
|
pthread_exit( (void *)rc );
|
120 |
|
|
CYG_FAIL( "pthread_exit() returned!!!" );
|
121 |
|
|
#else
|
122 |
|
|
exit(rc);
|
123 |
|
|
CYG_FAIL( "exit() returned!!!" );
|
124 |
|
|
#endif
|
125 |
|
|
|
126 |
|
|
CYG_REPORT_RETURN();
|
127 |
|
|
|
128 |
|
|
} // cyg_libc_invoke_main()
|
129 |
|
|
|
130 |
|
|
// EOF invokemain.cxx
|