head64.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * prepare to run common code
  3. *
  4. * Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
  5. */
  6. #include <linux/init.h>
  7. #include <linux/linkage.h>
  8. #include <linux/types.h>
  9. #include <linux/kernel.h>
  10. #include <linux/string.h>
  11. #include <linux/percpu.h>
  12. #include <linux/start_kernel.h>
  13. #include <linux/io.h>
  14. #include <linux/memblock.h>
  15. #include <asm/processor.h>
  16. #include <asm/proto.h>
  17. #include <asm/smp.h>
  18. #include <asm/setup.h>
  19. #include <asm/desc.h>
  20. #include <asm/pgtable.h>
  21. #include <asm/tlbflush.h>
  22. #include <asm/sections.h>
  23. #include <asm/kdebug.h>
  24. #include <asm/e820.h>
  25. #include <asm/trampoline.h>
  26. #include <asm/bios_ebda.h>
  27. static void __init zap_identity_mappings(void)
  28. {
  29. pgd_t *pgd = pgd_offset_k(0UL);
  30. pgd_clear(pgd);
  31. __flush_tlb_all();
  32. }
  33. /* Don't add a printk in there. printk relies on the PDA which is not initialized
  34. yet. */
  35. static void __init clear_bss(void)
  36. {
  37. memset(__bss_start, 0,
  38. (unsigned long) __bss_stop - (unsigned long) __bss_start);
  39. }
  40. static void __init copy_bootdata(char *real_mode_data)
  41. {
  42. char * command_line;
  43. 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);
  47. }
  48. }
  49. void __init x86_64_start_kernel(char * real_mode_data)
  50. {
  51. int i;
  52. /*
  53. * Build-time sanity checks on the kernel image and module
  54. * area mappings. (these are purely build-time and produce no code)
  55. */
  56. BUILD_BUG_ON(MODULES_VADDR < KERNEL_IMAGE_START);
  57. BUILD_BUG_ON(MODULES_VADDR-KERNEL_IMAGE_START < KERNEL_IMAGE_SIZE);
  58. BUILD_BUG_ON(MODULES_LEN + KERNEL_IMAGE_SIZE > 2*PUD_SIZE);
  59. BUILD_BUG_ON((KERNEL_IMAGE_START & ~PMD_MASK) != 0);
  60. BUILD_BUG_ON((MODULES_VADDR & ~PMD_MASK) != 0);
  61. BUILD_BUG_ON(!(MODULES_VADDR > __START_KERNEL));
  62. BUILD_BUG_ON(!(((MODULES_END - 1) & PGDIR_MASK) ==
  63. (__START_KERNEL & PGDIR_MASK)));
  64. BUILD_BUG_ON(__fix_to_virt(__end_of_fixed_addresses) <= MODULES_END);
  65. /* clear bss before set_intr_gate with early_idt_handler */
  66. clear_bss();
  67. /* Make NULL pointers segfault */
  68. zap_identity_mappings();
  69. /* Cleanup the over mapped high alias */
  70. cleanup_highmap();
  71. max_pfn_mapped = KERNEL_IMAGE_SIZE >> PAGE_SHIFT;
  72. for (i = 0; i < NUM_EXCEPTION_VECTORS; i++) {
  73. #ifdef CONFIG_EARLY_PRINTK
  74. set_intr_gate(i, &early_idt_handlers[i]);
  75. #else
  76. set_intr_gate(i, early_idt_handler);
  77. #endif
  78. }
  79. load_idt((const struct desc_ptr *)&idt_descr);
  80. if (console_loglevel == 10)
  81. early_printk("Kernel alive\n");
  82. x86_64_start_reservations(real_mode_data);
  83. }
  84. void __init x86_64_start_reservations(char *real_mode_data)
  85. {
  86. copy_bootdata(__va(real_mode_data));
  87. memblock_init();
  88. memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
  89. #ifdef CONFIG_BLK_DEV_INITRD
  90. /* Reserve INITRD */
  91. if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
  92. /* Assume only end is not page aligned */
  93. unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
  94. unsigned long ramdisk_size = boot_params.hdr.ramdisk_size;
  95. unsigned long ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
  96. memblock_x86_reserve_range(ramdisk_image, ramdisk_end, "RAMDISK");
  97. }
  98. #endif
  99. reserve_ebda_region();
  100. /*
  101. * At this point everything still needed from the boot loader
  102. * or BIOS or kernel text should be early reserved or marked not
  103. * RAM in e820. All other memory is free game.
  104. */
  105. start_kernel();
  106. }