1 |
27 |
unneback |
//=======================================================================
|
2 |
|
|
//
|
3 |
|
|
// mainthread.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 Red Hat, 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 version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//========================================================================
|
41 |
|
|
//#####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): jlarmour
|
44 |
|
|
// Contributors:
|
45 |
|
|
// Date: 2000-04-30
|
46 |
|
|
// Purpose: Provides a thread object to call into a user-supplied
|
47 |
|
|
// main()
|
48 |
|
|
// Description: Here we define the thread object that calls
|
49 |
|
|
// cyg_libc_invoke_main() which in turn will invoke
|
50 |
|
|
// the user-supplied main() entry point function (or
|
51 |
|
|
// alternatively the dummy empty one supplied by eCos)
|
52 |
|
|
// Usage: Both the stack (cyg_libc_main_stack) and the thread
|
53 |
|
|
// (cyg_libc_main_thread) can be overriden if you provide
|
54 |
|
|
// your own symbols with those names. In the case of the
|
55 |
|
|
// stack obviously you need to ensure
|
56 |
|
|
// CYGNUM_LIBC_MAIN_STACK_SIZE corresponds to your own
|
57 |
|
|
// stack.
|
58 |
|
|
// The thread object is also available externally if you
|
59 |
|
|
// want to control it (suspend/resume/etc.) either by
|
60 |
|
|
// extern Cyg_Thread cyg_libc_main_thread; from C++, using
|
61 |
|
|
// the kernel C++ API, or
|
62 |
|
|
// extern cyg_handle_t cyg_libc_main_thread; from C using
|
63 |
|
|
// the kernel C API.
|
64 |
|
|
//
|
65 |
|
|
//####DESCRIPTIONEND####
|
66 |
|
|
//
|
67 |
|
|
//========================================================================
|
68 |
|
|
|
69 |
|
|
// CONFIGURATION
|
70 |
|
|
|
71 |
|
|
#include <pkgconf/libc_startup.h> // C library configuration
|
72 |
|
|
|
73 |
|
|
#ifdef CYGSEM_LIBC_STARTUP_MAIN_THREAD
|
74 |
|
|
|
75 |
|
|
// INCLUDES
|
76 |
|
|
|
77 |
|
|
#include <cyg/infra/cyg_type.h> // Common type definitions and support
|
78 |
|
|
#include <pkgconf/kernel.h> // eCos kernel configuration
|
79 |
|
|
#include <cyg/kernel/thread.hxx> // eCos thread support
|
80 |
|
|
#include <cyg/kernel/thread.inl>
|
81 |
|
|
#include <cyg/hal/hal_arch.h> // for CYGNUM_HAL_STACK_SIZE_TYPICAL
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
// EXTERNS
|
85 |
|
|
|
86 |
|
|
#ifdef CYGSEM_LIBC_INVOKE_DEFAULT_STATIC_CONSTRUCTORS
|
87 |
|
|
extern cyg_bool cyg_hal_stop_constructors;
|
88 |
|
|
#endif
|
89 |
|
|
|
90 |
|
|
// FUNCTION PROTOTYPES
|
91 |
|
|
|
92 |
|
|
externC void
|
93 |
|
|
cyg_libc_invoke_main( CYG_ADDRWORD );
|
94 |
|
|
|
95 |
|
|
// STATICS
|
96 |
|
|
|
97 |
|
|
#ifdef CYGSEM_LIBC_MAIN_STACK_FROM_SYSTEM
|
98 |
|
|
|
99 |
|
|
// override stack size on some platforms
|
100 |
|
|
#ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL
|
101 |
|
|
# if CYGNUM_LIBC_MAIN_DEFAULT_STACK_SIZE < CYGNUM_HAL_STACK_SIZE_TYPICAL
|
102 |
|
|
# undef CYGNUM_LIBC_MAIN_DEFAULT_STACK_SIZE
|
103 |
|
|
# define CYGNUM_LIBC_MAIN_DEFAULT_STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
|
104 |
|
|
# endif
|
105 |
|
|
#endif
|
106 |
|
|
|
107 |
|
|
static cyg_uint8 cyg_libc_main_stack[ CYGNUM_LIBC_MAIN_DEFAULT_STACK_SIZE ];
|
108 |
|
|
|
109 |
|
|
#else // !ifdef CYGSEM_LIBC_MAIN_STACK_FROM_SYSTEM
|
110 |
|
|
|
111 |
|
|
extern char *cyg_libc_main_stack;
|
112 |
|
|
extern int cyg_libc_main_stack_size;
|
113 |
|
|
|
114 |
|
|
#endif // !ifdef CYGSEM_LIBC_MAIN_STACK_FROM_SYSTEM
|
115 |
|
|
|
116 |
|
|
// GLOBALS
|
117 |
|
|
|
118 |
|
|
// let the main thread be global so people can play with it (e.g. suspend
|
119 |
|
|
// or resume etc.) if that's what they want to do
|
120 |
|
|
Cyg_Thread cyg_libc_main_thread CYGBLD_ATTRIB_INIT_PRI(CYG_INIT_LIBC) =
|
121 |
|
|
Cyg_Thread(CYGNUM_LIBC_MAIN_THREAD_PRIORITY,
|
122 |
|
|
&cyg_libc_invoke_main, (CYG_ADDRWORD) 0,
|
123 |
|
|
"main",
|
124 |
|
|
(CYG_ADDRESS) &cyg_libc_main_stack[0],
|
125 |
|
|
#ifdef CYGSEM_LIBC_MAIN_STACK_FROM_SYSTEM
|
126 |
|
|
CYGNUM_LIBC_MAIN_DEFAULT_STACK_SIZE
|
127 |
|
|
#else
|
128 |
|
|
cyg_libc_main_stack_size
|
129 |
|
|
#endif
|
130 |
|
|
);
|
131 |
|
|
|
132 |
|
|
#endif // ifdef CYGSEM_LIBC_STARTUP_MAIN_THREAD
|
133 |
|
|
|
134 |
|
|
// EOF mainthread.cxx
|