source: mainline/kernel/arch/ia32/src/ia32.c@ 8844e70

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8844e70 was 235d31d, checked in by Jakub Jermar <jakub@…>, 11 years ago

Merge the CHT pre-integration branch

This branch contains:

  • the merge of lp:~adam-hraska+lp/helenos/rcu, which brings:
  • a new preemptible kernel RCU variant called A-RCU,
  • a preemptible variant of Podzimek's non-preemptible kernel RCU and
  • a new variant of usersace RCU,
  • a new concurrent hash table (CHT) implementation based on RCU,
  • a deployment of CHT in kernel futex handling,
  • a deployment of the userspace RCU in the implementation of upgradable futexes,

all described in Adam Hraska's master thesis named Read-Copy-Update
for HelenOS, defended in 2013 at MFF UK; furthemore, the branch
fixes two synchronization bugs in condvars and waitq, respectively:

  • revid:adam.hraska+hos@gmail.com-20121116144921-3to9u1tn1sg07rg7
  • revid:adam.hraska+hos@gmail.com-20121116173623-km7gwtqixwudpe66
  • build fixes required to pass make check
  • overhaul of ia64 and sparc64 trap handling, to allow exc_dispatch() to be used now when the kernel is more picky about CPU state accounting
  • an important fix of the sparc64/sun4v preemptible trap handler
  • various other fixes of issues discovered on non-x86 architectures
  • Property mode set to 100644
