Rev 1702 | Rev 1729 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1702 | Rev 1705 | ||
---|---|---|---|
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 |
29 | /** @addtogroup main |
30 | * @ingroup kernel |
- | |
31 | * @{ |
30 | * @{ |
32 | */ |
31 | */ |
33 | 32 | ||
34 | /** |
33 | /** |
35 | * @file |
34 | * @file |
36 | * @brief Kernel initialization thread. |
35 | * @brief Kernel initialization thread. |
37 | * |
36 | * |
38 | * This file contains kinit kernel thread which carries out |
37 | * This file contains kinit kernel thread which carries out |
39 | * high level system initialization. |
38 | * high level system initialization. |
40 | * |
39 | * |
41 | * This file is responsible for finishing SMP configuration |
40 | * This file is responsible for finishing SMP configuration |
42 | * and creation of userspace init tasks. |
41 | * and creation of userspace init tasks. |
43 | */ |
42 | */ |
44 | 43 | ||
45 | #include <main/kinit.h> |
44 | #include <main/kinit.h> |
46 | #include <config.h> |
45 | #include <config.h> |
47 | #include <arch.h> |
46 | #include <arch.h> |
48 | #include <proc/scheduler.h> |
47 | #include <proc/scheduler.h> |
49 | #include <proc/task.h> |
48 | #include <proc/task.h> |
50 | #include <proc/thread.h> |
49 | #include <proc/thread.h> |
51 | #include <panic.h> |
50 | #include <panic.h> |
52 | #include <func.h> |
51 | #include <func.h> |
53 | #include <cpu.h> |
52 | #include <cpu.h> |
54 | #include <arch/asm.h> |
53 | #include <arch/asm.h> |
55 | #include <mm/page.h> |
54 | #include <mm/page.h> |
56 | #include <arch/mm/page.h> |
55 | #include <arch/mm/page.h> |
57 | #include <mm/as.h> |
56 | #include <mm/as.h> |
58 | #include <mm/frame.h> |
57 | #include <mm/frame.h> |
59 | #include <print.h> |
58 | #include <print.h> |
60 | #include <memstr.h> |
59 | #include <memstr.h> |
61 | #include <console/console.h> |
60 | #include <console/console.h> |
62 | #include <interrupt.h> |
61 | #include <interrupt.h> |
63 | #include <console/kconsole.h> |
62 | #include <console/kconsole.h> |
64 | #include <security/cap.h> |
63 | #include <security/cap.h> |
65 | 64 | ||
66 | #ifdef CONFIG_SMP |
65 | #ifdef CONFIG_SMP |
67 | #include <arch/smp/mps.h> |
66 | #include <arch/smp/mps.h> |
68 | #endif /* CONFIG_SMP */ |
67 | #endif /* CONFIG_SMP */ |
69 | 68 | ||
70 | #include <synch/waitq.h> |
69 | #include <synch/waitq.h> |
71 | #include <synch/spinlock.h> |
70 | #include <synch/spinlock.h> |
72 | 71 | ||
73 | #ifdef CONFIG_TEST |
72 | #ifdef CONFIG_TEST |
74 | #include <test.h> |
73 | #include <test.h> |
75 | #endif /* CONFIG_TEST */ |
74 | #endif /* CONFIG_TEST */ |
76 | 75 | ||
77 | /** Kernel initialization thread. |
76 | /** Kernel initialization thread. |
78 | * |
77 | * |
79 | * kinit takes care of higher level kernel |
78 | * kinit takes care of higher level kernel |
80 | * initialization (i.e. thread creation, |
79 | * initialization (i.e. thread creation, |
81 | * userspace initialization etc.). |
80 | * userspace initialization etc.). |
82 | * |
81 | * |
83 | * @param arg Not used. |
82 | * @param arg Not used. |
84 | */ |
83 | */ |
85 | void kinit(void *arg) |
84 | void kinit(void *arg) |
86 | { |
85 | { |
87 | thread_t *t; |
86 | thread_t *t; |
88 | 87 | ||
89 | /* |
88 | /* |
90 | * Detach kinit as nobody will call thread_join_timeout() on it. |
89 | * Detach kinit as nobody will call thread_join_timeout() on it. |
91 | */ |
90 | */ |
92 | thread_detach(THREAD); |
91 | thread_detach(THREAD); |
93 | 92 | ||
94 | interrupts_disable(); |
93 | interrupts_disable(); |
95 | 94 | ||
96 | #ifdef CONFIG_SMP |
95 | #ifdef CONFIG_SMP |
97 | if (config.cpu_count > 1) { |
96 | if (config.cpu_count > 1) { |
98 | /* |
97 | /* |
99 | * Create the kmp thread and wait for its completion. |
98 | * Create the kmp thread and wait for its completion. |
100 | * cpu1 through cpuN-1 will come up consecutively and |
99 | * cpu1 through cpuN-1 will come up consecutively and |
101 | * not mess together with kcpulb threads. |
100 | * not mess together with kcpulb threads. |
102 | * Just a beautification. |
101 | * Just a beautification. |
103 | */ |
102 | */ |
104 | if ((t = thread_create(kmp, NULL, TASK, 0, "kmp"))) { |
103 | if ((t = thread_create(kmp, NULL, TASK, 0, "kmp"))) { |
105 | spinlock_lock(&t->lock); |
104 | spinlock_lock(&t->lock); |
106 | t->flags |= X_WIRED; |
105 | t->flags |= X_WIRED; |
107 | t->cpu = &cpus[0]; |
106 | t->cpu = &cpus[0]; |
108 | spinlock_unlock(&t->lock); |
107 | spinlock_unlock(&t->lock); |
109 | thread_ready(t); |
108 | thread_ready(t); |
110 | } |
109 | } |
111 | else { |
110 | else { |
112 | panic("thread_create/kmp\n"); |
111 | panic("thread_create/kmp\n"); |
113 | } |
112 | } |
114 | thread_join(t); |
113 | thread_join(t); |
115 | thread_detach(t); |
114 | thread_detach(t); |
116 | } |
115 | } |
117 | #endif /* CONFIG_SMP */ |
116 | #endif /* CONFIG_SMP */ |
118 | /* |
117 | /* |
119 | * Now that all CPUs are up, we can report what we've found. |
118 | * Now that all CPUs are up, we can report what we've found. |
120 | */ |
119 | */ |
121 | cpu_list(); |
120 | cpu_list(); |
122 | 121 | ||
123 | #ifdef CONFIG_SMP |
122 | #ifdef CONFIG_SMP |
124 | if (config.cpu_count > 1) { |
123 | if (config.cpu_count > 1) { |
125 | int i; |
124 | int i; |
126 | 125 | ||
127 | /* |
126 | /* |
128 | * For each CPU, create its load balancing thread. |
127 | * For each CPU, create its load balancing thread. |
129 | */ |
128 | */ |
130 | for (i = 0; i < config.cpu_count; i++) { |
129 | for (i = 0; i < config.cpu_count; i++) { |
131 | 130 | ||
132 | if ((t = thread_create(kcpulb, NULL, TASK, 0, "kcpulb"))) { |
131 | if ((t = thread_create(kcpulb, NULL, TASK, 0, "kcpulb"))) { |
133 | spinlock_lock(&t->lock); |
132 | spinlock_lock(&t->lock); |
134 | t->flags |= X_WIRED; |
133 | t->flags |= X_WIRED; |
135 | t->cpu = &cpus[i]; |
134 | t->cpu = &cpus[i]; |
136 | spinlock_unlock(&t->lock); |
135 | spinlock_unlock(&t->lock); |
137 | thread_ready(t); |
136 | thread_ready(t); |
138 | } |
137 | } |
139 | else panic("thread_create/kcpulb\n"); |
138 | else panic("thread_create/kcpulb\n"); |
140 | 139 | ||
141 | } |
140 | } |
142 | } |
141 | } |
143 | #endif /* CONFIG_SMP */ |
142 | #endif /* CONFIG_SMP */ |
144 | 143 | ||
145 | /* |
144 | /* |
146 | * At this point SMP, if present, is configured. |
145 | * At this point SMP, if present, is configured. |
147 | */ |
146 | */ |
148 | arch_post_smp_init(); |
147 | arch_post_smp_init(); |
149 | 148 | ||
150 | /* |
149 | /* |
151 | * Create kernel console. |
150 | * Create kernel console. |
152 | */ |
151 | */ |
153 | if ((t = thread_create(kconsole, "kconsole", TASK, 0, "kconsole"))) |
152 | if ((t = thread_create(kconsole, "kconsole", TASK, 0, "kconsole"))) |
154 | thread_ready(t); |
153 | thread_ready(t); |
155 | else |
154 | else |
156 | panic("thread_create/kconsole\n"); |
155 | panic("thread_create/kconsole\n"); |
157 | 156 | ||
158 | interrupts_enable(); |
157 | interrupts_enable(); |
159 | 158 | ||
160 | #ifdef CONFIG_TEST |
159 | #ifdef CONFIG_TEST |
161 | test(); |
160 | test(); |
162 | printf("\nTest finished, please reboot\n"); |
161 | printf("\nTest finished, please reboot\n"); |
163 | #else /* CONFIG_TEST */ |
162 | #else /* CONFIG_TEST */ |
164 | 163 | ||
165 | task_t *utask; |
164 | task_t *utask; |
166 | count_t i; |
165 | count_t i; |
167 | for (i = 0; i < init.cnt; i++) { |
166 | for (i = 0; i < init.cnt; i++) { |
168 | /* |
167 | /* |
169 | * Run user tasks. |
168 | * Run user tasks. |
170 | */ |
169 | */ |
171 | 170 | ||
172 | if (init.tasks[i].addr % FRAME_SIZE) |
171 | if (init.tasks[i].addr % FRAME_SIZE) |
173 | panic("init[%d].addr is not frame aligned", i); |
172 | panic("init[%d].addr is not frame aligned", i); |
174 | 173 | ||
175 | utask = task_run_program((void *) init.tasks[i].addr, "USPACE"); |
174 | utask = task_run_program((void *) init.tasks[i].addr, "USPACE"); |
176 | if (utask) { |
175 | if (utask) { |
177 | /* |
176 | /* |
178 | * Set capabilities to init userspace tasks. |
177 | * Set capabilities to init userspace tasks. |
179 | */ |
178 | */ |
180 | cap_set(utask, CAP_CAP | CAP_MEM_MANAGER | CAP_IO_MANAGER | CAP_PREEMPT_CONTROL | CAP_IRQ_REG); |
179 | cap_set(utask, CAP_CAP | CAP_MEM_MANAGER | CAP_IO_MANAGER | CAP_PREEMPT_CONTROL | CAP_IRQ_REG); |
181 | 180 | ||
182 | if (!ipc_phone_0) |
181 | if (!ipc_phone_0) |
183 | ipc_phone_0 = &utask->answerbox; |
182 | ipc_phone_0 = &utask->answerbox; |
184 | } else |
183 | } else |
185 | printf("Init task %zd not started.\n", i); |
184 | printf("Init task %zd not started.\n", i); |
186 | } |
185 | } |
187 | 186 | ||
188 | 187 | ||
189 | if (!stdin) { |
188 | if (!stdin) { |
190 | while (1) { |
189 | while (1) { |
191 | thread_sleep(1); |
190 | thread_sleep(1); |
192 | printf("kinit... "); |
191 | printf("kinit... "); |
193 | } |
192 | } |
194 | } |
193 | } |
195 | #endif /* CONFIG_TEST */ |
194 | #endif /* CONFIG_TEST */ |
196 | 195 | ||
197 | } |
196 | } |
198 | 197 | ||
199 | /** @} |
198 | /** @} |
200 | */ |
199 | */ |
201 | 200 | ||
202 | 201 |