Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/i386/kernel/head.S -- the 32-bit startup code. |
| 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> |
| 12 | #include <linux/linkage.h> |
| 13 | #include <asm/segment.h> |
| 14 | #include <asm/page.h> |
| 15 | #include <asm/pgtable.h> |
| 16 | #include <asm/desc.h> |
| 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> |
| 21 | |
| 22 | /* |
| 23 | * References to members of the new_cpu_data structure. |
| 24 | */ |
| 25 | |
| 26 | #define X86 new_cpu_data+CPUINFO_x86 |
| 27 | #define X86_VENDOR new_cpu_data+CPUINFO_x86_vendor |
| 28 | #define X86_MODEL new_cpu_data+CPUINFO_x86_model |
| 29 | #define X86_MASK new_cpu_data+CPUINFO_x86_mask |
| 30 | #define X86_HARD_MATH new_cpu_data+CPUINFO_hard_math |
| 31 | #define X86_CPUID new_cpu_data+CPUINFO_cpuid_level |
| 32 | #define X86_CAPABILITY new_cpu_data+CPUINFO_x86_capability |
| 33 | #define X86_VENDOR_ID new_cpu_data+CPUINFO_x86_vendor_id |
| 34 | |
| 35 | /* |
| 36 | * This is how much memory *in addition to the memory covered up to |
| 37 | * and including _end* we need mapped initially. We need one bit for |
| 38 | * each possible page, but only in low memory, which means |
| 39 | * 2^32/4096/8 = 128K worst case (4G/4G split.) |
| 40 | * |
| 41 | * Modulo rounding, each megabyte assigned here requires a kilobyte of |
| 42 | * memory, which is currently unreclaimed. |
| 43 | * |
| 44 | * This should be a multiple of a page. |
| 45 | */ |
| 46 | #define INIT_MAP_BEYOND_END (128*1024) |
| 47 | |
| 48 | |
| 49 | /* |
| 50 | * 32-bit kernel entrypoint; only used by the boot CPU. On entry, |
| 51 | * %esi points to the real-mode code as a 32-bit pointer. |
| 52 | * CS and DS must be 4 GB flat segments, but we don't depend on |
| 53 | * any particular GDT layout, because we load our own as soon as we |
| 54 | * can. |
| 55 | */ |
Vivek Goyal | f8657e1 | 2007-02-13 13:26:22 +0100 | [diff] [blame^] | 56 | .section .text.head,"ax",@progbits |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | ENTRY(startup_32) |
| 58 | |
Rusty Russell | c9ccf30 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 59 | #ifdef CONFIG_PARAVIRT |
| 60 | movl %cs, %eax |
| 61 | testl $0x3, %eax |
| 62 | jnz startup_paravirt |
| 63 | #endif |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | /* |
| 66 | * Set segments to known values. |
| 67 | */ |
| 68 | cld |
| 69 | lgdt boot_gdt_descr - __PAGE_OFFSET |
| 70 | movl $(__BOOT_DS),%eax |
| 71 | movl %eax,%ds |
| 72 | movl %eax,%es |
| 73 | movl %eax,%fs |
| 74 | movl %eax,%gs |
| 75 | |
| 76 | /* |
| 77 | * Clear BSS first so that there are no surprises... |
| 78 | * No need to cld as DF is already clear from cld above... |
| 79 | */ |
| 80 | xorl %eax,%eax |
| 81 | movl $__bss_start - __PAGE_OFFSET,%edi |
| 82 | movl $__bss_stop - __PAGE_OFFSET,%ecx |
| 83 | subl %edi,%ecx |
| 84 | shrl $2,%ecx |
| 85 | rep ; stosl |
Vivek Goyal | 484b90c | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 86 | /* |
| 87 | * Copy bootup parameters out of the way. |
| 88 | * Note: %esi still has the pointer to the real-mode data. |
| 89 | * With the kexec as boot loader, parameter segment might be loaded beyond |
| 90 | * kernel image and might not even be addressable by early boot page tables. |
| 91 | * (kexec on panic case). Hence copy out the parameters before initializing |
| 92 | * page tables. |
| 93 | */ |
| 94 | movl $(boot_params - __PAGE_OFFSET),%edi |
| 95 | movl $(PARAM_SIZE/4),%ecx |
| 96 | cld |
| 97 | rep |
| 98 | movsl |
| 99 | movl boot_params - __PAGE_OFFSET + NEW_CL_POINTER,%esi |
| 100 | andl %esi,%esi |
| 101 | jnz 2f # New command line protocol |
| 102 | cmpw $(OLD_CL_MAGIC),OLD_CL_MAGIC_ADDR |
| 103 | jne 1f |
| 104 | movzwl OLD_CL_OFFSET,%esi |
| 105 | addl $(OLD_CL_BASE_ADDR),%esi |
| 106 | 2: |
Alon Bar-Lev | 4e498b6 | 2007-02-12 00:54:11 -0800 | [diff] [blame] | 107 | movl $(boot_command_line - __PAGE_OFFSET),%edi |
Vivek Goyal | 484b90c | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 108 | movl $(COMMAND_LINE_SIZE/4),%ecx |
| 109 | rep |
| 110 | movsl |
| 111 | 1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * Initialize page tables. This creates a PDE and a set of page |
| 115 | * tables, which are located immediately beyond _end. The variable |
| 116 | * init_pg_tables_end is set up to point to the first "safe" location. |
| 117 | * Mappings are created both at virtual address 0 (identity mapping) |
| 118 | * and PAGE_OFFSET for up to _end+sizeof(page tables)+INIT_MAP_BEYOND_END. |
| 119 | * |
| 120 | * Warning: don't use %esi or the stack in this code. However, %esp |
| 121 | * can be used as a GPR if you really need it... |
| 122 | */ |
| 123 | page_pde_offset = (__PAGE_OFFSET >> 20); |
| 124 | |
| 125 | movl $(pg0 - __PAGE_OFFSET), %edi |
| 126 | movl $(swapper_pg_dir - __PAGE_OFFSET), %edx |
| 127 | movl $0x007, %eax /* 0x007 = PRESENT+RW+USER */ |
| 128 | 10: |
| 129 | leal 0x007(%edi),%ecx /* Create PDE entry */ |
| 130 | movl %ecx,(%edx) /* Store identity PDE entry */ |
| 131 | movl %ecx,page_pde_offset(%edx) /* Store kernel PDE entry */ |
| 132 | addl $4,%edx |
| 133 | movl $1024, %ecx |
| 134 | 11: |
| 135 | stosl |
| 136 | addl $0x1000,%eax |
| 137 | loop 11b |
| 138 | /* End condition: we must map up to and including INIT_MAP_BEYOND_END */ |
| 139 | /* bytes beyond the end of our own page tables; the +0x007 is the attribute bits */ |
| 140 | leal (INIT_MAP_BEYOND_END+0x007)(%edi),%ebp |
| 141 | cmpl %ebp,%eax |
| 142 | jb 10b |
| 143 | movl %edi,(init_pg_tables_end - __PAGE_OFFSET) |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | xorl %ebx,%ebx /* This is the boot CPU (BSP) */ |
| 146 | jmp 3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | /* |
| 148 | * Non-boot CPU entry point; entered from trampoline.S |
| 149 | * We can't lgdt here, because lgdt itself uses a data segment, but |
| 150 | * we know the trampoline has already loaded the boot_gdt_table GDT |
| 151 | * for us. |
Vivek Goyal | f8657e1 | 2007-02-13 13:26:22 +0100 | [diff] [blame^] | 152 | * |
| 153 | * If cpu hotplug is not supported then this code can go in init section |
| 154 | * which will be freed later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | */ |
Vivek Goyal | f8657e1 | 2007-02-13 13:26:22 +0100 | [diff] [blame^] | 156 | |
| 157 | #ifdef CONFIG_HOTPLUG_CPU |
| 158 | .section .text,"ax",@progbits |
| 159 | #else |
| 160 | .section .init.text,"ax",@progbits |
| 161 | #endif |
| 162 | |
| 163 | #ifdef CONFIG_SMP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | ENTRY(startup_32_smp) |
| 165 | cld |
| 166 | movl $(__BOOT_DS),%eax |
| 167 | movl %eax,%ds |
| 168 | movl %eax,%es |
| 169 | movl %eax,%fs |
| 170 | movl %eax,%gs |
| 171 | |
| 172 | /* |
| 173 | * New page tables may be in 4Mbyte page mode and may |
| 174 | * be using the global pages. |
| 175 | * |
| 176 | * NOTE! If we are on a 486 we may have no cr4 at all! |
| 177 | * So we do not try to touch it unless we really have |
| 178 | * some bits in it to set. This won't work if the BSP |
| 179 | * implements cr4 but this AP does not -- very unlikely |
| 180 | * but be warned! The same applies to the pse feature |
| 181 | * if not equally supported. --macro |
| 182 | * |
| 183 | * NOTE! We have to correct for the fact that we're |
| 184 | * not yet offset PAGE_OFFSET.. |
| 185 | */ |
| 186 | #define cr4_bits mmu_cr4_features-__PAGE_OFFSET |
| 187 | movl cr4_bits,%edx |
| 188 | andl %edx,%edx |
| 189 | jz 6f |
| 190 | movl %cr4,%eax # Turn on paging options (PSE,PAE,..) |
| 191 | orl %edx,%eax |
| 192 | movl %eax,%cr4 |
| 193 | |
| 194 | btl $5, %eax # check if PAE is enabled |
| 195 | jnc 6f |
| 196 | |
| 197 | /* Check if extended functions are implemented */ |
| 198 | movl $0x80000000, %eax |
| 199 | cpuid |
| 200 | cmpl $0x80000000, %eax |
| 201 | jbe 6f |
| 202 | mov $0x80000001, %eax |
| 203 | cpuid |
| 204 | /* Execute Disable bit supported? */ |
| 205 | btl $20, %edx |
| 206 | jnc 6f |
| 207 | |
| 208 | /* Setup EFER (Extended Feature Enable Register) */ |
| 209 | movl $0xc0000080, %ecx |
| 210 | rdmsr |
| 211 | |
| 212 | btsl $11, %eax |
| 213 | /* Make changes effective */ |
| 214 | wrmsr |
| 215 | |
| 216 | 6: |
| 217 | /* This is a secondary processor (AP) */ |
| 218 | xorl %ebx,%ebx |
| 219 | incl %ebx |
| 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | #endif /* CONFIG_SMP */ |
Vivek Goyal | f8657e1 | 2007-02-13 13:26:22 +0100 | [diff] [blame^] | 222 | 3: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | /* |
| 225 | * Enable paging |
| 226 | */ |
| 227 | movl $swapper_pg_dir-__PAGE_OFFSET,%eax |
| 228 | movl %eax,%cr3 /* set the page table pointer.. */ |
| 229 | movl %cr0,%eax |
| 230 | orl $0x80000000,%eax |
| 231 | movl %eax,%cr0 /* ..and set paging (PG) bit */ |
| 232 | ljmp $__BOOT_CS,$1f /* Clear prefetch and normalize %eip */ |
| 233 | 1: |
| 234 | /* Set up the stack pointer */ |
| 235 | lss stack_start,%esp |
| 236 | |
| 237 | /* |
| 238 | * Initialize eflags. Some BIOS's leave bits like NT set. This would |
| 239 | * confuse the debugger if this code is traced. |
| 240 | * XXX - best to initialize before switching to protected mode. |
| 241 | */ |
| 242 | pushl $0 |
| 243 | popfl |
| 244 | |
| 245 | #ifdef CONFIG_SMP |
| 246 | andl %ebx,%ebx |
| 247 | jz 1f /* Initial CPU cleans BSS */ |
| 248 | jmp checkCPUtype |
| 249 | 1: |
| 250 | #endif /* CONFIG_SMP */ |
| 251 | |
| 252 | /* |
| 253 | * start system 32-bit setup. We need to re-do some of the things done |
| 254 | * in 16-bit mode for the "real" operations. |
| 255 | */ |
| 256 | call setup_idt |
| 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | checkCPUtype: |
| 259 | |
| 260 | movl $-1,X86_CPUID # -1 for no CPUID initially |
| 261 | |
| 262 | /* check if it is 486 or 386. */ |
| 263 | /* |
| 264 | * XXX - this does a lot of unnecessary setup. Alignment checks don't |
| 265 | * apply at our cpl of 0 and the stack ought to be aligned already, and |
| 266 | * we don't need to preserve eflags. |
| 267 | */ |
| 268 | |
| 269 | movb $3,X86 # at least 386 |
| 270 | pushfl # push EFLAGS |
| 271 | popl %eax # get EFLAGS |
| 272 | movl %eax,%ecx # save original EFLAGS |
| 273 | xorl $0x240000,%eax # flip AC and ID bits in EFLAGS |
| 274 | pushl %eax # copy to EFLAGS |
| 275 | popfl # set EFLAGS |
| 276 | pushfl # get new EFLAGS |
| 277 | popl %eax # put it in eax |
| 278 | xorl %ecx,%eax # change in flags |
| 279 | pushl %ecx # restore original EFLAGS |
| 280 | popfl |
| 281 | testl $0x40000,%eax # check if AC bit changed |
| 282 | je is386 |
| 283 | |
| 284 | movb $4,X86 # at least 486 |
| 285 | testl $0x200000,%eax # check if ID bit changed |
| 286 | je is486 |
| 287 | |
| 288 | /* get vendor info */ |
| 289 | xorl %eax,%eax # call CPUID with 0 -> return vendor ID |
| 290 | cpuid |
| 291 | movl %eax,X86_CPUID # save CPUID level |
| 292 | movl %ebx,X86_VENDOR_ID # lo 4 chars |
| 293 | movl %edx,X86_VENDOR_ID+4 # next 4 chars |
| 294 | movl %ecx,X86_VENDOR_ID+8 # last 4 chars |
| 295 | |
| 296 | orl %eax,%eax # do we have processor info as well? |
| 297 | je is486 |
| 298 | |
| 299 | movl $1,%eax # Use the CPUID instruction to get CPU type |
| 300 | cpuid |
| 301 | movb %al,%cl # save reg for future use |
| 302 | andb $0x0f,%ah # mask processor family |
| 303 | movb %ah,X86 |
| 304 | andb $0xf0,%al # mask model |
| 305 | shrb $4,%al |
| 306 | movb %al,X86_MODEL |
| 307 | andb $0x0f,%cl # mask mask revision |
| 308 | movb %cl,X86_MASK |
| 309 | movl %edx,X86_CAPABILITY |
| 310 | |
| 311 | is486: movl $0x50022,%ecx # set AM, WP, NE and MP |
| 312 | jmp 2f |
| 313 | |
| 314 | is386: movl $2,%ecx # set MP |
| 315 | 2: movl %cr0,%eax |
| 316 | andl $0x80000011,%eax # Save PG,PE,ET |
| 317 | orl %ecx,%eax |
| 318 | movl %eax,%cr0 |
| 319 | |
| 320 | call check_x87 |
Jeremy Fitzhardinge | f95d47c | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 321 | call setup_pda |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | lgdt cpu_gdt_descr |
| 323 | lidt idt_descr |
| 324 | ljmp $(__KERNEL_CS),$1f |
| 325 | 1: movl $(__KERNEL_DS),%eax # reload all the segment registers |
| 326 | movl %eax,%ss # after changing gdt. |
| 327 | |
| 328 | movl $(__USER_DS),%eax # DS/ES contains default USER segment |
| 329 | movl %eax,%ds |
| 330 | movl %eax,%es |
| 331 | |
Jeremy Fitzhardinge | 464d1a7 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 332 | xorl %eax,%eax # Clear GS and LDT |
| 333 | movl %eax,%gs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | lldt %ax |
Jeremy Fitzhardinge | f95d47c | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 335 | |
| 336 | movl $(__KERNEL_PDA),%eax |
Jeremy Fitzhardinge | 464d1a7 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 337 | mov %eax,%fs |
Jeremy Fitzhardinge | f95d47c | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | cld # gcc2 wants the direction flag cleared at all times |
Jeremy Fitzhardinge | 26fd5e0 | 2006-10-21 18:37:02 +0200 | [diff] [blame] | 340 | pushl $0 # fake return address for unwinder |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | #ifdef CONFIG_SMP |
Shaohua Li | d92de65 | 2005-06-25 14:54:49 -0700 | [diff] [blame] | 342 | movb ready, %cl |
| 343 | movb $1, ready |
Andi Kleen | 29fe5f3 | 2006-08-30 19:37:09 +0200 | [diff] [blame] | 344 | cmpb $0,%cl # the first CPU calls start_kernel |
| 345 | jne initialize_secondary # all other CPUs call initialize_secondary |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | #endif /* CONFIG_SMP */ |
Andi Kleen | 29fe5f3 | 2006-08-30 19:37:09 +0200 | [diff] [blame] | 347 | jmp start_kernel |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
| 349 | /* |
| 350 | * We depend on ET to be correct. This checks for 287/387. |
| 351 | */ |
| 352 | check_x87: |
| 353 | movb $0,X86_HARD_MATH |
| 354 | clts |
| 355 | fninit |
| 356 | fstsw %ax |
| 357 | cmpb $0,%al |
| 358 | je 1f |
| 359 | movl %cr0,%eax /* no coprocessor: have to set bits */ |
| 360 | xorl $4,%eax /* set EM */ |
| 361 | movl %eax,%cr0 |
| 362 | ret |
| 363 | ALIGN |
| 364 | 1: movb $1,X86_HARD_MATH |
| 365 | .byte 0xDB,0xE4 /* fsetpm for 287, ignored by 387 */ |
| 366 | ret |
| 367 | |
| 368 | /* |
Jeremy Fitzhardinge | f95d47c | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 369 | * Point the GDT at this CPU's PDA. On boot this will be |
| 370 | * cpu_gdt_table and boot_pda; for secondary CPUs, these will be |
| 371 | * that CPU's GDT and PDA. |
| 372 | */ |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 373 | ENTRY(setup_pda) |
Jeremy Fitzhardinge | f95d47c | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 374 | /* get the PDA pointer */ |
| 375 | movl start_pda, %eax |
| 376 | |
| 377 | /* slot the PDA address into the GDT */ |
| 378 | mov cpu_gdt_descr+2, %ecx |
| 379 | mov %ax, (__KERNEL_PDA+0+2)(%ecx) /* base & 0x0000ffff */ |
| 380 | shr $16, %eax |
| 381 | mov %al, (__KERNEL_PDA+4+0)(%ecx) /* base & 0x00ff0000 */ |
| 382 | mov %ah, (__KERNEL_PDA+4+3)(%ecx) /* base & 0xff000000 */ |
| 383 | ret |
| 384 | |
| 385 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | * setup_idt |
| 387 | * |
| 388 | * sets up a idt with 256 entries pointing to |
| 389 | * ignore_int, interrupt gates. It doesn't actually load |
| 390 | * idt - that can be done only after paging has been enabled |
| 391 | * and the kernel moved to PAGE_OFFSET. Interrupts |
| 392 | * are enabled elsewhere, when we can be relatively |
| 393 | * sure everything is ok. |
| 394 | * |
| 395 | * Warning: %esi is live across this function. |
| 396 | */ |
| 397 | setup_idt: |
| 398 | lea ignore_int,%edx |
| 399 | movl $(__KERNEL_CS << 16),%eax |
| 400 | movw %dx,%ax /* selector = 0x0010 = cs */ |
| 401 | movw $0x8E00,%dx /* interrupt gate - dpl=0, present */ |
| 402 | |
| 403 | lea idt_table,%edi |
| 404 | mov $256,%ecx |
| 405 | rp_sidt: |
| 406 | movl %eax,(%edi) |
| 407 | movl %edx,4(%edi) |
| 408 | addl $8,%edi |
| 409 | dec %ecx |
| 410 | jne rp_sidt |
Chuck Ebbert | ec5c092 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 411 | |
| 412 | .macro set_early_handler handler,trapno |
| 413 | lea \handler,%edx |
| 414 | movl $(__KERNEL_CS << 16),%eax |
| 415 | movw %dx,%ax |
| 416 | movw $0x8E00,%dx /* interrupt gate - dpl=0, present */ |
| 417 | lea idt_table,%edi |
| 418 | movl %eax,8*\trapno(%edi) |
| 419 | movl %edx,8*\trapno+4(%edi) |
| 420 | .endm |
| 421 | |
| 422 | set_early_handler handler=early_divide_err,trapno=0 |
| 423 | set_early_handler handler=early_illegal_opcode,trapno=6 |
| 424 | set_early_handler handler=early_protection_fault,trapno=13 |
| 425 | set_early_handler handler=early_page_fault,trapno=14 |
| 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | ret |
| 428 | |
Chuck Ebbert | ec5c092 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 429 | early_divide_err: |
| 430 | xor %edx,%edx |
| 431 | pushl $0 /* fake errcode */ |
| 432 | jmp early_fault |
| 433 | |
| 434 | early_illegal_opcode: |
| 435 | movl $6,%edx |
| 436 | pushl $0 /* fake errcode */ |
| 437 | jmp early_fault |
| 438 | |
| 439 | early_protection_fault: |
| 440 | movl $13,%edx |
| 441 | jmp early_fault |
| 442 | |
| 443 | early_page_fault: |
| 444 | movl $14,%edx |
| 445 | jmp early_fault |
| 446 | |
| 447 | early_fault: |
| 448 | cld |
| 449 | #ifdef CONFIG_PRINTK |
| 450 | movl $(__KERNEL_DS),%eax |
| 451 | movl %eax,%ds |
| 452 | movl %eax,%es |
| 453 | cmpl $2,early_recursion_flag |
| 454 | je hlt_loop |
| 455 | incl early_recursion_flag |
| 456 | movl %cr2,%eax |
| 457 | pushl %eax |
| 458 | pushl %edx /* trapno */ |
| 459 | pushl $fault_msg |
| 460 | #ifdef CONFIG_EARLY_PRINTK |
| 461 | call early_printk |
| 462 | #else |
| 463 | call printk |
| 464 | #endif |
| 465 | #endif |
| 466 | hlt_loop: |
| 467 | hlt |
| 468 | jmp hlt_loop |
| 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | /* This is the default interrupt "handler" :-) */ |
| 471 | ALIGN |
| 472 | ignore_int: |
| 473 | cld |
Matt Mackall | d59745c | 2005-05-01 08:59:02 -0700 | [diff] [blame] | 474 | #ifdef CONFIG_PRINTK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | pushl %eax |
| 476 | pushl %ecx |
| 477 | pushl %edx |
| 478 | pushl %es |
| 479 | pushl %ds |
| 480 | movl $(__KERNEL_DS),%eax |
| 481 | movl %eax,%ds |
| 482 | movl %eax,%es |
Chuck Ebbert | ec5c092 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 483 | cmpl $2,early_recursion_flag |
| 484 | je hlt_loop |
| 485 | incl early_recursion_flag |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | pushl 16(%esp) |
| 487 | pushl 24(%esp) |
| 488 | pushl 32(%esp) |
| 489 | pushl 40(%esp) |
| 490 | pushl $int_msg |
Ingo Molnar | c0cdf19 | 2006-02-11 17:55:56 -0800 | [diff] [blame] | 491 | #ifdef CONFIG_EARLY_PRINTK |
| 492 | call early_printk |
| 493 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | call printk |
Ingo Molnar | c0cdf19 | 2006-02-11 17:55:56 -0800 | [diff] [blame] | 495 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | addl $(5*4),%esp |
| 497 | popl %ds |
| 498 | popl %es |
| 499 | popl %edx |
| 500 | popl %ecx |
| 501 | popl %eax |
Matt Mackall | d59745c | 2005-05-01 08:59:02 -0700 | [diff] [blame] | 502 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | iret |
| 504 | |
Vivek Goyal | f8657e1 | 2007-02-13 13:26:22 +0100 | [diff] [blame^] | 505 | .section .text |
Rusty Russell | c9ccf30 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 506 | #ifdef CONFIG_PARAVIRT |
| 507 | startup_paravirt: |
| 508 | cld |
| 509 | movl $(init_thread_union+THREAD_SIZE),%esp |
| 510 | |
| 511 | /* We take pains to preserve all the regs. */ |
| 512 | pushl %edx |
| 513 | pushl %ecx |
| 514 | pushl %eax |
| 515 | |
| 516 | /* paravirt.o is last in link, and that probe fn never returns */ |
| 517 | pushl $__start_paravirtprobe |
| 518 | 1: |
| 519 | movl 0(%esp), %eax |
| 520 | pushl (%eax) |
| 521 | movl 8(%esp), %eax |
| 522 | call *(%esp) |
| 523 | popl %eax |
| 524 | |
| 525 | movl 4(%esp), %eax |
| 526 | movl 8(%esp), %ecx |
| 527 | movl 12(%esp), %edx |
| 528 | |
| 529 | addl $4, (%esp) |
| 530 | jmp 1b |
| 531 | #endif |
| 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | /* |
| 534 | * Real beginning of normal "text" segment |
| 535 | */ |
| 536 | ENTRY(stext) |
| 537 | ENTRY(_stext) |
| 538 | |
| 539 | /* |
| 540 | * BSS section |
| 541 | */ |
| 542 | .section ".bss.page_aligned","w" |
| 543 | ENTRY(swapper_pg_dir) |
| 544 | .fill 1024,4,0 |
| 545 | ENTRY(empty_zero_page) |
| 546 | .fill 4096,1,0 |
| 547 | |
| 548 | /* |
| 549 | * This starts the data section. |
| 550 | */ |
| 551 | .data |
Jeremy Fitzhardinge | f95d47c | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 552 | ENTRY(start_pda) |
| 553 | .long boot_pda |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
| 555 | ENTRY(stack_start) |
| 556 | .long init_thread_union+THREAD_SIZE |
| 557 | .long __BOOT_DS |
| 558 | |
| 559 | ready: .byte 0 |
| 560 | |
Chuck Ebbert | ec5c092 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 561 | early_recursion_flag: |
| 562 | .long 0 |
| 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | int_msg: |
| 565 | .asciz "Unknown interrupt or fault at EIP %p %p %p\n" |
| 566 | |
Chuck Ebbert | ec5c092 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 567 | fault_msg: |
| 568 | .ascii "Int %d: CR2 %p err %p EIP %p CS %p flags %p\n" |
| 569 | .asciz "Stack: %p %p %p %p %p %p %p %p\n" |
| 570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | /* |
| 572 | * The IDT and GDT 'descriptors' are a strange 48-bit object |
| 573 | * only used by the lidt and lgdt instructions. They are not |
| 574 | * like usual segment descriptors - they consist of a 16-bit |
| 575 | * segment size, and 32-bit linear address value: |
| 576 | */ |
| 577 | |
| 578 | .globl boot_gdt_descr |
| 579 | .globl idt_descr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
| 581 | ALIGN |
| 582 | # early boot GDT descriptor (must use 1:1 address mapping) |
| 583 | .word 0 # 32 bit align gdt_desc.address |
| 584 | boot_gdt_descr: |
| 585 | .word __BOOT_DS+7 |
| 586 | .long boot_gdt_table - __PAGE_OFFSET |
| 587 | |
| 588 | .word 0 # 32-bit align idt_desc.address |
| 589 | idt_descr: |
| 590 | .word IDT_ENTRIES*8-1 # idt contains 256 entries |
| 591 | .long idt_table |
| 592 | |
| 593 | # boot GDT descriptor (later on used by CPU#0): |
| 594 | .word 0 # 32 bit align gdt_desc.address |
Jeremy Fitzhardinge | f95d47c | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 595 | ENTRY(cpu_gdt_descr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | .word GDT_ENTRIES*8-1 |
| 597 | .long cpu_gdt_table |
| 598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | /* |
| 600 | * The boot_gdt_table must mirror the equivalent in setup.S and is |
| 601 | * used only for booting. |
| 602 | */ |
| 603 | .align L1_CACHE_BYTES |
| 604 | ENTRY(boot_gdt_table) |
| 605 | .fill GDT_ENTRY_BOOT_CS,8,0 |
| 606 | .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */ |
| 607 | .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */ |
| 608 | |
| 609 | /* |
| 610 | * The Global Descriptor Table contains 28 quadwords, per-CPU. |
| 611 | */ |
Jan Beulich | 4ef0652 | 2006-03-23 02:59:51 -0800 | [diff] [blame] | 612 | .align L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | ENTRY(cpu_gdt_table) |
| 614 | .quad 0x0000000000000000 /* NULL descriptor */ |
| 615 | .quad 0x0000000000000000 /* 0x0b reserved */ |
| 616 | .quad 0x0000000000000000 /* 0x13 reserved */ |
| 617 | .quad 0x0000000000000000 /* 0x1b reserved */ |
| 618 | .quad 0x0000000000000000 /* 0x20 unused */ |
| 619 | .quad 0x0000000000000000 /* 0x28 unused */ |
| 620 | .quad 0x0000000000000000 /* 0x33 TLS entry 1 */ |
| 621 | .quad 0x0000000000000000 /* 0x3b TLS entry 2 */ |
| 622 | .quad 0x0000000000000000 /* 0x43 TLS entry 3 */ |
| 623 | .quad 0x0000000000000000 /* 0x4b reserved */ |
| 624 | .quad 0x0000000000000000 /* 0x53 reserved */ |
| 625 | .quad 0x0000000000000000 /* 0x5b reserved */ |
| 626 | |
| 627 | .quad 0x00cf9a000000ffff /* 0x60 kernel 4GB code at 0x00000000 */ |
| 628 | .quad 0x00cf92000000ffff /* 0x68 kernel 4GB data at 0x00000000 */ |
| 629 | .quad 0x00cffa000000ffff /* 0x73 user 4GB code at 0x00000000 */ |
| 630 | .quad 0x00cff2000000ffff /* 0x7b user 4GB data at 0x00000000 */ |
| 631 | |
| 632 | .quad 0x0000000000000000 /* 0x80 TSS descriptor */ |
| 633 | .quad 0x0000000000000000 /* 0x88 LDT descriptor */ |
| 634 | |
Zachary Amsden | e6a9918 | 2006-01-06 00:11:56 -0800 | [diff] [blame] | 635 | /* |
| 636 | * Segments used for calling PnP BIOS have byte granularity. |
| 637 | * They code segments and data segments have fixed 64k limits, |
| 638 | * the transfer segment sizes are set at run time. |
| 639 | */ |
| 640 | .quad 0x00409a000000ffff /* 0x90 32-bit code */ |
| 641 | .quad 0x00009a000000ffff /* 0x98 16-bit code */ |
| 642 | .quad 0x000092000000ffff /* 0xa0 16-bit data */ |
Zachary Amsden | 5fe9fe3c | 2006-01-06 00:11:55 -0800 | [diff] [blame] | 643 | .quad 0x0000920000000000 /* 0xa8 16-bit data */ |
| 644 | .quad 0x0000920000000000 /* 0xb0 16-bit data */ |
Zachary Amsden | 99022c4 | 2006-01-06 00:11:53 -0800 | [diff] [blame] | 645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | /* |
| 647 | * The APM segments have byte granularity and their bases |
Zachary Amsden | 99022c4 | 2006-01-06 00:11:53 -0800 | [diff] [blame] | 648 | * are set at run time. All have 64k limits. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | */ |
Zachary Amsden | 99022c4 | 2006-01-06 00:11:53 -0800 | [diff] [blame] | 650 | .quad 0x00409a000000ffff /* 0xb8 APM CS code */ |
| 651 | .quad 0x00009a000000ffff /* 0xc0 APM CS 16 code (16 bit) */ |
| 652 | .quad 0x004092000000ffff /* 0xc8 APM DS data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
Stas Sergeev | be44d2a | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 654 | .quad 0x00c0920000000000 /* 0xd0 - ESPFIX SS */ |
Jeremy Fitzhardinge | f95d47c | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 655 | .quad 0x00cf92000000ffff /* 0xd8 - PDA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | .quad 0x0000000000000000 /* 0xe0 - unused */ |
| 657 | .quad 0x0000000000000000 /* 0xe8 - unused */ |
| 658 | .quad 0x0000000000000000 /* 0xf0 - unused */ |
| 659 | .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */ |
| 660 | |