Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel'
[palacios.git] / kitten / kernel / init_task.c
1 #include <lwk/kernel.h>
2 #include <lwk/smp.h>
3 #include <lwk/params.h>
4 #include <lwk/init.h>
5 #include <lwk/elf.h>
6
7 /**
8  * Maximum number of arguments and environment variables that may
9  * be passed to the init_task.
10  */
11 #define INIT_MAX_ARGC 32
12 #define INIT_MAX_ENVC 32
13
14 /**
15  * Maximum length of the init_argv= and init_envp= strings on the
16  * kernel boot command line.
17  */
18 #define INIT_ARGV_LEN 1024
19 #define INIT_ENVP_LEN 1024
20
21 /**
22  * Amount of memory to reserve for the init_task's heap.
23  */
24 unsigned long init_heap_size = (1024 * 1024 * 4);  /* 4 MB */
25 param(init_heap_size, ulong);
26
27 /**
28  * Amount of memory to reserve for the init_task's stack.
29  */
30 unsigned long init_stack_size = (1024 * 256);  /* 256 KB */
31 param(init_stack_size, ulong);
32
33 /**
34  * Arguments to pass to the init_task.
35  */
36 static char init_argv_str[INIT_ARGV_LEN] = { 0 };
37 param_string(init_argv, init_argv_str, sizeof(init_argv_str));
38
39 /**
40  * Environment to pass to the init_task.
41  */
42 static char init_envp_str[INIT_ENVP_LEN] = { 0 };
43 param_string(init_envp, init_envp_str, sizeof(init_envp_str));
44
45 /**
46  * Creates the init_task.
47  */
48 int
49 create_init_task(void)
50 {
51         int status;
52         start_state_t start_state;
53
54         if (!init_elf_image) {
55                 printk("No init_elf_image found.\n");
56                 return -EINVAL;
57         }
58         
59         /* Initialize the start_state fields that we know up-front */
60         start_state.uid     = 0;
61         start_state.gid     = 0;
62         start_state.cpu_id  = this_cpu;
63         start_state.cpumask = NULL;
64
65         /* This initializes start_state aspace_id, entry_point, and stack_ptr */
66         status =
67         elf_load(
68                 __va(init_elf_image),
69                 init_elf_image,
70                 "init_task",
71                 INIT_ASPACE_ID,
72                 PAGE_SIZE,
73                 init_heap_size,
74                 init_stack_size,
75                 init_argv_str,
76                 init_envp_str,
77                 &start_state,
78                 0,
79                 &elf_dflt_alloc_pmem
80         );
81         if (status) {
82                 printk("Failed to load init_task (status=%d).\n", status);
83                 return status;
84         }
85
86         /* This prevents the address space from being deleted by
87          * user-space, since the kernel never releases this reference */
88         if (!aspace_acquire(INIT_ASPACE_ID)) {
89                 printk("Failed to acquire INIT_ASPACE_ID.\n");
90                 return status;
91         }
92
93         return task_create(INIT_TASK_ID, "init_task", &start_state, NULL);
94 }