1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2007. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be found in |
---|
6 | * the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #include <bsp.h> |
---|
13 | |
---|
14 | #include <assert.h> |
---|
15 | #include <pthread.h> |
---|
16 | #include <stdlib.h> |
---|
17 | |
---|
18 | #if defined(MAIN_USE_NETWORKING) |
---|
19 | #include <rtems/rtems_bsdnet.h> |
---|
20 | #include "networkconfig.h" |
---|
21 | #endif |
---|
22 | #if defined(ENABLE_UNTAR_ROOT_FILESYSTEM) |
---|
23 | #include <rtems/untar.h> |
---|
24 | /* |
---|
25 | * The tarfile image is built automatically externally. |
---|
26 | */ |
---|
27 | #include "FilesystemImage.h" |
---|
28 | #endif |
---|
29 | |
---|
30 | |
---|
31 | extern rtems_configuration_table BSP_Configuration; |
---|
32 | |
---|
33 | /* |
---|
34 | * Using GNAT's Distributed Systems Annex support requires |
---|
35 | * each node in the system to have different pid's. In a |
---|
36 | * single CPU RTEMS system, it is always one. This lets the |
---|
37 | * user override the RTEMS default. |
---|
38 | */ |
---|
39 | #ifdef GNAT_PID |
---|
40 | #include <unistd.h> |
---|
41 | |
---|
42 | pid_t getpid() |
---|
43 | { |
---|
44 | return GNAT_PID; |
---|
45 | } |
---|
46 | #endif |
---|
47 | |
---|
48 | /* |
---|
49 | * Set up first argument |
---|
50 | */ |
---|
51 | static int argc = 1; |
---|
52 | static char arg0[20] = "rtems"; |
---|
53 | static char *argv[20] = { arg0 }; |
---|
54 | |
---|
55 | #if defined(MAIN_USE_REQUIRES_COMMAND_LINE) |
---|
56 | |
---|
57 | #define COMMAND_LINE_MAXIMUM 200 |
---|
58 | |
---|
59 | #include <stdio.h> |
---|
60 | #include <ctype.h> |
---|
61 | |
---|
62 | void parse_arguments( |
---|
63 | char *buffer, |
---|
64 | size_t maximum_length |
---|
65 | ) |
---|
66 | { |
---|
67 | char *cp; |
---|
68 | char *linebuf = buffer; |
---|
69 | size_t length; |
---|
70 | |
---|
71 | for (;;) { |
---|
72 | |
---|
73 | #if defined(MAIN_COMMAND_LINE) |
---|
74 | strncpy (linebuf, MAIN_COMMAND_LINE, maximum_length); |
---|
75 | #else |
---|
76 | /* |
---|
77 | * Read a line |
---|
78 | */ |
---|
79 | printf (">>> %s ", argv[0]); |
---|
80 | fflush (stdout); |
---|
81 | fgets (linebuf, maximum_length, stdin); |
---|
82 | |
---|
83 | length = strnlen( linebuf, maximum_length ); |
---|
84 | if ( linebuf[length - 1] == '\n' || linebuf[length - 1] == '\r' ) { |
---|
85 | linebuf[length - 1] = '\0'; |
---|
86 | } |
---|
87 | #endif |
---|
88 | |
---|
89 | /* |
---|
90 | * Break line into arguments |
---|
91 | */ |
---|
92 | cp = linebuf; |
---|
93 | for (;;) { |
---|
94 | while (isspace (*cp)) |
---|
95 | *cp++ = '\0'; |
---|
96 | if (*cp == '\0') |
---|
97 | break; |
---|
98 | if (argc >= ((sizeof argv / sizeof argv[0]) - 1)) { |
---|
99 | printf ("Too many arguments.\n"); |
---|
100 | argc = 0; |
---|
101 | break; |
---|
102 | } |
---|
103 | argv[argc++] = cp; |
---|
104 | while (!isspace (*cp)) { |
---|
105 | if (*cp == '\0') |
---|
106 | break; |
---|
107 | cp++; |
---|
108 | } |
---|
109 | } |
---|
110 | if (argc > 1) { |
---|
111 | argv[argc] = NULL; |
---|
112 | break; |
---|
113 | } |
---|
114 | printf ("You must give some arguments!\n"); |
---|
115 | } |
---|
116 | |
---|
117 | #if defined(DEBUG_COMMAND_LINE_ARGUMENTS) |
---|
118 | { |
---|
119 | int i; |
---|
120 | for (i=0; i<argc ; i++ ) { |
---|
121 | printf( "argv[%d] = ***%s***\n", i, argv[i] ); |
---|
122 | } |
---|
123 | printf( "\n" ); |
---|
124 | } |
---|
125 | #endif |
---|
126 | } |
---|
127 | |
---|
128 | |
---|
129 | #endif |
---|
130 | |
---|
131 | /* |
---|
132 | * By having the POSIX_Init thread create a second thread just |
---|
133 | * to invoke gnat_main, we can override all default attributes |
---|
134 | * of the "Ada environment task". Otherwise, we would be |
---|
135 | * stuck with the defaults set by RTEMS. |
---|
136 | */ |
---|
137 | |
---|
138 | void *start_gnat_main( void * argument ) |
---|
139 | { |
---|
140 | extern int gnat_main ( int argc, char **argv, char **envp ); |
---|
141 | |
---|
142 | #if defined(MAIN_USE_REQUIRES_COMMAND_LINE) |
---|
143 | /* |
---|
144 | * This is scoped to match the Ada program. |
---|
145 | */ |
---|
146 | char command_line[ COMMAND_LINE_MAXIMUM ]; |
---|
147 | |
---|
148 | parse_arguments( command_line, COMMAND_LINE_MAXIMUM ); |
---|
149 | #endif |
---|
150 | |
---|
151 | (void) gnat_main ( argc, argv, 0 ); |
---|
152 | |
---|
153 | exit( 0 ); |
---|
154 | |
---|
155 | return 0; |
---|
156 | } |
---|
157 | |
---|
158 | #ifndef GNAT_MAIN_STACKSPACE |
---|
159 | #define GNAT_MAIN_STACKSPACE 0 |
---|
160 | #endif |
---|
161 | |
---|
162 | void *POSIX_Init( void *argument ) |
---|
163 | { |
---|
164 | pthread_t thread_id; |
---|
165 | pthread_attr_t attr; |
---|
166 | size_t stacksize; |
---|
167 | int status; |
---|
168 | extern size_t _ada_pthread_minimum_stack_size(); |
---|
169 | |
---|
170 | #if defined(ENABLE_UNTAR_ROOT_FILESYSTEM) |
---|
171 | printk("Loading filesystem image\n"); |
---|
172 | status = Untar_FromMemory( (char *)FilesystemImage, FilesystemImage_size ); |
---|
173 | #endif |
---|
174 | |
---|
175 | #if defined(MAIN_USE_NETWORKING) |
---|
176 | printk("Initializing Network\n"); |
---|
177 | rtems_bsdnet_initialize_network (); |
---|
178 | rtems_bsdnet_show_inet_routes (); |
---|
179 | #endif |
---|
180 | |
---|
181 | #if defined(MAIN_CALL_C_INITIALIZE_APPLICATION) |
---|
182 | { |
---|
183 | extern void initialize_application(); |
---|
184 | printk("Invoking C Application Initialization\n"); |
---|
185 | initialize_application(); |
---|
186 | } |
---|
187 | #endif |
---|
188 | |
---|
189 | /* |
---|
190 | * Now create the thread that will be the GNAT Ada main. |
---|
191 | */ |
---|
192 | status = pthread_attr_init( &attr ); |
---|
193 | assert( !status ); |
---|
194 | |
---|
195 | stacksize = GNAT_MAIN_STACKSPACE * 1024; |
---|
196 | if ( stacksize < _ada_pthread_minimum_stack_size() ) |
---|
197 | stacksize = _ada_pthread_minimum_stack_size(); |
---|
198 | |
---|
199 | status = pthread_attr_setstacksize( &attr, stacksize ); |
---|
200 | assert( !status ); |
---|
201 | |
---|
202 | attr.schedpolicy = SCHED_RR; |
---|
203 | attr.schedparam.sched_priority = 122; |
---|
204 | status = pthread_create( &thread_id, &attr, start_gnat_main, NULL ); |
---|
205 | assert( !status ); |
---|
206 | |
---|
207 | pthread_exit( 0 ); |
---|
208 | return 0; |
---|
209 | } |
---|
210 | |
---|
211 | /* configuration information */ |
---|
212 | |
---|
213 | #if defined(HAS_EXTRA_CONFIGURATION) |
---|
214 | #include "config.h" |
---|
215 | #endif |
---|
216 | |
---|
217 | /* Standard output and a clock tick so time passes */ |
---|
218 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
219 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
220 | |
---|
221 | /* We need to be able to create sockets */ |
---|
222 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 20 |
---|
223 | |
---|
224 | /* We need the full IMFS to pass the full ACATS */ |
---|
225 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
226 | |
---|
227 | /* This is overkill but is definitely enough to run the network stack */ |
---|
228 | #define CONFIGURE_MAXIMUM_TASKS 20 |
---|
229 | #define CONFIGURE_MAXIMUM_SEMAPHORES 20 |
---|
230 | |
---|
231 | /* We want a clock tick every millisecond */ |
---|
232 | #define CONFIGURE_MICROSECONDS_PER_TICK RTEMS_MILLISECONDS_TO_MICROSECONDS(1) |
---|
233 | |
---|
234 | /* The initialization task is a POSIX Initialization thread with default |
---|
235 | * attributes. |
---|
236 | */ |
---|
237 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
238 | |
---|
239 | /* We are using GNAT/RTEMS with a maximum of 20 Ada tasks and no fake Ada |
---|
240 | * tasks. |
---|
241 | * NOTE: A fake Ada task is a task created outside the Ada run-time that |
---|
242 | * calls into Ada. |
---|
243 | */ |
---|
244 | #define CONFIGURE_GNAT_RTEMS |
---|
245 | #define CONFIGURE_MAXIMUM_ADA_TASKS 20 |
---|
246 | |
---|
247 | #if !defined(CONFIGURE_MAXIMUM_FAKE_ADA_TASKS) |
---|
248 | #define CONFIGURE_MAXIMUM_FAKE_ADA_TASKS 0 |
---|
249 | #endif |
---|
250 | |
---|
251 | #if !defined(ADA_APPLICATION_NEEDS_EXTRA_MEMORY) |
---|
252 | #define ADA_APPLICATION_NEEDS_EXTRA_MEMORY 0 |
---|
253 | #endif |
---|
254 | |
---|
255 | /* Account for any extra task stack size */ |
---|
256 | #define CONFIGURE_MEMORY_OVERHEAD \ |
---|
257 | (ADA_APPLICATION_NEEDS_EXTRA_MEMORY + GNAT_MAIN_STACKSPACE) |
---|
258 | |
---|
259 | /* Make sure the C Program Heap and Workspace are zeroed for GNAT */ |
---|
260 | #define CONFIGURE_ZERO_WORKSPACE_AUTOMATICALLY TRUE |
---|
261 | |
---|
262 | #define CONFIGURE_INIT |
---|
263 | |
---|
264 | void _flush_cache() {} |
---|
265 | #include <rtems/confdefs.h> |
---|