Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * |
3 | * Copyright (C) 1991, 1992 Linus Torvalds | |
4 | * | |
5 | * Enhanced CPU detection and feature setting code by Mike Jagdis | |
6 | * and Martin Mares, November 1997. | |
7 | */ | |
8 | ||
9 | .text | |
1da177e4 | 10 | #include <linux/threads.h> |
8b2f7fff | 11 | #include <linux/init.h> |
1da177e4 LT |
12 | #include <linux/linkage.h> |
13 | #include <asm/segment.h> | |
0341c14d JF |
14 | #include <asm/page_types.h> |
15 | #include <asm/pgtable_types.h> | |
1da177e4 LT |
16 | #include <asm/desc.h> |
17 | #include <asm/cache.h> | |
18 | #include <asm/thread_info.h> | |
86feeaa8 | 19 | #include <asm/asm-offsets.h> |
1da177e4 | 20 | #include <asm/setup.h> |
551889a6 | 21 | #include <asm/processor-flags.h> |
60a5317f | 22 | #include <asm/percpu.h> |
551889a6 IC |
23 | |
24 | /* Physical address */ | |
25 | #define pa(X) ((X) - __PAGE_OFFSET) | |
1da177e4 LT |
26 | |
27 | /* | |
28 | * References to members of the new_cpu_data structure. | |
29 | */ | |
30 | ||
31 | #define X86 new_cpu_data+CPUINFO_x86 | |
32 | #define X86_VENDOR new_cpu_data+CPUINFO_x86_vendor | |
33 | #define X86_MODEL new_cpu_data+CPUINFO_x86_model | |
34 | #define X86_MASK new_cpu_data+CPUINFO_x86_mask | |
35 | #define X86_HARD_MATH new_cpu_data+CPUINFO_hard_math | |
36 | #define X86_CPUID new_cpu_data+CPUINFO_cpuid_level | |
37 | #define X86_CAPABILITY new_cpu_data+CPUINFO_x86_capability | |
38 | #define X86_VENDOR_ID new_cpu_data+CPUINFO_x86_vendor_id | |
39 | ||
40 | /* | |
41 | * This is how much memory *in addition to the memory covered up to | |
9ce8c2ed JF |
42 | * and including _end* we need mapped initially. |
43 | * We need: | |
2bd2753f YL |
44 | * (KERNEL_IMAGE_SIZE/4096) / 1024 pages (worst case, non PAE) |
45 | * (KERNEL_IMAGE_SIZE/4096) / 512 + 4 pages (worst case for PAE) | |
1da177e4 LT |
46 | * |
47 | * Modulo rounding, each megabyte assigned here requires a kilobyte of | |
48 | * memory, which is currently unreclaimed. | |
49 | * | |
50 | * This should be a multiple of a page. | |
2bd2753f YL |
51 | * |
52 | * KERNEL_IMAGE_SIZE should be greater than pa(_end) | |
53 | * and small than max_low_pfn, otherwise will waste some page table entries | |
1da177e4 | 54 | */ |
7543c1de | 55 | LOW_PAGES = (KERNEL_IMAGE_SIZE + PAGE_SIZE_asm - 1)>>PAGE_SHIFT |
1da177e4 | 56 | |
9ce8c2ed JF |
57 | #if PTRS_PER_PMD > 1 |
58 | PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PMD) + PTRS_PER_PGD | |
59 | #else | |
60 | PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PGD) | |
61 | #endif | |
9ce8c2ed JF |
62 | ALLOCATOR_SLOP = 4 |
63 | ||
2bd2753f YL |
64 | INIT_MAP_SIZE = (PAGE_TABLE_SIZE + ALLOCATOR_SLOP) * PAGE_SIZE_asm |
65 | RESERVE_BRK(pagetables, INIT_MAP_SIZE) | |
796216a5 | 66 | |
1da177e4 LT |
67 | /* |
68 | * 32-bit kernel entrypoint; only used by the boot CPU. On entry, | |
69 | * %esi points to the real-mode code as a 32-bit pointer. | |
70 | * CS and DS must be 4 GB flat segments, but we don't depend on | |
71 | * any particular GDT layout, because we load our own as soon as we | |
72 | * can. | |
73 | */ | |
f8657e1b | 74 | .section .text.head,"ax",@progbits |
1da177e4 | 75 | ENTRY(startup_32) |
a24e7851 RR |
76 | /* test KEEP_SEGMENTS flag to see if the bootloader is asking |
77 | us to not reload segments */ | |
78 | testb $(1<<6), BP_loadflags(%esi) | |
79 | jnz 2f | |
1da177e4 LT |
80 | |
81 | /* | |
82 | * Set segments to known values. | |
83 | */ | |
551889a6 | 84 | lgdt pa(boot_gdt_descr) |
1da177e4 LT |
85 | movl $(__BOOT_DS),%eax |
86 | movl %eax,%ds | |
87 | movl %eax,%es | |
88 | movl %eax,%fs | |
89 | movl %eax,%gs | |
a24e7851 | 90 | 2: |
1da177e4 LT |
91 | |
92 | /* | |
93 | * Clear BSS first so that there are no surprises... | |
1da177e4 | 94 | */ |
a24e7851 | 95 | cld |
1da177e4 | 96 | xorl %eax,%eax |
551889a6 IC |
97 | movl $pa(__bss_start),%edi |
98 | movl $pa(__bss_stop),%ecx | |
1da177e4 LT |
99 | subl %edi,%ecx |
100 | shrl $2,%ecx | |
101 | rep ; stosl | |
484b90c4 VG |
102 | /* |
103 | * Copy bootup parameters out of the way. | |
104 | * Note: %esi still has the pointer to the real-mode data. | |
105 | * With the kexec as boot loader, parameter segment might be loaded beyond | |
106 | * kernel image and might not even be addressable by early boot page tables. | |
107 | * (kexec on panic case). Hence copy out the parameters before initializing | |
108 | * page tables. | |
109 | */ | |
551889a6 | 110 | movl $pa(boot_params),%edi |
484b90c4 VG |
111 | movl $(PARAM_SIZE/4),%ecx |
112 | cld | |
113 | rep | |
114 | movsl | |
551889a6 | 115 | movl pa(boot_params) + NEW_CL_POINTER,%esi |
484b90c4 | 116 | andl %esi,%esi |
fa76dab9 | 117 | jz 1f # No comand line |
551889a6 | 118 | movl $pa(boot_command_line),%edi |
484b90c4 VG |
119 | movl $(COMMAND_LINE_SIZE/4),%ecx |
120 | rep | |
121 | movsl | |
122 | 1: | |
1da177e4 | 123 | |
a24e7851 | 124 | #ifdef CONFIG_PARAVIRT |
551889a6 IC |
125 | /* This is can only trip for a broken bootloader... */ |
126 | cmpw $0x207, pa(boot_params + BP_version) | |
a24e7851 RR |
127 | jb default_entry |
128 | ||
129 | /* Paravirt-compatible boot parameters. Look to see what architecture | |
130 | we're booting under. */ | |
551889a6 | 131 | movl pa(boot_params + BP_hardware_subarch), %eax |
a24e7851 RR |
132 | cmpl $num_subarch_entries, %eax |
133 | jae bad_subarch | |
134 | ||
551889a6 | 135 | movl pa(subarch_entries)(,%eax,4), %eax |
a24e7851 RR |
136 | subl $__PAGE_OFFSET, %eax |
137 | jmp *%eax | |
138 | ||
139 | bad_subarch: | |
140 | WEAK(lguest_entry) | |
141 | WEAK(xen_entry) | |
142 | /* Unknown implementation; there's really | |
143 | nothing we can do at this point. */ | |
144 | ud2a | |
8b2f7fff SR |
145 | |
146 | __INITDATA | |
147 | ||
a24e7851 RR |
148 | subarch_entries: |
149 | .long default_entry /* normal x86/PC */ | |
150 | .long lguest_entry /* lguest hypervisor */ | |
151 | .long xen_entry /* Xen hypervisor */ | |
152 | num_subarch_entries = (. - subarch_entries) / 4 | |
153 | .previous | |
154 | #endif /* CONFIG_PARAVIRT */ | |
155 | ||
1da177e4 LT |
156 | /* |
157 | * Initialize page tables. This creates a PDE and a set of page | |
2bd2753f | 158 | * tables, which are located immediately beyond __brk_base. The variable |
ccf3fe02 | 159 | * _brk_end is set up to point to the first "safe" location. |
1da177e4 | 160 | * Mappings are created both at virtual address 0 (identity mapping) |
2bd2753f | 161 | * and PAGE_OFFSET for up to _end. |
1da177e4 | 162 | * |
551889a6 | 163 | * Note that the stack is not yet set up! |
1da177e4 | 164 | */ |
a24e7851 | 165 | default_entry: |
551889a6 IC |
166 | #ifdef CONFIG_X86_PAE |
167 | ||
168 | /* | |
169 | * In PAE mode swapper_pg_dir is statically defined to contain enough | |
170 | * entries to cover the VMSPLIT option (that is the top 1, 2 or 3 | |
171 | * entries). The identity mapping is handled by pointing two PGD | |
172 | * entries to the first kernel PMD. | |
173 | * | |
174 | * Note the upper half of each PMD or PTE are always zero at | |
175 | * this stage. | |
176 | */ | |
177 | ||
86b2b70e | 178 | #define KPMDS (((-__PAGE_OFFSET) >> 30) & 3) /* Number of kernel PMDs */ |
551889a6 IC |
179 | |
180 | xorl %ebx,%ebx /* %ebx is kept at zero */ | |
181 | ||
ccf3fe02 | 182 | movl $pa(__brk_base), %edi |
551889a6 | 183 | movl $pa(swapper_pg_pmd), %edx |
b2bc2731 | 184 | movl $PTE_IDENT_ATTR, %eax |
551889a6 | 185 | 10: |
b2bc2731 | 186 | leal PDE_IDENT_ATTR(%edi),%ecx /* Create PMD entry */ |
551889a6 IC |
187 | movl %ecx,(%edx) /* Store PMD entry */ |
188 | /* Upper half already zero */ | |
189 | addl $8,%edx | |
190 | movl $512,%ecx | |
191 | 11: | |
192 | stosl | |
193 | xchgl %eax,%ebx | |
194 | stosl | |
195 | xchgl %eax,%ebx | |
196 | addl $0x1000,%eax | |
197 | loop 11b | |
198 | ||
199 | /* | |
2bd2753f | 200 | * End condition: we must map up to the end. |
551889a6 | 201 | */ |
2bd2753f | 202 | movl $pa(_end) + PTE_IDENT_ATTR, %ebp |
551889a6 IC |
203 | cmpl %ebp,%eax |
204 | jb 10b | |
205 | 1: | |
ccf3fe02 JF |
206 | addl $__PAGE_OFFSET, %edi |
207 | movl %edi, pa(_brk_end) | |
6af61a76 YL |
208 | shrl $12, %eax |
209 | movl %eax, pa(max_pfn_mapped) | |
551889a6 IC |
210 | |
211 | /* Do early initialization of the fixmap area */ | |
b2bc2731 | 212 | movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax |
551889a6 IC |
213 | movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8) |
214 | #else /* Not PAE */ | |
215 | ||
216 | page_pde_offset = (__PAGE_OFFSET >> 20); | |
217 | ||
ccf3fe02 | 218 | movl $pa(__brk_base), %edi |
551889a6 | 219 | movl $pa(swapper_pg_dir), %edx |
b2bc2731 | 220 | movl $PTE_IDENT_ATTR, %eax |
1da177e4 | 221 | 10: |
b2bc2731 | 222 | leal PDE_IDENT_ATTR(%edi),%ecx /* Create PDE entry */ |
1da177e4 LT |
223 | movl %ecx,(%edx) /* Store identity PDE entry */ |
224 | movl %ecx,page_pde_offset(%edx) /* Store kernel PDE entry */ | |
225 | addl $4,%edx | |
226 | movl $1024, %ecx | |
227 | 11: | |
228 | stosl | |
229 | addl $0x1000,%eax | |
230 | loop 11b | |
551889a6 | 231 | /* |
2bd2753f | 232 | * End condition: we must map up to end |
551889a6 | 233 | */ |
2bd2753f | 234 | movl $pa(_end) + PTE_IDENT_ATTR, %ebp |
1da177e4 LT |
235 | cmpl %ebp,%eax |
236 | jb 10b | |
ccf3fe02 JF |
237 | addl $__PAGE_OFFSET, %edi |
238 | movl %edi, pa(_brk_end) | |
6af61a76 YL |
239 | shrl $12, %eax |
240 | movl %eax, pa(max_pfn_mapped) | |
17d57a92 | 241 | |
551889a6 | 242 | /* Do early initialization of the fixmap area */ |
b2bc2731 | 243 | movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax |
551889a6 IC |
244 | movl %eax,pa(swapper_pg_dir+0xffc) |
245 | #endif | |
1da177e4 | 246 | jmp 3f |
1da177e4 LT |
247 | /* |
248 | * Non-boot CPU entry point; entered from trampoline.S | |
249 | * We can't lgdt here, because lgdt itself uses a data segment, but | |
52de74dd | 250 | * we know the trampoline has already loaded the boot_gdt for us. |
f8657e1b VG |
251 | * |
252 | * If cpu hotplug is not supported then this code can go in init section | |
253 | * which will be freed later | |
1da177e4 | 254 | */ |
f8657e1b | 255 | |
5fe4486c | 256 | #ifndef CONFIG_HOTPLUG_CPU |
f8657e1b VG |
257 | .section .init.text,"ax",@progbits |
258 | #endif | |
259 | ||
260 | #ifdef CONFIG_SMP | |
1da177e4 LT |
261 | ENTRY(startup_32_smp) |
262 | cld | |
263 | movl $(__BOOT_DS),%eax | |
264 | movl %eax,%ds | |
265 | movl %eax,%es | |
266 | movl %eax,%fs | |
267 | movl %eax,%gs | |
5756dd59 IC |
268 | #endif /* CONFIG_SMP */ |
269 | 3: | |
1da177e4 LT |
270 | |
271 | /* | |
272 | * New page tables may be in 4Mbyte page mode and may | |
273 | * be using the global pages. | |
274 | * | |
275 | * NOTE! If we are on a 486 we may have no cr4 at all! | |
276 | * So we do not try to touch it unless we really have | |
277 | * some bits in it to set. This won't work if the BSP | |
278 | * implements cr4 but this AP does not -- very unlikely | |
279 | * but be warned! The same applies to the pse feature | |
280 | * if not equally supported. --macro | |
281 | * | |
282 | * NOTE! We have to correct for the fact that we're | |
283 | * not yet offset PAGE_OFFSET.. | |
284 | */ | |
551889a6 | 285 | #define cr4_bits pa(mmu_cr4_features) |
1da177e4 LT |
286 | movl cr4_bits,%edx |
287 | andl %edx,%edx | |
288 | jz 6f | |
289 | movl %cr4,%eax # Turn on paging options (PSE,PAE,..) | |
290 | orl %edx,%eax | |
291 | movl %eax,%cr4 | |
292 | ||
293 | btl $5, %eax # check if PAE is enabled | |
294 | jnc 6f | |
295 | ||
296 | /* Check if extended functions are implemented */ | |
297 | movl $0x80000000, %eax | |
298 | cpuid | |
299 | cmpl $0x80000000, %eax | |
300 | jbe 6f | |
301 | mov $0x80000001, %eax | |
302 | cpuid | |
303 | /* Execute Disable bit supported? */ | |
304 | btl $20, %edx | |
305 | jnc 6f | |
306 | ||
307 | /* Setup EFER (Extended Feature Enable Register) */ | |
308 | movl $0xc0000080, %ecx | |
309 | rdmsr | |
310 | ||
311 | btsl $11, %eax | |
312 | /* Make changes effective */ | |
313 | wrmsr | |
314 | ||
315 | 6: | |
1da177e4 LT |
316 | |
317 | /* | |
318 | * Enable paging | |
319 | */ | |
551889a6 | 320 | movl $pa(swapper_pg_dir),%eax |
1da177e4 LT |
321 | movl %eax,%cr3 /* set the page table pointer.. */ |
322 | movl %cr0,%eax | |
551889a6 | 323 | orl $X86_CR0_PG,%eax |
1da177e4 LT |
324 | movl %eax,%cr0 /* ..and set paging (PG) bit */ |
325 | ljmp $__BOOT_CS,$1f /* Clear prefetch and normalize %eip */ | |
326 | 1: | |
327 | /* Set up the stack pointer */ | |
328 | lss stack_start,%esp | |
329 | ||
330 | /* | |
331 | * Initialize eflags. Some BIOS's leave bits like NT set. This would | |
332 | * confuse the debugger if this code is traced. | |
333 | * XXX - best to initialize before switching to protected mode. | |
334 | */ | |
335 | pushl $0 | |
336 | popfl | |
337 | ||
338 | #ifdef CONFIG_SMP | |
50359501 | 339 | cmpb $0, ready |
1da177e4 LT |
340 | jz 1f /* Initial CPU cleans BSS */ |
341 | jmp checkCPUtype | |
342 | 1: | |
343 | #endif /* CONFIG_SMP */ | |
344 | ||
345 | /* | |
346 | * start system 32-bit setup. We need to re-do some of the things done | |
347 | * in 16-bit mode for the "real" operations. | |
348 | */ | |
349 | call setup_idt | |
350 | ||
1da177e4 LT |
351 | checkCPUtype: |
352 | ||
353 | movl $-1,X86_CPUID # -1 for no CPUID initially | |
354 | ||
355 | /* check if it is 486 or 386. */ | |
356 | /* | |
357 | * XXX - this does a lot of unnecessary setup. Alignment checks don't | |
358 | * apply at our cpl of 0 and the stack ought to be aligned already, and | |
359 | * we don't need to preserve eflags. | |
360 | */ | |
361 | ||
362 | movb $3,X86 # at least 386 | |
363 | pushfl # push EFLAGS | |
364 | popl %eax # get EFLAGS | |
365 | movl %eax,%ecx # save original EFLAGS | |
366 | xorl $0x240000,%eax # flip AC and ID bits in EFLAGS | |
367 | pushl %eax # copy to EFLAGS | |
368 | popfl # set EFLAGS | |
369 | pushfl # get new EFLAGS | |
370 | popl %eax # put it in eax | |
371 | xorl %ecx,%eax # change in flags | |
372 | pushl %ecx # restore original EFLAGS | |
373 | popfl | |
374 | testl $0x40000,%eax # check if AC bit changed | |
375 | je is386 | |
376 | ||
377 | movb $4,X86 # at least 486 | |
378 | testl $0x200000,%eax # check if ID bit changed | |
379 | je is486 | |
380 | ||
381 | /* get vendor info */ | |
382 | xorl %eax,%eax # call CPUID with 0 -> return vendor ID | |
383 | cpuid | |
384 | movl %eax,X86_CPUID # save CPUID level | |
385 | movl %ebx,X86_VENDOR_ID # lo 4 chars | |
386 | movl %edx,X86_VENDOR_ID+4 # next 4 chars | |
387 | movl %ecx,X86_VENDOR_ID+8 # last 4 chars | |
388 | ||
389 | orl %eax,%eax # do we have processor info as well? | |
390 | je is486 | |
391 | ||
392 | movl $1,%eax # Use the CPUID instruction to get CPU type | |
393 | cpuid | |
394 | movb %al,%cl # save reg for future use | |
395 | andb $0x0f,%ah # mask processor family | |
396 | movb %ah,X86 | |
397 | andb $0xf0,%al # mask model | |
398 | shrb $4,%al | |
399 | movb %al,X86_MODEL | |
400 | andb $0x0f,%cl # mask mask revision | |
401 | movb %cl,X86_MASK | |
402 | movl %edx,X86_CAPABILITY | |
403 | ||
404 | is486: movl $0x50022,%ecx # set AM, WP, NE and MP | |
405 | jmp 2f | |
406 | ||
407 | is386: movl $2,%ecx # set MP | |
408 | 2: movl %cr0,%eax | |
409 | andl $0x80000011,%eax # Save PG,PE,ET | |
410 | orl %ecx,%eax | |
411 | movl %eax,%cr0 | |
412 | ||
413 | call check_x87 | |
2a57ff1a | 414 | lgdt early_gdt_descr |
1da177e4 LT |
415 | lidt idt_descr |
416 | ljmp $(__KERNEL_CS),$1f | |
417 | 1: movl $(__KERNEL_DS),%eax # reload all the segment registers | |
418 | movl %eax,%ss # after changing gdt. | |
419 | ||
420 | movl $(__USER_DS),%eax # DS/ES contains default USER segment | |
421 | movl %eax,%ds | |
422 | movl %eax,%es | |
423 | ||
0dd76d73 BG |
424 | movl $(__KERNEL_PERCPU), %eax |
425 | movl %eax,%fs # set this cpu's percpu | |
426 | ||
60a5317f TH |
427 | #ifdef CONFIG_CC_STACKPROTECTOR |
428 | /* | |
429 | * The linker can't handle this by relocation. Manually set | |
430 | * base address in stack canary segment descriptor. | |
431 | */ | |
432 | cmpb $0,ready | |
433 | jne 1f | |
434 | movl $per_cpu__gdt_page,%eax | |
435 | movl $per_cpu__stack_canary,%ecx | |
5c79d2a5 | 436 | subl $20, %ecx |
60a5317f TH |
437 | movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax) |
438 | shrl $16, %ecx | |
439 | movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax) | |
440 | movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax) | |
441 | 1: | |
442 | #endif | |
443 | movl $(__KERNEL_STACK_CANARY),%eax | |
464d1a78 | 444 | movl %eax,%gs |
60a5317f TH |
445 | |
446 | xorl %eax,%eax # Clear LDT | |
1da177e4 | 447 | lldt %ax |
f95d47ca | 448 | |
1da177e4 | 449 | cld # gcc2 wants the direction flag cleared at all times |
26fd5e08 | 450 | pushl $0 # fake return address for unwinder |
1da177e4 | 451 | #ifdef CONFIG_SMP |
d92de65c SL |
452 | movb ready, %cl |
453 | movb $1, ready | |
29fe5f3b | 454 | cmpb $0,%cl # the first CPU calls start_kernel |
7c3576d2 | 455 | je 1f |
3e970473 | 456 | movl (stack_start), %esp |
7c3576d2 | 457 | 1: |
1da177e4 | 458 | #endif /* CONFIG_SMP */ |
e3f77edf | 459 | jmp *(initial_code) |
1da177e4 LT |
460 | |
461 | /* | |
462 | * We depend on ET to be correct. This checks for 287/387. | |
463 | */ | |
464 | check_x87: | |
465 | movb $0,X86_HARD_MATH | |
466 | clts | |
467 | fninit | |
468 | fstsw %ax | |
469 | cmpb $0,%al | |
470 | je 1f | |
471 | movl %cr0,%eax /* no coprocessor: have to set bits */ | |
472 | xorl $4,%eax /* set EM */ | |
473 | movl %eax,%cr0 | |
474 | ret | |
475 | ALIGN | |
476 | 1: movb $1,X86_HARD_MATH | |
477 | .byte 0xDB,0xE4 /* fsetpm for 287, ignored by 387 */ | |
478 | ret | |
479 | ||
480 | /* | |
481 | * setup_idt | |
482 | * | |
483 | * sets up a idt with 256 entries pointing to | |
484 | * ignore_int, interrupt gates. It doesn't actually load | |
485 | * idt - that can be done only after paging has been enabled | |
486 | * and the kernel moved to PAGE_OFFSET. Interrupts | |
487 | * are enabled elsewhere, when we can be relatively | |
488 | * sure everything is ok. | |
489 | * | |
490 | * Warning: %esi is live across this function. | |
491 | */ | |
492 | setup_idt: | |
493 | lea ignore_int,%edx | |
494 | movl $(__KERNEL_CS << 16),%eax | |
495 | movw %dx,%ax /* selector = 0x0010 = cs */ | |
496 | movw $0x8E00,%dx /* interrupt gate - dpl=0, present */ | |
497 | ||
498 | lea idt_table,%edi | |
499 | mov $256,%ecx | |
500 | rp_sidt: | |
501 | movl %eax,(%edi) | |
502 | movl %edx,4(%edi) | |
503 | addl $8,%edi | |
504 | dec %ecx | |
505 | jne rp_sidt | |
ec5c0926 CE |
506 | |
507 | .macro set_early_handler handler,trapno | |
508 | lea \handler,%edx | |
509 | movl $(__KERNEL_CS << 16),%eax | |
510 | movw %dx,%ax | |
511 | movw $0x8E00,%dx /* interrupt gate - dpl=0, present */ | |
512 | lea idt_table,%edi | |
513 | movl %eax,8*\trapno(%edi) | |
514 | movl %edx,8*\trapno+4(%edi) | |
515 | .endm | |
516 | ||
517 | set_early_handler handler=early_divide_err,trapno=0 | |
518 | set_early_handler handler=early_illegal_opcode,trapno=6 | |
519 | set_early_handler handler=early_protection_fault,trapno=13 | |
520 | set_early_handler handler=early_page_fault,trapno=14 | |
521 | ||
1da177e4 LT |
522 | ret |
523 | ||
ec5c0926 CE |
524 | early_divide_err: |
525 | xor %edx,%edx | |
526 | pushl $0 /* fake errcode */ | |
527 | jmp early_fault | |
528 | ||
529 | early_illegal_opcode: | |
530 | movl $6,%edx | |
531 | pushl $0 /* fake errcode */ | |
532 | jmp early_fault | |
533 | ||
534 | early_protection_fault: | |
535 | movl $13,%edx | |
536 | jmp early_fault | |
537 | ||
538 | early_page_fault: | |
539 | movl $14,%edx | |
540 | jmp early_fault | |
541 | ||
542 | early_fault: | |
543 | cld | |
544 | #ifdef CONFIG_PRINTK | |
382f64ab | 545 | pusha |
ec5c0926 CE |
546 | movl $(__KERNEL_DS),%eax |
547 | movl %eax,%ds | |
548 | movl %eax,%es | |
549 | cmpl $2,early_recursion_flag | |
550 | je hlt_loop | |
551 | incl early_recursion_flag | |
552 | movl %cr2,%eax | |
553 | pushl %eax | |
554 | pushl %edx /* trapno */ | |
555 | pushl $fault_msg | |
ec5c0926 | 556 | call printk |
ec5c0926 | 557 | #endif |
94878efd | 558 | call dump_stack |
ec5c0926 CE |
559 | hlt_loop: |
560 | hlt | |
561 | jmp hlt_loop | |
562 | ||
1da177e4 LT |
563 | /* This is the default interrupt "handler" :-) */ |
564 | ALIGN | |
565 | ignore_int: | |
566 | cld | |
d59745ce | 567 | #ifdef CONFIG_PRINTK |
1da177e4 LT |
568 | pushl %eax |
569 | pushl %ecx | |
570 | pushl %edx | |
571 | pushl %es | |
572 | pushl %ds | |
573 | movl $(__KERNEL_DS),%eax | |
574 | movl %eax,%ds | |
575 | movl %eax,%es | |
ec5c0926 CE |
576 | cmpl $2,early_recursion_flag |
577 | je hlt_loop | |
578 | incl early_recursion_flag | |
1da177e4 LT |
579 | pushl 16(%esp) |
580 | pushl 24(%esp) | |
581 | pushl 32(%esp) | |
582 | pushl 40(%esp) | |
583 | pushl $int_msg | |
584 | call printk | |
d5e397cb IM |
585 | |
586 | call dump_stack | |
587 | ||
1da177e4 LT |
588 | addl $(5*4),%esp |
589 | popl %ds | |
590 | popl %es | |
591 | popl %edx | |
592 | popl %ecx | |
593 | popl %eax | |
d59745ce | 594 | #endif |
1da177e4 LT |
595 | iret |
596 | ||
583323b9 TG |
597 | .section .cpuinit.data,"wa" |
598 | .align 4 | |
599 | ENTRY(initial_code) | |
600 | .long i386_start_kernel | |
601 | ||
f8657e1b | 602 | .section .text |
1da177e4 LT |
603 | /* |
604 | * Real beginning of normal "text" segment | |
605 | */ | |
606 | ENTRY(stext) | |
607 | ENTRY(_stext) | |
608 | ||
609 | /* | |
610 | * BSS section | |
611 | */ | |
5ead97c8 JF |
612 | .section ".bss.page_aligned","wa" |
613 | .align PAGE_SIZE_asm | |
551889a6 | 614 | #ifdef CONFIG_X86_PAE |
ed2b7e2b | 615 | swapper_pg_pmd: |
551889a6 IC |
616 | .fill 1024*KPMDS,4,0 |
617 | #else | |
1da177e4 LT |
618 | ENTRY(swapper_pg_dir) |
619 | .fill 1024,4,0 | |
551889a6 | 620 | #endif |
aa65af3f | 621 | swapper_pg_fixmap: |
b1c931e3 | 622 | .fill 1024,4,0 |
1da177e4 LT |
623 | ENTRY(empty_zero_page) |
624 | .fill 4096,1,0 | |
2bd2753f | 625 | |
1da177e4 LT |
626 | /* |
627 | * This starts the data section. | |
628 | */ | |
551889a6 IC |
629 | #ifdef CONFIG_X86_PAE |
630 | .section ".data.page_aligned","wa" | |
631 | /* Page-aligned for the benefit of paravirt? */ | |
632 | .align PAGE_SIZE_asm | |
633 | ENTRY(swapper_pg_dir) | |
b2bc2731 | 634 | .long pa(swapper_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */ |
551889a6 | 635 | # if KPMDS == 3 |
b2bc2731 SS |
636 | .long pa(swapper_pg_pmd+PGD_IDENT_ATTR),0 |
637 | .long pa(swapper_pg_pmd+PGD_IDENT_ATTR+0x1000),0 | |
638 | .long pa(swapper_pg_pmd+PGD_IDENT_ATTR+0x2000),0 | |
551889a6 IC |
639 | # elif KPMDS == 2 |
640 | .long 0,0 | |
b2bc2731 SS |
641 | .long pa(swapper_pg_pmd+PGD_IDENT_ATTR),0 |
642 | .long pa(swapper_pg_pmd+PGD_IDENT_ATTR+0x1000),0 | |
551889a6 IC |
643 | # elif KPMDS == 1 |
644 | .long 0,0 | |
645 | .long 0,0 | |
b2bc2731 | 646 | .long pa(swapper_pg_pmd+PGD_IDENT_ATTR),0 |
551889a6 IC |
647 | # else |
648 | # error "Kernel PMDs should be 1, 2 or 3" | |
649 | # endif | |
650 | .align PAGE_SIZE_asm /* needs to be page-sized too */ | |
651 | #endif | |
652 | ||
1da177e4 | 653 | .data |
1da177e4 LT |
654 | ENTRY(stack_start) |
655 | .long init_thread_union+THREAD_SIZE | |
656 | .long __BOOT_DS | |
657 | ||
658 | ready: .byte 0 | |
659 | ||
ec5c0926 CE |
660 | early_recursion_flag: |
661 | .long 0 | |
662 | ||
1da177e4 | 663 | int_msg: |
d5e397cb | 664 | .asciz "Unknown interrupt or fault at: %p %p %p\n" |
1da177e4 | 665 | |
ec5c0926 | 666 | fault_msg: |
575ca735 VN |
667 | /* fault info: */ |
668 | .ascii "BUG: Int %d: CR2 %p\n" | |
669 | /* pusha regs: */ | |
670 | .ascii " EDI %p ESI %p EBP %p ESP %p\n" | |
671 | .ascii " EBX %p EDX %p ECX %p EAX %p\n" | |
672 | /* fault frame: */ | |
673 | .ascii " err %p EIP %p CS %p flg %p\n" | |
674 | .ascii "Stack: %p %p %p %p %p %p %p %p\n" | |
675 | .ascii " %p %p %p %p %p %p %p %p\n" | |
676 | .asciz " %p %p %p %p %p %p %p %p\n" | |
ec5c0926 | 677 | |
9702785a | 678 | #include "../../x86/xen/xen-head.S" |
5ead97c8 | 679 | |
1da177e4 LT |
680 | /* |
681 | * The IDT and GDT 'descriptors' are a strange 48-bit object | |
682 | * only used by the lidt and lgdt instructions. They are not | |
683 | * like usual segment descriptors - they consist of a 16-bit | |
684 | * segment size, and 32-bit linear address value: | |
685 | */ | |
686 | ||
687 | .globl boot_gdt_descr | |
688 | .globl idt_descr | |
1da177e4 LT |
689 | |
690 | ALIGN | |
691 | # early boot GDT descriptor (must use 1:1 address mapping) | |
692 | .word 0 # 32 bit align gdt_desc.address | |
693 | boot_gdt_descr: | |
694 | .word __BOOT_DS+7 | |
52de74dd | 695 | .long boot_gdt - __PAGE_OFFSET |
1da177e4 LT |
696 | |
697 | .word 0 # 32-bit align idt_desc.address | |
698 | idt_descr: | |
699 | .word IDT_ENTRIES*8-1 # idt contains 256 entries | |
700 | .long idt_table | |
701 | ||
702 | # boot GDT descriptor (later on used by CPU#0): | |
703 | .word 0 # 32 bit align gdt_desc.address | |
2a57ff1a | 704 | ENTRY(early_gdt_descr) |
1da177e4 | 705 | .word GDT_ENTRIES*8-1 |
7a61d35d | 706 | .long per_cpu__gdt_page /* Overwritten for secondary CPUs */ |
1da177e4 | 707 | |
1da177e4 | 708 | /* |
52de74dd | 709 | * The boot_gdt must mirror the equivalent in setup.S and is |
1da177e4 LT |
710 | * used only for booting. |
711 | */ | |
712 | .align L1_CACHE_BYTES | |
52de74dd | 713 | ENTRY(boot_gdt) |
1da177e4 LT |
714 | .fill GDT_ENTRY_BOOT_CS,8,0 |
715 | .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */ | |
716 | .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */ |