head64.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. void __init x86_64_start_kernel(char * real_mode_data)
  52. {
  53. int i;
  54. for (i = 0; i < 256; i++)
  55. set_intr_gate(i, early_idt_handler);
  56. asm volatile("lidt %0" :: "m" (idt_descr));
  57. clear_bss();
  58. /*
  59. * This must be called really, really early:
  60. */
  61. lockdep_init();
  62. /*
  63. * switch to init_level4_pgt from boot_level4_pgt
  64. */
  65. memcpy(init_level4_pgt, boot_level4_pgt, PTRS_PER_PGD*sizeof(pgd_t));
  66. asm volatile("movq %0,%%cr3" :: "r" (__pa_symbol(&init_level4_pgt)));
  67. for (i = 0; i < NR_CPUS; i++)
  68. cpu_pda(i) = &boot_cpu_pda[i];
  69. pda_init(0);
  70. copy_bootdata(real_mode_data);
  71. #ifdef CONFIG_SMP
  72. cpu_set(0, cpu_online_map);
  73. #endif
  74. start_kernel();
  75. }