source: mainline/kernel/arch/ia32/src/ia32.c@ 5e53e02

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5e53e02 was a71c158, checked in by Martin Decky <martin@…>, 16 years ago

kernel output devices now suport multiple instances (except ski and sgcn, which respect the same interface, but behave as singletons)
if more than one output device gets initialized, the output is cloned to all of them
get rid of arch_grab_console() and arch_release_console() (output devices can implement a generic "redraw" method, input devices respect the "silent" global variable)
related cleanups and modifications

  • Property mode set to 100644
File size: 5.6 KB
Line 
1/*
2 * Copyright (c) 2001-2004 Jakub Jermar
3 * Copyright (c) 2009 Jiri Svoboda
4 * Copyright (c) 2009 Martin Decky
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
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
17 * derived from this software without specific prior written permission.
18 *
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
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/** @addtogroup ia32
32 * @{
33 */
34/** @file
35 */
36
37#include <arch.h>
38
39#include <arch/types.h>
40
41#include <arch/pm.h>
42
43#include <genarch/multiboot/multiboot.h>
44#include <genarch/drivers/legacy/ia32/io.h>
45#include <genarch/drivers/ega/ega.h>
46#include <arch/drivers/vesa.h>
47#include <genarch/drivers/i8042/i8042.h>
48#include <genarch/kbrd/kbrd.h>
49#include <arch/drivers/i8254.h>
50#include <arch/drivers/i8259.h>
51
52#include <arch/context.h>
53
54#include <config.h>
55
56#include <arch/interrupt.h>
57#include <arch/asm.h>
58#include <genarch/acpi/acpi.h>
59
60#include <arch/bios/bios.h>
61
62#include <interrupt.h>
63#include <ddi/irq.h>
64#include <arch/debugger.h>
65#include <proc/thread.h>
66#include <syscall/syscall.h>
67#include <console/console.h>
68#include <sysinfo/sysinfo.h>
69#include <arch/boot/boot.h>
70
71#ifdef CONFIG_SMP
72#include <arch/smp/apic.h>
73#endif
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 */
80void 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
92void arch_pre_mm_init(void)
93{
94 pm_init();
95
96 if (config.cpu_active == 1) {
97 interrupt_init();
98 bios_init();
99
100 /* PIC */
101 i8259_init();
102 }
103}
104
105void arch_post_mm_init(void)
106{
107 if (config.cpu_active == 1) {
108 /* Initialize IRQ routing */
109 irq_init(IRQ_COUNT, IRQ_COUNT);
110
111 /* hard clock */
112 i8254_init();
113
114#if (defined(CONFIG_FB) || defined(CONFIG_EGA))
115 bool vesa = false;
116#endif
117
118#ifdef CONFIG_FB
119 vesa = vesa_init();
120#endif
121
122#ifdef CONFIG_EGA
123 if (!vesa) {
124 outdev_t *egadev = ega_init(EGA_BASE, EGA_VIDEORAM);
125 if (egadev)
126 stdout_wire(egadev);
127 }
128#endif
129
130 /* Enable debugger */
131 debugger_init();
132 /* Merge all memory zones to 1 big zone */
133 zone_merge_all();
134 }
135}
136
137void arch_post_cpu_init()
138{
139#ifdef CONFIG_SMP
140 if (config.cpu_active > 1) {
141 l_apic_init();
142 l_apic_debug();
143 }
144#endif
145}
146
147void arch_pre_smp_init(void)
148{
149 if (config.cpu_active == 1) {
150#ifdef CONFIG_SMP
151 acpi_init();
152#endif /* CONFIG_SMP */
153 }
154}
155
156void arch_post_smp_init(void)
157{
158#ifdef CONFIG_PC_KBD
159 /*
160 * Initialize the i8042 controller. Then initialize the keyboard
161 * module and connect it to i8042. Enable keyboard interrupts.
162 */
163 i8042_instance_t *i8042_instance = i8042_init((i8042_t *) I8042_BASE, IRQ_KBD);
164 if (i8042_instance) {
165 kbrd_instance_t *kbrd_instance = kbrd_init();
166 if (kbrd_instance) {
167 indev_t *sink = stdin_wire();
168 indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
169 i8042_wire(i8042_instance, kbrd);
170 trap_virtual_enable_irqs(1 << IRQ_KBD);
171 }
172 }
173
174 /*
175 * This is the necessary evil until the userspace driver is entirely
176 * self-sufficient.
177 */
178 sysinfo_set_item_val("kbd", NULL, true);
179 sysinfo_set_item_val("kbd.inr", NULL, IRQ_KBD);
180 sysinfo_set_item_val("kbd.address.physical", NULL,
181 (uintptr_t) I8042_BASE);
182 sysinfo_set_item_val("kbd.address.kernel", NULL,
183 (uintptr_t) I8042_BASE);
184#endif
185}
186
187void calibrate_delay_loop(void)
188{
189 i8254_calibrate_delay_loop();
190 if (config.cpu_active == 1) {
191 /*
192 * This has to be done only on UP.
193 * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked.
194 */
195 i8254_normal_operation();
196 }
197}
198
199/** Set thread-local-storage pointer
200 *
201 * TLS pointer is set in GS register. That means, the GS contains
202 * selector, and the descriptor->base is the correct address.
203 */
204unative_t sys_tls_set(unative_t addr)
205{
206 THREAD->arch.tls = addr;
207 set_tls_desc(addr);
208
209 return 0;
210}
211
212/** Construct function pointer
213 *
214 * @param fptr function pointer structure
215 * @param addr function address
216 * @param caller calling function address
217 *
218 * @return address of the function pointer
219 *
220 */
221void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
222{
223 return addr;
224}
225
226void arch_reboot(void)
227{
228#ifdef CONFIG_PC_KBD
229 i8042_cpu_reset((i8042_t *) I8042_BASE);
230#endif
231}
232
233/** @}
234 */
Note: See TracBrowser for help on using the repository browser.