blob: 2ea42ceb08f30e1bbad7f927dac4fe2d3b6426f2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 * $Id: head64.c,v 1.22 2001/07/06 14:28:20 ak Exp $
7 */
8
9#include <linux/init.h>
10#include <linux/linkage.h>
11#include <linux/types.h>
12#include <linux/kernel.h>
13#include <linux/string.h>
14#include <linux/percpu.h>
15
16#include <asm/processor.h>
17#include <asm/proto.h>
18#include <asm/smp.h>
19#include <asm/bootsetup.h>
20#include <asm/setup.h>
21#include <asm/desc.h>
Siddha, Suresh Bf6c2e332005-11-05 17:25:53 +010022#include <asm/pgtable.h>
Andi Kleen2bc04142005-11-05 17:25:53 +010023#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25/* Don't add a printk in there. printk relies on the PDA which is not initialized
26 yet. */
27static void __init clear_bss(void)
28{
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 memset(__bss_start, 0,
Andi Kleen2bc04142005-11-05 17:25:53 +010030 (unsigned long) __bss_stop - (unsigned long) __bss_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031}
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#define NEW_CL_POINTER 0x228 /* Relative to real mode data */
34#define OLD_CL_MAGIC_ADDR 0x90020
35#define OLD_CL_MAGIC 0xA33F
36#define OLD_CL_BASE_ADDR 0x90000
37#define OLD_CL_OFFSET 0x90022
38
39extern char saved_command_line[];
40
41static void __init copy_bootdata(char *real_mode_data)
42{
43 int new_data;
44 char * command_line;
45
Venkatesh Pallipadif9ba7052005-05-01 08:58:51 -070046 memcpy(x86_boot_params, real_mode_data, BOOT_PARAM_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 new_data = *(int *) (x86_boot_params + NEW_CL_POINTER);
48 if (!new_data) {
49 if (OLD_CL_MAGIC != * (u16 *) OLD_CL_MAGIC_ADDR) {
50 printk("so old bootloader that it does not support commandline?!\n");
51 return;
52 }
53 new_data = OLD_CL_BASE_ADDR + * (u16 *) OLD_CL_OFFSET;
54 printk("old bootloader convention, maybe loadlin?\n");
55 }
56 command_line = (char *) ((u64)(new_data));
57 memcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
58 printk("Bootdata ok (command line is %s)\n", saved_command_line);
59}
60
61static void __init setup_boot_cpu_data(void)
62{
63 unsigned int dummy, eax;
64
65 /* get vendor info */
66 cpuid(0, (unsigned int *)&boot_cpu_data.cpuid_level,
67 (unsigned int *)&boot_cpu_data.x86_vendor_id[0],
68 (unsigned int *)&boot_cpu_data.x86_vendor_id[8],
69 (unsigned int *)&boot_cpu_data.x86_vendor_id[4]);
70
71 /* get cpu type */
72 cpuid(1, &eax, &dummy, &dummy,
73 (unsigned int *) &boot_cpu_data.x86_capability);
74 boot_cpu_data.x86 = (eax >> 8) & 0xf;
75 boot_cpu_data.x86_model = (eax >> 4) & 0xf;
76 boot_cpu_data.x86_mask = eax & 0xf;
77}
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079void __init x86_64_start_kernel(char * real_mode_data)
80{
81 char *s;
82 int i;
83
84 for (i = 0; i < 256; i++)
85 set_intr_gate(i, early_idt_handler);
86 asm volatile("lidt %0" :: "m" (idt_descr));
87 clear_bss();
Siddha, Suresh Bf6c2e332005-11-05 17:25:53 +010088
89 /*
90 * switch to init_level4_pgt from boot_level4_pgt
91 */
92 memcpy(init_level4_pgt, boot_level4_pgt, PTRS_PER_PGD*sizeof(pgd_t));
93 asm volatile("movq %0,%%cr3" :: "r" (__pa_symbol(&init_level4_pgt)));
94
Ravikiran G Thirumalai365ba912006-01-11 22:45:42 +010095 for (i = 0; i < NR_CPUS; i++)
96 cpu_pda(i) = &boot_cpu_pda[i];
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 pda_init(0);
99 copy_bootdata(real_mode_data);
100#ifdef CONFIG_SMP
101 cpu_set(0, cpu_online_map);
102#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 s = strstr(saved_command_line, "earlyprintk=");
104 if (s != NULL)
105 setup_early_printk(s);
Matt Tolentino2b976902005-06-23 00:08:06 -0700106#ifdef CONFIG_NUMA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 s = strstr(saved_command_line, "numa=");
108 if (s != NULL)
109 numa_setup(s+5);
110#endif
111#ifdef CONFIG_X86_IO_APIC
112 if (strstr(saved_command_line, "disableapic"))
113 disable_apic = 1;
114#endif
115 /* You need early console to see that */
116 if (__pa_symbol(&_end) >= KERNEL_TEXT_SIZE)
117 panic("Kernel too big for kernel mapping\n");
118
119 setup_boot_cpu_data();
120 start_kernel();
121}