Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Siddha, Suresh B | f6c2e33 | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 20 | #include <asm/pgtable.h> |
Andi Kleen | 2bc0414 | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 21 | #include <asm/sections.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | /* Don't add a printk in there. printk relies on the PDA which is not initialized |
| 24 | yet. */ |
| 25 | static void __init clear_bss(void) |
| 26 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | memset(__bss_start, 0, |
Andi Kleen | 2bc0414 | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 28 | (unsigned long) __bss_stop - (unsigned long) __bss_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #define NEW_CL_POINTER 0x228 /* Relative to real mode data */ |
Vivek Goyal | 278c0eb | 2007-05-02 19:27:07 +0200 | [diff] [blame^] | 32 | #define OLD_CL_MAGIC_ADDR 0x20 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #define OLD_CL_MAGIC 0xA33F |
Vivek Goyal | 278c0eb | 2007-05-02 19:27:07 +0200 | [diff] [blame^] | 34 | #define OLD_CL_OFFSET 0x22 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | static void __init copy_bootdata(char *real_mode_data) |
| 37 | { |
Vivek Goyal | 278c0eb | 2007-05-02 19:27:07 +0200 | [diff] [blame^] | 38 | unsigned long new_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | char * command_line; |
| 40 | |
Venkatesh Pallipadi | f9ba705 | 2005-05-01 08:58:51 -0700 | [diff] [blame] | 41 | memcpy(x86_boot_params, real_mode_data, BOOT_PARAM_SIZE); |
Vivek Goyal | 278c0eb | 2007-05-02 19:27:07 +0200 | [diff] [blame^] | 42 | new_data = *(u32 *) (x86_boot_params + NEW_CL_POINTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | if (!new_data) { |
Vivek Goyal | 278c0eb | 2007-05-02 19:27:07 +0200 | [diff] [blame^] | 44 | if (OLD_CL_MAGIC != *(u16 *)(real_mode_data + OLD_CL_MAGIC_ADDR)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | return; |
| 46 | } |
Vivek Goyal | 278c0eb | 2007-05-02 19:27:07 +0200 | [diff] [blame^] | 47 | new_data = __pa(real_mode_data) + *(u16 *)(real_mode_data + OLD_CL_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
Vivek Goyal | 278c0eb | 2007-05-02 19:27:07 +0200 | [diff] [blame^] | 49 | command_line = __va(new_data); |
Alon Bar-Lev | adf4885 | 2007-02-12 00:54:25 -0800 | [diff] [blame] | 50 | memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | void __init x86_64_start_kernel(char * real_mode_data) |
| 54 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | int i; |
| 56 | |
Yinghai Lu | 3df0af0 | 2006-12-07 02:14:12 +0100 | [diff] [blame] | 57 | /* clear bss before set_intr_gate with early_idt_handler */ |
| 58 | clear_bss(); |
| 59 | |
| 60 | for (i = 0; i < IDT_ENTRIES; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | set_intr_gate(i, early_idt_handler); |
| 62 | asm volatile("lidt %0" :: "m" (idt_descr)); |
Siddha, Suresh B | f6c2e33 | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 63 | |
Andi Kleen | 43c85c9 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 64 | early_printk("Kernel alive\n"); |
Ingo Molnar | 2148270 | 2006-07-03 00:24:57 -0700 | [diff] [blame] | 65 | |
| 66 | /* |
Siddha, Suresh B | f6c2e33 | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 67 | * switch to init_level4_pgt from boot_level4_pgt |
| 68 | */ |
| 69 | memcpy(init_level4_pgt, boot_level4_pgt, PTRS_PER_PGD*sizeof(pgd_t)); |
| 70 | asm volatile("movq %0,%%cr3" :: "r" (__pa_symbol(&init_level4_pgt))); |
| 71 | |
Ravikiran G Thirumalai | 365ba91 | 2006-01-11 22:45:42 +0100 | [diff] [blame] | 72 | for (i = 0; i < NR_CPUS; i++) |
| 73 | cpu_pda(i) = &boot_cpu_pda[i]; |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | pda_init(0); |
Vivek Goyal | 278c0eb | 2007-05-02 19:27:07 +0200 | [diff] [blame^] | 76 | copy_bootdata(__va(real_mode_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #ifdef CONFIG_SMP |
| 78 | cpu_set(0, cpu_online_map); |
| 79 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | start_kernel(); |
| 81 | } |