blob: 6c34bdd22e2634df6bdb41cc1db8aba482ddf33f [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>
Vivek Goyalcfd243d2007-05-02 19:27:07 +020021#include <asm/tlbflush.h>
Andi Kleen2bc04142005-11-05 17:25:53 +010022#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Vivek Goyalcfd243d2007-05-02 19:27:07 +020024static void __init zap_identity_mappings(void)
25{
26 pgd_t *pgd = pgd_offset_k(0UL);
27 pgd_clear(pgd);
28 __flush_tlb();
29}
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031/* Don't add a printk in there. printk relies on the PDA which is not initialized
32 yet. */
33static void __init clear_bss(void)
34{
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 memset(__bss_start, 0,
Andi Kleen2bc04142005-11-05 17:25:53 +010036 (unsigned long) __bss_stop - (unsigned long) __bss_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037}
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define NEW_CL_POINTER 0x228 /* Relative to real mode data */
Vivek Goyal278c0eb2007-05-02 19:27:07 +020040#define OLD_CL_MAGIC_ADDR 0x20
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define OLD_CL_MAGIC 0xA33F
Vivek Goyal278c0eb2007-05-02 19:27:07 +020042#define OLD_CL_OFFSET 0x22
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static void __init copy_bootdata(char *real_mode_data)
45{
Vivek Goyal278c0eb2007-05-02 19:27:07 +020046 unsigned long new_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 char * command_line;
48
Venkatesh Pallipadif9ba7052005-05-01 08:58:51 -070049 memcpy(x86_boot_params, real_mode_data, BOOT_PARAM_SIZE);
Vivek Goyal278c0eb2007-05-02 19:27:07 +020050 new_data = *(u32 *) (x86_boot_params + NEW_CL_POINTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 if (!new_data) {
Vivek Goyal278c0eb2007-05-02 19:27:07 +020052 if (OLD_CL_MAGIC != *(u16 *)(real_mode_data + OLD_CL_MAGIC_ADDR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 return;
54 }
Vivek Goyal278c0eb2007-05-02 19:27:07 +020055 new_data = __pa(real_mode_data) + *(u16 *)(real_mode_data + OLD_CL_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 }
Vivek Goyal278c0eb2007-05-02 19:27:07 +020057 command_line = __va(new_data);
Alon Bar-Levadf48852007-02-12 00:54:25 -080058 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061void __init x86_64_start_kernel(char * real_mode_data)
62{
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 int i;
64
Yinghai Lu3df0af02006-12-07 02:14:12 +010065 /* clear bss before set_intr_gate with early_idt_handler */
66 clear_bss();
67
Vivek Goyalcfd243d2007-05-02 19:27:07 +020068 /* Make NULL pointers segfault */
69 zap_identity_mappings();
70
Yinghai Lu3df0af02006-12-07 02:14:12 +010071 for (i = 0; i < IDT_ENTRIES; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 set_intr_gate(i, early_idt_handler);
73 asm volatile("lidt %0" :: "m" (idt_descr));
Siddha, Suresh Bf6c2e332005-11-05 17:25:53 +010074
Andi Kleen43c85c92006-09-26 10:52:32 +020075 early_printk("Kernel alive\n");
Ingo Molnar21482702006-07-03 00:24:57 -070076
Ravikiran G Thirumalai365ba912006-01-11 22:45:42 +010077 for (i = 0; i < NR_CPUS; i++)
78 cpu_pda(i) = &boot_cpu_pda[i];
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 pda_init(0);
Vivek Goyal278c0eb2007-05-02 19:27:07 +020081 copy_bootdata(__va(real_mode_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#ifdef CONFIG_SMP
83 cpu_set(0, cpu_online_map);
84#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 start_kernel();
86}