Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * |
| 6 | * Enhanced CPU detection and feature setting code by Mike Jagdis |
| 7 | * and Martin Mares, November 1997. |
| 8 | */ |
| 9 | |
| 10 | .text |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/threads.h> |
Sam Ravnborg | 8b2f7ff | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 12 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/linkage.h> |
| 14 | #include <asm/segment.h> |
Jeremy Fitzhardinge | 0341c14 | 2009-02-13 11:14:01 -0800 | [diff] [blame] | 15 | #include <asm/page_types.h> |
| 16 | #include <asm/pgtable_types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <asm/cache.h> |
| 18 | #include <asm/thread_info.h> |
Sam Ravnborg | 86feeaa | 2005-09-09 19:28:28 +0200 | [diff] [blame] | 19 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/setup.h> |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 21 | #include <asm/processor-flags.h> |
H. Peter Anvin | 8a50e51 | 2009-11-13 15:28:13 -0800 | [diff] [blame] | 22 | #include <asm/msr-index.h> |
Borislav Petkov | cd4d09e | 2016-01-26 22:12:04 +0100 | [diff] [blame] | 23 | #include <asm/cpufeatures.h> |
Tejun Heo | 60a5317 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 24 | #include <asm/percpu.h> |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 25 | #include <asm/nops.h> |
Alexander Kuleshov | fb148d8 | 2015-02-19 13:34:58 +0600 | [diff] [blame] | 26 | #include <asm/bootparam.h> |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 27 | #include <asm/export.h> |
Boris Ostrovsky | 1e620f9 | 2016-12-08 11:44:31 -0500 | [diff] [blame] | 28 | #include <asm/pgtable_32.h> |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 29 | |
| 30 | /* Physical address */ |
| 31 | #define pa(X) ((X) - __PAGE_OFFSET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * References to members of the new_cpu_data structure. |
| 35 | */ |
| 36 | |
| 37 | #define X86 new_cpu_data+CPUINFO_x86 |
| 38 | #define X86_VENDOR new_cpu_data+CPUINFO_x86_vendor |
| 39 | #define X86_MODEL new_cpu_data+CPUINFO_x86_model |
Jia Zhang | b399151 | 2018-01-01 09:52:10 +0800 | [diff] [blame] | 40 | #define X86_STEPPING new_cpu_data+CPUINFO_x86_stepping |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define X86_HARD_MATH new_cpu_data+CPUINFO_hard_math |
| 42 | #define X86_CPUID new_cpu_data+CPUINFO_cpuid_level |
| 43 | #define X86_CAPABILITY new_cpu_data+CPUINFO_x86_capability |
| 44 | #define X86_VENDOR_ID new_cpu_data+CPUINFO_x86_vendor_id |
| 45 | |
Jeremy Fitzhardinge | 9ce8c2e | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 46 | |
Josh Poimboeuf | 22dc391 | 2016-09-21 16:04:06 -0500 | [diff] [blame] | 47 | #define SIZEOF_PTREGS 17*4 |
| 48 | |
Borislav Petkov | 04c1734 | 2015-06-19 13:49:06 +0200 | [diff] [blame] | 49 | /* |
Jeremy Fitzhardinge | c090f53 | 2009-03-16 12:07:54 -0700 | [diff] [blame] | 50 | * Worst-case size of the kernel mapping we need to make: |
H. Peter Anvin | 147dd56 | 2010-12-16 19:11:09 -0800 | [diff] [blame] | 51 | * a relocatable kernel can live anywhere in lowmem, so we need to be able |
| 52 | * to map all of lowmem. |
Jeremy Fitzhardinge | c090f53 | 2009-03-16 12:07:54 -0700 | [diff] [blame] | 53 | */ |
H. Peter Anvin | 147dd56 | 2010-12-16 19:11:09 -0800 | [diff] [blame] | 54 | KERNEL_PAGES = LOWMEM_PAGES |
Jeremy Fitzhardinge | c090f53 | 2009-03-16 12:07:54 -0700 | [diff] [blame] | 55 | |
Stratos Psomadakis | 7bf04be | 2011-02-25 22:46:13 +0200 | [diff] [blame] | 56 | INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE |
Yinghai Lu | 2bd2753 | 2009-03-09 01:15:57 -0700 | [diff] [blame] | 57 | RESERVE_BRK(pagetables, INIT_MAP_SIZE) |
Jeremy Fitzhardinge | 796216a | 2009-03-12 16:09:49 -0700 | [diff] [blame] | 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | /* |
| 60 | * 32-bit kernel entrypoint; only used by the boot CPU. On entry, |
| 61 | * %esi points to the real-mode code as a 32-bit pointer. |
| 62 | * CS and DS must be 4 GB flat segments, but we don't depend on |
| 63 | * any particular GDT layout, because we load our own as soon as we |
| 64 | * can. |
| 65 | */ |
Tim Abbott | 4ae59b9 | 2009-09-16 16:44:28 -0400 | [diff] [blame] | 66 | __HEAD |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | ENTRY(startup_32) |
Josh Poimboeuf | b32f96c | 2016-08-18 10:59:03 -0500 | [diff] [blame] | 68 | movl pa(initial_stack),%ecx |
H. Peter Anvin | 11d4c3f | 2011-02-04 16:14:11 -0800 | [diff] [blame] | 69 | |
Rusty Russell | a24e785 | 2007-10-21 16:41:35 -0700 | [diff] [blame] | 70 | /* test KEEP_SEGMENTS flag to see if the bootloader is asking |
| 71 | us to not reload segments */ |
Alexander Kuleshov | fb148d8 | 2015-02-19 13:34:58 +0600 | [diff] [blame] | 72 | testb $KEEP_SEGMENTS, BP_loadflags(%esi) |
Rusty Russell | a24e785 | 2007-10-21 16:41:35 -0700 | [diff] [blame] | 73 | jnz 2f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * Set segments to known values. |
| 77 | */ |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 78 | lgdt pa(boot_gdt_descr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | movl $(__BOOT_DS),%eax |
| 80 | movl %eax,%ds |
| 81 | movl %eax,%es |
| 82 | movl %eax,%fs |
| 83 | movl %eax,%gs |
H. Peter Anvin | 11d4c3f | 2011-02-04 16:14:11 -0800 | [diff] [blame] | 84 | movl %eax,%ss |
Rusty Russell | a24e785 | 2007-10-21 16:41:35 -0700 | [diff] [blame] | 85 | 2: |
H. Peter Anvin | 11d4c3f | 2011-02-04 16:14:11 -0800 | [diff] [blame] | 86 | leal -__PAGE_OFFSET(%ecx),%esp |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | * Clear BSS first so that there are no surprises... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | */ |
Rusty Russell | a24e785 | 2007-10-21 16:41:35 -0700 | [diff] [blame] | 91 | cld |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | xorl %eax,%eax |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 93 | movl $pa(__bss_start),%edi |
| 94 | movl $pa(__bss_stop),%ecx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | subl %edi,%ecx |
| 96 | shrl $2,%ecx |
| 97 | rep ; stosl |
Vivek Goyal | 484b90c | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 98 | /* |
| 99 | * Copy bootup parameters out of the way. |
| 100 | * Note: %esi still has the pointer to the real-mode data. |
| 101 | * With the kexec as boot loader, parameter segment might be loaded beyond |
| 102 | * kernel image and might not even be addressable by early boot page tables. |
| 103 | * (kexec on panic case). Hence copy out the parameters before initializing |
| 104 | * page tables. |
| 105 | */ |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 106 | movl $pa(boot_params),%edi |
Vivek Goyal | 484b90c | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 107 | movl $(PARAM_SIZE/4),%ecx |
| 108 | cld |
| 109 | rep |
| 110 | movsl |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 111 | movl pa(boot_params) + NEW_CL_POINTER,%esi |
Vivek Goyal | 484b90c | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 112 | andl %esi,%esi |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 113 | jz 1f # No command line |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 114 | movl $pa(boot_command_line),%edi |
Vivek Goyal | 484b90c | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 115 | movl $(COMMAND_LINE_SIZE/4),%ecx |
| 116 | rep |
| 117 | movsl |
| 118 | 1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Thomas Gleixner | dc3119e70 | 2011-02-23 10:08:31 +0100 | [diff] [blame] | 120 | #ifdef CONFIG_OLPC |
Andres Salomon | fd699c7 | 2010-06-18 17:46:53 -0400 | [diff] [blame] | 121 | /* save OFW's pgdir table for later use when calling into OFW */ |
| 122 | movl %cr3, %eax |
| 123 | movl %eax, pa(olpc_ofw_pgd) |
| 124 | #endif |
| 125 | |
Borislav Petkov | fe05589 | 2015-10-20 11:54:45 +0200 | [diff] [blame] | 126 | #ifdef CONFIG_MICROCODE |
Fenghua Yu | 63b553c | 2012-12-20 23:44:29 -0800 | [diff] [blame] | 127 | /* Early load ucode on BSP. */ |
| 128 | call load_ucode_bsp |
| 129 | #endif |
| 130 | |
Boris Ostrovsky | 1e620f9 | 2016-12-08 11:44:31 -0500 | [diff] [blame] | 131 | /* Create early pagetables. */ |
| 132 | call mk_early_pgtbl_32 |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 133 | |
Boris Ostrovsky | 1e620f9 | 2016-12-08 11:44:31 -0500 | [diff] [blame] | 134 | /* Do early initialization of the fixmap area */ |
| 135 | movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax |
| 136 | #ifdef CONFIG_X86_PAE |
Joe Korty | 86b2b70 | 2008-06-02 17:21:06 -0400 | [diff] [blame] | 137 | #define KPMDS (((-__PAGE_OFFSET) >> 30) & 3) /* Number of kernel PMDs */ |
Borislav Petkov | b40827fa | 2010-08-28 15:58:33 +0200 | [diff] [blame] | 138 | movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8) |
Boris Ostrovsky | 1e620f9 | 2016-12-08 11:44:31 -0500 | [diff] [blame] | 139 | #else |
Borislav Petkov | b40827fa | 2010-08-28 15:58:33 +0200 | [diff] [blame] | 140 | movl %eax,pa(initial_page_table+0xffc) |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 141 | #endif |
Rusty Russell | d50d8fe | 2011-01-04 17:20:54 +1030 | [diff] [blame] | 142 | |
| 143 | #ifdef CONFIG_PARAVIRT |
| 144 | /* This is can only trip for a broken bootloader... */ |
| 145 | cmpw $0x207, pa(boot_params + BP_version) |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 146 | jb .Ldefault_entry |
Rusty Russell | d50d8fe | 2011-01-04 17:20:54 +1030 | [diff] [blame] | 147 | |
| 148 | /* Paravirt-compatible boot parameters. Look to see what architecture |
| 149 | we're booting under. */ |
| 150 | movl pa(boot_params + BP_hardware_subarch), %eax |
| 151 | cmpl $num_subarch_entries, %eax |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 152 | jae .Lbad_subarch |
Rusty Russell | d50d8fe | 2011-01-04 17:20:54 +1030 | [diff] [blame] | 153 | |
| 154 | movl pa(subarch_entries)(,%eax,4), %eax |
| 155 | subl $__PAGE_OFFSET, %eax |
| 156 | jmp *%eax |
| 157 | |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 158 | .Lbad_subarch: |
Rusty Russell | d50d8fe | 2011-01-04 17:20:54 +1030 | [diff] [blame] | 159 | WEAK(xen_entry) |
| 160 | /* Unknown implementation; there's really |
| 161 | nothing we can do at this point. */ |
| 162 | ud2a |
| 163 | |
| 164 | __INITDATA |
| 165 | |
| 166 | subarch_entries: |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 167 | .long .Ldefault_entry /* normal x86/PC */ |
Rusty Russell | d50d8fe | 2011-01-04 17:20:54 +1030 | [diff] [blame] | 168 | .long xen_entry /* Xen hypervisor */ |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 169 | .long .Ldefault_entry /* Moorestown MID */ |
Rusty Russell | d50d8fe | 2011-01-04 17:20:54 +1030 | [diff] [blame] | 170 | num_subarch_entries = (. - subarch_entries) / 4 |
| 171 | .previous |
| 172 | #else |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 173 | jmp .Ldefault_entry |
Rusty Russell | d50d8fe | 2011-01-04 17:20:54 +1030 | [diff] [blame] | 174 | #endif /* CONFIG_PARAVIRT */ |
| 175 | |
Fenghua Yu | 3e2a0cc | 2012-11-13 11:32:45 -0800 | [diff] [blame] | 176 | #ifdef CONFIG_HOTPLUG_CPU |
| 177 | /* |
| 178 | * Boot CPU0 entry point. It's called from play_dead(). Everything has been set |
| 179 | * up already except stack. We just set up stack here. Then call |
| 180 | * start_secondary(). |
| 181 | */ |
| 182 | ENTRY(start_cpu0) |
Josh Poimboeuf | b32f96c | 2016-08-18 10:59:03 -0500 | [diff] [blame] | 183 | movl initial_stack, %ecx |
Fenghua Yu | 3e2a0cc | 2012-11-13 11:32:45 -0800 | [diff] [blame] | 184 | movl %ecx, %esp |
Josh Poimboeuf | 6616a14 | 2016-09-21 16:04:02 -0500 | [diff] [blame] | 185 | call *(initial_code) |
| 186 | 1: jmp 1b |
Fenghua Yu | 3e2a0cc | 2012-11-13 11:32:45 -0800 | [diff] [blame] | 187 | ENDPROC(start_cpu0) |
| 188 | #endif |
| 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | /* |
| 191 | * Non-boot CPU entry point; entered from trampoline.S |
| 192 | * We can't lgdt here, because lgdt itself uses a data segment, but |
Sebastien Dugue | 52de74d | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 193 | * we know the trampoline has already loaded the boot_gdt for us. |
Vivek Goyal | f8657e1 | 2007-02-13 13:26:22 +0100 | [diff] [blame] | 194 | * |
| 195 | * If cpu hotplug is not supported then this code can go in init section |
| 196 | * which will be freed later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | */ |
| 198 | ENTRY(startup_32_smp) |
| 199 | cld |
| 200 | movl $(__BOOT_DS),%eax |
| 201 | movl %eax,%ds |
| 202 | movl %eax,%es |
| 203 | movl %eax,%fs |
| 204 | movl %eax,%gs |
Josh Poimboeuf | b32f96c | 2016-08-18 10:59:03 -0500 | [diff] [blame] | 205 | movl pa(initial_stack),%ecx |
H. Peter Anvin | 11d4c3f | 2011-02-04 16:14:11 -0800 | [diff] [blame] | 206 | movl %eax,%ss |
| 207 | leal -__PAGE_OFFSET(%ecx),%esp |
Jarkko Sakkinen | 48927bb | 2012-05-08 21:22:28 +0300 | [diff] [blame] | 208 | |
Borislav Petkov | fe05589 | 2015-10-20 11:54:45 +0200 | [diff] [blame] | 209 | #ifdef CONFIG_MICROCODE |
Fenghua Yu | 63b553c | 2012-12-20 23:44:29 -0800 | [diff] [blame] | 210 | /* Early load ucode on AP. */ |
| 211 | call load_ucode_ap |
| 212 | #endif |
| 213 | |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 214 | .Ldefault_entry: |
H. Peter Anvin | 021ef05 | 2013-01-19 10:29:37 -0800 | [diff] [blame] | 215 | movl $(CR0_STATE & ~X86_CR0_PG),%eax |
| 216 | movl %eax,%cr0 |
| 217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | /* |
Borislav Petkov | 9efb58d | 2013-02-11 15:22:16 +0100 | [diff] [blame] | 219 | * We want to start out with EFLAGS unambiguously cleared. Some BIOSes leave |
| 220 | * bits like NT set. This would confuse the debugger if this code is traced. So |
| 221 | * initialize them properly now before switching to protected mode. That means |
| 222 | * DF in particular (even though we have cleared it earlier after copying the |
| 223 | * command line) because GCC expects it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | */ |
H. Peter Anvin | 5a5a51d | 2012-09-24 16:05:48 -0700 | [diff] [blame] | 225 | pushl $0 |
| 226 | popfl |
Borislav Petkov | 9efb58d | 2013-02-11 15:22:16 +0100 | [diff] [blame] | 227 | |
| 228 | /* |
| 229 | * New page tables may be in 4Mbyte page mode and may be using the global pages. |
| 230 | * |
| 231 | * NOTE! If we are on a 486 we may have no cr4 at all! Specifically, cr4 exists |
| 232 | * if and only if CPUID exists and has flags other than the FPU flag set. |
| 233 | */ |
| 234 | movl $-1,pa(X86_CPUID) # preset CPUID level |
| 235 | movl $X86_EFLAGS_ID,%ecx |
| 236 | pushl %ecx |
| 237 | popfl # set EFLAGS=ID |
H. Peter Anvin | 5a5a51d | 2012-09-24 16:05:48 -0700 | [diff] [blame] | 238 | pushfl |
Borislav Petkov | 9efb58d | 2013-02-11 15:22:16 +0100 | [diff] [blame] | 239 | popl %eax # get EFLAGS |
| 240 | testl $X86_EFLAGS_ID,%eax # did EFLAGS.ID remained set? |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 241 | jz .Lenable_paging # hw disallowed setting of ID bit |
Borislav Petkov | 9efb58d | 2013-02-11 15:22:16 +0100 | [diff] [blame] | 242 | # which means no CPUID and no CR4 |
| 243 | |
| 244 | xorl %eax,%eax |
| 245 | cpuid |
| 246 | movl %eax,pa(X86_CPUID) # save largest std CPUID function |
H. Peter Anvin | 5a5a51d | 2012-09-24 16:05:48 -0700 | [diff] [blame] | 247 | |
H. Peter Anvin | 6662c34 | 2012-11-27 08:54:36 -0800 | [diff] [blame] | 248 | movl $1,%eax |
| 249 | cpuid |
Borislav Petkov | 9efb58d | 2013-02-11 15:22:16 +0100 | [diff] [blame] | 250 | andl $~1,%edx # Ignore CPUID.FPU |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 251 | jz .Lenable_paging # No flags or only CPUID.FPU = no CR4 |
H. Peter Anvin | 6662c34 | 2012-11-27 08:54:36 -0800 | [diff] [blame] | 252 | |
H. Peter Anvin | 5a5a51d | 2012-09-24 16:05:48 -0700 | [diff] [blame] | 253 | movl pa(mmu_cr4_features),%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | movl %eax,%cr4 |
| 255 | |
H. Peter Anvin | 8a50e51 | 2009-11-13 15:28:13 -0800 | [diff] [blame] | 256 | testb $X86_CR4_PAE, %al # check if PAE is enabled |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 257 | jz .Lenable_paging |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | /* Check if extended functions are implemented */ |
| 260 | movl $0x80000000, %eax |
| 261 | cpuid |
H. Peter Anvin | 8a50e51 | 2009-11-13 15:28:13 -0800 | [diff] [blame] | 262 | /* Value must be in the range 0x80000001 to 0x8000ffff */ |
| 263 | subl $0x80000001, %eax |
| 264 | cmpl $(0x8000ffff-0x80000001), %eax |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 265 | ja .Lenable_paging |
Kees Cook | ebba638 | 2010-11-10 10:35:53 -0800 | [diff] [blame] | 266 | |
| 267 | /* Clear bogus XD_DISABLE bits */ |
| 268 | call verify_cpu |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | mov $0x80000001, %eax |
| 271 | cpuid |
| 272 | /* Execute Disable bit supported? */ |
H. Peter Anvin | 8a50e51 | 2009-11-13 15:28:13 -0800 | [diff] [blame] | 273 | btl $(X86_FEATURE_NX & 31), %edx |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 274 | jnc .Lenable_paging |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
| 276 | /* Setup EFER (Extended Feature Enable Register) */ |
H. Peter Anvin | 8a50e51 | 2009-11-13 15:28:13 -0800 | [diff] [blame] | 277 | movl $MSR_EFER, %ecx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | rdmsr |
| 279 | |
H. Peter Anvin | 8a50e51 | 2009-11-13 15:28:13 -0800 | [diff] [blame] | 280 | btsl $_EFER_NX, %eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | /* Make changes effective */ |
| 282 | wrmsr |
| 283 | |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 284 | .Lenable_paging: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | /* |
| 287 | * Enable paging |
| 288 | */ |
Borislav Petkov | b40827fa | 2010-08-28 15:58:33 +0200 | [diff] [blame] | 289 | movl $pa(initial_page_table), %eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | movl %eax,%cr3 /* set the page table pointer.. */ |
H. Peter Anvin | 021ef05 | 2013-01-19 10:29:37 -0800 | [diff] [blame] | 291 | movl $CR0_STATE,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | movl %eax,%cr0 /* ..and set paging (PG) bit */ |
| 293 | ljmp $__BOOT_CS,$1f /* Clear prefetch and normalize %eip */ |
| 294 | 1: |
H. Peter Anvin | 11d4c3f | 2011-02-04 16:14:11 -0800 | [diff] [blame] | 295 | /* Shift the stack pointer to a virtual address */ |
| 296 | addl $__PAGE_OFFSET, %esp |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
| 298 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | * start system 32-bit setup. We need to re-do some of the things done |
| 300 | * in 16-bit mode for the "real" operations. |
| 301 | */ |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 302 | movl setup_once_ref,%eax |
| 303 | andl %eax,%eax |
| 304 | jz 1f # Did we do this already? |
| 305 | call *%eax |
| 306 | 1: |
Borislav Petkov | 166df91 | 2013-02-11 15:22:15 +0100 | [diff] [blame] | 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | /* |
Borislav Petkov | 166df91 | 2013-02-11 15:22:15 +0100 | [diff] [blame] | 309 | * Check if it is 486 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | */ |
Wang YanQing | 237d154 | 2013-06-28 22:45:16 +0800 | [diff] [blame] | 311 | movb $4,X86 # at least 486 |
Borislav Petkov | c3a22a2 | 2013-02-11 15:22:17 +0100 | [diff] [blame] | 312 | cmpl $-1,X86_CPUID |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 313 | je .Lis486 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
| 315 | /* get vendor info */ |
| 316 | xorl %eax,%eax # call CPUID with 0 -> return vendor ID |
| 317 | cpuid |
| 318 | movl %eax,X86_CPUID # save CPUID level |
| 319 | movl %ebx,X86_VENDOR_ID # lo 4 chars |
| 320 | movl %edx,X86_VENDOR_ID+4 # next 4 chars |
| 321 | movl %ecx,X86_VENDOR_ID+8 # last 4 chars |
| 322 | |
| 323 | orl %eax,%eax # do we have processor info as well? |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 324 | je .Lis486 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | movl $1,%eax # Use the CPUID instruction to get CPU type |
| 327 | cpuid |
| 328 | movb %al,%cl # save reg for future use |
| 329 | andb $0x0f,%ah # mask processor family |
| 330 | movb %ah,X86 |
| 331 | andb $0xf0,%al # mask model |
| 332 | shrb $4,%al |
| 333 | movb %al,X86_MODEL |
| 334 | andb $0x0f,%cl # mask mask revision |
Jia Zhang | b399151 | 2018-01-01 09:52:10 +0800 | [diff] [blame] | 335 | movb %cl,X86_STEPPING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | movl %edx,X86_CAPABILITY |
| 337 | |
Josh Poimboeuf | 1b00255 | 2016-09-21 16:03:59 -0500 | [diff] [blame] | 338 | .Lis486: |
Borislav Petkov | c3a22a2 | 2013-02-11 15:22:17 +0100 | [diff] [blame] | 339 | movl $0x50022,%ecx # set AM, WP, NE and MP |
Borislav Petkov | 166df91 | 2013-02-11 15:22:15 +0100 | [diff] [blame] | 340 | movl %cr0,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | andl $0x80000011,%eax # Save PG,PE,ET |
| 342 | orl %ecx,%eax |
| 343 | movl %eax,%cr0 |
| 344 | |
Rusty Russell | 2a57ff1 | 2007-02-13 13:26:26 +0100 | [diff] [blame] | 345 | lgdt early_gdt_descr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | ljmp $(__KERNEL_CS),$1f |
| 347 | 1: movl $(__KERNEL_DS),%eax # reload all the segment registers |
| 348 | movl %eax,%ss # after changing gdt. |
| 349 | |
| 350 | movl $(__USER_DS),%eax # DS/ES contains default USER segment |
| 351 | movl %eax,%ds |
| 352 | movl %eax,%es |
| 353 | |
Brian Gerst | 0dd76d7 | 2009-01-21 17:26:05 +0900 | [diff] [blame] | 354 | movl $(__KERNEL_PERCPU), %eax |
| 355 | movl %eax,%fs # set this cpu's percpu |
| 356 | |
Tejun Heo | 60a5317 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 357 | movl $(__KERNEL_STACK_CANARY),%eax |
Jeremy Fitzhardinge | 464d1a7 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 358 | movl %eax,%gs |
Tejun Heo | 60a5317 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 359 | |
| 360 | xorl %eax,%eax # Clear LDT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | lldt %ax |
Jeremy Fitzhardinge | f95d47c | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 362 | |
Josh Poimboeuf | 6616a14 | 2016-09-21 16:04:02 -0500 | [diff] [blame] | 363 | call *(initial_code) |
| 364 | 1: jmp 1b |
| 365 | ENDPROC(startup_32_smp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 367 | #include "verify_cpu.S" |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | /* |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 370 | * setup_once |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | * |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 372 | * The setup work we only want to run on the BSP. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | * |
| 374 | * Warning: %esi is live across this function. |
| 375 | */ |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 376 | __INIT |
| 377 | setup_once: |
Linus Torvalds | 050e9ba | 2018-06-14 12:21:18 +0900 | [diff] [blame^] | 378 | #ifdef CONFIG_STACKPROTECTOR |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 379 | /* |
| 380 | * Configure the stack canary. The linker can't handle this by |
| 381 | * relocation. Manually set base address in stack canary |
| 382 | * segment descriptor. |
| 383 | */ |
| 384 | movl $gdt_page,%eax |
| 385 | movl $stack_canary,%ecx |
| 386 | movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax) |
| 387 | shrl $16, %ecx |
| 388 | movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax) |
| 389 | movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax) |
| 390 | #endif |
Chuck Ebbert | ec5c092 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 391 | |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 392 | andl $0,setup_once_ref /* Once is enough, thanks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | ret |
| 394 | |
Andy Lutomirski | 425be56 | 2015-05-22 16:15:47 -0700 | [diff] [blame] | 395 | ENTRY(early_idt_handler_array) |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 396 | # 36(%esp) %eflags |
| 397 | # 32(%esp) %cs |
| 398 | # 28(%esp) %eip |
| 399 | # 24(%rsp) error code |
| 400 | i = 0 |
| 401 | .rept NUM_EXCEPTION_VECTORS |
Josh Poimboeuf | 82c62fa | 2017-10-20 11:21:35 -0500 | [diff] [blame] | 402 | .if ((EXCEPTION_ERRCODE_MASK >> i) & 1) == 0 |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 403 | pushl $0 # Dummy error code, to make stack frame uniform |
| 404 | .endif |
| 405 | pushl $i # 20(%esp) Vector number |
Andy Lutomirski | 425be56 | 2015-05-22 16:15:47 -0700 | [diff] [blame] | 406 | jmp early_idt_handler_common |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 407 | i = i + 1 |
Andy Lutomirski | 425be56 | 2015-05-22 16:15:47 -0700 | [diff] [blame] | 408 | .fill early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 409 | .endr |
Andy Lutomirski | 425be56 | 2015-05-22 16:15:47 -0700 | [diff] [blame] | 410 | ENDPROC(early_idt_handler_array) |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 411 | |
Andy Lutomirski | 425be56 | 2015-05-22 16:15:47 -0700 | [diff] [blame] | 412 | early_idt_handler_common: |
| 413 | /* |
| 414 | * The stack is the hardware frame, an error code or zero, and the |
| 415 | * vector number. |
| 416 | */ |
Chuck Ebbert | ec5c092 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 417 | cld |
H. Peter Anvin | 5fa1019 | 2014-03-07 15:05:20 -0800 | [diff] [blame] | 418 | |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 419 | incl %ss:early_recursion_flag |
| 420 | |
Andy Lutomirski | 7bbcdb1 | 2016-04-02 07:01:32 -0700 | [diff] [blame] | 421 | /* The vector number is in pt_regs->gs */ |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 422 | |
Andy Lutomirski | 7bbcdb1 | 2016-04-02 07:01:32 -0700 | [diff] [blame] | 423 | cld |
Andy Lutomirski | 630c186 | 2017-07-28 06:00:31 -0700 | [diff] [blame] | 424 | pushl %fs /* pt_regs->fs (__fsh varies by model) */ |
| 425 | pushl %es /* pt_regs->es (__esh varies by model) */ |
| 426 | pushl %ds /* pt_regs->ds (__dsh varies by model) */ |
Andy Lutomirski | 7bbcdb1 | 2016-04-02 07:01:32 -0700 | [diff] [blame] | 427 | pushl %eax /* pt_regs->ax */ |
| 428 | pushl %ebp /* pt_regs->bp */ |
| 429 | pushl %edi /* pt_regs->di */ |
| 430 | pushl %esi /* pt_regs->si */ |
| 431 | pushl %edx /* pt_regs->dx */ |
| 432 | pushl %ecx /* pt_regs->cx */ |
| 433 | pushl %ebx /* pt_regs->bx */ |
| 434 | |
| 435 | /* Fix up DS and ES */ |
| 436 | movl $(__KERNEL_DS), %ecx |
| 437 | movl %ecx, %ds |
| 438 | movl %ecx, %es |
| 439 | |
| 440 | /* Load the vector number into EDX */ |
| 441 | movl PT_GS(%esp), %edx |
| 442 | |
Andy Lutomirski | 630c186 | 2017-07-28 06:00:31 -0700 | [diff] [blame] | 443 | /* Load GS into pt_regs->gs (and maybe clobber __gsh) */ |
Andy Lutomirski | 7bbcdb1 | 2016-04-02 07:01:32 -0700 | [diff] [blame] | 444 | movw %gs, PT_GS(%esp) |
Andy Lutomirski | 7bbcdb1 | 2016-04-02 07:01:32 -0700 | [diff] [blame] | 445 | |
Andy Lutomirski | 7bbcdb1 | 2016-04-02 07:01:32 -0700 | [diff] [blame] | 446 | movl %esp, %eax /* args are pt_regs (EAX), trapnr (EDX) */ |
| 447 | call early_fixup_exception |
Andy Lutomirski | 7bbcdb1 | 2016-04-02 07:01:32 -0700 | [diff] [blame] | 448 | |
| 449 | popl %ebx /* pt_regs->bx */ |
| 450 | popl %ecx /* pt_regs->cx */ |
| 451 | popl %edx /* pt_regs->dx */ |
| 452 | popl %esi /* pt_regs->si */ |
| 453 | popl %edi /* pt_regs->di */ |
| 454 | popl %ebp /* pt_regs->bp */ |
| 455 | popl %eax /* pt_regs->ax */ |
Andy Lutomirski | 630c186 | 2017-07-28 06:00:31 -0700 | [diff] [blame] | 456 | popl %ds /* pt_regs->ds (always ignores __dsh) */ |
| 457 | popl %es /* pt_regs->es (always ignores __esh) */ |
| 458 | popl %fs /* pt_regs->fs (always ignores __fsh) */ |
| 459 | popl %gs /* pt_regs->gs (always ignores __gsh) */ |
Andy Lutomirski | 7bbcdb1 | 2016-04-02 07:01:32 -0700 | [diff] [blame] | 460 | decl %ss:early_recursion_flag |
| 461 | addl $4, %esp /* pop pt_regs->orig_ax */ |
| 462 | iret |
Andy Lutomirski | 425be56 | 2015-05-22 16:15:47 -0700 | [diff] [blame] | 463 | ENDPROC(early_idt_handler_common) |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | /* This is the default interrupt "handler" :-) */ |
Thomas Gleixner | 87e8178 | 2017-08-28 08:47:48 +0200 | [diff] [blame] | 466 | ENTRY(early_ignore_irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | cld |
Matt Mackall | d59745c | 2005-05-01 08:59:02 -0700 | [diff] [blame] | 468 | #ifdef CONFIG_PRINTK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | pushl %eax |
| 470 | pushl %ecx |
| 471 | pushl %edx |
| 472 | pushl %es |
| 473 | pushl %ds |
| 474 | movl $(__KERNEL_DS),%eax |
| 475 | movl %eax,%ds |
| 476 | movl %eax,%es |
Chuck Ebbert | ec5c092 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 477 | cmpl $2,early_recursion_flag |
| 478 | je hlt_loop |
| 479 | incl early_recursion_flag |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | pushl 16(%esp) |
| 481 | pushl 24(%esp) |
| 482 | pushl 32(%esp) |
| 483 | pushl 40(%esp) |
| 484 | pushl $int_msg |
| 485 | call printk |
Ingo Molnar | d5e397c | 2009-01-26 06:09:00 +0100 | [diff] [blame] | 486 | |
| 487 | call dump_stack |
| 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | addl $(5*4),%esp |
| 490 | popl %ds |
| 491 | popl %es |
| 492 | popl %edx |
| 493 | popl %ecx |
| 494 | popl %eax |
Matt Mackall | d59745c | 2005-05-01 08:59:02 -0700 | [diff] [blame] | 495 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | iret |
Andy Lutomirski | 0e861fb | 2016-04-02 07:01:34 -0700 | [diff] [blame] | 497 | |
| 498 | hlt_loop: |
| 499 | hlt |
| 500 | jmp hlt_loop |
Thomas Gleixner | 87e8178 | 2017-08-28 08:47:48 +0200 | [diff] [blame] | 501 | ENDPROC(early_ignore_irq) |
Jiri Slaby | 04b5de3 | 2017-08-31 14:16:53 +0200 | [diff] [blame] | 502 | |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 503 | __INITDATA |
| 504 | .align 4 |
Andy Lutomirski | 0e861fb | 2016-04-02 07:01:34 -0700 | [diff] [blame] | 505 | GLOBAL(early_recursion_flag) |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 506 | .long 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 508 | __REFDATA |
| 509 | .align 4 |
Thomas Gleixner | 583323b | 2008-07-27 21:43:11 +0200 | [diff] [blame] | 510 | ENTRY(initial_code) |
| 511 | .long i386_start_kernel |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 512 | ENTRY(setup_once_ref) |
| 513 | .long setup_once |
Thomas Gleixner | 583323b | 2008-07-27 21:43:11 +0200 | [diff] [blame] | 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | /* |
| 516 | * BSS section |
| 517 | */ |
Tim Abbott | 02b7da3 | 2009-09-20 18:14:14 -0400 | [diff] [blame] | 518 | __PAGE_ALIGNED_BSS |
Stratos Psomadakis | 7bf04be | 2011-02-25 22:46:13 +0200 | [diff] [blame] | 519 | .align PAGE_SIZE |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 520 | #ifdef CONFIG_X86_PAE |
Boris Ostrovsky | 1e620f9 | 2016-12-08 11:44:31 -0500 | [diff] [blame] | 521 | .globl initial_pg_pmd |
Rusty Russell | d50d8fe | 2011-01-04 17:20:54 +1030 | [diff] [blame] | 522 | initial_pg_pmd: |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 523 | .fill 1024*KPMDS,4,0 |
| 524 | #else |
Arnd Bergmann | 553bbc1 | 2016-11-16 15:17:09 +0100 | [diff] [blame] | 525 | .globl initial_page_table |
| 526 | initial_page_table: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | .fill 1024,4,0 |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 528 | #endif |
Rusty Russell | d50d8fe | 2011-01-04 17:20:54 +1030 | [diff] [blame] | 529 | initial_pg_fixmap: |
Eric W. Biderman | b1c931e | 2007-07-15 23:37:28 -0700 | [diff] [blame] | 530 | .fill 1024,4,0 |
Arnd Bergmann | 553bbc1 | 2016-11-16 15:17:09 +0100 | [diff] [blame] | 531 | .globl empty_zero_page |
| 532 | empty_zero_page: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | .fill 4096,1,0 |
Arnd Bergmann | 553bbc1 | 2016-11-16 15:17:09 +0100 | [diff] [blame] | 534 | .globl swapper_pg_dir |
| 535 | swapper_pg_dir: |
Borislav Petkov | b40827fa | 2010-08-28 15:58:33 +0200 | [diff] [blame] | 536 | .fill 1024,4,0 |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 537 | EXPORT_SYMBOL(empty_zero_page) |
Yinghai Lu | 2bd2753 | 2009-03-09 01:15:57 -0700 | [diff] [blame] | 538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | /* |
| 540 | * This starts the data section. |
| 541 | */ |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 542 | #ifdef CONFIG_X86_PAE |
Tim Abbott | abe1ee3 | 2009-09-20 18:14:15 -0400 | [diff] [blame] | 543 | __PAGE_ALIGNED_DATA |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 544 | /* Page-aligned for the benefit of paravirt? */ |
Stratos Psomadakis | 7bf04be | 2011-02-25 22:46:13 +0200 | [diff] [blame] | 545 | .align PAGE_SIZE |
Borislav Petkov | b40827fa | 2010-08-28 15:58:33 +0200 | [diff] [blame] | 546 | ENTRY(initial_page_table) |
| 547 | .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */ |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 548 | # if KPMDS == 3 |
Borislav Petkov | b40827fa | 2010-08-28 15:58:33 +0200 | [diff] [blame] | 549 | .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 |
| 550 | .long pa(initial_pg_pmd+PGD_IDENT_ATTR+0x1000),0 |
| 551 | .long pa(initial_pg_pmd+PGD_IDENT_ATTR+0x2000),0 |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 552 | # elif KPMDS == 2 |
| 553 | .long 0,0 |
Borislav Petkov | b40827fa | 2010-08-28 15:58:33 +0200 | [diff] [blame] | 554 | .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 |
| 555 | .long pa(initial_pg_pmd+PGD_IDENT_ATTR+0x1000),0 |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 556 | # elif KPMDS == 1 |
| 557 | .long 0,0 |
| 558 | .long 0,0 |
Borislav Petkov | b40827fa | 2010-08-28 15:58:33 +0200 | [diff] [blame] | 559 | .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 560 | # else |
| 561 | # error "Kernel PMDs should be 1, 2 or 3" |
| 562 | # endif |
Stratos Psomadakis | 7bf04be | 2011-02-25 22:46:13 +0200 | [diff] [blame] | 563 | .align PAGE_SIZE /* needs to be page-sized too */ |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 564 | #endif |
| 565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | .data |
H. Peter Anvin | 11d4c3f | 2011-02-04 16:14:11 -0800 | [diff] [blame] | 567 | .balign 4 |
Josh Poimboeuf | b32f96c | 2016-08-18 10:59:03 -0500 | [diff] [blame] | 568 | ENTRY(initial_stack) |
Josh Poimboeuf | 22dc391 | 2016-09-21 16:04:06 -0500 | [diff] [blame] | 569 | /* |
| 570 | * The SIZEOF_PTREGS gap is a convention which helps the in-kernel |
| 571 | * unwinder reliably detect the end of the stack. |
| 572 | */ |
| 573 | .long init_thread_union + THREAD_SIZE - SIZEOF_PTREGS - \ |
| 574 | TOP_OF_KERNEL_STACK_PADDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 576 | __INITRODATA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | int_msg: |
Ingo Molnar | d5e397c | 2009-01-26 06:09:00 +0100 | [diff] [blame] | 578 | .asciz "Unknown interrupt or fault at: %p %p %p\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Thomas Gleixner | 9702785 | 2007-10-11 11:16:51 +0200 | [diff] [blame] | 580 | #include "../../x86/xen/xen-head.S" |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | /* |
| 583 | * The IDT and GDT 'descriptors' are a strange 48-bit object |
| 584 | * only used by the lidt and lgdt instructions. They are not |
| 585 | * like usual segment descriptors - they consist of a 16-bit |
| 586 | * segment size, and 32-bit linear address value: |
| 587 | */ |
| 588 | |
H. Peter Anvin | 4c5023a | 2012-04-18 17:16:50 -0700 | [diff] [blame] | 589 | .data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | .globl boot_gdt_descr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
| 592 | ALIGN |
| 593 | # early boot GDT descriptor (must use 1:1 address mapping) |
| 594 | .word 0 # 32 bit align gdt_desc.address |
| 595 | boot_gdt_descr: |
| 596 | .word __BOOT_DS+7 |
Sebastien Dugue | 52de74d | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 597 | .long boot_gdt - __PAGE_OFFSET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | # boot GDT descriptor (later on used by CPU#0): |
| 600 | .word 0 # 32 bit align gdt_desc.address |
Rusty Russell | 2a57ff1 | 2007-02-13 13:26:26 +0100 | [diff] [blame] | 601 | ENTRY(early_gdt_descr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | .word GDT_ENTRIES*8-1 |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 603 | .long gdt_page /* Overwritten for secondary CPUs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | /* |
Sebastien Dugue | 52de74d | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 606 | * The boot_gdt must mirror the equivalent in setup.S and is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | * used only for booting. |
| 608 | */ |
| 609 | .align L1_CACHE_BYTES |
Sebastien Dugue | 52de74d | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 610 | ENTRY(boot_gdt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | .fill GDT_ENTRY_BOOT_CS,8,0 |
| 612 | .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */ |
| 613 | .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */ |