Blame view

arch/x86/kernel/head64.c 3.29 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
835c34a16   Dave Jones   Delete filenames ...
2
   *  prepare to run common code
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
   *
   *  Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
6
7
8
9
10
11
12
   */
  
  #include <linux/init.h>
  #include <linux/linkage.h>
  #include <linux/types.h>
  #include <linux/kernel.h>
  #include <linux/string.h>
  #include <linux/percpu.h>
eaf76e8b9   Thomas Gleixner   x86: remove dupli...
13
  #include <linux/start_kernel.h>
8b664aa66   Huang, Ying   x86, boot: add li...
14
  #include <linux/io.h>
72d7c3b33   Yinghai Lu   x86: Use memblock...
15
  #include <linux/memblock.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
17
18
19
  
  #include <asm/processor.h>
  #include <asm/proto.h>
  #include <asm/smp.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
21
  #include <asm/setup.h>
  #include <asm/desc.h>
f6c2e3330   Siddha, Suresh B   [PATCH] x86_64: U...
22
  #include <asm/pgtable.h>
cfd243d4a   Vivek Goyal   [PATCH] x86-64: R...
23
  #include <asm/tlbflush.h>
2bc0414ee   Andi Kleen   [PATCH] x86_64: O...
24
  #include <asm/sections.h>
718fc13b4   Thomas Gleixner   x86: move debug r...
25
  #include <asm/kdebug.h>
751752789   Andi Kleen   x86: replace hard...
26
  #include <asm/e820.h>
3e1e9002a   Rafael J. Wysocki   x86: change stati...
27
  #include <asm/trampoline.h>
47a3d5da7   Thomas Gleixner   x86: Add early pl...
28
  #include <asm/bios_ebda.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29

