[f761f1eb] | 1 | /*
|
---|
| 2 | * Copyright (C) 2001-2004 Jakub Jermar
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | #include <main/kinit.h>
|
---|
[2677758] | 30 | #include <config.h>
|
---|
| 31 | #include <arch.h>
|
---|
[f761f1eb] | 32 | #include <proc/scheduler.h>
|
---|
| 33 | #include <proc/task.h>
|
---|
| 34 | #include <proc/thread.h>
|
---|
| 35 | #include <panic.h>
|
---|
| 36 | #include <func.h>
|
---|
| 37 | #include <cpu.h>
|
---|
| 38 | #include <arch/asm.h>
|
---|
| 39 | #include <mm/page.h>
|
---|
| 40 | #include <arch/mm/page.h>
|
---|
[20d50a1] | 41 | #include <mm/as.h>
|
---|
[ff3b3197] | 42 | #include <mm/frame.h>
|
---|
[9c0a9b3] | 43 | #include <print.h>
|
---|
[399ccd9] | 44 | #include <memstr.h>
|
---|
[ff3b3197] | 45 | #include <console/console.h>
|
---|
[aace6624] | 46 | #include <interrupt.h>
|
---|
[f4338d2] | 47 | #include <console/kconsole.h>
|
---|
[e74cb73] | 48 | #include <ipc/ns.h>
|
---|
[f761f1eb] | 49 |
|
---|
[5f85c91] | 50 | #ifdef CONFIG_SMP
|
---|
[ed0dd65] | 51 | #include <arch/smp/mps.h>
|
---|
[5f85c91] | 52 | #endif /* CONFIG_SMP */
|
---|
[f761f1eb] | 53 |
|
---|
| 54 | #include <synch/waitq.h>
|
---|
| 55 | #include <synch/spinlock.h>
|
---|
| 56 |
|
---|
[36a140b] | 57 | #ifdef CONFIG_TEST
|
---|
[f761f1eb] | 58 | #include <test.h>
|
---|
[36a140b] | 59 | #endif /* CONFIG_TEST */
|
---|
[f761f1eb] | 60 |
|
---|
[880de6e] | 61 | /** Kernel initialization thread.
|
---|
| 62 | *
|
---|
| 63 | * kinit takes care of higher level kernel
|
---|
| 64 | * initialization (i.e. thread creation,
|
---|
| 65 | * userspace initialization etc.).
|
---|
| 66 | *
|
---|
| 67 | * @param arg Not used.
|
---|
| 68 | */
|
---|
[f761f1eb] | 69 | void kinit(void *arg)
|
---|
| 70 | {
|
---|
[80d2bdb] | 71 | thread_t *t;
|
---|
[f761f1eb] | 72 |
|
---|
[22f7769] | 73 | interrupts_disable();
|
---|
[f761f1eb] | 74 |
|
---|
[5f85c91] | 75 | #ifdef CONFIG_SMP
|
---|
[f761f1eb] | 76 | if (config.cpu_count > 1) {
|
---|
| 77 | /*
|
---|
| 78 | * Create the kmp thread and wait for its completion.
|
---|
| 79 | * cpu1 through cpuN-1 will come up consecutively and
|
---|
[169c408] | 80 | * not mess together with kcpulb threads.
|
---|
[f761f1eb] | 81 | * Just a beautification.
|
---|
| 82 | */
|
---|
[5a95b25] | 83 | if ((t = thread_create(kmp, NULL, TASK, 0))) {
|
---|
[f761f1eb] | 84 | spinlock_lock(&t->lock);
|
---|
| 85 | t->flags |= X_WIRED;
|
---|
| 86 | t->cpu = &cpus[0];
|
---|
| 87 | spinlock_unlock(&t->lock);
|
---|
| 88 | thread_ready(t);
|
---|
| 89 | waitq_sleep(&kmp_completion_wq);
|
---|
| 90 | }
|
---|
[2677758] | 91 | else panic("thread_create/kmp\n");
|
---|
[f761f1eb] | 92 | }
|
---|
[5f85c91] | 93 | #endif /* CONFIG_SMP */
|
---|
[f761f1eb] | 94 | /*
|
---|
| 95 | * Now that all CPUs are up, we can report what we've found.
|
---|
| 96 | */
|
---|
[0132630] | 97 | cpu_list();
|
---|
[f761f1eb] | 98 |
|
---|
[5f85c91] | 99 | #ifdef CONFIG_SMP
|
---|
[f761f1eb] | 100 | if (config.cpu_count > 1) {
|
---|
[0132630] | 101 | int i;
|
---|
| 102 |
|
---|
[76cec1e] | 103 | /*
|
---|
[f761f1eb] | 104 | * For each CPU, create its load balancing thread.
|
---|
| 105 | */
|
---|
| 106 | for (i = 0; i < config.cpu_count; i++) {
|
---|
| 107 |
|
---|
[5a95b25] | 108 | if ((t = thread_create(kcpulb, NULL, TASK, 0))) {
|
---|
[f761f1eb] | 109 | spinlock_lock(&t->lock);
|
---|
| 110 | t->flags |= X_WIRED;
|
---|
| 111 | t->cpu = &cpus[i];
|
---|
| 112 | spinlock_unlock(&t->lock);
|
---|
| 113 | thread_ready(t);
|
---|
| 114 | }
|
---|
[2677758] | 115 | else panic("thread_create/kcpulb\n");
|
---|
[f761f1eb] | 116 |
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
[5f85c91] | 119 | #endif /* CONFIG_SMP */
|
---|
[f761f1eb] | 120 |
|
---|
[a83a802] | 121 | /*
|
---|
| 122 | * At this point SMP, if present, is configured.
|
---|
| 123 | */
|
---|
| 124 | arch_post_smp_init();
|
---|
| 125 |
|
---|
[2677758] | 126 | /*
|
---|
| 127 | * Create kernel console.
|
---|
| 128 | */
|
---|
[5a95b25] | 129 | if ((t = thread_create(kconsole, "kconsole", TASK, 0)))
|
---|
[2677758] | 130 | thread_ready(t);
|
---|
[77147d6] | 131 | else
|
---|
| 132 | panic("thread_create/kconsole\n");
|
---|
[2677758] | 133 |
|
---|
[22f7769] | 134 | interrupts_enable();
|
---|
[f761f1eb] | 135 |
|
---|
[e74cb73] | 136 | /* Initialize name service */
|
---|
| 137 | ns_start();
|
---|
[6d9c49a] | 138 |
|
---|
[44c259c] | 139 | if (config.init_size > 0) {
|
---|
| 140 | /*
|
---|
| 141 | * Create the first user task.
|
---|
| 142 | */
|
---|
[77147d6] | 143 |
|
---|
[021d471] | 144 | if (config.init_addr % FRAME_SIZE)
|
---|
[77147d6] | 145 | panic("config.init_addr is not frame aligned");
|
---|
[ef67bab] | 146 |
|
---|
[5be1923] | 147 | if (!task_run_program((void *)config.init_addr)) {
|
---|
| 148 | printf("Userspace not started.\n");
|
---|
[de6b301] | 149 | }
|
---|
[44c259c] | 150 | }
|
---|
[f761f1eb] | 151 |
|
---|
[36a140b] | 152 | #ifdef CONFIG_TEST
|
---|
[f761f1eb] | 153 | test();
|
---|
[36a140b] | 154 | #endif /* CONFIG_TEST */
|
---|
[f761f1eb] | 155 |
|
---|
[ff3b3197] | 156 | if (!stdin) {
|
---|
| 157 | while (1) {
|
---|
| 158 | thread_sleep(1);
|
---|
| 159 | printf("kinit... ");
|
---|
| 160 | }
|
---|
[f761f1eb] | 161 | }
|
---|
| 162 |
|
---|
| 163 | }
|
---|