Rev 4055 | Rev 4296 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4055 | Rev 4156 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2001-2004 Jakub Jermar |
2 | * Copyright (c) 2001-2004 Jakub Jermar |
3 | * Copyright (c) 2009 Jiri Svoboda |
3 | * Copyright (c) 2009 Jiri Svoboda |
4 | * Copyright (c) 2009 Martin Decky |
4 | * Copyright (c) 2009 Martin Decky |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions |
8 | * modification, are permitted provided that the following conditions |
9 | * are met: |
9 | * are met: |
10 | * |
10 | * |
11 | * - Redistributions of source code must retain the above copyright |
11 | * - Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. |
12 | * notice, this list of conditions and the following disclaimer. |
13 | * - Redistributions in binary form must reproduce the above copyright |
13 | * - Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the |
14 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. |
15 | * documentation and/or other materials provided with the distribution. |
16 | * - The name of the author may not be used to endorse or promote products |
16 | * - The name of the author may not be used to endorse or promote products |
17 | * derived from this software without specific prior written permission. |
17 | * derived from this software without specific prior written permission. |
18 | * |
18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | */ |
29 | */ |
30 | 30 | ||
31 | /** @addtogroup ia32 |
31 | /** @addtogroup ia32 |
32 | * @{ |
32 | * @{ |
33 | */ |
33 | */ |
34 | /** @file |
34 | /** @file |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <arch.h> |
37 | #include <arch.h> |
38 | 38 | ||
39 | #include <arch/types.h> |
39 | #include <arch/types.h> |
40 | 40 | ||
41 | #include <arch/pm.h> |
41 | #include <arch/pm.h> |
42 | 42 | ||
43 | #include <genarch/multiboot/multiboot.h> |
43 | #include <genarch/multiboot/multiboot.h> |
44 | #include <genarch/drivers/legacy/ia32/io.h> |
44 | #include <genarch/drivers/legacy/ia32/io.h> |
45 | #include <genarch/drivers/ega/ega.h> |
45 | #include <genarch/drivers/ega/ega.h> |
46 | #include <arch/drivers/vesa.h> |
46 | #include <arch/drivers/vesa.h> |
47 | #include <genarch/drivers/i8042/i8042.h> |
47 | #include <genarch/drivers/i8042/i8042.h> |
48 | #include <genarch/kbrd/kbrd.h> |
48 | #include <genarch/kbrd/kbrd.h> |
49 | #include <arch/drivers/i8254.h> |
49 | #include <arch/drivers/i8254.h> |
50 | #include <arch/drivers/i8259.h> |
50 | #include <arch/drivers/i8259.h> |
51 | 51 | ||
52 | #include <arch/context.h> |
52 | #include <arch/context.h> |
53 | 53 | ||
54 | #include <config.h> |
54 | #include <config.h> |
55 | 55 | ||
56 | #include <arch/interrupt.h> |
56 | #include <arch/interrupt.h> |
57 | #include <arch/asm.h> |
57 | #include <arch/asm.h> |
58 | #include <genarch/acpi/acpi.h> |
58 | #include <genarch/acpi/acpi.h> |
59 | 59 | ||
60 | #include <arch/bios/bios.h> |
60 | #include <arch/bios/bios.h> |
61 | 61 | ||
62 | #include <interrupt.h> |
62 | #include <interrupt.h> |
63 | #include <ddi/irq.h> |
63 | #include <ddi/irq.h> |
64 | #include <arch/debugger.h> |
64 | #include <arch/debugger.h> |
65 | #include <proc/thread.h> |
65 | #include <proc/thread.h> |
66 | #include <syscall/syscall.h> |
66 | #include <syscall/syscall.h> |
67 | #include <console/console.h> |
67 | #include <console/console.h> |
68 | #include <ddi/device.h> |
- | |
69 | #include <sysinfo/sysinfo.h> |
68 | #include <sysinfo/sysinfo.h> |
70 | #include <arch/boot/boot.h> |
69 | #include <arch/boot/boot.h> |
71 | 70 | ||
72 | #ifdef CONFIG_SMP |
71 | #ifdef CONFIG_SMP |
73 | #include <arch/smp/apic.h> |
72 | #include <arch/smp/apic.h> |
74 | #endif |
73 | #endif |
75 | 74 | ||
76 | /** Perform ia32-specific initialization before main_bsp() is called. |
75 | /** Perform ia32-specific initialization before main_bsp() is called. |
77 | * |
76 | * |
78 | * @param signature Should contain the multiboot signature. |
77 | * @param signature Should contain the multiboot signature. |
79 | * @param mi Pointer to the multiboot information structure. |
78 | * @param mi Pointer to the multiboot information structure. |
80 | */ |
79 | */ |
81 | void arch_pre_main(uint32_t signature, const multiboot_info_t *mi) |
80 | void arch_pre_main(uint32_t signature, const multiboot_info_t *mi) |
82 | { |
81 | { |
83 | /* Parse multiboot information obtained from the bootloader. */ |
82 | /* Parse multiboot information obtained from the bootloader. */ |
84 | multiboot_info_parse(signature, mi); |
83 | multiboot_info_parse(signature, mi); |
85 | 84 | ||
86 | #ifdef CONFIG_SMP |
85 | #ifdef CONFIG_SMP |
87 | /* Copy AP bootstrap routines below 1 MB. */ |
86 | /* Copy AP bootstrap routines below 1 MB. */ |
88 | memcpy((void *) AP_BOOT_OFFSET, (void *) BOOT_OFFSET, |
87 | memcpy((void *) AP_BOOT_OFFSET, (void *) BOOT_OFFSET, |
89 | (size_t) &_hardcoded_unmapped_size); |
88 | (size_t) &_hardcoded_unmapped_size); |
90 | #endif |
89 | #endif |
91 | } |
90 | } |
92 | 91 | ||
93 | void arch_pre_mm_init(void) |
92 | void arch_pre_mm_init(void) |
94 | { |
93 | { |
95 | pm_init(); |
94 | pm_init(); |
96 | 95 | ||
97 | if (config.cpu_active == 1) { |
96 | if (config.cpu_active == 1) { |
98 | interrupt_init(); |
97 | interrupt_init(); |
99 | bios_init(); |
98 | bios_init(); |
100 | 99 | ||
101 | /* PIC */ |
100 | /* PIC */ |
102 | i8259_init(); |
101 | i8259_init(); |
103 | } |
102 | } |
104 | } |
103 | } |
105 | 104 | ||
106 | void arch_post_mm_init(void) |
105 | void arch_post_mm_init(void) |
107 | { |
106 | { |
108 | if (config.cpu_active == 1) { |
107 | if (config.cpu_active == 1) { |
109 | /* Initialize IRQ routing */ |
108 | /* Initialize IRQ routing */ |
110 | irq_init(IRQ_COUNT, IRQ_COUNT); |
109 | irq_init(IRQ_COUNT, IRQ_COUNT); |
111 | 110 | ||
112 | /* hard clock */ |
111 | /* hard clock */ |
113 | i8254_init(); |
112 | i8254_init(); |
114 | 113 | ||
115 | #ifdef CONFIG_FB |
114 | #ifdef CONFIG_FB |
116 | if (vesa_present()) |
115 | if (vesa_present()) |
117 | vesa_init(); |
116 | vesa_init(); |
118 | else |
117 | else |
119 | #endif |
118 | #endif |
- | 119 | #ifdef CONFIG_EGA |
|
120 | ega_init(EGA_BASE, EGA_VIDEORAM); /* video */ |
120 | ega_init(EGA_BASE, EGA_VIDEORAM); /* video */ |
- | 121 | #else |
|
- | 122 | {} |
|
- | 123 | #endif |
|
121 | 124 | ||
122 | /* Enable debugger */ |
125 | /* Enable debugger */ |
123 | debugger_init(); |
126 | debugger_init(); |
124 | /* Merge all memory zones to 1 big zone */ |
127 | /* Merge all memory zones to 1 big zone */ |
125 | zone_merge_all(); |
128 | zone_merge_all(); |
126 | } |
129 | } |
127 | } |
130 | } |
128 | 131 | ||
129 | void arch_post_cpu_init() |
132 | void arch_post_cpu_init() |
130 | { |
133 | { |
131 | #ifdef CONFIG_SMP |
134 | #ifdef CONFIG_SMP |
132 | if (config.cpu_active > 1) { |
135 | if (config.cpu_active > 1) { |
133 | l_apic_init(); |
136 | l_apic_init(); |
134 | l_apic_debug(); |
137 | l_apic_debug(); |
135 | } |
138 | } |
136 | #endif |
139 | #endif |
137 | } |
140 | } |
138 | 141 | ||
139 | void arch_pre_smp_init(void) |
142 | void arch_pre_smp_init(void) |
140 | { |
143 | { |
141 | if (config.cpu_active == 1) { |
144 | if (config.cpu_active == 1) { |
142 | #ifdef CONFIG_SMP |
145 | #ifdef CONFIG_SMP |
143 | acpi_init(); |
146 | acpi_init(); |
144 | #endif /* CONFIG_SMP */ |
147 | #endif /* CONFIG_SMP */ |
145 | } |
148 | } |
146 | } |
149 | } |
147 | 150 | ||
148 | void arch_post_smp_init(void) |
151 | void arch_post_smp_init(void) |
149 | { |
152 | { |
150 | devno_t devno = device_assign_devno(); |
153 | #ifdef CONFIG_PC_KBD |
151 | - | ||
152 | /* |
154 | /* |
153 | * Initialize the keyboard module and conect it to stdin. Then |
- | |
154 | * initialize the i8042 controller and connect it to kbrdin. Enable |
155 | * Initialize the i8042 controller. Then initialize the keyboard |
155 | * keyboard interrupts. |
156 | * module and connect it to i8042. Enable keyboard interrupts. |
156 | */ |
157 | */ |
- | 158 | indev_t *kbrdin = i8042_init((i8042_t *) I8042_BASE, IRQ_KBD); |
|
- | 159 | if (kbrdin) { |
|
157 | kbrd_init(stdin); |
160 | kbrd_init(kbrdin); |
158 | (void) i8042_init((i8042_t *) I8042_BASE, devno, IRQ_KBD, &kbrdin); |
- | |
159 | trap_virtual_enable_irqs(1 << IRQ_KBD); |
161 | trap_virtual_enable_irqs(1 << IRQ_KBD); |
- | 162 | } |
|
160 | 163 | ||
161 | /* |
164 | /* |
162 | * This is the necessary evil until the userspace driver is entirely |
165 | * This is the necessary evil until the userspace driver is entirely |
163 | * self-sufficient. |
166 | * self-sufficient. |
164 | */ |
167 | */ |
165 | sysinfo_set_item_val("kbd", NULL, true); |
168 | sysinfo_set_item_val("kbd", NULL, true); |
166 | sysinfo_set_item_val("kbd.devno", NULL, devno); |
- | |
167 | sysinfo_set_item_val("kbd.inr", NULL, IRQ_KBD); |
169 | sysinfo_set_item_val("kbd.inr", NULL, IRQ_KBD); |
168 | sysinfo_set_item_val("kbd.address.physical", NULL, |
170 | sysinfo_set_item_val("kbd.address.physical", NULL, |
169 | (uintptr_t) I8042_BASE); |
171 | (uintptr_t) I8042_BASE); |
170 | sysinfo_set_item_val("kbd.address.kernel", NULL, |
172 | sysinfo_set_item_val("kbd.address.kernel", NULL, |
171 | (uintptr_t) I8042_BASE); |
173 | (uintptr_t) I8042_BASE); |
- | 174 | #endif |
|
172 | } |
175 | } |
173 | 176 | ||
174 | void calibrate_delay_loop(void) |
177 | void calibrate_delay_loop(void) |
175 | { |
178 | { |
176 | i8254_calibrate_delay_loop(); |
179 | i8254_calibrate_delay_loop(); |
177 | if (config.cpu_active == 1) { |
180 | if (config.cpu_active == 1) { |
178 | /* |
181 | /* |
179 | * This has to be done only on UP. |
182 | * This has to be done only on UP. |
180 | * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked. |
183 | * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked. |
181 | */ |
184 | */ |
182 | i8254_normal_operation(); |
185 | i8254_normal_operation(); |
183 | } |
186 | } |
184 | } |
187 | } |
185 | 188 | ||
186 | /** Set thread-local-storage pointer |
189 | /** Set thread-local-storage pointer |
187 | * |
190 | * |
188 | * TLS pointer is set in GS register. That means, the GS contains |
191 | * TLS pointer is set in GS register. That means, the GS contains |
189 | * selector, and the descriptor->base is the correct address. |
192 | * selector, and the descriptor->base is the correct address. |
190 | */ |
193 | */ |
191 | unative_t sys_tls_set(unative_t addr) |
194 | unative_t sys_tls_set(unative_t addr) |
192 | { |
195 | { |
193 | THREAD->arch.tls = addr; |
196 | THREAD->arch.tls = addr; |
194 | set_tls_desc(addr); |
197 | set_tls_desc(addr); |
195 | 198 | ||
196 | return 0; |
199 | return 0; |
197 | } |
200 | } |
198 | 201 | ||
199 | /** Acquire console back for kernel |
202 | /** Acquire console back for kernel |
200 | * |
203 | * |
201 | */ |
204 | */ |
202 | void arch_grab_console(void) |
205 | void arch_grab_console(void) |
203 | { |
206 | { |
204 | #ifdef CONFIG_FB |
207 | #ifdef CONFIG_FB |
- | 208 | if (vesa_present()) |
|
205 | vesa_redraw(); |
209 | vesa_redraw(); |
- | 210 | else |
|
- | 211 | #endif |
|
- | 212 | #ifdef CONFIG_EGA |
|
- | 213 | ega_redraw(); |
|
206 | #else |
214 | #else |
207 | ega_redraw(); |
215 | {} |
208 | #endif |
216 | #endif |
209 | } |
217 | } |
210 | 218 | ||
211 | /** Return console to userspace |
219 | /** Return console to userspace |
212 | * |
220 | * |
213 | */ |
221 | */ |
214 | void arch_release_console(void) |
222 | void arch_release_console(void) |
215 | { |
223 | { |
216 | } |
224 | } |
217 | 225 | ||
218 | /** Construct function pointer |
226 | /** Construct function pointer |
219 | * |
227 | * |
220 | * @param fptr function pointer structure |
228 | * @param fptr function pointer structure |
221 | * @param addr function address |
229 | * @param addr function address |
222 | * @param caller calling function address |
230 | * @param caller calling function address |
223 | * |
231 | * |
224 | * @return address of the function pointer |
232 | * @return address of the function pointer |
225 | * |
233 | * |
226 | */ |
234 | */ |
227 | void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller) |
235 | void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller) |
228 | { |
236 | { |
229 | return addr; |
237 | return addr; |
230 | } |
238 | } |
231 | 239 | ||
232 | /** @} |
240 | /** @} |
233 | */ |
241 | */ |
234 | 242 |