File size: 6.3 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#include <typedefs.h>
39#include <errno.h>
40#include <memstr.h>
41#include <interrupt.h>
42#include <console/console.h>
43#include <syscall/syscall.h>
44#include <sysinfo/sysinfo.h>
45#include <arch/bios/bios.h>
46#include <arch/boot/boot.h>
47#include <arch/drivers/i8254.h>
48#include <arch/drivers/i8259.h>
49#include <genarch/acpi/acpi.h>
50#include <genarch/drivers/ega/ega.h>
51#include <genarch/drivers/i8042/i8042.h>
52#include <genarch/drivers/ns16550/ns16550.h>
53#include <genarch/drivers/legacy/ia32/io.h>
54#include <genarch/fb/bfb.h>
55#include <genarch/kbrd/kbrd.h>
56#include <genarch/srln/srln.h>
57#include <genarch/multiboot/multiboot.h>
58#include <genarch/multiboot/multiboot2.h>
59
60#ifdef CONFIG_SMP
61#include <arch/smp/apic.h>
62#endif
63
64/** Perform ia32-specific initialization before main_bsp() is called.
65 *
66 * @param signature Multiboot signature.
67 * @param info Multiboot information structure.
68 *
69 */
70void arch_pre_main(uint32_t signature, void *info)
71{
72 /* Parse multiboot information obtained from the bootloader. */
73 multiboot_info_parse(signature, (multiboot_info_t *) info);
74 multiboot2_info_parse(signature, (multiboot2_info_t *) info);
75
76#ifdef CONFIG_SMP
77 /* Copy AP bootstrap routines below 1 MB. */
78 memcpy((void *) AP_BOOT_OFFSET, (void *) BOOT_OFFSET,
79 (size_t) &_hardcoded_unmapped_size);
80#endif
81}
82
83void arch_pre_mm_init(void)
84{
85 pm_init();
86
87 if (config.cpu_active == 1) {
88 interrupt_init();
89 bios_init();
90
91 /* PIC */
92 i8259_init();
93 }
94}
95
96void arch_post_mm_init(void)
97{
98 if (config.cpu_active == 1) {
99 /* Initialize IRQ routing */
100 irq_init(IRQ_COUNT, IRQ_COUNT);
101
102 /* hard clock */
103 i8254_init();
104
105#if (defined(CONFIG_FB) || defined(CONFIG_EGA))
106 bool bfb = false;
107#endif
108
109#ifdef CONFIG_FB
110 bfb = bfb_init();
111#endif
112
113#ifdef CONFIG_EGA
114 if (!bfb) {
115 outdev_t *egadev = ega_init(EGA_BASE, EGA_VIDEORAM);
116 if (egadev)
117 stdout_wire(egadev);
118 }
119#endif
120
121 /* Merge all memory zones to 1 big zone */
122 zone_merge_all();
123 }
124}
125
126void arch_post_cpu_init(void)
127{
128#ifdef CONFIG_SMP
129 if (config.cpu_active > 1) {
130 l_apic_init();
131 l_apic_debug();
132 }
133#endif
134}
135
136void arch_pre_smp_init(void)
137{
138 if (config.cpu_active == 1) {
139#ifdef CONFIG_SMP
140 acpi_init();
141#endif /* CONFIG_SMP */
142 }
143}
144
145void arch_post_smp_init(void)
146{
147 /* Currently the only supported platform for ia32 is 'pc'. */
148 static const char *platform = "pc";
149
150 sysinfo_set_item_data("platform", NULL, (void *) platform,
151 str_size(platform));
152
153#ifdef CONFIG_PC_KBD
154 /*
155 * Initialize the i8042 controller. Then initialize the keyboard
156 * module and connect it to i8042. Enable keyboard interrupts.
157 */
158 i8042_instance_t *i8042_instance = i8042_init((i8042_t *) I8042_BASE, IRQ_KBD);
159 if (i8042_instance) {
160 kbrd_instance_t *kbrd_instance = kbrd_init();
161 if (kbrd_instance) {
162 indev_t *sink = stdin_wire();
163 indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
164 i8042_wire(i8042_instance, kbrd);
165 trap_virtual_enable_irqs(1 << IRQ_KBD);
166 trap_virtual_enable_irqs(1 << IRQ_MOUSE);
167 }
168 }
169#endif
170
171#if (defined(CONFIG_NS16550) || defined(CONFIG_NS16550_OUT))
172 /*
173 * Initialize the ns16550 controller.
174 */
175#ifdef CONFIG_NS16550_OUT
176 outdev_t *ns16550_out;
177 outdev_t **ns16550_out_ptr = &ns16550_out;
178#else
179 outdev_t **ns16550_out_ptr = NULL;
180#endif
181 ns16550_instance_t *ns16550_instance
182 = ns16550_init((ns16550_t *) NS16550_BASE, IRQ_NS16550, NULL, NULL,
183 ns16550_out_ptr);
184 if (ns16550_instance) {
185#ifdef CONFIG_NS16550
186 srln_instance_t *srln_instance = srln_init();
187 if (srln_instance) {
188 indev_t *sink = stdin_wire();
189 indev_t *srln = srln_wire(srln_instance, sink);
190 ns16550_wire(ns16550_instance, srln);
191 trap_virtual_enable_irqs(1 << IRQ_NS16550);
192 }
193#endif
194#ifdef CONFIG_NS16550_OUT
195 if (ns16550_out) {
196 stdout_wire(ns16550_out);
197 }
198#endif
199 }
200#endif
201
202 if (irqs_info != NULL)
203 sysinfo_set_item_val(irqs_info, NULL, true);
204}
205
206void calibrate_delay_loop(void)
207{
208 i8254_calibrate_delay_loop();
209 if (config.cpu_active == 1) {
210 /*
211 * This has to be done only on UP.
212 * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked.
213 */
214 i8254_normal_operation();
215 }
216}
217
218/** Set thread-local-storage pointer
219 *
220 * TLS pointer is set in GS register. That means, the GS contains
221 * selector, and the descriptor->base is the correct address.
222 */
223sysarg_t sys_tls_set(uintptr_t addr)
224{
225 THREAD->arch.tls = addr;
226 set_tls_desc(addr);
227
228 return EOK;
229}
230
231/** Construct function pointer
232 *
233 * @param fptr function pointer structure
234 * @param addr function address
235 * @param caller calling function address
236 *
237 * @return address of the function pointer
238 *
239 */
240void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
241{
242 return addr;
243}
244
245void arch_reboot(void)
246{
247#ifdef CONFIG_PC_KBD
248 i8042_cpu_reset((i8042_t *) I8042_BASE);
249#endif
250}
251
252void irq_initialize_arch(irq_t *irq)
253{
254 (void) irq;
255}
256
257/** @}
258 */
Note: See TracBrowser for help on using the repository browser.