head64.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 EBDA_ADDR_POINTER 0x40E
  46. static __init void reserve_ebda(void)
  47. {
  48. unsigned ebda_addr, ebda_size;
  49. /*
  50. * there is a real-mode segmented pointer pointing to the
  51. * 4K EBDA area at 0x40E
  52. */
  53. ebda_addr = *(unsigned short *)__va(EBDA_ADDR_POINTER);
  54. ebda_addr <<= 4;
  55. if (!ebda_addr)
  56. return;
  57. ebda_size = *(unsigned short *)__va(ebda_addr);
  58. /* Round EBDA up to pages */
  59. if (ebda_size == 0)
  60. ebda_size = 1;
  61. ebda_size <<= 10;
  62. ebda_size = round_up(ebda_size + (ebda_addr & ~PAGE_MASK), PAGE_SIZE);
  63. if (ebda_size > 64*1024)
  64. ebda_size = 64*1024;
  65. reserve_early(ebda_addr, ebda_addr + ebda_size, "EBDA");
  66. }
  67. void __init x86_64_start_kernel(char * real_mode_data)
  68. {
  69. int i;
  70. /* clear bss before set_intr_gate with early_idt_handler */
  71. clear_bss();
  72. /* Make NULL pointers segfault */
  73. zap_identity_mappings();
  74. /* Cleanup the over mapped high alias */
  75. cleanup_highmap();
  76. for (i = 0; i < IDT_ENTRIES; i++) {
  77. #ifdef CONFIG_EARLY_PRINTK
  78. set_intr_gate(i, &early_idt_handlers[i]);
  79. #else
  80. set_intr_gate(i, early_idt_handler);
  81. #endif
  82. }
  83. load_idt((const struct desc_ptr *)&idt_descr);
  84. early_printk("Kernel alive\n");
  85. for (i = 0; i < NR_CPUS; i++)
  86. cpu_pda(i) = &boot_cpu_pda[i];
  87. pda_init(0);
  88. copy_bootdata(__va(real_mode_data));
  89. reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS");
  90. /* Reserve INITRD */
  91. if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
  92. unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
  93. unsigned long ramdisk_size = boot_params.hdr.ramdisk_size;
  94. unsigned long ramdisk_end = ramdisk_image + ramdisk_size;
  95. reserve_early(ramdisk_image, ramdisk_end, "RAMDISK");
  96. }
  97. reserve_ebda();
  98. /*
  99. * At this point everything still needed from the boot loader
  100. * or BIOS or kernel text should be early reserved or marked not
  101. * RAM in e820. All other memory is free game.
  102. */
  103. start_kernel();
  104. }