head64.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. return;
  42. }
  43. new_data = OLD_CL_BASE_ADDR + * (u16 *) OLD_CL_OFFSET;
  44. }
  45. command_line = (char *) ((u64)(new_data));
  46. memcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
  47. }
  48. void __init x86_64_start_kernel(char * real_mode_data)
  49. {
  50. int i;
  51. for (i = 0; i < 256; i++)
  52. set_intr_gate(i, early_idt_handler);
  53. asm volatile("lidt %0" :: "m" (idt_descr));
  54. clear_bss();
  55. early_printk("Kernel alive\n");
  56. /*
  57. * switch to init_level4_pgt from boot_level4_pgt
  58. */
  59. memcpy(init_level4_pgt, boot_level4_pgt, PTRS_PER_PGD*sizeof(pgd_t));
  60. asm volatile("movq %0,%%cr3" :: "r" (__pa_symbol(&init_level4_pgt)));
  61. for (i = 0; i < NR_CPUS; i++)
  62. cpu_pda(i) = &boot_cpu_pda[i];
  63. pda_init(0);
  64. copy_bootdata(real_mode_data);
  65. #ifdef CONFIG_SMP
  66. cpu_set(0, cpu_online_map);
  67. #endif
  68. start_kernel();
  69. }