head64.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 <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/tlbflush.h>
  20. #include <asm/sections.h>
  21. static void __init zap_identity_mappings(void)
  22. {
  23. pgd_t *pgd = pgd_offset_k(0UL);
  24. pgd_clear(pgd);
  25. __flush_tlb();
  26. }
  27. /* Don't add a printk in there. printk relies on the PDA which is not initialized
  28. yet. */
  29. static void __init clear_bss(void)
  30. {
  31. memset(__bss_start, 0,
  32. (unsigned long) __bss_stop - (unsigned long) __bss_start);
  33. }
  34. #define NEW_CL_POINTER 0x228 /* Relative to real mode data */
  35. #define OLD_CL_MAGIC_ADDR 0x20
  36. #define OLD_CL_MAGIC 0xA33F
  37. #define OLD_CL_OFFSET 0x22
  38. static void __init copy_bootdata(char *real_mode_data)
  39. {
  40. unsigned long new_data;
  41. char * command_line;
  42. memcpy(x86_boot_params, real_mode_data, BOOT_PARAM_SIZE);
  43. new_data = *(u32 *) (x86_boot_params + NEW_CL_POINTER);
  44. if (!new_data) {
  45. if (OLD_CL_MAGIC != *(u16 *)(real_mode_data + OLD_CL_MAGIC_ADDR)) {
  46. return;
  47. }
  48. new_data = __pa(real_mode_data) + *(u16 *)(real_mode_data + OLD_CL_OFFSET);
  49. }
  50. command_line = __va(new_data);
  51. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  52. }
  53. void __init x86_64_start_kernel(char * real_mode_data)
  54. {
  55. int i;
  56. /* clear bss before set_intr_gate with early_idt_handler */
  57. clear_bss();
  58. /* Make NULL pointers segfault */
  59. zap_identity_mappings();
  60. for (i = 0; i < IDT_ENTRIES; i++)
  61. set_intr_gate(i, early_idt_handler);
  62. asm volatile("lidt %0" :: "m" (idt_descr));
  63. early_printk("Kernel alive\n");
  64. for (i = 0; i < NR_CPUS; i++)
  65. cpu_pda(i) = &boot_cpu_pda[i];
  66. pda_init(0);
  67. copy_bootdata(__va(real_mode_data));
  68. #ifdef CONFIG_SMP
  69. cpu_set(0, cpu_online_map);
  70. #endif
  71. start_kernel();
  72. }