head64.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 <asm/processor.h>
  14. #include <asm/proto.h>
  15. #include <asm/smp.h>
  16. #include <asm/setup.h>
  17. #include <asm/desc.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/tlbflush.h>
  20. #include <asm/sections.h>
  21. #include <asm/kdebug.h>
  22. #include <asm/e820.h>
  23. static void __init zap_identity_mappings(void)
  24. {
  25. pgd_t *pgd = pgd_offset_k(0UL);
  26. pgd_clear(pgd);
  27. __flush_tlb_all();
  28. }
  29. /* Don't add a printk in there. printk relies on the PDA which is not initialized
  30. yet. */
  31. static void __init clear_bss(void)
  32. {
  33. memset(__bss_start, 0,
  34. (unsigned long) __bss_stop - (unsigned long) __bss_start);
  35. }
  36. static void __init copy_bootdata(char *real_mode_data)
  37. {
  38. char * command_line;
  39. memcpy(&boot_params, real_mode_data, sizeof boot_params);
  40. if (boot_params.hdr.cmd_line_ptr) {
  41. command_line = __va(boot_params.hdr.cmd_line_ptr);
  42. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  43. }
  44. }
  45. #define BIOS_EBDA_SEGMENT 0x40E
  46. #define BIOS_LOWMEM_KILOBYTES 0x413
  47. /*
  48. * The BIOS places the EBDA/XBDA at the top of conventional
  49. * memory, and usually decreases the reported amount of
  50. * conventional memory (int 0x12) too. This also contains a
  51. * workaround for Dell systems that neglect to reserve EBDA.
  52. * The same workaround also avoids a problem with the AMD768MPX
  53. * chipset: reserve a page before VGA to prevent PCI prefetch
  54. * into it (errata #56). Usually the page is reserved anyways,
  55. * unless you have no PS/2 mouse plugged in.
  56. */
  57. static void __init reserve_ebda_region(void)
  58. {
  59. unsigned int lowmem, ebda_addr;
  60. /* To determine the position of the EBDA and the */
  61. /* end of conventional memory, we need to look at */
  62. /* the BIOS data area. In a paravirtual environment */
  63. /* that area is absent. We'll just have to assume */
  64. /* that the paravirt case can handle memory setup */
  65. /* correctly, without our help. */
  66. if (paravirt_enabled())
  67. return;
  68. /* end of low (conventional) memory */
  69. lowmem = *(unsigned short *)__va(BIOS_LOWMEM_KILOBYTES);
  70. lowmem <<= 10;
  71. /* start of EBDA area */
  72. ebda_addr = *(unsigned short *)__va(BIOS_EBDA_SEGMENT);
  73. ebda_addr <<= 4;
  74. /* Fixup: bios puts an EBDA in the top 64K segment */
  75. /* of conventional memory, but does not adjust lowmem. */
  76. if ((lowmem - ebda_addr) <= 0x10000)
  77. lowmem = ebda_addr;
  78. /* Fixup: bios does not report an EBDA at all. */
  79. /* Some old Dells seem to need 4k anyhow (bugzilla 2990) */
  80. if ((ebda_addr == 0) && (lowmem >= 0x9f000))
  81. lowmem = 0x9f000;
  82. /* Paranoia: should never happen, but... */
  83. if ((lowmem == 0) || (lowmem >= 0x100000))
  84. lowmem = 0x9f000;
  85. /* reserve all memory between lowmem and the 1MB mark */
  86. reserve_early(lowmem, 0x100000, "BIOS reserved");
  87. }
  88. void __init x86_64_start_kernel(char * real_mode_data)
  89. {
  90. int i;
  91. /*
  92. * Build-time sanity checks on the kernel image and module
  93. * area mappings. (these are purely build-time and produce no code)
  94. */
  95. BUILD_BUG_ON(MODULES_VADDR < KERNEL_IMAGE_START);
  96. BUILD_BUG_ON(MODULES_VADDR-KERNEL_IMAGE_START < KERNEL_IMAGE_SIZE);
  97. BUILD_BUG_ON(MODULES_LEN + KERNEL_IMAGE_SIZE > 2*PUD_SIZE);
  98. BUILD_BUG_ON((KERNEL_IMAGE_START & ~PMD_MASK) != 0);
  99. BUILD_BUG_ON((MODULES_VADDR & ~PMD_MASK) != 0);
  100. BUILD_BUG_ON(!(MODULES_VADDR > __START_KERNEL));
  101. BUILD_BUG_ON(!(((MODULES_END - 1) & PGDIR_MASK) ==
  102. (__START_KERNEL & PGDIR_MASK)));
  103. /* clear bss before set_intr_gate with early_idt_handler */
  104. clear_bss();
  105. /* Make NULL pointers segfault */
  106. zap_identity_mappings();
  107. /* Cleanup the over mapped high alias */
  108. cleanup_highmap();
  109. for (i = 0; i < NUM_EXCEPTION_VECTORS; i++) {
  110. #ifdef CONFIG_EARLY_PRINTK
  111. set_intr_gate(i, &early_idt_handlers[i]);
  112. #else
  113. set_intr_gate(i, early_idt_handler);
  114. #endif
  115. }
  116. load_idt((const struct desc_ptr *)&idt_descr);
  117. early_printk("Kernel alive\n");
  118. for (i = 0; i < NR_CPUS; i++)
  119. cpu_pda(i) = &boot_cpu_pda[i];
  120. pda_init(0);
  121. copy_bootdata(__va(real_mode_data));
  122. reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS");
  123. #ifdef CONFIG_BLK_DEV_INITRD
  124. /* Reserve INITRD */
  125. if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
  126. unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
  127. unsigned long ramdisk_size = boot_params.hdr.ramdisk_size;
  128. unsigned long ramdisk_end = ramdisk_image + ramdisk_size;
  129. reserve_early(ramdisk_image, ramdisk_end, "RAMDISK");
  130. }
  131. #endif
  132. reserve_ebda_region();
  133. /*
  134. * At this point everything still needed from the boot loader
  135. * or BIOS or kernel text should be early reserved or marked not
  136. * RAM in e820. All other memory is free game.
  137. */
  138. start_kernel();
  139. }