Rev 1662 | Rev 1705 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1662 | Rev 1702 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
- | 29 | /** @addtogroup main |
|
- | 30 | * @ingroup kernel |
|
- | 31 | * @{ |
|
- | 32 | */ |
|
- | 33 | ||
29 | /** |
34 | /** |
30 | * @file kinit.c |
35 | * @file |
31 | * @brief Kernel initialization thread. |
36 | * @brief Kernel initialization thread. |
32 | * |
37 | * |
33 | * This file contains kinit kernel thread which carries out |
38 | * This file contains kinit kernel thread which carries out |
34 | * high level system initialization. |
39 | * high level system initialization. |
35 | * |
40 | * |
36 | * This file is responsible for finishing SMP configuration |
41 | * This file is responsible for finishing SMP configuration |
37 | * and creation of userspace init tasks. |
42 | * and creation of userspace init tasks. |
38 | */ |
43 | */ |
39 | 44 | ||
40 | #include <main/kinit.h> |
45 | #include <main/kinit.h> |
41 | #include <config.h> |
46 | #include <config.h> |
42 | #include <arch.h> |
47 | #include <arch.h> |
43 | #include <proc/scheduler.h> |
48 | #include <proc/scheduler.h> |
44 | #include <proc/task.h> |
49 | #include <proc/task.h> |
45 | #include <proc/thread.h> |
50 | #include <proc/thread.h> |
46 | #include <panic.h> |
51 | #include <panic.h> |
47 | #include <func.h> |
52 | #include <func.h> |
48 | #include <cpu.h> |
53 | #include <cpu.h> |
49 | #include <arch/asm.h> |
54 | #include <arch/asm.h> |
50 | #include <mm/page.h> |
55 | #include <mm/page.h> |
51 | #include <arch/mm/page.h> |
56 | #include <arch/mm/page.h> |
52 | #include <mm/as.h> |
57 | #include <mm/as.h> |
53 | #include <mm/frame.h> |
58 | #include <mm/frame.h> |
54 | #include <print.h> |
59 | #include <print.h> |
55 | #include <memstr.h> |
60 | #include <memstr.h> |
56 | #include <console/console.h> |
61 | #include <console/console.h> |
57 | #include <interrupt.h> |
62 | #include <interrupt.h> |
58 | #include <console/kconsole.h> |
63 | #include <console/kconsole.h> |
59 | #include <security/cap.h> |
64 | #include <security/cap.h> |
60 | 65 | ||
61 | #ifdef CONFIG_SMP |
66 | #ifdef CONFIG_SMP |
62 | #include <arch/smp/mps.h> |
67 | #include <arch/smp/mps.h> |
63 | #endif /* CONFIG_SMP */ |
68 | #endif /* CONFIG_SMP */ |
64 | 69 | ||
65 | #include <synch/waitq.h> |
70 | #include <synch/waitq.h> |
66 | #include <synch/spinlock.h> |
71 | #include <synch/spinlock.h> |
67 | 72 | ||
68 | #ifdef CONFIG_TEST |
73 | #ifdef CONFIG_TEST |
69 | #include <test.h> |
74 | #include <test.h> |
70 | #endif /* CONFIG_TEST */ |
75 | #endif /* CONFIG_TEST */ |
71 | 76 | ||
72 | /** Kernel initialization thread. |
77 | /** Kernel initialization thread. |
73 | * |
78 | * |
74 | * kinit takes care of higher level kernel |
79 | * kinit takes care of higher level kernel |
75 | * initialization (i.e. thread creation, |
80 | * initialization (i.e. thread creation, |
76 | * userspace initialization etc.). |
81 | * userspace initialization etc.). |
77 | * |
82 | * |
78 | * @param arg Not used. |
83 | * @param arg Not used. |
79 | */ |
84 | */ |
80 | void kinit(void *arg) |
85 | void kinit(void *arg) |
81 | { |
86 | { |
82 | thread_t *t; |
87 | thread_t *t; |
83 | 88 | ||
84 | /* |
89 | /* |
85 | * Detach kinit as nobody will call thread_join_timeout() on it. |
90 | * Detach kinit as nobody will call thread_join_timeout() on it. |
86 | */ |
91 | */ |
87 | thread_detach(THREAD); |
92 | thread_detach(THREAD); |
88 | 93 | ||
89 | interrupts_disable(); |
94 | interrupts_disable(); |
90 | 95 | ||
91 | #ifdef CONFIG_SMP |
96 | #ifdef CONFIG_SMP |
92 | if (config.cpu_count > 1) { |
97 | if (config.cpu_count > 1) { |
93 | /* |
98 | /* |
94 | * Create the kmp thread and wait for its completion. |
99 | * Create the kmp thread and wait for its completion. |
95 | * cpu1 through cpuN-1 will come up consecutively and |
100 | * cpu1 through cpuN-1 will come up consecutively and |
96 | * not mess together with kcpulb threads. |
101 | * not mess together with kcpulb threads. |
97 | * Just a beautification. |
102 | * Just a beautification. |
98 | */ |
103 | */ |
99 | if ((t = thread_create(kmp, NULL, TASK, 0, "kmp"))) { |
104 | if ((t = thread_create(kmp, NULL, TASK, 0, "kmp"))) { |
100 | spinlock_lock(&t->lock); |
105 | spinlock_lock(&t->lock); |
101 | t->flags |= X_WIRED; |
106 | t->flags |= X_WIRED; |
102 | t->cpu = &cpus[0]; |
107 | t->cpu = &cpus[0]; |
103 | spinlock_unlock(&t->lock); |
108 | spinlock_unlock(&t->lock); |
104 | thread_ready(t); |
109 | thread_ready(t); |
105 | } |
110 | } |
106 | else { |
111 | else { |
107 | panic("thread_create/kmp\n"); |
112 | panic("thread_create/kmp\n"); |
108 | } |
113 | } |
109 | thread_join(t); |
114 | thread_join(t); |
110 | thread_detach(t); |
115 | thread_detach(t); |
111 | } |
116 | } |
112 | #endif /* CONFIG_SMP */ |
117 | #endif /* CONFIG_SMP */ |
113 | /* |
118 | /* |
114 | * Now that all CPUs are up, we can report what we've found. |
119 | * Now that all CPUs are up, we can report what we've found. |
115 | */ |
120 | */ |
116 | cpu_list(); |
121 | cpu_list(); |
117 | 122 | ||
118 | #ifdef CONFIG_SMP |
123 | #ifdef CONFIG_SMP |
119 | if (config.cpu_count > 1) { |
124 | if (config.cpu_count > 1) { |
120 | int i; |
125 | int i; |
121 | 126 | ||
122 | /* |
127 | /* |
123 | * For each CPU, create its load balancing thread. |
128 | * For each CPU, create its load balancing thread. |
124 | */ |
129 | */ |
125 | for (i = 0; i < config.cpu_count; i++) { |
130 | for (i = 0; i < config.cpu_count; i++) { |
126 | 131 | ||
127 | if ((t = thread_create(kcpulb, NULL, TASK, 0, "kcpulb"))) { |
132 | if ((t = thread_create(kcpulb, NULL, TASK, 0, "kcpulb"))) { |
128 | spinlock_lock(&t->lock); |
133 | spinlock_lock(&t->lock); |
129 | t->flags |= X_WIRED; |
134 | t->flags |= X_WIRED; |
130 | t->cpu = &cpus[i]; |
135 | t->cpu = &cpus[i]; |
131 | spinlock_unlock(&t->lock); |
136 | spinlock_unlock(&t->lock); |
132 | thread_ready(t); |
137 | thread_ready(t); |
133 | } |
138 | } |
134 | else panic("thread_create/kcpulb\n"); |
139 | else panic("thread_create/kcpulb\n"); |
135 | 140 | ||
136 | } |
141 | } |
137 | } |
142 | } |
138 | #endif /* CONFIG_SMP */ |
143 | #endif /* CONFIG_SMP */ |
139 | 144 | ||
140 | /* |
145 | /* |
141 | * At this point SMP, if present, is configured. |
146 | * At this point SMP, if present, is configured. |
142 | */ |
147 | */ |
143 | arch_post_smp_init(); |
148 | arch_post_smp_init(); |
144 | 149 | ||
145 | /* |
150 | /* |
146 | * Create kernel console. |
151 | * Create kernel console. |
147 | */ |
152 | */ |
148 | if ((t = thread_create(kconsole, "kconsole", TASK, 0, "kconsole"))) |
153 | if ((t = thread_create(kconsole, "kconsole", TASK, 0, "kconsole"))) |
149 | thread_ready(t); |
154 | thread_ready(t); |
150 | else |
155 | else |
151 | panic("thread_create/kconsole\n"); |
156 | panic("thread_create/kconsole\n"); |
152 | 157 | ||
153 | interrupts_enable(); |
158 | interrupts_enable(); |
154 | 159 | ||
155 | #ifdef CONFIG_TEST |
160 | #ifdef CONFIG_TEST |
156 | test(); |
161 | test(); |
157 | printf("\nTest finished, please reboot\n"); |
162 | printf("\nTest finished, please reboot\n"); |
158 | #else /* CONFIG_TEST */ |
163 | #else /* CONFIG_TEST */ |
159 | 164 | ||
160 | task_t *utask; |
165 | task_t *utask; |
161 | count_t i; |
166 | count_t i; |
162 | for (i = 0; i < init.cnt; i++) { |
167 | for (i = 0; i < init.cnt; i++) { |
163 | /* |
168 | /* |
164 | * Run user tasks. |
169 | * Run user tasks. |
165 | */ |
170 | */ |
166 | 171 | ||
167 | if (init.tasks[i].addr % FRAME_SIZE) |
172 | if (init.tasks[i].addr % FRAME_SIZE) |
168 | panic("init[%d].addr is not frame aligned", i); |
173 | panic("init[%d].addr is not frame aligned", i); |
169 | 174 | ||
170 | utask = task_run_program((void *) init.tasks[i].addr, "USPACE"); |
175 | utask = task_run_program((void *) init.tasks[i].addr, "USPACE"); |
171 | if (utask) { |
176 | if (utask) { |
172 | /* |
177 | /* |
173 | * Set capabilities to init userspace tasks. |
178 | * Set capabilities to init userspace tasks. |
174 | */ |
179 | */ |
175 | cap_set(utask, CAP_CAP | CAP_MEM_MANAGER | CAP_IO_MANAGER | CAP_PREEMPT_CONTROL | CAP_IRQ_REG); |
180 | cap_set(utask, CAP_CAP | CAP_MEM_MANAGER | CAP_IO_MANAGER | CAP_PREEMPT_CONTROL | CAP_IRQ_REG); |
176 | 181 | ||
177 | if (!ipc_phone_0) |
182 | if (!ipc_phone_0) |
178 | ipc_phone_0 = &utask->answerbox; |
183 | ipc_phone_0 = &utask->answerbox; |
179 | } else |
184 | } else |
180 | printf("Init task %zd not started.\n", i); |
185 | printf("Init task %zd not started.\n", i); |
181 | } |
186 | } |
182 | 187 | ||
183 | 188 | ||
184 | if (!stdin) { |
189 | if (!stdin) { |
185 | while (1) { |
190 | while (1) { |
186 | thread_sleep(1); |
191 | thread_sleep(1); |
187 | printf("kinit... "); |
192 | printf("kinit... "); |
188 | } |
193 | } |
189 | } |
194 | } |
190 | #endif /* CONFIG_TEST */ |
195 | #endif /* CONFIG_TEST */ |
191 | 196 | ||
192 | } |
197 | } |
- | 198 | ||
- | 199 | /** @} |
|
- | 200 | */ |
|
- | 201 | ||
193 | 202 |