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