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