head64.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * linux/arch/x86_64/kernel/head64.c -- 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 <asm/processor.h>
  13. #include <asm/proto.h>
  14. #include <asm/smp.h>
  15. #include <asm/bootsetup.h>
  16. #include <asm/setup.h>
  17. #include <asm/desc.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/sections.h>
  20. /* Don't add a printk in there. printk relies on the PDA which is not initialized
  21. yet. */
  22. static void __init clear_bss(void)
  23. {
  24. memset(__bss_start, 0,
  25. (unsigned long) __bss_stop - (unsigned long) __bss_start);
  26. }
  27. #define NEW_CL_POINTER 0x228 /* Relative to real mode data */
  28. #define OLD_CL_MAGIC_ADDR 0x90020
  29. #define OLD_CL_MAGIC 0xA33F
  30. #define OLD_CL_BASE_ADDR 0x90000
  31. #define OLD_CL_OFFSET 0x90022
  32. extern char saved_command_line[];
  33. static void __init copy_bootdata(char *real_mode_data)
  34. {
  35. int new_data;
  36. char * command_line;
  37. memcpy(x86_boot_params, real_mode_data, BOOT_PARAM_SIZE);
  38. new_data = *(int *) (x86_boot_params + NEW_CL_POINTER);
  39. if (!new_data) {
  40. if (OLD_CL_MAGIC != * (u16 *) OLD_CL_MAGIC_ADDR) {
  41. printk("so old bootloader that it does not support commandline?!\n");
  42. return;
  43. }
  44. new_data = OLD_CL_BASE_ADDR + * (u16 *) OLD_CL_OFFSET;
  45. printk("old bootloader convention, maybe loadlin?\n");
  46. }
  47. command_line = (char *) ((u64)(new_data));
  48. memcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
  49. printk("Bootdata ok (command line is %s)\n", saved_command_line);
  50. }
  51. static void __init setup_boot_cpu_data(void)
  52. {
  53. unsigned int dummy, eax;
  54. /* get vendor info */
  55. cpuid(0, (unsigned int *)&boot_cpu_data.cpuid_level,
  56. (unsigned int *)&boot_cpu_data.x86_vendor_id[0],
  57. (unsigned int *)&boot_cpu_data.x86_vendor_id[8],
  58. (unsigned int *)&boot_cpu_data.x86_vendor_id[4]);
  59. /* get cpu type */
  60. cpuid(1, &eax, &dummy, &dummy,
  61. (unsigned int *) &boot_cpu_data.x86_capability);
  62. boot_cpu_data.x86 = (eax >> 8) & 0xf;
  63. boot_cpu_data.x86_model = (eax >> 4) & 0xf;
  64. boot_cpu_data.x86_mask = eax & 0xf;
  65. }
  66. void __init x86_64_start_kernel(char * real_mode_data)
  67. {
  68. char *s;
  69. int i;
  70. for (i = 0; i < 256; i++)
  71. set_intr_gate(i, early_idt_handler);
  72. asm volatile("lidt %0" :: "m" (idt_descr));
  73. clear_bss();
  74. /*
  75. * This must be called really, really early:
  76. */
  77. lockdep_init();
  78. /*
  79. * switch to init_level4_pgt from boot_level4_pgt
  80. */
  81. memcpy(init_level4_pgt, boot_level4_pgt, PTRS_PER_PGD*sizeof(pgd_t));
  82. asm volatile("movq %0,%%cr3" :: "r" (__pa_symbol(&init_level4_pgt)));
  83. for (i = 0; i < NR_CPUS; i++)
  84. cpu_pda(i) = &boot_cpu_pda[i];
  85. pda_init(0);
  86. copy_bootdata(real_mode_data);
  87. #ifdef CONFIG_SMP
  88. cpu_set(0, cpu_online_map);
  89. #endif
  90. s = strstr(saved_command_line, "earlyprintk=");
  91. if (s != NULL)
  92. setup_early_printk(strchr(s, '=') + 1);
  93. #ifdef CONFIG_NUMA
  94. s = strstr(saved_command_line, "numa=");
  95. if (s != NULL)
  96. numa_setup(s+5);
  97. #endif
  98. #ifdef CONFIG_X86_IO_APIC
  99. if (strstr(saved_command_line, "disableapic"))
  100. disable_apic = 1;
  101. #endif
  102. /* You need early console to see that */
  103. if (__pa_symbol(&_end) >= KERNEL_TEXT_SIZE)
  104. panic("Kernel too big for kernel mapping\n");
  105. setup_boot_cpu_data();
  106. start_kernel();
  107. }