blob: a7eee0a4751d6b42568aac385c8c9625fa4e3741 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Vivek Goyalcfd243d2007-05-02 19:27:07 +020023static void __init zap_identity_mappings(void)
24{
25 pgd_t *pgd = pgd_offset_k(0UL);
26 pgd_clear(pgd);
27 __flush_tlb();
28}
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030/* Don't add a printk in there. printk relies on the PDA which is not initialized
31 yet. */
32static void __init clear_bss(void)
33{
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 memset(__bss_start, 0,
Andi Kleen2bc04142005-11-05 17:25:53 +010035 (unsigned long) __bss_stop - (unsigned long) __bss_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036}
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038static void __init copy_bootdata(char *real_mode_data)
39{
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 char * command_line;
41
H. Peter Anvin30c82642007-10-15 17:13:22 -070042 memcpy(&boot_params, real_mode_data, sizeof boot_params);
43 if (boot_params.hdr.cmd_line_ptr) {
44 command_line = __va(boot_params.hdr.cmd_line_ptr);
45 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049void __init x86_64_start_kernel(char * real_mode_data)
50{
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 int i;
52
Yinghai Lu3df0af02006-12-07 02:14:12 +010053 /* clear bss before set_intr_gate with early_idt_handler */
54 clear_bss();
55
Vivek Goyalcfd243d2007-05-02 19:27:07 +020056 /* Make NULL pointers segfault */
57 zap_identity_mappings();
58
Yinghai Lu3df0af02006-12-07 02:14:12 +010059 for (i = 0; i < IDT_ENTRIES; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 set_intr_gate(i, early_idt_handler);
61 asm volatile("lidt %0" :: "m" (idt_descr));
Siddha, Suresh Bf6c2e332005-11-05 17:25:53 +010062
Andi Kleen43c85c92006-09-26 10:52:32 +020063 early_printk("Kernel alive\n");
Ingo Molnar21482702006-07-03 00:24:57 -070064
Ravikiran G Thirumalai365ba912006-01-11 22:45:42 +010065 for (i = 0; i < NR_CPUS; i++)
66 cpu_pda(i) = &boot_cpu_pda[i];
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 pda_init(0);
Vivek Goyal278c0eb2007-05-02 19:27:07 +020069 copy_bootdata(__va(real_mode_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#ifdef CONFIG_SMP
71 cpu_set(0, cpu_online_map);
72#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 start_kernel();
74}