cfd243d4a   Vivek Goyal   [PATCH] x86-64: R...
30
31
32
33
  static void __init zap_identity_mappings(void)
  {
  	pgd_t *pgd = pgd_offset_k(0UL);
  	pgd_clear(pgd);
cd5828966   Ingo Molnar   x86: fix more non...
34
  	__flush_tlb_all();
cfd243d4a   Vivek Goyal   [PATCH] x86-64: R...
35
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
38
39
  /* Don't add a printk in there. printk relies on the PDA which is not initialized 
     yet. */
  static void __init clear_bss(void)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
  	memset(__bss_start, 0,
2bc0414ee   Andi Kleen   [PATCH] x86_64: O...
41
  	       (unsigned long) __bss_stop - (unsigned long) __bss_start);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
44
  static void __init copy_bootdata(char *real_mode_data)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45
  	char * command_line;
30c826451   H. Peter Anvin   [x86] remove uses...
46
47
48
49
  	memcpy(&boot_params, real_mode_data, sizeof boot_params);
  	if (boot_params.hdr.cmd_line_ptr) {
  		command_line = __va(boot_params.hdr.cmd_line_ptr);
  		memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
51
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
53
  void __init x86_64_start_kernel(char * real_mode_data)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
54
  	int i;
b4e0409a3   Ingo Molnar   x86: check vmlinu...
55
56
57
58
59
60
61
62
63
64
65
66
  	/*
  	 * Build-time sanity checks on the kernel image and module
  	 * area mappings. (these are purely build-time and produce no code)
  	 */
  	BUILD_BUG_ON(MODULES_VADDR < KERNEL_IMAGE_START);
  	BUILD_BUG_ON(MODULES_VADDR-KERNEL_IMAGE_START < KERNEL_IMAGE_SIZE);
  	BUILD_BUG_ON(MODULES_LEN + KERNEL_IMAGE_SIZE > 2*PUD_SIZE);
  	BUILD_BUG_ON((KERNEL_IMAGE_START & ~PMD_MASK) != 0);
  	BUILD_BUG_ON((MODULES_VADDR & ~PMD_MASK) != 0);
  	BUILD_BUG_ON(!(MODULES_VADDR > __START_KERNEL));
  	BUILD_BUG_ON(!(((MODULES_END - 1) & PGDIR_MASK) ==
  				(__START_KERNEL & PGDIR_MASK)));
66d4bdf22   Jan Beulich   x86-64: fix overl...
67
  	BUILD_BUG_ON(__fix_to_virt(__end_of_fixed_addresses) <= MODULES_END);
b4e0409a3   Ingo Molnar   x86: check vmlinu...
68

3df0af0eb   Yinghai Lu   [PATCH] x86_64: c...
69
70
  	/* clear bss before set_intr_gate with early_idt_handler */
  	clear_bss();
cfd243d4a   Vivek Goyal   [PATCH] x86-64: R...
71
72
  	/* Make NULL pointers segfault */
  	zap_identity_mappings();
67e87f0a1   Jeremy Fitzhardinge   x86-64: Only set ...
73
  	max_pfn_mapped = KERNEL_IMAGE_SIZE >> PAGE_SHIFT;
5524ea320   Andi Kleen   x86: don't set up...
74
  	for (i = 0; i < NUM_EXCEPTION_VECTORS; i++) {
076f9776f   Ingo Molnar   x86: make early p...
75
  #ifdef CONFIG_EARLY_PRINTK
8866cd9dc   Roland McGrath   x86: early_idt_ha...
76
  		set_intr_gate(i, &early_idt_handlers[i]);
076f9776f   Ingo Molnar   x86: make early p...
77
78
79
80
  #else
  		set_intr_gate(i, early_idt_handler);
  #endif
  	}
9d1c6e7c8   Glauber de Oliveira Costa   x86: use descript...
81
  	load_idt((const struct desc_ptr *)&idt_descr);
f6c2e3330   Siddha, Suresh B   [PATCH] x86_64: U...
82

12544697f   dcg   x86_64: be less a...
83
84
85
  	if (console_loglevel == 10)
  		early_printk("Kernel alive
  ");
2148270cd   Ingo Molnar   [PATCH] lockdep: ...
86

f97013fd8   Jeremy Fitzhardinge   x86, 64-bit: spli...
87
88
89
90
91
  	x86_64_start_reservations(real_mode_data);
  }
  
  void __init x86_64_start_reservations(char *real_mode_data)
  {
278c0eb7f   Vivek Goyal   [PATCH] x86-64: m...
92
  	copy_bootdata(__va(real_mode_data));
9de819fe7   Yinghai Lu   x86: do not set b...
93

24aa07882   Tejun Heo   memblock, x86: Re...
94
95
  	memblock_reserve(__pa_symbol(&_text),
  			 __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
751752789   Andi Kleen   x86: replace hard...
96

2b8106a0a   Yinghai Lu   x86_64: do not re...
97
  #ifdef CONFIG_BLK_DEV_INITRD
751752789   Andi Kleen   x86: replace hard...
98
99
  	/* Reserve INITRD */
  	if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
c967da6a0   Yinghai Lu   x86: Make sure fr...
100
  		/* Assume only end is not page aligned */
751752789   Andi Kleen   x86: replace hard...
101
102
  		unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
  		unsigned long ramdisk_size  = boot_params.hdr.ramdisk_size;
c967da6a0   Yinghai Lu   x86: Make sure fr...
103
  		unsigned long ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_size);
24aa07882   Tejun Heo   memblock, x86: Re...
104
  		memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
751752789   Andi Kleen   x86: replace hard...
105
  	}
2b8106a0a   Yinghai Lu   x86_64: do not re...
106
  #endif
751752789   Andi Kleen   x86: replace hard...
107

47a3d5da7   Thomas Gleixner   x86: Add early pl...
108
  	reserve_ebda_region();
751752789   Andi Kleen   x86: replace hard...
109
110
111
112
113
114
  
  	/*
  	 * At this point everything still needed from the boot loader
  	 * or BIOS or kernel text should be early reserved or marked not
  	 * RAM in e820. All other memory is free game.
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
116
  	start_kernel();
  }