source: rtems/c/src/lib/libbsp/shared/bspinit.c @ a36094f

4.115
Last change on this file since a36094f was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#include <stdlib.h>
11#include <string.h>
12
13#include <bsp.h>
14#include <bsp/bootcard.h>
15#ifdef RTEMS_NETWORKING
16  #include <rtems/rtems_bsdnet.h>
17#endif
18
19/*
20 *  Necessary prototypes
21 */
22rtems_task Init (rtems_task_argument arg);
23int main (int argc, char* argv[]);
24
25/*
26 * This routine calls main from a confdefs.h default Init task
27 * set up. The bootcard will provide the task argument as
28 * command line string (ASCIIZ).
29 */
30
31rtems_task Init (rtems_task_argument arg)
32{
33  const char* boot_cmdline = *((const char**) arg);
34  char*       cmdline = 0;
35  char*       command;
36  int         argc = 0;
37  char**      argv = NULL;
38  int         result = -124;
39
40  if (boot_cmdline)
41  {
42    cmdline = malloc (strlen (boot_cmdline) + 1);
43
44    if (cmdline)
45    {
46      strcpy (cmdline, boot_cmdline);
47
48      command = cmdline;
49
50      /*
51       * Break the line up into arguments with "" being ignored.
52       */
53      while (true)
54      {
55        command = strtok (command, " \t\r\n");
56        if (command == NULL)
57          break;
58        argc++;
59        command = '\0';
60      }
61
62      argv = calloc (argc, sizeof (char*));
63
64      if (argv)
65      {
66        int a;
67
68        command = cmdline;
69        argv[0] = command;
70
71        for (a = 1; a < argc; a++)
72        {
73          command += strlen (command) + 1;
74          argv[a] = command;
75        }
76      }
77      else
78        argc = 0;
79    }
80  }
81
82#ifdef RTEMS_NETWORKING
83  rtems_bsdnet_initialize_network ();
84#endif
85
86  result = main (argc, argv);
87
88  free (argv);
89  free (cmdline);
90
91  exit (result);
92}
93
94/*
95 * By making this a weak alias and a user can provide there own.
96 */
97
98void Init (rtems_task_argument arg) __attribute__ ((weak));
Note: See TracBrowser for help on using the repository browser.