blob: d156bfbffa9afb808c81cdf4c706634c151af5d5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Dave Jones835c34a2007-10-12 21:10:53 -04002 * prepare to run common code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/setup.h>
18#include <asm/desc.h>
Siddha, Suresh Bf6c2e332005-11-05 17:25:53 +010019#include <asm/pgtable.h>
Vivek Goyalcfd243d2007-05-02 19:27:07 +020020#include <asm/tlbflush.h>
Andi Kleen2bc04142005-11-05 17:25:53 +010021#include <asm/sections.h>
Thomas Gleixner718fc132008-01-30 13:30:17 +010022#include <asm/kdebug.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 -070039static void __init copy_bootdata(char *real_mode_data)
40{
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 char * command_line;
42
H. Peter Anvin30c82642007-10-15 17:13:22 -070043 memcpy(&boot_params, real_mode_data, sizeof boot_params);
44 if (boot_params.hdr.cmd_line_ptr) {
45 command_line = __va(boot_params.hdr.cmd_line_ptr);
46 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050void __init x86_64_start_kernel(char * real_mode_data)
51{
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 int i;
53
Yinghai Lu3df0af02006-12-07 02:14:12 +010054 /* clear bss before set_intr_gate with early_idt_handler */
55 clear_bss();
56
Vivek Goyalcfd243d2007-05-02 19:27:07 +020057 /* Make NULL pointers segfault */
58 zap_identity_mappings();
59
Yinghai Lu3df0af02006-12-07 02:14:12 +010060 for (i = 0; i < IDT_ENTRIES; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 set_intr_gate(i, early_idt_handler);
Glauber de Oliveira Costa9d1c6e72007-10-19 20:35:03 +020062 load_idt((const struct desc_ptr *)&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
Ravikiran G Thirumalai365ba912006-01-11 22:45:42 +010066 for (i = 0; i < NR_CPUS; i++)
67 cpu_pda(i) = &boot_cpu_pda[i];
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 pda_init(0);
Vivek Goyal278c0eb2007-05-02 19:27:07 +020070 copy_bootdata(__va(real_mode_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#ifdef CONFIG_SMP
72 cpu_set(0, cpu_online_map);
73#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 start_kernel();
75}