Rev 3593 | Rev 3817 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3593 | Rev 3742 | ||
|---|---|---|---|
| Line 80... | Line 80... | ||
| 80 | * |
80 | * |
| 81 | * @param arg Not used. |
81 | * @param arg Not used. |
| 82 | */ |
82 | */ |
| 83 | void kinit(void *arg) |
83 | void kinit(void *arg) |
| 84 | { |
84 | { |
| - | 85 | ||
| - | 86 | #if defined(CONFIG_SMP) || defined(CONFIG_KCONSOLE) |
|
| 85 | thread_t *t; |
87 | thread_t *thread; |
| - | 88 | #endif |
|
| 86 | 89 | ||
| 87 | /* |
90 | /* |
| 88 | * Detach kinit as nobody will call thread_join_timeout() on it. |
91 | * Detach kinit as nobody will call thread_join_timeout() on it. |
| 89 | */ |
92 | */ |
| 90 | thread_detach(THREAD); |
93 | thread_detach(THREAD); |
| Line 98... | Line 101... | ||
| 98 | * Create the kmp thread and wait for its completion. |
101 | * Create the kmp thread and wait for its completion. |
| 99 | * cpu1 through cpuN-1 will come up consecutively and |
102 | * cpu1 through cpuN-1 will come up consecutively and |
| 100 | * not mess together with kcpulb threads. |
103 | * not mess together with kcpulb threads. |
| 101 | * Just a beautification. |
104 | * Just a beautification. |
| 102 | */ |
105 | */ |
| 103 | if ((t = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED, |
106 | thread = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED, "kmp", true); |
| 104 | "kmp", true))) { |
107 | if (thread != NULL) { |
| 105 | spinlock_lock(&t->lock); |
108 | spinlock_lock(&thread->lock); |
| 106 | t->cpu = &cpus[0]; |
109 | thread->cpu = &cpus[0]; |
| 107 | spinlock_unlock(&t->lock); |
110 | spinlock_unlock(&thread->lock); |
| 108 | thread_ready(t); |
111 | thread_ready(thread); |
| 109 | } else |
112 | } else |
| 110 | panic("thread_create/kmp\n"); |
113 | panic("Unable to create kmp thread\n"); |
| 111 | thread_join(t); |
114 | thread_join(thread); |
| 112 | thread_detach(t); |
115 | thread_detach(thread); |
| 113 | } |
116 | } |
| 114 | #endif /* CONFIG_SMP */ |
117 | #endif /* CONFIG_SMP */ |
| 115 | /* |
- | |
| 116 | * Now that all CPUs are up, we can report what we've found. |
- | |
| 117 | */ |
- | |
| 118 | cpu_list(); |
- | |
| 119 | 118 | ||
| 120 | #ifdef CONFIG_SMP |
119 | #ifdef CONFIG_SMP |
| 121 | if (config.cpu_count > 1) { |
120 | if (config.cpu_count > 1) { |
| 122 | count_t i; |
121 | count_t i; |
| 123 | 122 | ||
| 124 | /* |
123 | /* |
| 125 | * For each CPU, create its load balancing thread. |
124 | * For each CPU, create its load balancing thread. |
| 126 | */ |
125 | */ |
| 127 | for (i = 0; i < config.cpu_count; i++) { |
126 | for (i = 0; i < config.cpu_count; i++) { |
| 128 | - | ||
| 129 | if ((t = thread_create(kcpulb, NULL, TASK, |
127 | thread = thread_create(kcpulb, NULL, TASK, THREAD_FLAG_WIRED, "kcpulb", true); |
| 130 | THREAD_FLAG_WIRED, "kcpulb", true))) { |
128 | if (thread != NULL) { |
| 131 | spinlock_lock(&t->lock); |
129 | spinlock_lock(&thread->lock); |
| 132 | t->cpu = &cpus[i]; |
130 | thread->cpu = &cpus[i]; |
| 133 | spinlock_unlock(&t->lock); |
131 | spinlock_unlock(&thread->lock); |
| 134 | thread_ready(t); |
132 | thread_ready(thread); |
| 135 | } else |
133 | } else |
| 136 | panic("thread_create/kcpulb\n"); |
134 | printf("Unable to create kcpulb thread for cpu" PRIc "\n", i); |
| 137 | 135 | ||
| 138 | } |
136 | } |
| 139 | } |
137 | } |
| 140 | #endif /* CONFIG_SMP */ |
138 | #endif /* CONFIG_SMP */ |
| 141 | 139 | ||
| 142 | /* |
140 | /* |
| 143 | * At this point SMP, if present, is configured. |
141 | * At this point SMP, if present, is configured. |
| 144 | */ |
142 | */ |
| 145 | arch_post_smp_init(); |
143 | arch_post_smp_init(); |
| 146 | 144 | ||
| - | 145 | #ifdef CONFIG_KCONSOLE |
|
| - | 146 | if (stdin) { |
|
| 147 | /* |
147 | /* |
| 148 | * Create kernel console. |
148 | * Create kernel console. |
| 149 | */ |
149 | */ |
| 150 | t = thread_create(kconsole, (void *) "kconsole", TASK, 0, "kconsole", |
150 | thread = thread_create(kconsole_thread, NULL, TASK, 0, "kconsole", false); |
| 151 | false); |
- | |
| 152 | if (t) |
151 | if (thread != NULL) |
| 153 | thread_ready(t); |
152 | thread_ready(thread); |
| 154 | else |
153 | else |
| 155 | panic("thread_create/kconsole\n"); |
154 | printf("Unable to create kconsole thread\n"); |
| - | 155 | } |
|
| - | 156 | #endif /* CONFIG_KCONSOLE */ |
|
| 156 | 157 | ||
| 157 | interrupts_enable(); |
158 | interrupts_enable(); |
| 158 | 159 | ||
| 159 | /* |
160 | /* |
| 160 | * Create user tasks, load RAM disk images. |
161 | * Create user tasks, load RAM disk images. |
| 161 | */ |
162 | */ |
| 162 | count_t i; |
163 | count_t i; |
| 163 | program_t programs[CONFIG_INIT_TASKS]; |
164 | program_t programs[CONFIG_INIT_TASKS]; |
| 164 | 165 | ||
| 165 | for (i = 0; i < init.cnt; i++) { |
166 | for (i = 0; i < init.cnt; i++) { |
| 166 | if (init.tasks[i].addr % FRAME_SIZE) { |
167 | if (init.tasks[i].addr % FRAME_SIZE) { |
| 167 | printf("init[%" PRIc "].addr is not frame aligned", i); |
168 | printf("init[%" PRIc "].addr is not frame aligned\n", i); |
| 168 | continue; |
169 | continue; |
| 169 | } |
170 | } |
| 170 | 171 | ||
| 171 | int rc = program_create_from_image((void *) init.tasks[i].addr, |
172 | int rc = program_create_from_image((void *) init.tasks[i].addr, |
| 172 | "init-bin", &programs[i]); |
173 | "init-bin", &programs[i]); |
| 173 | 174 | ||
| 174 | if (rc == 0 && programs[i].task != NULL) { |
175 | if ((rc == 0) && (programs[i].task != NULL)) { |
| 175 | /* |
176 | /* |
| 176 | * Set capabilities to init userspace tasks. |
177 | * Set capabilities to init userspace tasks. |
| 177 | */ |
178 | */ |
| 178 | cap_set(programs[i].task, CAP_CAP | CAP_MEM_MANAGER | |
179 | cap_set(programs[i].task, CAP_CAP | CAP_MEM_MANAGER | |
| 179 | CAP_IO_MANAGER | CAP_PREEMPT_CONTROL | CAP_IRQ_REG); |
180 | CAP_IO_MANAGER | CAP_PREEMPT_CONTROL | CAP_IRQ_REG); |
| Line 182... | Line 183... | ||
| 182 | ipc_phone_0 = &programs[i].task->answerbox; |
183 | ipc_phone_0 = &programs[i].task->answerbox; |
| 183 | } else if (rc == 0) { |
184 | } else if (rc == 0) { |
| 184 | /* It was the program loader and was registered */ |
185 | /* It was the program loader and was registered */ |
| 185 | } else { |
186 | } else { |
| 186 | /* RAM disk image */ |
187 | /* RAM disk image */ |
| 187 | int rd = init_rd((rd_header_t *) init.tasks[i].addr, |
188 | int rd = init_rd((rd_header_t *) init.tasks[i].addr, init.tasks[i].size); |
| 188 | init.tasks[i].size); |
- | |
| 189 | 189 | ||
| 190 | if (rd != RE_OK) |
190 | if (rd != RE_OK) |
| 191 | printf("Init binary %" PRIc " not used, error " |
191 | printf("Init binary %" PRIc " not used (error %d)\n", i, rd); |
| 192 | "code %d.\n", i, rd); |
- | |
| 193 | } |
192 | } |
| 194 | } |
193 | } |
| 195 | 194 | ||
| 196 | /* |
195 | /* |
| 197 | * Run user tasks with reasonable delays |
196 | * Run user tasks with reasonable delays |
| Line 201... | Line 200... | ||
| 201 | thread_usleep(50000); |
200 | thread_usleep(50000); |
| 202 | program_ready(&programs[i]); |
201 | program_ready(&programs[i]); |
| 203 | } |
202 | } |
| 204 | } |
203 | } |
| 205 | 204 | ||
| - | 205 | #ifdef CONFIG_KCONSOLE |
|
| 206 | if (!stdin) { |
206 | if (!stdin) { |
| - | 207 | printf("kinit: No stdin\nKernel alive: "); |
|
| - | 208 | ||
| - | 209 | uint64_t i = 0; |
|
| 207 | while (1) { |
210 | while (1) { |
| - | 211 | printf(PRIu64 " ", i); |
|
| 208 | thread_sleep(1); |
212 | thread_sleep(1); |
| 209 | printf("kinit... "); |
213 | i++; |
| 210 | } |
214 | } |
| 211 | } |
215 | } |
| - | 216 | #endif /* CONFIG_KCONSOLE */ |
|
| 212 | } |
217 | } |
| 213 | 218 | ||
| 214 | /** @} |
219 | /** @} |
| 215 | */ |
220 | */ |