00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00044 #include <main/kinit.h>
00045 #include <config.h>
00046 #include <arch.h>
00047 #include <proc/scheduler.h>
00048 #include <proc/task.h>
00049 #include <proc/thread.h>
00050 #include <panic.h>
00051 #include <func.h>
00052 #include <cpu.h>
00053 #include <arch/asm.h>
00054 #include <mm/page.h>
00055 #include <arch/mm/page.h>
00056 #include <mm/as.h>
00057 #include <mm/frame.h>
00058 #include <print.h>
00059 #include <memstr.h>
00060 #include <console/console.h>
00061 #include <interrupt.h>
00062 #include <console/kconsole.h>
00063 #include <security/cap.h>
00064
00065 #ifdef CONFIG_SMP
00066 #include <arch/smp/mps.h>
00067 #endif
00068
00069 #include <synch/waitq.h>
00070 #include <synch/spinlock.h>
00071
00072 #ifdef CONFIG_TEST
00073 #include <test.h>
00074 #endif
00075
00084 void kinit(void *arg)
00085 {
00086 thread_t *t;
00087
00088
00089
00090
00091 thread_detach(THREAD);
00092
00093 interrupts_disable();
00094
00095 #ifdef CONFIG_SMP
00096 if (config.cpu_count > 1) {
00097
00098
00099
00100
00101
00102
00103 if ((t = thread_create(kmp, NULL, TASK, 0, "kmp"))) {
00104 spinlock_lock(&t->lock);
00105 t->flags |= X_WIRED;
00106 t->cpu = &cpus[0];
00107 spinlock_unlock(&t->lock);
00108 thread_ready(t);
00109 } else
00110 panic("thread_create/kmp\n");
00111 thread_join(t);
00112 thread_detach(t);
00113 }
00114 #endif
00115
00116
00117
00118 cpu_list();
00119
00120 #ifdef CONFIG_SMP
00121 if (config.cpu_count > 1) {
00122 int i;
00123
00124
00125
00126
00127 for (i = 0; i < config.cpu_count; i++) {
00128
00129 if ((t = thread_create(kcpulb, NULL, TASK, 0, "kcpulb"))) {
00130 spinlock_lock(&t->lock);
00131 t->flags |= X_WIRED;
00132 t->cpu = &cpus[i];
00133 spinlock_unlock(&t->lock);
00134 thread_ready(t);
00135 } else
00136 panic("thread_create/kcpulb\n");
00137
00138 }
00139 }
00140 #endif
00141
00142
00143
00144
00145 arch_post_smp_init();
00146
00147
00148
00149
00150 if ((t = thread_create(kconsole, "kconsole", TASK, 0, "kconsole")))
00151 thread_ready(t);
00152 else
00153 panic("thread_create/kconsole\n");
00154
00155 interrupts_enable();
00156
00157 #ifdef CONFIG_TEST
00158 test();
00159 printf("\nTest finished, please reboot\n");
00160 #else
00161
00162 task_t *utask;
00163 count_t i;
00164 for (i = 0; i < init.cnt; i++) {
00165
00166
00167
00168
00169 if (init.tasks[i].addr % FRAME_SIZE)
00170 panic("init[%d].addr is not frame aligned", i);
00171
00172 utask = task_run_program((void *) init.tasks[i].addr, "USPACE");
00173 if (utask) {
00174
00175
00176
00177 cap_set(utask, CAP_CAP | CAP_MEM_MANAGER | CAP_IO_MANAGER | CAP_PREEMPT_CONTROL | CAP_IRQ_REG);
00178
00179 if (!ipc_phone_0)
00180 ipc_phone_0 = &utask->answerbox;
00181 } else
00182 printf("Init task %zd not started.\n", i);
00183 }
00184
00185
00186 if (!stdin) {
00187 while (1) {
00188 thread_sleep(1);
00189 printf("kinit... ");
00190 }
00191 }
00192 #endif
00193
00194 }
00195