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