blob: a2b6331434dab960dcf895a214a4fad063a66d71 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070011#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 Ravnborg86feeaa2005-09-09 19:28:28 +020019#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#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
Jeremy Fitzhardinge9ce8c2e2007-05-02 19:27:16 +020037 * and including _end* we need mapped initially.
38 * We need:
39 * - one bit for each possible page, but only in low memory, which means
40 * 2^32/4096/8 = 128K worst case (4G/4G split.)
41 * - enough space to map all low memory, which means
42 * (2^32/4096) / 1024 pages (worst case, non PAE)
43 * (2^32/4096) / 512 + 4 pages (worst case for PAE)
44 * - a few pages for allocator use before the kernel pagetable has
45 * been set up
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 *
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.
51 */
Jeremy Fitzhardinge9ce8c2e2007-05-02 19:27:16 +020052LOW_PAGES = 1<<(32-PAGE_SHIFT_asm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Ingo Molnar1e3e1972007-10-17 18:04:34 +020054/*
55 * To preserve the DMA pool in PAGEALLOC kernels, we'll allocate
56 * pagetables from above the 16MB DMA limit, so we'll have to set
57 * up pagetables 16MB more (worst-case):
58 */
59#ifdef CONFIG_DEBUG_PAGEALLOC
60LOW_PAGES = LOW_PAGES + 0x1000000
61#endif
62
Jeremy Fitzhardinge9ce8c2e2007-05-02 19:27:16 +020063#if PTRS_PER_PMD > 1
64PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PMD) + PTRS_PER_PGD
65#else
66PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PGD)
67#endif
68BOOTBITMAP_SIZE = LOW_PAGES / 8
69ALLOCATOR_SLOP = 4
70
71INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE + (PAGE_TABLE_SIZE + ALLOCATOR_SLOP)*PAGE_SIZE_asm
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73/*
74 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
75 * %esi points to the real-mode code as a 32-bit pointer.
76 * CS and DS must be 4 GB flat segments, but we don't depend on
77 * any particular GDT layout, because we load our own as soon as we
78 * can.
79 */
Vivek Goyalf8657e12007-02-13 13:26:22 +010080.section .text.head,"ax",@progbits
Linus Torvalds1da177e2005-04-16 15:20:36 -070081ENTRY(startup_32)
Rusty Russella24e7852007-10-21 16:41:35 -070082 /* check to see if KEEP_SEGMENTS flag is meaningful */
83 cmpw $0x207, BP_version(%esi)
84 jb 1f
85
86 /* test KEEP_SEGMENTS flag to see if the bootloader is asking
87 us to not reload segments */
88 testb $(1<<6), BP_loadflags(%esi)
89 jnz 2f
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91/*
92 * Set segments to known values.
93 */
Rusty Russella24e7852007-10-21 16:41:35 -0700941: lgdt boot_gdt_descr - __PAGE_OFFSET
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 movl $(__BOOT_DS),%eax
96 movl %eax,%ds
97 movl %eax,%es
98 movl %eax,%fs
99 movl %eax,%gs
Rusty Russella24e7852007-10-21 16:41:35 -07001002:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102/*
103 * Clear BSS first so that there are no surprises...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 */
Rusty Russella24e7852007-10-21 16:41:35 -0700105 cld
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 xorl %eax,%eax
107 movl $__bss_start - __PAGE_OFFSET,%edi
108 movl $__bss_stop - __PAGE_OFFSET,%ecx
109 subl %edi,%ecx
110 shrl $2,%ecx
111 rep ; stosl
Vivek Goyal484b90c2005-09-03 15:56:31 -0700112/*
113 * Copy bootup parameters out of the way.
114 * Note: %esi still has the pointer to the real-mode data.
115 * With the kexec as boot loader, parameter segment might be loaded beyond
116 * kernel image and might not even be addressable by early boot page tables.
117 * (kexec on panic case). Hence copy out the parameters before initializing
118 * page tables.
119 */
120 movl $(boot_params - __PAGE_OFFSET),%edi
121 movl $(PARAM_SIZE/4),%ecx
122 cld
123 rep
124 movsl
125 movl boot_params - __PAGE_OFFSET + NEW_CL_POINTER,%esi
126 andl %esi,%esi
H. Peter Anvinfa76dab2007-10-23 22:37:25 +0200127 jz 1f # No comand line
Alon Bar-Lev4e498b62007-02-12 00:54:11 -0800128 movl $(boot_command_line - __PAGE_OFFSET),%edi
Vivek Goyal484b90c2005-09-03 15:56:31 -0700129 movl $(COMMAND_LINE_SIZE/4),%ecx
130 rep
131 movsl
1321:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Rusty Russella24e7852007-10-21 16:41:35 -0700134#ifdef CONFIG_PARAVIRT
135 cmpw $0x207, (boot_params + BP_version - __PAGE_OFFSET)
136 jb default_entry
137
138 /* Paravirt-compatible boot parameters. Look to see what architecture
139 we're booting under. */
140 movl (boot_params + BP_hardware_subarch - __PAGE_OFFSET), %eax
141 cmpl $num_subarch_entries, %eax
142 jae bad_subarch
143
144 movl subarch_entries - __PAGE_OFFSET(,%eax,4), %eax
145 subl $__PAGE_OFFSET, %eax
146 jmp *%eax
147
148bad_subarch:
149WEAK(lguest_entry)
150WEAK(xen_entry)
151 /* Unknown implementation; there's really
152 nothing we can do at this point. */
153 ud2a
154.data
155subarch_entries:
156 .long default_entry /* normal x86/PC */
157 .long lguest_entry /* lguest hypervisor */
158 .long xen_entry /* Xen hypervisor */
159num_subarch_entries = (. - subarch_entries) / 4
160.previous
161#endif /* CONFIG_PARAVIRT */
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163/*
164 * Initialize page tables. This creates a PDE and a set of page
165 * tables, which are located immediately beyond _end. The variable
166 * init_pg_tables_end is set up to point to the first "safe" location.
167 * Mappings are created both at virtual address 0 (identity mapping)
168 * and PAGE_OFFSET for up to _end+sizeof(page tables)+INIT_MAP_BEYOND_END.
169 *
170 * Warning: don't use %esi or the stack in this code. However, %esp
171 * can be used as a GPR if you really need it...
172 */
173page_pde_offset = (__PAGE_OFFSET >> 20);
174
Rusty Russella24e7852007-10-21 16:41:35 -0700175default_entry:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 movl $(pg0 - __PAGE_OFFSET), %edi
177 movl $(swapper_pg_dir - __PAGE_OFFSET), %edx
178 movl $0x007, %eax /* 0x007 = PRESENT+RW+USER */
17910:
180 leal 0x007(%edi),%ecx /* Create PDE entry */
181 movl %ecx,(%edx) /* Store identity PDE entry */
182 movl %ecx,page_pde_offset(%edx) /* Store kernel PDE entry */
183 addl $4,%edx
184 movl $1024, %ecx
18511:
186 stosl
187 addl $0x1000,%eax
188 loop 11b
189 /* End condition: we must map up to and including INIT_MAP_BEYOND_END */
190 /* bytes beyond the end of our own page tables; the +0x007 is the attribute bits */
191 leal (INIT_MAP_BEYOND_END+0x007)(%edi),%ebp
192 cmpl %ebp,%eax
193 jb 10b
194 movl %edi,(init_pg_tables_end - __PAGE_OFFSET)
195
Eric W. Biederman17d57a92007-12-01 18:34:06 -0700196 /* Do an early initialization of the fixmap area */
197 movl $(swapper_pg_dir - __PAGE_OFFSET), %edx
198 movl $(swapper_pg_pmd - __PAGE_OFFSET), %eax
Rusty Russell476c6c12008-01-01 21:48:36 +1100199 addl $0x67, %eax /* 0x67 == _PAGE_TABLE */
Eric W. Biederman17d57a92007-12-01 18:34:06 -0700200 movl %eax, 4092(%edx)
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 jmp 3f
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203/*
204 * Non-boot CPU entry point; entered from trampoline.S
205 * We can't lgdt here, because lgdt itself uses a data segment, but
Sebastien Dugue52de74d2007-05-02 19:27:10 +0200206 * we know the trampoline has already loaded the boot_gdt for us.
Vivek Goyalf8657e12007-02-13 13:26:22 +0100207 *
208 * If cpu hotplug is not supported then this code can go in init section
209 * which will be freed later
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 */
Vivek Goyalf8657e12007-02-13 13:26:22 +0100211
Andi Kleen5fe44862007-08-10 22:31:10 +0200212#ifndef CONFIG_HOTPLUG_CPU
Vivek Goyalf8657e12007-02-13 13:26:22 +0100213.section .init.text,"ax",@progbits
214#endif
215
216#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217ENTRY(startup_32_smp)
218 cld
219 movl $(__BOOT_DS),%eax
220 movl %eax,%ds
221 movl %eax,%es
222 movl %eax,%fs
223 movl %eax,%gs
Ian Campbell5756dd52008-01-30 13:33:27 +0100224#endif /* CONFIG_SMP */
2253:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227/*
228 * New page tables may be in 4Mbyte page mode and may
229 * be using the global pages.
230 *
231 * NOTE! If we are on a 486 we may have no cr4 at all!
232 * So we do not try to touch it unless we really have
233 * some bits in it to set. This won't work if the BSP
234 * implements cr4 but this AP does not -- very unlikely
235 * but be warned! The same applies to the pse feature
236 * if not equally supported. --macro
237 *
238 * NOTE! We have to correct for the fact that we're
239 * not yet offset PAGE_OFFSET..
240 */
241#define cr4_bits mmu_cr4_features-__PAGE_OFFSET
242 movl cr4_bits,%edx
243 andl %edx,%edx
244 jz 6f
245 movl %cr4,%eax # Turn on paging options (PSE,PAE,..)
246 orl %edx,%eax
247 movl %eax,%cr4
248
249 btl $5, %eax # check if PAE is enabled
250 jnc 6f
251
252 /* Check if extended functions are implemented */
253 movl $0x80000000, %eax
254 cpuid
255 cmpl $0x80000000, %eax
256 jbe 6f
257 mov $0x80000001, %eax
258 cpuid
259 /* Execute Disable bit supported? */
260 btl $20, %edx
261 jnc 6f
262
263 /* Setup EFER (Extended Feature Enable Register) */
264 movl $0xc0000080, %ecx
265 rdmsr
266
267 btsl $11, %eax
268 /* Make changes effective */
269 wrmsr
270
2716:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273/*
274 * Enable paging
275 */
276 movl $swapper_pg_dir-__PAGE_OFFSET,%eax
277 movl %eax,%cr3 /* set the page table pointer.. */
278 movl %cr0,%eax
279 orl $0x80000000,%eax
280 movl %eax,%cr0 /* ..and set paging (PG) bit */
281 ljmp $__BOOT_CS,$1f /* Clear prefetch and normalize %eip */
2821:
283 /* Set up the stack pointer */
284 lss stack_start,%esp
285
286/*
287 * Initialize eflags. Some BIOS's leave bits like NT set. This would
288 * confuse the debugger if this code is traced.
289 * XXX - best to initialize before switching to protected mode.
290 */
291 pushl $0
292 popfl
293
294#ifdef CONFIG_SMP
Ian Campbell50359502008-01-30 13:33:27 +0100295 cmpb $0, ready
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 jz 1f /* Initial CPU cleans BSS */
297 jmp checkCPUtype
2981:
299#endif /* CONFIG_SMP */
300
301/*
302 * start system 32-bit setup. We need to re-do some of the things done
303 * in 16-bit mode for the "real" operations.
304 */
305 call setup_idt
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307checkCPUtype:
308
309 movl $-1,X86_CPUID # -1 for no CPUID initially
310
311/* check if it is 486 or 386. */
312/*
313 * XXX - this does a lot of unnecessary setup. Alignment checks don't
314 * apply at our cpl of 0 and the stack ought to be aligned already, and
315 * we don't need to preserve eflags.
316 */
317
318 movb $3,X86 # at least 386
319 pushfl # push EFLAGS
320 popl %eax # get EFLAGS
321 movl %eax,%ecx # save original EFLAGS
322 xorl $0x240000,%eax # flip AC and ID bits in EFLAGS
323 pushl %eax # copy to EFLAGS
324 popfl # set EFLAGS
325 pushfl # get new EFLAGS
326 popl %eax # put it in eax
327 xorl %ecx,%eax # change in flags
328 pushl %ecx # restore original EFLAGS
329 popfl
330 testl $0x40000,%eax # check if AC bit changed
331 je is386
332
333 movb $4,X86 # at least 486
334 testl $0x200000,%eax # check if ID bit changed
335 je is486
336
337 /* get vendor info */
338 xorl %eax,%eax # call CPUID with 0 -> return vendor ID
339 cpuid
340 movl %eax,X86_CPUID # save CPUID level
341 movl %ebx,X86_VENDOR_ID # lo 4 chars
342 movl %edx,X86_VENDOR_ID+4 # next 4 chars
343 movl %ecx,X86_VENDOR_ID+8 # last 4 chars
344
345 orl %eax,%eax # do we have processor info as well?
346 je is486
347
348 movl $1,%eax # Use the CPUID instruction to get CPU type
349 cpuid
350 movb %al,%cl # save reg for future use
351 andb $0x0f,%ah # mask processor family
352 movb %ah,X86
353 andb $0xf0,%al # mask model
354 shrb $4,%al
355 movb %al,X86_MODEL
356 andb $0x0f,%cl # mask mask revision
357 movb %cl,X86_MASK
358 movl %edx,X86_CAPABILITY
359
360is486: movl $0x50022,%ecx # set AM, WP, NE and MP
361 jmp 2f
362
363is386: movl $2,%ecx # set MP
3642: movl %cr0,%eax
365 andl $0x80000011,%eax # Save PG,PE,ET
366 orl %ecx,%eax
367 movl %eax,%cr0
368
369 call check_x87
Rusty Russell2a57ff12007-02-13 13:26:26 +0100370 lgdt early_gdt_descr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 lidt idt_descr
372 ljmp $(__KERNEL_CS),$1f
3731: movl $(__KERNEL_DS),%eax # reload all the segment registers
374 movl %eax,%ss # after changing gdt.
Jeremy Fitzhardinge7c3576d2007-05-02 19:27:16 +0200375 movl %eax,%fs # gets reset once there's real percpu
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 movl $(__USER_DS),%eax # DS/ES contains default USER segment
378 movl %eax,%ds
379 movl %eax,%es
380
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100381 xorl %eax,%eax # Clear GS and LDT
382 movl %eax,%gs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 lldt %ax
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 cld # gcc2 wants the direction flag cleared at all times
Jeremy Fitzhardinge26fd5e02006-10-21 18:37:02 +0200386 pushl $0 # fake return address for unwinder
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#ifdef CONFIG_SMP
Shaohua Lid92de652005-06-25 14:54:49 -0700388 movb ready, %cl
389 movb $1, ready
Andi Kleen29fe5f32006-08-30 19:37:09 +0200390 cmpb $0,%cl # the first CPU calls start_kernel
Jeremy Fitzhardinge7c3576d2007-05-02 19:27:16 +0200391 je 1f
392 movl $(__KERNEL_PERCPU), %eax
393 movl %eax,%fs # set this cpu's percpu
394 jmp initialize_secondary # all other CPUs call initialize_secondary
3951:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396#endif /* CONFIG_SMP */
Andi Kleen29fe5f32006-08-30 19:37:09 +0200397 jmp start_kernel
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399/*
400 * We depend on ET to be correct. This checks for 287/387.
401 */
402check_x87:
403 movb $0,X86_HARD_MATH
404 clts
405 fninit
406 fstsw %ax
407 cmpb $0,%al
408 je 1f
409 movl %cr0,%eax /* no coprocessor: have to set bits */
410 xorl $4,%eax /* set EM */
411 movl %eax,%cr0
412 ret
413 ALIGN
4141: movb $1,X86_HARD_MATH
415 .byte 0xDB,0xE4 /* fsetpm for 287, ignored by 387 */
416 ret
417
418/*
419 * setup_idt
420 *
421 * sets up a idt with 256 entries pointing to
422 * ignore_int, interrupt gates. It doesn't actually load
423 * idt - that can be done only after paging has been enabled
424 * and the kernel moved to PAGE_OFFSET. Interrupts
425 * are enabled elsewhere, when we can be relatively
426 * sure everything is ok.
427 *
428 * Warning: %esi is live across this function.
429 */
430setup_idt:
431 lea ignore_int,%edx
432 movl $(__KERNEL_CS << 16),%eax
433 movw %dx,%ax /* selector = 0x0010 = cs */
434 movw $0x8E00,%dx /* interrupt gate - dpl=0, present */
435
436 lea idt_table,%edi
437 mov $256,%ecx
438rp_sidt:
439 movl %eax,(%edi)
440 movl %edx,4(%edi)
441 addl $8,%edi
442 dec %ecx
443 jne rp_sidt
Chuck Ebbertec5c0922006-09-26 10:52:39 +0200444
445.macro set_early_handler handler,trapno
446 lea \handler,%edx
447 movl $(__KERNEL_CS << 16),%eax
448 movw %dx,%ax
449 movw $0x8E00,%dx /* interrupt gate - dpl=0, present */
450 lea idt_table,%edi
451 movl %eax,8*\trapno(%edi)
452 movl %edx,8*\trapno+4(%edi)
453.endm
454
455 set_early_handler handler=early_divide_err,trapno=0
456 set_early_handler handler=early_illegal_opcode,trapno=6
457 set_early_handler handler=early_protection_fault,trapno=13
458 set_early_handler handler=early_page_fault,trapno=14
459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 ret
461
Chuck Ebbertec5c0922006-09-26 10:52:39 +0200462early_divide_err:
463 xor %edx,%edx
464 pushl $0 /* fake errcode */
465 jmp early_fault
466
467early_illegal_opcode:
468 movl $6,%edx
469 pushl $0 /* fake errcode */
470 jmp early_fault
471
472early_protection_fault:
473 movl $13,%edx
474 jmp early_fault
475
476early_page_fault:
477 movl $14,%edx
478 jmp early_fault
479
480early_fault:
481 cld
482#ifdef CONFIG_PRINTK
Ingo Molnar382f64a2007-10-17 18:04:41 +0200483 pusha
Chuck Ebbertec5c0922006-09-26 10:52:39 +0200484 movl $(__KERNEL_DS),%eax
485 movl %eax,%ds
486 movl %eax,%es
487 cmpl $2,early_recursion_flag
488 je hlt_loop
489 incl early_recursion_flag
490 movl %cr2,%eax
491 pushl %eax
492 pushl %edx /* trapno */
493 pushl $fault_msg
494#ifdef CONFIG_EARLY_PRINTK
495 call early_printk
496#else
497 call printk
498#endif
499#endif
Ingo Molnar94878ef2008-01-30 13:33:09 +0100500 call dump_stack
Chuck Ebbertec5c0922006-09-26 10:52:39 +0200501hlt_loop:
502 hlt
503 jmp hlt_loop
504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505/* This is the default interrupt "handler" :-) */
506 ALIGN
507ignore_int:
508 cld
Matt Mackalld59745c2005-05-01 08:59:02 -0700509#ifdef CONFIG_PRINTK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 pushl %eax
511 pushl %ecx
512 pushl %edx
513 pushl %es
514 pushl %ds
515 movl $(__KERNEL_DS),%eax
516 movl %eax,%ds
517 movl %eax,%es
Chuck Ebbertec5c0922006-09-26 10:52:39 +0200518 cmpl $2,early_recursion_flag
519 je hlt_loop
520 incl early_recursion_flag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 pushl 16(%esp)
522 pushl 24(%esp)
523 pushl 32(%esp)
524 pushl 40(%esp)
525 pushl $int_msg
Ingo Molnarc0cdf192006-02-11 17:55:56 -0800526#ifdef CONFIG_EARLY_PRINTK
527 call early_printk
528#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 call printk
Ingo Molnarc0cdf192006-02-11 17:55:56 -0800530#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 addl $(5*4),%esp
532 popl %ds
533 popl %es
534 popl %edx
535 popl %ecx
536 popl %eax
Matt Mackalld59745c2005-05-01 08:59:02 -0700537#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 iret
539
Vivek Goyalf8657e12007-02-13 13:26:22 +0100540.section .text
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541/*
542 * Real beginning of normal "text" segment
543 */
544ENTRY(stext)
545ENTRY(_stext)
546
547/*
548 * BSS section
549 */
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700550.section ".bss.page_aligned","wa"
551 .align PAGE_SIZE_asm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552ENTRY(swapper_pg_dir)
553 .fill 1024,4,0
Eric W. Bidermanb1c931e2007-07-15 23:37:28 -0700554ENTRY(swapper_pg_pmd)
555 .fill 1024,4,0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556ENTRY(empty_zero_page)
557 .fill 4096,1,0
558
559/*
560 * This starts the data section.
561 */
562.data
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563ENTRY(stack_start)
564 .long init_thread_union+THREAD_SIZE
565 .long __BOOT_DS
566
567ready: .byte 0
568
Chuck Ebbertec5c0922006-09-26 10:52:39 +0200569early_recursion_flag:
570 .long 0
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572int_msg:
573 .asciz "Unknown interrupt or fault at EIP %p %p %p\n"
574
Chuck Ebbertec5c0922006-09-26 10:52:39 +0200575fault_msg:
Ingo Molnar382f64a2007-10-17 18:04:41 +0200576 .ascii \
577/* fault info: */ "BUG: Int %d: CR2 %p\n" \
578/* pusha regs: */ " EDI %p ESI %p EBP %p ESP %p\n" \
579 " EBX %p EDX %p ECX %p EAX %p\n" \
580/* fault frame: */ " err %p EIP %p CS %p flg %p\n" \
581 \
582 "Stack: %p %p %p %p %p %p %p %p\n" \
583 " %p %p %p %p %p %p %p %p\n" \
584 " %p %p %p %p %p %p %p %p\n"
Chuck Ebbertec5c0922006-09-26 10:52:39 +0200585
Thomas Gleixner97027852007-10-11 11:16:51 +0200586#include "../../x86/xen/xen-head.S"
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588/*
589 * The IDT and GDT 'descriptors' are a strange 48-bit object
590 * only used by the lidt and lgdt instructions. They are not
591 * like usual segment descriptors - they consist of a 16-bit
592 * segment size, and 32-bit linear address value:
593 */
594
595.globl boot_gdt_descr
596.globl idt_descr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 ALIGN
599# early boot GDT descriptor (must use 1:1 address mapping)
600 .word 0 # 32 bit align gdt_desc.address
601boot_gdt_descr:
602 .word __BOOT_DS+7
Sebastien Dugue52de74d2007-05-02 19:27:10 +0200603 .long boot_gdt - __PAGE_OFFSET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 .word 0 # 32-bit align idt_desc.address
606idt_descr:
607 .word IDT_ENTRIES*8-1 # idt contains 256 entries
608 .long idt_table
609
610# boot GDT descriptor (later on used by CPU#0):
611 .word 0 # 32 bit align gdt_desc.address
Rusty Russell2a57ff12007-02-13 13:26:26 +0100612ENTRY(early_gdt_descr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 .word GDT_ENTRIES*8-1
Jeremy Fitzhardinge7a61d352007-05-02 19:27:15 +0200614 .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616/*
Sebastien Dugue52de74d2007-05-02 19:27:10 +0200617 * The boot_gdt must mirror the equivalent in setup.S and is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 * used only for booting.
619 */
620 .align L1_CACHE_BYTES
Sebastien Dugue52de74d2007-05-02 19:27:10 +0200621ENTRY(boot_gdt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 .fill GDT_ENTRY_BOOT_CS,8,0
623 .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
624 .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */