Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux...
[pandora-kernel.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/sections.h>
22
23 /* Don't add a printk in there. printk relies on the PDA which is not initialized 
24    yet. */
25 static void __init clear_bss(void)
26 {
27         memset(__bss_start, 0,
28                (unsigned long) __bss_stop - (unsigned long) __bss_start);
29 }
30
31 #define NEW_CL_POINTER          0x228   /* Relative to real mode data */
32 #define OLD_CL_MAGIC_ADDR       0x90020
33 #define OLD_CL_MAGIC            0xA33F
34 #define OLD_CL_BASE_ADDR        0x90000
35 #define OLD_CL_OFFSET           0x90022
36
37 extern char saved_command_line[];
38
39 static void __init copy_bootdata(char *real_mode_data)
40 {
41         int new_data;
42         char * command_line;
43
44         memcpy(x86_boot_params, real_mode_data, BOOT_PARAM_SIZE);
45         new_data = *(int *) (x86_boot_params + NEW_CL_POINTER);
46         if (!new_data) {
47                 if (OLD_CL_MAGIC != * (u16 *) OLD_CL_MAGIC_ADDR) {
48                         printk("so old bootloader that it does not support commandline?!\n");
49                         return;
50                 }
51                 new_data = OLD_CL_BASE_ADDR + * (u16 *) OLD_CL_OFFSET;
52                 printk("old bootloader convention, maybe loadlin?\n");
53         }
54         command_line = (char *) ((u64)(new_data));
55         memcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
56         printk("Bootdata ok (command line is %s)\n", saved_command_line);       
57 }
58
59 static void __init setup_boot_cpu_data(void)
60 {
61         unsigned int dummy, eax;
62
63         /* get vendor info */
64         cpuid(0, (unsigned int *)&boot_cpu_data.cpuid_level,
65               (unsigned int *)&boot_cpu_data.x86_vendor_id[0],
66               (unsigned int *)&boot_cpu_data.x86_vendor_id[8],
67               (unsigned int *)&boot_cpu_data.x86_vendor_id[4]);
68
69         /* get cpu type */
70         cpuid(1, &eax, &dummy, &dummy,
71                 (unsigned int *) &boot_cpu_data.x86_capability);
72         boot_cpu_data.x86 = (eax >> 8) & 0xf;
73         boot_cpu_data.x86_model = (eax >> 4) & 0xf;
74         boot_cpu_data.x86_mask = eax & 0xf;
75 }
76
77 void __init x86_64_start_kernel(char * real_mode_data)
78 {
79         char *s;
80         int i;
81
82         for (i = 0; i < 256; i++)
83                 set_intr_gate(i, early_idt_handler);
84         asm volatile("lidt %0" :: "m" (idt_descr));
85         clear_bss();
86
87         /*
88          * This must be called really, really early:
89          */
90         lockdep_init();
91
92         /*
93          * switch to init_level4_pgt from boot_level4_pgt
94          */
95         memcpy(init_level4_pgt, boot_level4_pgt, PTRS_PER_PGD*sizeof(pgd_t));
96         asm volatile("movq %0,%%cr3" :: "r" (__pa_symbol(&init_level4_pgt)));
97
98         for (i = 0; i < NR_CPUS; i++)
99                 cpu_pda(i) = &boot_cpu_pda[i];
100
101         pda_init(0);
102         copy_bootdata(real_mode_data);
103 #ifdef CONFIG_SMP
104         cpu_set(0, cpu_online_map);
105 #endif
106         s = strstr(saved_command_line, "earlyprintk=");
107         if (s != NULL)
108                 setup_early_printk(strchr(s, '=') + 1);
109 #ifdef CONFIG_NUMA
110         s = strstr(saved_command_line, "numa=");
111         if (s != NULL)
112                 numa_setup(s+5);
113 #endif
114 #ifdef CONFIG_X86_IO_APIC
115         if (strstr(saved_command_line, "disableapic"))
116                 disable_apic = 1;
117 #endif
118         /* You need early console to see that */
119         if (__pa_symbol(&_end) >= KERNEL_TEXT_SIZE)
120                 panic("Kernel too big for kernel mapping\n");
121
122         setup_boot_cpu_data();
123         start_kernel();
124 }