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.com/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 | * This routine calls main from a confdefs.h default Init task |
---|
21 | * set up. The bootcard will provide the task argument as |
---|
22 | * command line string (ASCIIZ). |
---|
23 | */ |
---|
24 | |
---|
25 | int main (int argc, char* argv[]); |
---|
26 | |
---|
27 | void Init (rtems_task_argument arg) |
---|
28 | { |
---|
29 | const char* boot_cmdline = *((const char**) arg); |
---|
30 | char* cmdline = 0; |
---|
31 | char* command; |
---|
32 | int argc = 0; |
---|
33 | char** argv = NULL; |
---|
34 | int result = -124; |
---|
35 | |
---|
36 | if (boot_cmdline) |
---|
37 | { |
---|
38 | cmdline = malloc (strlen (boot_cmdline) + 1); |
---|
39 | |
---|
40 | if (cmdline) |
---|
41 | { |
---|
42 | strcpy (cmdline, boot_cmdline); |
---|
43 | |
---|
44 | command = cmdline; |
---|
45 | |
---|
46 | /* |
---|
47 | * Break the line up into arguments with "" being ignored. |
---|
48 | */ |
---|
49 | while (true) |
---|
50 | { |
---|
51 | command = strtok (command, " \t\r\n"); |
---|
52 | if (command == NULL) |
---|
53 | break; |
---|
54 | argc++; |
---|
55 | command = '\0'; |
---|
56 | } |
---|
57 | |
---|
58 | argv = calloc (argc, sizeof (char*)); |
---|
59 | |
---|
60 | if (argv) |
---|
61 | { |
---|
62 | int a; |
---|
63 | |
---|
64 | command = cmdline; |
---|
65 | argv[0] = command; |
---|
66 | |
---|
67 | for (a = 1; a < argc; a++) |
---|
68 | { |
---|
69 | command += strlen (command) + 1; |
---|
70 | argv[a] = command; |
---|
71 | } |
---|
72 | } |
---|
73 | else |
---|
74 | argc = 0; |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | #ifdef RTEMS_NETWORKING |
---|
79 | rtems_bsdnet_initialize_network (); |
---|
80 | #endif |
---|
81 | |
---|
82 | result = main (argc, argv); |
---|
83 | |
---|
84 | free (argv); |
---|
85 | free (cmdline); |
---|
86 | |
---|
87 | exit (result); |
---|
88 | } |
---|
89 | |
---|
90 | /* |
---|
91 | * By making this a weak alias and a user can provide there own. |
---|
92 | */ |
---|
93 | |
---|
94 | void Init (rtems_task_argument arg) __attribute__ ((weak)); |
---|