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