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 */ |
| 32 | #define OLD_CL_MAGIC_ADDR 0x90020 |
| 33 | #define OLD_CL_MAGIC 0xA33F |
| 34 | #define OLD_CL_BASE_ADDR 0x90000 |
| 35 | #define OLD_CL_OFFSET 0x90022 |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static void __init copy_bootdata(char *real_mode_data) |
| 38 | { |
| 39 | int new_data; |
| 40 | char * command_line; |
| 41 | |
Venkatesh Pallipadi | f9ba705 | 2005-05-01 08:58:51 -0700 | [diff] [blame] | 42 | memcpy(x86_boot_params, real_mode_data, BOOT_PARAM_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | new_data = *(int *) (x86_boot_params + NEW_CL_POINTER); |
| 44 | if (!new_data) { |
| 45 | if (OLD_CL_MAGIC != * (u16 *) OLD_CL_MAGIC_ADDR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | return; |
| 47 | } |
| 48 | new_data = OLD_CL_BASE_ADDR + * (u16 *) OLD_CL_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | command_line = (char *) ((u64)(new_data)); |
Alon Bar-Lev | adf4885 | 2007-02-12 00:54:25 -0800 | [diff] [blame] | 51 | memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | void __init x86_64_start_kernel(char * real_mode_data) |
| 55 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | int i; |
| 57 | |
Yinghai Lu | 3df0af0 | 2006-12-07 02:14:12 +0100 | [diff] [blame] | 58 | /* clear bss before set_intr_gate with early_idt_handler */ |
| 59 | clear_bss(); |
| 60 | |
| 61 | for (i = 0; i < IDT_ENTRIES; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | set_intr_gate(i, early_idt_handler); |
| 63 | asm volatile("lidt %0" :: "m" (idt_descr)); |
Siddha, Suresh B | f6c2e33 | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 64 | |
Andi Kleen | 43c85c9 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 65 | early_printk("Kernel alive\n"); |
Ingo Molnar | 2148270 | 2006-07-03 00:24:57 -0700 | [diff] [blame] | 66 | |
| 67 | /* |
Siddha, Suresh B | f6c2e33 | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 68 | * switch to init_level4_pgt from boot_level4_pgt |
| 69 | */ |
| 70 | memcpy(init_level4_pgt, boot_level4_pgt, PTRS_PER_PGD*sizeof(pgd_t)); |
| 71 | asm volatile("movq %0,%%cr3" :: "r" (__pa_symbol(&init_level4_pgt))); |
| 72 | |
Ravikiran G Thirumalai | 365ba91 | 2006-01-11 22:45:42 +0100 | [diff] [blame] | 73 | for (i = 0; i < NR_CPUS; i++) |
| 74 | cpu_pda(i) = &boot_cpu_pda[i]; |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | pda_init(0); |
| 77 | copy_bootdata(real_mode_data); |
| 78 | #ifdef CONFIG_SMP |
| 79 | cpu_set(0, cpu_online_map); |
| 80 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | start_kernel(); |
| 82 | } |