Merge master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6
[sfrench/cifs-2.6.git] / arch / x86_64 / kernel / head64.c
1 /*
2  *  linux/arch/x86_64/kernel/head64.c -- prepare to run common code
3  *
4  *  Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
5  */
6
7 #include <linux/init.h>
8 #include <linux/linkage.h>
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <linux/percpu.h>
13
14 #include <asm/processor.h>
15 #include <asm/proto.h>
16 #include <asm/smp.h>
17 #include <asm/bootsetup.h>
18 #include <asm/setup.h>
19 #include <asm/desc.h>
20 #include <asm/pgtable.h>
21 #include <asm/tlbflush.h>
22 #include <asm/sections.h>
23
24 static void __init zap_identity_mappings(void)
25 {
26         pgd_t *pgd = pgd_offset_k(0UL);
27         pgd_clear(pgd);
28         __flush_tlb();
29 }
30
31 /* Don't add a printk in there. printk relies on the PDA which is not initialized 
32    yet. */
33 static void __init clear_bss(void)
34 {
35         memset(__bss_start, 0,
36                (unsigned long) __bss_stop - (unsigned long) __bss_start);
37 }
38
39 #define NEW_CL_POINTER          0x228   /* Relative to real mode data */
40 #define OLD_CL_MAGIC_ADDR       0x20
41 #define OLD_CL_MAGIC            0xA33F
42 #define OLD_CL_OFFSET           0x22
43
44 static void __init copy_bootdata(char *real_mode_data)
45 {
46         unsigned long new_data;
47         char * command_line;
48
49         memcpy(x86_boot_params, real_mode_data, BOOT_PARAM_SIZE);
50         new_data = *(u32 *) (x86_boot_params + NEW_CL_POINTER);
51         if (!new_data) {
52                 if (OLD_CL_MAGIC != *(u16 *)(real_mode_data + OLD_CL_MAGIC_ADDR)) {
53                         return;
54                 }
55                 new_data = __pa(real_mode_data) + *(u16 *)(real_mode_data + OLD_CL_OFFSET);
56         }
57         command_line = __va(new_data);
58         memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
59 }
60
61 void __init x86_64_start_kernel(char * real_mode_data)
62 {
63         int i;
64
65         /*
66          * Make sure kernel is aligned to 2MB address. Catching it at compile
67          * time is better. Change your config file and compile the kernel
68          * for a 2MB aligned address (CONFIG_PHYSICAL_START)
69          */
70         BUILD_BUG_ON(CONFIG_PHYSICAL_START & (__KERNEL_ALIGN - 1));
71
72         /* clear bss before set_intr_gate with early_idt_handler */
73         clear_bss();
74
75         /* Make NULL pointers segfault */
76         zap_identity_mappings();
77
78         for (i = 0; i < IDT_ENTRIES; i++)
79                 set_intr_gate(i, early_idt_handler);
80         asm volatile("lidt %0" :: "m" (idt_descr));
81
82         early_printk("Kernel alive\n");
83
84         for (i = 0; i < NR_CPUS; i++)
85                 cpu_pda(i) = &boot_cpu_pda[i];
86
87         pda_init(0);
88         copy_bootdata(__va(real_mode_data));
89 #ifdef CONFIG_SMP
90         cpu_set(0, cpu_online_map);
91 #endif
92         start_kernel();
93 }