source: mainline/kernel/arch/amd64/src/amd64.c@ 650cd22

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 650cd22 was af9dd1e, checked in by Jakub Jermar <jakub@…>, 9 years ago

Remove SYS_TLS_SET

  • Property mode set to 100644
File size: 6.9 KB
Line 
1/*
2 * Copyright (c) 2005 Ondrej Palkovsky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
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
15 * derived from this software without specific prior written permission.
16 *
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
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup amd64
30 * @{
31 */
32/** @file
33 */
34
35#include <arch.h>
36#include <typedefs.h>
37#include <errno.h>
38#include <memstr.h>
39#include <interrupt.h>
40#include <console/console.h>
41#include <syscall/syscall.h>
42#include <sysinfo/sysinfo.h>
43#include <arch/bios/bios.h>
44#include <arch/boot/boot.h>
45#include <arch/drivers/i8254.h>
46#include <arch/drivers/i8259.h>
47#include <arch/syscall.h>
48#include <genarch/acpi/acpi.h>
49#include <genarch/drivers/ega/ega.h>
50#include <genarch/drivers/i8042/i8042.h>
51#include <genarch/drivers/ns16550/ns16550.h>
52#include <genarch/drivers/legacy/ia32/io.h>
53#include <genarch/fb/bfb.h>
54#include <genarch/kbrd/kbrd.h>
55#include <genarch/srln/srln.h>
56#include <genarch/multiboot/multiboot.h>
57#include <genarch/multiboot/multiboot2.h>
58#include <arch/pm.h>
59#include <arch/vreg.h>
60#include <arch/kseg.h>
61
62#ifdef CONFIG_SMP
63#include <arch/smp/apic.h>
64#endif
65
66/** Disable I/O on non-privileged levels
67 *
68 * Clean IOPL(12,13) and NT(14) flags in EFLAGS register
69 */
70static void clean_IOPL_NT_flags(void)
71{
72 asm volatile (
73 "pushfq\n"
74 "pop %%rax\n"
75 "and $~(0x7000), %%rax\n"
76 "pushq %%rax\n"
77 "popfq\n"
78 ::: "%rax"
79 );
80}
81
82/** Disable alignment check
83 *
84 * Clean AM(18) flag in CR0 register
85 */
86static void clean_AM_flag(void)
87{
88 asm volatile (
89 "mov %%cr0, %%rax\n"
90 "and $~(0x40000), %%rax\n"
91 "mov %%rax, %%cr0\n"
92 ::: "%rax"
93 );
94}
95
96/** Perform amd64-specific initialization before main_bsp() is called.
97 *
98 * @param signature Multiboot signature.
99 * @param info Multiboot information structure.
100 *
101 */
102void arch_pre_main(uint32_t signature, void *info)
103{
104 /* Parse multiboot information obtained from the bootloader. */
105 multiboot_info_parse(signature, (multiboot_info_t *) info);
106 multiboot2_info_parse(signature, (multiboot2_info_t *) info);
107
108#ifdef CONFIG_SMP
109 /* Copy AP bootstrap routines below 1 MB. */
110 memcpy((void *) AP_BOOT_OFFSET, (void *) BOOT_OFFSET,
111 (size_t) &_hardcoded_unmapped_size);
112#endif
113}
114
115void arch_pre_mm_init(void)
116{
117 /* Enable no-execute pages */
118 set_efer_flag(AMD_NXE_FLAG);
119 /* Enable FPU */
120 cpu_setup_fpu();
121
122 /* Initialize segmentation */
123 pm_init();
124
125 /* Disable I/O on nonprivileged levels
126 * clear the NT (nested-thread) flag
127 */
128 clean_IOPL_NT_flags();
129 /* Disable alignment check */
130 clean_AM_flag();
131
132 if (config.cpu_active == 1) {
133 interrupt_init();
134 bios_init();
135
136 /* PIC */
137 i8259_init();
138 }
139}
140
141
142void arch_post_mm_init(void)
143{
144 vreg_init();
145 kseg_init();
146
147 if (config.cpu_active == 1) {
148 /* Initialize IRQ routing */
149 irq_init(IRQ_COUNT, IRQ_COUNT);
150
151 /* hard clock */
152 i8254_init();
153
154#if (defined(CONFIG_FB) || defined(CONFIG_EGA))
155 bool bfb = false;
156#endif
157
158#ifdef CONFIG_FB
159 bfb = bfb_init();
160#endif
161
162#ifdef CONFIG_EGA
163 if (!bfb) {
164 outdev_t *egadev = ega_init(EGA_BASE, EGA_VIDEORAM);
165 if (egadev)
166 stdout_wire(egadev);
167 }
168#endif
169
170 /* Merge all memory zones to 1 big zone */
171 zone_merge_all();
172 }
173
174 /* Setup fast SYSCALL/SYSRET */
175 syscall_setup_cpu();
176}
177
178void arch_post_cpu_init(void)
179{
180#ifdef CONFIG_SMP
181 if (config.cpu_active > 1) {
182 l_apic_init();
183 l_apic_debug();
184 }
185#endif
186}
187
188void arch_pre_smp_init(void)
189{
190 if (config.cpu_active == 1) {
191#ifdef CONFIG_SMP
192 acpi_init();
193#endif /* CONFIG_SMP */
194 }
195}
196
197void arch_post_smp_init(void)
198{
199 /* Currently the only supported platform for amd64 is 'pc'. */
200 static const char *platform = "pc";
201
202 sysinfo_set_item_data("platform", NULL, (void *) platform,
203 str_size(platform));
204
205#ifdef CONFIG_PC_KBD
206 /*
207 * Initialize the i8042 controller. Then initialize the keyboard
208 * module and connect it to i8042. Enable keyboard interrupts.
209 */
210 i8042_instance_t *i8042_instance = i8042_init((i8042_t *) I8042_BASE, IRQ_KBD);
211 if (i8042_instance) {
212 kbrd_instance_t *kbrd_instance = kbrd_init();
213 if (kbrd_instance) {
214 indev_t *sink = stdin_wire();
215 indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
216 i8042_wire(i8042_instance, kbrd);
217 trap_virtual_enable_irqs(1 << IRQ_KBD);
218 trap_virtual_enable_irqs(1 << IRQ_MOUSE);
219 }
220 }
221#endif
222
223#if (defined(CONFIG_NS16550) || defined(CONFIG_NS16550_OUT))
224 /*
225 * Initialize the ns16550 controller.
226 */
227#ifdef CONFIG_NS16550_OUT
228 outdev_t *ns16550_out;
229 outdev_t **ns16550_out_ptr = &ns16550_out;
230#else
231 outdev_t **ns16550_out_ptr = NULL;
232#endif
233 ns16550_instance_t *ns16550_instance
234 = ns16550_init((ns16550_t *) NS16550_BASE, IRQ_NS16550, NULL, NULL,
235 ns16550_out_ptr);
236 if (ns16550_instance) {
237#ifdef CONFIG_NS16550
238 srln_instance_t *srln_instance = srln_init();
239 if (srln_instance) {
240 indev_t *sink = stdin_wire();
241 indev_t *srln = srln_wire(srln_instance, sink);
242 ns16550_wire(ns16550_instance, srln);
243 trap_virtual_enable_irqs(1 << IRQ_NS16550);
244 }
245#endif
246#ifdef CONFIG_NS16550_OUT
247 if (ns16550_out) {
248 stdout_wire(ns16550_out);
249 }
250#endif
251 }
252#endif
253
254 if (irqs_info != NULL)
255 sysinfo_set_item_val(irqs_info, NULL, true);
256}
257
258void calibrate_delay_loop(void)
259{
260 i8254_calibrate_delay_loop();
261 if (config.cpu_active == 1) {
262 /*
263 * This has to be done only on UP.
264 * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked.
265 */
266 i8254_normal_operation();
267 }
268}
269
270/** Construct function pointer
271 *
272 * @param fptr function pointer structure
273 * @param addr function address
274 * @param caller calling function address
275 *
276 * @return address of the function pointer
277 *
278 */
279void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
280{
281 return addr;
282}
283
284void arch_reboot(void)
285{
286#ifdef CONFIG_PC_KBD
287 i8042_cpu_reset((i8042_t *) I8042_BASE);
288#endif
289}
290
291void irq_initialize_arch(irq_t *irq)
292{
293 (void) irq;
294}
295
296/** @}
297 */
Note: See TracBrowser for help on using the repository browser.