source: mainline/generic/src/main/kinit.c@ a597e3f0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a597e3f0 was ff14c520, checked in by Jakub Jermar <jakub@…>, 19 years ago

It is now possible to associate symbolic names with both threads and tasks.
More verbose kconsole threads, tasks and scheduler commands.

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[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>
[f761f1eb]48
[5f85c91]49#ifdef CONFIG_SMP
[ed0dd65]50#include <arch/smp/mps.h>
[5f85c91]51#endif /* CONFIG_SMP */
[f761f1eb]52
53#include <synch/waitq.h>
54#include <synch/spinlock.h>
55
[36a140b]56#ifdef CONFIG_TEST
[f761f1eb]57#include <test.h>
[36a140b]58#endif /* CONFIG_TEST */
[f761f1eb]59
[880de6e]60/** Kernel initialization thread.
61 *
62 * kinit takes care of higher level kernel
63 * initialization (i.e. thread creation,
64 * userspace initialization etc.).
65 *
66 * @param arg Not used.
67 */
[f761f1eb]68void kinit(void *arg)
69{
[80d2bdb]70 thread_t *t;
[2d5a54f3]71 task_t *utask;
[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 */
[ff14c520]83 if ((t = thread_create(kmp, NULL, TASK, 0, "kmp"))) {
[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
[ff14c520]108 if ((t = thread_create(kcpulb, NULL, TASK, 0, "kcpulb"))) {
[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 */
[ff14c520]129 if ((t = thread_create(kconsole, "kconsole", TASK, 0, "kconsole")))
[2677758]130 thread_ready(t);
[77147d6]131 else
132 panic("thread_create/kconsole\n");
[2677758]133
[22f7769]134 interrupts_enable();
[b6b576c]135
136 count_t i;
137 for (i = 0; i < init.cnt; i++) {
[44c259c]138 /*
[b6b576c]139 * Run user tasks.
[44c259c]140 */
[77147d6]141
[b6b576c]142 if (init.tasks[i].addr % FRAME_SIZE)
143 panic("init[%d].addr is not frame aligned", i);
[ef67bab]144
[ff14c520]145 utask = task_run_program((void *) init.tasks[i].addr, "USPACE");
[2ba7810]146 if (utask) {
147 if (!ipc_phone_0)
148 ipc_phone_0 = &utask->answerbox;
149 } else
[b7dcabb]150 printf("Init task %d not started.\n", i);
[44c259c]151 }
[f761f1eb]152
[36a140b]153#ifdef CONFIG_TEST
[f761f1eb]154 test();
[36a140b]155#endif /* CONFIG_TEST */
[f761f1eb]156
[ff3b3197]157 if (!stdin) {
158 while (1) {
159 thread_sleep(1);
160 printf("kinit... ");
161 }
[f761f1eb]162 }
163
164}
Note: See TracBrowser for help on using the repository browser.