fedora core 6 1.2949 + vserver 2.2.0
[linux-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  *  Jun Nakajima <jun.nakajima@intel.com>
7  *      Modified for Xen.
8  */
9
10 #include <linux/init.h>
11 #include <linux/linkage.h>
12 #include <linux/types.h>
13 #include <linux/kernel.h>
14 #include <linux/string.h>
15 #include <linux/percpu.h>
16 #include <linux/module.h>
17
18 #include <asm/processor.h>
19 #include <asm/proto.h>
20 #include <asm/smp.h>
21 #include <asm/bootsetup.h>
22 #include <asm/setup.h>
23 #include <asm/desc.h>
24 #include <asm/pgtable.h>
25 #include <asm/sections.h>
26
27 #ifdef CONFIG_XEN
28 unsigned long start_pfn;
29 #endif
30
31 /* Don't add a printk in there. printk relies on the PDA which is not initialized 
32    yet. */
33 #ifndef CONFIG_XEN
34 static void __init clear_bss(void)
35 {
36         memset(__bss_start, 0,
37                (unsigned long) __bss_stop - (unsigned long) __bss_start);
38 }
39 #endif
40
41 #define NEW_CL_POINTER          0x228   /* Relative to real mode data */
42 #define OLD_CL_MAGIC_ADDR       0x90020
43 #define OLD_CL_MAGIC            0xA33F
44 #define OLD_CL_BASE_ADDR        0x90000
45 #define OLD_CL_OFFSET           0x90022
46
47 extern char saved_command_line[];
48
49 static void __init copy_bootdata(char *real_mode_data)
50 {
51 #ifndef CONFIG_XEN
52         int new_data;
53         char * command_line;
54
55         memcpy(x86_boot_params, real_mode_data, BOOT_PARAM_SIZE);
56         new_data = *(int *) (x86_boot_params + NEW_CL_POINTER);
57         if (!new_data) {
58                 if (OLD_CL_MAGIC != * (u16 *) OLD_CL_MAGIC_ADDR) {
59                         return;
60                 }
61                 new_data = OLD_CL_BASE_ADDR + * (u16 *) OLD_CL_OFFSET;
62         }
63         command_line = (char *) ((u64)(new_data));
64         memcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
65 #else
66         int max_cmdline;
67
68         if ((max_cmdline = MAX_GUEST_CMDLINE) > COMMAND_LINE_SIZE)
69                 max_cmdline = COMMAND_LINE_SIZE;
70         memcpy(saved_command_line, xen_start_info->cmd_line, max_cmdline);
71         saved_command_line[max_cmdline-1] = '\0';
72 #endif
73 }
74
75 #ifdef CONFIG_XEN
76 #include <xen/interface/memory.h>
77 unsigned long *machine_to_phys_mapping;
78 EXPORT_SYMBOL(machine_to_phys_mapping);
79 unsigned int machine_to_phys_order;
80 EXPORT_SYMBOL(machine_to_phys_order);
81 #endif
82
83 void __init x86_64_start_kernel(char * real_mode_data)
84 {
85 #ifdef CONFIG_XEN
86         struct xen_machphys_mapping mapping;
87         unsigned long machine_to_phys_nr_ents;
88 #endif
89         int i;
90
91 #ifdef CONFIG_XEN
92         xen_start_info = (struct start_info *)real_mode_data;
93         if (!xen_feature(XENFEAT_auto_translated_physmap)) {
94                 phys_to_machine_mapping =
95                         (unsigned long *)xen_start_info->mfn_list;
96                 start_pfn = (__pa(xen_start_info->pt_base) >> PAGE_SHIFT) +
97                         xen_start_info->nr_pt_frames;
98         }
99
100         machine_to_phys_mapping = (unsigned long *)MACH2PHYS_VIRT_START;
101         machine_to_phys_nr_ents = MACH2PHYS_NR_ENTRIES;
102         if (HYPERVISOR_memory_op(XENMEM_machphys_mapping, &mapping) == 0) {
103                 machine_to_phys_mapping = (unsigned long *)mapping.v_start;
104                 machine_to_phys_nr_ents = mapping.max_mfn + 1;
105         }
106         while ((1UL << machine_to_phys_order) < machine_to_phys_nr_ents )
107                 machine_to_phys_order++;
108
109 #else
110         /* clear bss before set_intr_gate with early_idt_handler */
111         clear_bss();
112
113         for (i = 0; i < IDT_ENTRIES; i++)
114                 set_intr_gate(i, early_idt_handler);
115         asm volatile("lidt %0" :: "m" (idt_descr));
116 #endif /* CONFIG_XEN */
117         early_printk("Kernel alive\n");
118
119 #ifndef CONFIG_XEN
120         /*
121          * switch to init_level4_pgt from boot_level4_pgt
122          */
123         memcpy(init_level4_pgt, boot_level4_pgt, PTRS_PER_PGD*sizeof(pgd_t));
124         asm volatile("movq %0,%%cr3" :: "r" (__pa_symbol(&init_level4_pgt)));
125 #endif
126
127         for (i = 0; i < NR_CPUS; i++)
128                 cpu_pda(i) = &boot_cpu_pda[i];
129
130         pda_init(0);
131         copy_bootdata(real_mode_data);
132 #ifdef CONFIG_SMP
133         cpu_set(0, cpu_online_map);
134 #endif
135         start_kernel();
136 }