source: ada-examples/rtems_init.c @ 14f44a3

ada-examples-4-10-branchada-examples-4-9-branch
Last change on this file since 14f44a3 was 14f44a3, checked in by Joel Sherrill <joel.sherrill@…>, on 10/17/07 at 20:55:06

2007-10-17 Joel Sherrill <joel.sherrill@…>

  • Makefile, Makefile.shared, rtems_init.c, irq_test/interrupt_pkg.adb, irq_test/interrupt_pkg.ads, irq_test/irqforce.c, irq_test/irqtest.adb, rootfs/etc/hosts: Adding new tests as improvements are made to the RTEMS port of the GNAT run-time.
  • empty/Makefile, empty/README, empty/empty.adb, hello_via_task/.cvsignore, hello_via_task/Makefile, hello_via_task/hello.adb, irq_test/.cvsignore, irq_test/Makefile, irq_test/README, irq_test_c/.cvsignore, irq_test_c/Makefile, irq_test_c/README, irq_test_c/init.c, irq_test_c/irqforce.c: New files.
  • Property mode set to 100644
File size: 5.4 KB
Line 
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
31extern 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 */
51static int   argc     = 1;
52static char  arg0[20] = "rtems";
53static 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
62void 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 
138void *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
162void *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  status = pthread_attr_init( &attr );
182  assert( !status );
183
184  stacksize = GNAT_MAIN_STACKSPACE * 1024;
185  if ( stacksize < _ada_pthread_minimum_stack_size() )
186    stacksize = _ada_pthread_minimum_stack_size();
187
188  status = pthread_attr_setstacksize( &attr, stacksize );
189  assert( !status );
190
191  status = pthread_create( &thread_id, &attr, start_gnat_main, NULL );
192  assert( !status );
193
194  pthread_exit( 0 );
195  return 0;
196}
197
198/* configuration information */
199
200/* Standard output and a clock tick so time passes */
201#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
202#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
203
204/* We need to be able to create sockets */
205#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS        20
206
207/* We need the full IMFS to pass the full ACATS */
208#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
209
210/* This is overkill but is definitely enough to run the network stack */
211#define CONFIGURE_MAXIMUM_TASKS                         20
212#define CONFIGURE_MAXIMUM_SEMAPHORES                    20
213
214/* We want a clock tick every millisecond */
215#define CONFIGURE_MICROSECONDS_PER_TICK RTEMS_MILLISECONDS_TO_MICROSECONDS(1)
216
217/* The initialization task is a POSIX Initialization thread with default attributes */
218#define CONFIGURE_POSIX_INIT_THREAD_TABLE
219
220/* We are using GNAT/RTEMS with a maximum of 20 Ada tasks and no fake Ada tasks. */
221/* A fake Ada task is a task created outside the Ada run-time that calls into Ada. */
222#define CONFIGURE_GNAT_RTEMS
223#define CONFIGURE_MAXIMUM_ADA_TASKS      20
224#define CONFIGURE_MAXIMUM_FAKE_ADA_TASKS 0
225
226/* Account for any extra task stack size */
227#define CONFIGURE_MEMORY_OVERHEAD        (GNAT_MAIN_STACKSPACE)
228
229#define CONFIGURE_INIT
230
231#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.