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