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