head64.c 3.2 KB

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