blob: 5c529c1e3d6c9c3954691cccdb7ec7c72e5e8d32 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
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>
Siddha, Suresh Bf6c2e332005-11-05 17:25:53 +010020#include <asm/pgtable.h>
Andi Kleen2bc04142005-11-05 17:25:53 +010021#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23/* Don't add a printk in there. printk relies on the PDA which is not initialized
24 yet. */
25static void __init clear_bss(void)
26{
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 memset(__bss_start, 0,
Andi Kleen2bc04142005-11-05 17:25:53 +010028 (unsigned long) __bss_stop - (unsigned long) __bss_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029}
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#define NEW_CL_POINTER 0x228 /* Relative to real mode data */
Vivek Goyal278c0eb2007-05-02 19:27:07 +020032#define OLD_CL_MAGIC_ADDR 0x20
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#define OLD_CL_MAGIC 0xA33F
Vivek Goyal278c0eb2007-05-02 19:27:07 +020034#define OLD_CL_OFFSET 0x22
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036static void __init copy_bootdata(char *real_mode_data)
37{
Vivek Goyal278c0eb2007-05-02 19:27:07 +020038 unsigned long new_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 char * command_line;
40
Venkatesh Pallipadif9ba7052005-05-01 08:58:51 -070041 memcpy(x86_boot_params, real_mode_data, BOOT_PARAM_SIZE);
Vivek Goyal278c0eb2007-05-02 19:27:07 +020042 new_data = *(u32 *) (x86_boot_params + NEW_CL_POINTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 if (!new_data) {
Vivek Goyal278c0eb2007-05-02 19:27:07 +020044 if (OLD_CL_MAGIC != *(u16 *)(real_mode_data + OLD_CL_MAGIC_ADDR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 return;
46 }
Vivek Goyal278c0eb2007-05-02 19:27:07 +020047 new_data = __pa(real_mode_data) + *(u16 *)(real_mode_data + OLD_CL_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 }
Vivek Goyal278c0eb2007-05-02 19:27:07 +020049 command_line = __va(new_data);
Alon Bar-Levadf48852007-02-12 00:54:25 -080050 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053void __init x86_64_start_kernel(char * real_mode_data)
54{
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 int i;
56
Yinghai Lu3df0af02006-12-07 02:14:12 +010057 /* clear bss before set_intr_gate with early_idt_handler */
58 clear_bss();
59
60 for (i = 0; i < IDT_ENTRIES; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 set_intr_gate(i, early_idt_handler);
62 asm volatile("lidt %0" :: "m" (idt_descr));
Siddha, Suresh Bf6c2e332005-11-05 17:25:53 +010063
Andi Kleen43c85c92006-09-26 10:52:32 +020064 early_printk("Kernel alive\n");
Ingo Molnar21482702006-07-03 00:24:57 -070065
66 /*
Siddha, Suresh Bf6c2e332005-11-05 17:25:53 +010067 * switch to init_level4_pgt from boot_level4_pgt
68 */
69 memcpy(init_level4_pgt, boot_level4_pgt, PTRS_PER_PGD*sizeof(pgd_t));
70 asm volatile("movq %0,%%cr3" :: "r" (__pa_symbol(&init_level4_pgt)));
71
Ravikiran G Thirumalai365ba912006-01-11 22:45:42 +010072 for (i = 0; i < NR_CPUS; i++)
73 cpu_pda(i) = &boot_cpu_pda[i];
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 pda_init(0);
Vivek Goyal278c0eb2007-05-02 19:27:07 +020076 copy_bootdata(__va(real_mode_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#ifdef CONFIG_SMP
78 cpu_set(0, cpu_online_map);
79#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 start_kernel();
81}