head64.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. #include <asm/bios_ebda.h>
  24. static void __init zap_identity_mappings(void)
  25. {
  26. pgd_t *pgd = pgd_offset_k(0UL);
  27. pgd_clear(pgd);
  28. __flush_tlb_all();
  29. }
  30. /* Don't add a printk in there. printk relies on the PDA which is not initialized
  31. yet. */
  32. static void __init clear_bss(void)
  33. {
  34. memset(__bss_start, 0,
  35. (unsigned long) __bss_stop - (unsigned long) __bss_start);
  36. }
  37. static void __init copy_bootdata(char *real_mode_data)
  38. {
  39. char * command_line;
  40. memcpy(&boot_params, real_mode_data, sizeof boot_params);
  41. if (boot_params.hdr.cmd_line_ptr) {
  42. command_line = __va(boot_params.hdr.cmd_line_ptr);
  43. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  44. }
  45. }
  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 = get_bios_ebda();
  73. /* Fixup: bios puts an EBDA in the top 64K segment */
  74. /* of conventional memory, but does not adjust lowmem. */
  75. if ((lowmem - ebda_addr) <= 0x10000)
  76. lowmem = ebda_addr;
  77. /* Fixup: bios does not report an EBDA at all. */
  78. /* Some old Dells seem to need 4k anyhow (bugzilla 2990) */
  79. if ((ebda_addr == 0) && (lowmem >= 0x9f000))
  80. lowmem = 0x9f000;
  81. /* Paranoia: should never happen, but... */
  82. if ((lowmem == 0) || (lowmem >= 0x100000))
  83. lowmem = 0x9f000;
  84. /* reserve all memory between lowmem and the 1MB mark */
  85. reserve_early(lowmem, 0x100000, "BIOS reserved");
  86. }
  87. void __init x86_64_start_kernel(char * real_mode_data)
  88. {
  89. int i;
  90. /*
  91. * Build-time sanity checks on the kernel image and module
  92. * area mappings. (these are purely build-time and produce no code)
  93. */
  94. BUILD_BUG_ON(MODULES_VADDR < KERNEL_IMAGE_START);
  95. BUILD_BUG_ON(MODULES_VADDR-KERNEL_IMAGE_START < KERNEL_IMAGE_SIZE);
  96. BUILD_BUG_ON(MODULES_LEN + KERNEL_IMAGE_SIZE > 2*PUD_SIZE);
  97. BUILD_BUG_ON((KERNEL_IMAGE_START & ~PMD_MASK) != 0);
  98. BUILD_BUG_ON((MODULES_VADDR & ~PMD_MASK) != 0);
  99. BUILD_BUG_ON(!(MODULES_VADDR > __START_KERNEL));
  100. BUILD_BUG_ON(!(((MODULES_END - 1) & PGDIR_MASK) ==
  101. (__START_KERNEL & PGDIR_MASK)));
  102. /* clear bss before set_intr_gate with early_idt_handler */
  103. clear_bss();
  104. /* Make NULL pointers segfault */
  105. zap_identity_mappings();
  106. /* Cleanup the over mapped high alias */
  107. cleanup_highmap();
  108. for (i = 0; i < NUM_EXCEPTION_VECTORS; i++) {
  109. #ifdef CONFIG_EARLY_PRINTK
  110. set_intr_gate(i, &early_idt_handlers[i]);
  111. #else
  112. set_intr_gate(i, early_idt_handler);
  113. #endif
  114. }
  115. load_idt((const struct desc_ptr *)&idt_descr);
  116. early_printk("Kernel alive\n");
  117. for (i = 0; i < NR_CPUS; i++)
  118. cpu_pda(i) = &boot_cpu_pda[i];
  119. pda_init(0);
  120. copy_bootdata(__va(real_mode_data));
  121. reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS");
  122. #ifdef CONFIG_BLK_DEV_INITRD
  123. /* Reserve INITRD */
  124. if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
  125. unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
  126. unsigned long ramdisk_size = boot_params.hdr.ramdisk_size;
  127. unsigned long ramdisk_end = ramdisk_image + ramdisk_size;
  128. reserve_early(ramdisk_image, ramdisk_end, "RAMDISK");
  129. }
  130. #endif
  131. reserve_ebda_region();
  132. /*
  133. * At this point everything still needed from the boot loader
  134. * or BIOS or kernel text should be early reserved or marked not
  135. * RAM in e820. All other memory is free game.
  136. */
  137. start_kernel();
  138. }