Rev 2787 | Rev 3425 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2787 | Rev 3424 | ||
|---|---|---|---|
| Line 76... | Line 76... | ||
| 76 | #include <arch.h> |
76 | #include <arch.h> |
| 77 | #include <arch/faddr.h> |
77 | #include <arch/faddr.h> |
| 78 | #include <ipc/ipc.h> |
78 | #include <ipc/ipc.h> |
| 79 | #include <macros.h> |
79 | #include <macros.h> |
| 80 | #include <adt/btree.h> |
80 | #include <adt/btree.h> |
| 81 | #include <console/klog.h> |
- | |
| 82 | #include <smp/smp.h> |
81 | #include <smp/smp.h> |
| 83 | #include <ddi/ddi.h> |
82 | #include <ddi/ddi.h> |
| - | 83 | #include <console/console.h> |
|
| 84 | 84 | ||
| 85 | /** Global configuration structure. */ |
85 | /** Global configuration structure. */ |
| 86 | config_t config; |
86 | config_t config; |
| 87 | 87 | ||
| 88 | /** Initial user-space tasks */ |
88 | /** Initial user-space tasks */ |
| Line 129... | Line 129... | ||
| 129 | 129 | ||
| 130 | #define CONFIG_STACK_SIZE ((1 << STACK_FRAMES) * STACK_SIZE) |
130 | #define CONFIG_STACK_SIZE ((1 << STACK_FRAMES) * STACK_SIZE) |
| 131 | 131 | ||
| 132 | /** Main kernel routine for bootstrap CPU. |
132 | /** Main kernel routine for bootstrap CPU. |
| 133 | * |
133 | * |
| 134 | * Initializes the kernel by bootstrap CPU. |
134 | * The code here still runs on the boot stack, which knows nothing about |
| 135 | * This function passes control directly to |
135 | * preemption counts. Because of that, this function cannot directly call |
| - | 136 | * functions that disable or enable preemption (e.g. spinlock_lock()). The |
|
| - | 137 | * primary task of this function is to calculate address of a new stack and |
|
| 136 | * main_bsp_separated_stack(). |
138 | * switch to it. |
| 137 | * |
139 | * |
| 138 | * Assuming interrupts_disable(). |
140 | * Assuming interrupts_disable(). |
| 139 | * |
141 | * |
| 140 | */ |
142 | */ |
| 141 | void main_bsp(void) |
143 | void main_bsp(void) |
| Line 184... | Line 186... | ||
| 184 | * Second part of main_bsp(). |
186 | * Second part of main_bsp(). |
| 185 | * |
187 | * |
| 186 | */ |
188 | */ |
| 187 | void main_bsp_separated_stack(void) |
189 | void main_bsp_separated_stack(void) |
| 188 | { |
190 | { |
| 189 | task_t *k; |
- | |
| 190 | thread_t *t; |
191 | /* Keep this the first thing. */ |
| 191 | count_t i; |
- | |
| 192 | - | ||
| 193 | the_initialize(THE); |
192 | the_initialize(THE); |
| 194 | 193 | ||
| - | 194 | LOG(); |
|
| - | 195 | ||
| - | 196 | version_print(); |
|
| - | 197 | ||
| - | 198 | LOG("\nconfig.base=%#" PRIp " config.kernel_size=%" PRIs |
|
| - | 199 | "\nconfig.stack_base=%#" PRIp " config.stack_size=%" PRIs, |
|
| - | 200 | config.base, config.kernel_size, config.stack_base, |
|
| - | 201 | config.stack_size); |
|
| - | 202 | ||
| - | 203 | ||
| 195 | /* |
204 | /* |
| 196 | * kconsole data structures must be initialized very early |
205 | * kconsole data structures must be initialized very early |
| 197 | * because other subsystems will register their respective |
206 | * because other subsystems will register their respective |
| 198 | * commands. |
207 | * commands. |
| 199 | */ |
208 | */ |
| 200 | kconsole_init(); |
209 | LOG_EXEC(kconsole_init()); |
| 201 | 210 | ||
| 202 | /* |
211 | /* |
| 203 | * Exception handler initialization, before architecture |
212 | * Exception handler initialization, before architecture |
| 204 | * starts adding its own handlers |
213 | * starts adding its own handlers |
| 205 | */ |
214 | */ |
| 206 | exc_init(); |
215 | LOG_EXEC(exc_init()); |
| 207 | 216 | ||
| 208 | /* |
217 | /* |
| 209 | * Memory management subsystems initialization. |
218 | * Memory management subsystems initialization. |
| 210 | */ |
219 | */ |
| 211 | arch_pre_mm_init(); |
220 | LOG_EXEC(arch_pre_mm_init()); |
| 212 | frame_init(); |
221 | LOG_EXEC(frame_init()); |
| 213 | /* Initialize at least 1 memory segment big enough for slab to work. */ |
- | |
| 214 | slab_cache_init(); |
- | |
| 215 | btree_init(); |
- | |
| 216 | as_init(); |
- | |
| 217 | page_init(); |
- | |
| 218 | tlb_init(); |
- | |
| 219 | ddi_init(); |
- | |
| 220 | tasklet_init(); |
- | |
| 221 | arch_post_mm_init(); |
- | |
| 222 | 222 | ||
| - | 223 | /* Initialize at least 1 memory segment big enough for slab to work. */ |
|
| - | 224 | LOG_EXEC(slab_cache_init()); |
|
| - | 225 | LOG_EXEC(btree_init()); |
|
| 223 | version_print(); |
226 | LOG_EXEC(as_init()); |
| 224 | printf("kernel: %.*p hardcoded_ktext_size=%zd KB, " |
227 | LOG_EXEC(page_init()); |
| - | 228 | LOG_EXEC(tlb_init()); |
|
| 225 | "hardcoded_kdata_size=%zd KB\n", sizeof(uintptr_t) * 2, |
229 | LOG_EXEC(ddi_init()); |
| 226 | config.base, SIZE2KB(hardcoded_ktext_size), |
230 | LOG_EXEC(tasklet_init()); |
| 227 | SIZE2KB(hardcoded_kdata_size)); |
231 | LOG_EXEC(arch_post_mm_init()); |
| 228 | printf("stack: %.*p size=%zd KB\n", sizeof(uintptr_t) * 2, |
232 | LOG_EXEC(arch_pre_smp_init()); |
| 229 | config.stack_base, SIZE2KB(config.stack_size)); |
233 | LOG_EXEC(smp_init()); |
| 230 | 234 | ||
| 231 | arch_pre_smp_init(); |
- | |
| 232 | smp_init(); |
- | |
| 233 | /* Slab must be initialized after we know the number of processors. */ |
235 | /* Slab must be initialized after we know the number of processors. */ |
| 234 | slab_enable_cpucache(); |
236 | LOG_EXEC(slab_enable_cpucache()); |
| 235 | 237 | ||
| 236 | printf("Detected %zu CPU(s), %llu MB free memory\n", |
238 | printf("Detected %" PRIc " CPU(s), %" PRIu64" MB free memory\n", |
| 237 | config.cpu_count, SIZE2MB(zone_total_size())); |
239 | config.cpu_count, SIZE2MB(zone_total_size())); |
| 238 | cpu_init(); |
- | |
| 239 | 240 | ||
| - | 241 | LOG_EXEC(cpu_init()); |
|
| - | 242 | ||
| 240 | calibrate_delay_loop(); |
243 | LOG_EXEC(calibrate_delay_loop()); |
| 241 | clock_counter_init(); |
244 | LOG_EXEC(clock_counter_init()); |
| 242 | timeout_init(); |
245 | LOG_EXEC(timeout_init()); |
| 243 | scheduler_init(); |
246 | LOG_EXEC(scheduler_init()); |
| 244 | task_init(); |
247 | LOG_EXEC(task_init()); |
| 245 | thread_init(); |
248 | LOG_EXEC(thread_init()); |
| 246 | futex_init(); |
249 | LOG_EXEC(futex_init()); |
| 247 | klog_init(); |
- | |
| 248 | 250 | ||
| 249 | if (init.cnt > 0) { |
251 | if (init.cnt > 0) { |
| - | 252 | count_t i; |
|
| 250 | for (i = 0; i < init.cnt; i++) |
253 | for (i = 0; i < init.cnt; i++) |
| 251 | printf("init[%zd].addr=%.*p, init[%zd].size=%zd\n", i, |
254 | printf("init[%" PRIc "].addr=%#" PRIp ", init[%" PRIc |
| 252 | sizeof(uintptr_t) * 2, init.tasks[i].addr, i, |
255 | "].size=%#" PRIs "\n", i, init.tasks[i].addr, |
| 253 | init.tasks[i].size); |
256 | i, init.tasks[i].size); |
| 254 | } else |
257 | } else |
| 255 | printf("No init binaries found\n"); |
258 | printf("No init binaries found\n"); |
| 256 | 259 | ||
| 257 | ipc_init(); |
260 | LOG_EXEC(ipc_init()); |
| - | 261 | LOG_EXEC(klog_init()); |
|
| 258 | 262 | ||
| 259 | /* |
263 | /* |
| 260 | * Create kernel task. |
264 | * Create kernel task. |
| 261 | */ |
265 | */ |
| 262 | k = task_create(AS_KERNEL, "kernel"); |
266 | task_t *kernel = task_create(AS_KERNEL, "kernel"); |
| 263 | if (!k) |
267 | if (!kernel) |
| 264 | panic("can't create kernel task\n"); |
268 | panic("Can't create kernel task\n"); |
| 265 | 269 | ||
| 266 | /* |
270 | /* |
| 267 | * Create the first thread. |
271 | * Create the first thread. |
| 268 | */ |
272 | */ |
| 269 | t = thread_create(kinit, NULL, k, 0, "kinit", true); |
273 | thread_t *kinit_thread = thread_create(kinit, NULL, kernel, 0, "kinit", |
| 270 | if (!t) |
274 | true); |
| - | 275 | if (!kinit_thread) |
|
| 271 | panic("can't create kinit thread\n"); |
276 | panic("Can't create kinit thread\n"); |
| 272 | thread_ready(t); |
277 | LOG_EXEC(thread_ready(kinit_thread)); |
| 273 | 278 | ||
| 274 | /* |
279 | /* |
| 275 | * This call to scheduler() will return to kinit, |
280 | * This call to scheduler() will return to kinit, |
| 276 | * starting the thread of kernel threads. |
281 | * starting the thread of kernel threads. |
| 277 | */ |
282 | */ |