|
0
|
1 //======================================================================= |
|
|
2 // |
|
|
3 // cstartup.cxx |
|
|
4 // |
|
|
5 // Starting C library support |
|
|
6 // |
|
|
7 //======================================================================== |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
|
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //======================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): jlarmour |
|
|
33 // Contributors: jlarmour@cygnus.co.uk |
|
|
34 // Date: 1998-08-27 |
|
|
35 // Purpose: |
|
|
36 // Description: |
|
|
37 // Usage: |
|
|
38 // |
|
|
39 //####DESCRIPTIONEND#### |
|
|
40 // |
|
|
41 //======================================================================== |
|
|
42 |
|
|
43 // CONFIGURATION |
|
|
44 |
|
|
45 #include <pkgconf/libc.h> // Configuration header |
|
|
46 |
|
|
47 // Include the C library? |
|
|
48 #ifdef CYGPKG_LIBC |
|
|
49 |
|
|
50 // INCLUDES |
|
|
51 |
|
|
52 #include <cyg/infra/cyg_type.h> // Common type definitions and support |
|
|
53 #include <cyg/infra/cyg_trac.h> // Common tracing support |
|
|
54 #include <cyg/infra/cyg_ass.h> // Common assertion support |
|
|
55 #include "clibincl/stdlibsupp.hxx" // __libc_exit() ( i.e. exit() ) |
|
|
56 |
|
|
57 #ifdef CYGPKG_KERNEL |
|
|
58 # include <cyg/kernel/thread.hxx> // eCos thread support |
|
|
59 # include <cyg/kernel/thread.inl> |
|
|
60 #endif |
|
|
61 |
|
|
62 |
|
|
63 // FUNCTION PROTOTYPES |
|
|
64 |
|
|
65 // We provide a weakly named main to allow this to link if the user |
|
|
66 // doesn't provide their own main. This isn't strictly good behaviour, |
|
|
67 // but if the user wants good performance then of _course_ they should |
|
|
68 // play with the config options and this won't be called. Or it might |
|
|
69 // be "giving them enough rope" etc. :-) |
|
|
70 |
|
|
71 // The definition of the normal user-supplied main() is here aliased |
|
|
72 // to a dummy main function. It isn't called main itself in order to |
|
|
73 // throw GDB off the scent, which otherwise gets confused. These |
|
|
74 // attributes have no effect on a user-supplied main() if one is supplied |
|
|
75 |
|
|
76 externC int |
|
|
77 cyg_libc_dummy_main( int argc, char *argv[] ); |
|
|
78 |
|
|
79 externC int |
|
|
80 main( int argc, char *argv[] ) |
|
|
81 CYGPRI_LIBC_WEAK_ALIAS("cyg_libc_dummy_main"); |
|
|
82 |
|
|
83 static inline void |
|
|
84 invoke_main( CYG_ADDRWORD ); |
|
|
85 |
|
|
86 // STATICS |
|
|
87 |
|
|
88 #ifdef CYGPKG_KERNEL |
|
|
89 static cyg_uint8 main_stack[ CYGNUM_LIBC_MAIN_STACK_SIZE ]; |
|
|
90 |
|
|
91 |
|
|
92 // GLOBALS |
|
|
93 |
|
|
94 // let the main thread be global so people can play with it (e.g. suspend |
|
|
95 // or resume etc.) if that's what they want to do |
|
|
96 Cyg_Thread cyg_libc_main_thread( &invoke_main, (CYG_ADDRWORD) 0, |
|
|
97 CYGNUM_LIBC_MAIN_STACK_SIZE, |
|
|
98 (CYG_ADDRESS) &main_stack ); |
|
|
99 #endif |
|
|
100 |
|
|
101 |
|
|
102 // FUNCTIONS |
|
|
103 |
|
|
104 externC int |
|
|
105 cyg_libc_dummy_main( int argc, char *argv[] ) |
|
|
106 { |
|
|
107 CYG_REPORT_FUNCNAMETYPE("main", "returning %d" ); |
|
|
108 |
|
|
109 // try to be helpful by diagnosing malformed arguments |
|
|
110 CYG_PRECONDITION( argv != NULL, "argv is NULL!" ); |
|
|
111 CYG_PRECONDITION( argv[argc] == NULL, "argv[argc] isn't NULL!" ); |
|
|
112 |
|
|
113 CYG_REPORT_FUNCARG2("argc=%d, argv[0]=%s", argc, |
|
|
114 (argv[0]==NULL) ? "NULL" : argv[0] ); |
|
|
115 |
|
|
116 CYG_TRACE0( true, "This is the system-supplied default main()" ); |
|
|
117 |
|
|
118 CYG_REPORT_RETVAL(0); |
|
|
119 return 0; // some CPUs have 0 hard-wired - faster than a reg |
|
|
120 } |
|
|
121 |
|
|
122 // Making invoke_main() static inline has no effect if the kernel is |
|
|
123 // present, and makes it inline if not! Cor. |
|
|
124 static inline void |
|
|
125 invoke_main( CYG_ADDRWORD ) |
|
|
126 { |
|
|
127 CYG_REPORT_FUNCNAME( "invoke_main" ); |
|
|
128 CYG_REPORT_FUNCARG1( "argument is %s", "ignored" ); |
|
|
129 |
|
|
130 // argv[argc] must be NULL according to the ISO C standard 5.1.2.2.1 |
|
|
131 char *temp_argv[] = CYGDAT_LIBC_ARGUMENTS ; |
|
|
132 int rc; |
|
|
133 |
|
|
134 rc = main( (sizeof(temp_argv)/sizeof(char *)) - 1, &temp_argv[0] ); |
|
|
135 |
|
|
136 CYG_TRACE1( true, "main() has returned with code %d. Calling exit()", |
|
|
137 rc ); |
|
|
138 |
|
|
139 __libc_exit(rc); |
|
|
140 |
|
|
141 CYG_FAIL( "__libc_exit() returned!!!" ); |
|
|
142 |
|
|
143 CYG_REPORT_RETURN(); |
|
|
144 |
|
|
145 } // invoke_main(); |
|
|
146 |
|
|
147 externC void |
|
|
148 cyg_iso_c_start( void ) |
|
|
149 { |
|
|
150 CYG_REPORT_FUNCNAME( "cyg_iso_c_start" ); |
|
|
151 CYG_REPORT_FUNCARGVOID(); |
|
|
152 |
|
|
153 #ifdef CYGPKG_KERNEL |
|
|
154 CYG_TRACE0( true, "Resuming cyg_libc_main_thread" ); |
|
|
155 cyg_libc_main_thread.resume(); |
|
|
156 #else |
|
|
157 invoke_main(0); |
|
|
158 #endif |
|
|
159 |
|
|
160 CYG_REPORT_RETURN(); |
|
|
161 } // cyg_iso_c_start() |
|
|
162 |
|
|
163 |
|
|
164 #endif // ifdef CYGPKG_LIBC |
|
|
165 |
|
|
166 // EOF cstartup.cxx |