head64.c 5.1 KB

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