1
2
3
4
5
6
7
8
9
10.text
11#include <linux/threads.h>
12#include <linux/init.h>
13#include <linux/linkage.h>
14#include <asm/segment.h>
15#include <asm/page_types.h>
16#include <asm/pgtable_types.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/msr-index.h>
23#include <asm/cpufeatures.h>
24#include <asm/percpu.h>
25#include <asm/nops.h>
26#include <asm/bootparam.h>
27#include <asm/export.h>
28#include <asm/pgtable_32.h>
29
30
31#define pa(X) ((X) - __PAGE_OFFSET)
32
33
34
35
36
37#define X86 new_cpu_data+CPUINFO_x86
38#define X86_VENDOR new_cpu_data+CPUINFO_x86_vendor
39#define X86_MODEL new_cpu_data+CPUINFO_x86_model
40#define X86_STEPPING new_cpu_data+CPUINFO_x86_stepping
41#define X86_HARD_MATH new_cpu_data+CPUINFO_hard_math
42#define X86_CPUID new_cpu_data+CPUINFO_cpuid_level
43#define X86_CAPABILITY new_cpu_data+CPUINFO_x86_capability
44#define X86_VENDOR_ID new_cpu_data+CPUINFO_x86_vendor_id
45
46
47#define SIZEOF_PTREGS 17*4
48
49
50
51
52
53
54KERNEL_PAGES = LOWMEM_PAGES
55
56INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
57RESERVE_BRK(pagetables, INIT_MAP_SIZE)
58
59
60
61
62
63
64
65
66__HEAD
67SYM_CODE_START(startup_32)
68 movl pa(initial_stack),%ecx
69
70
71
72
73 lgdt pa(boot_gdt_descr)
74 movl $(__BOOT_DS),%eax
75 movl %eax,%ds
76 movl %eax,%es
77 movl %eax,%fs
78 movl %eax,%gs
79 movl %eax,%ss
80 leal -__PAGE_OFFSET(%ecx),%esp
81
82
83
84
85 cld
86 xorl %eax,%eax
87 movl $pa(__bss_start),%edi
88 movl $pa(__bss_stop),%ecx
89 subl %edi,%ecx
90 shrl $2,%ecx
91 rep ; stosl
92
93
94
95
96
97
98
99
100 movl $pa(boot_params),%edi
101 movl $(PARAM_SIZE/4),%ecx
102 cld
103 rep
104 movsl
105 movl pa(boot_params) + NEW_CL_POINTER,%esi
106 andl %esi,%esi
107 jz 1f
108 movl $pa(boot_command_line),%edi
109 movl $(COMMAND_LINE_SIZE/4),%ecx
110 rep
111 movsl
1121:
113
114#ifdef CONFIG_OLPC
115
116 movl %cr3, %eax
117 movl %eax, pa(olpc_ofw_pgd)
118#endif
119
120#ifdef CONFIG_MICROCODE
121
122 call load_ucode_bsp
123#endif
124
125
126 call mk_early_pgtbl_32
127
128
129 movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
130#ifdef CONFIG_X86_PAE
131#define KPMDS (((-__PAGE_OFFSET) >> 30) & 3)
132 movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
133#else
134 movl %eax,pa(initial_page_table+0xffc)
135#endif
136
137#ifdef CONFIG_PARAVIRT
138
139 cmpw $0x207, pa(boot_params + BP_version)
140 jb .Ldefault_entry
141
142
143
144 movl pa(boot_params + BP_hardware_subarch), %eax
145 cmpl $num_subarch_entries, %eax
146 jae .Lbad_subarch
147
148 movl pa(subarch_entries)(,%eax,4), %eax
149 subl $__PAGE_OFFSET, %eax
150 jmp *%eax
151
152.Lbad_subarch:
153SYM_INNER_LABEL_ALIGN(xen_entry, SYM_L_WEAK)
154
155
156 ud2a
157
158 __INITDATA
159
160subarch_entries:
161 .long .Ldefault_entry
162 .long xen_entry
163 .long .Ldefault_entry
164num_subarch_entries = (. - subarch_entries) / 4
165.previous
166#else
167 jmp .Ldefault_entry
168#endif
169SYM_CODE_END(startup_32)
170
171#ifdef CONFIG_HOTPLUG_CPU
172
173
174
175
176
177SYM_FUNC_START(start_cpu0)
178 movl initial_stack, %ecx
179 movl %ecx, %esp
180 call *(initial_code)
1811: jmp 1b
182SYM_FUNC_END(start_cpu0)
183#endif
184
185
186
187
188
189
190
191
192
193SYM_FUNC_START(startup_32_smp)
194 cld
195 movl $(__BOOT_DS),%eax
196 movl %eax,%ds
197 movl %eax,%es
198 movl %eax,%fs
199 movl %eax,%gs
200 movl pa(initial_stack),%ecx
201 movl %eax,%ss
202 leal -__PAGE_OFFSET(%ecx),%esp
203
204#ifdef CONFIG_MICROCODE
205
206 call load_ucode_ap
207#endif
208
209.Ldefault_entry:
210 movl $(CR0_STATE & ~X86_CR0_PG),%eax
211 movl %eax,%cr0
212
213
214
215
216
217
218
219
220 pushl $0
221 popfl
222
223
224
225
226
227
228
229 movl $-1,pa(X86_CPUID)
230 movl $X86_EFLAGS_ID,%ecx
231 pushl %ecx
232 popfl
233 pushfl
234 popl %eax
235 testl $X86_EFLAGS_ID,%eax
236 jz .Lenable_paging
237
238
239 xorl %eax,%eax
240 cpuid
241 movl %eax,pa(X86_CPUID)
242
243 movl $1,%eax
244 cpuid
245 andl $~1,%edx
246 jz .Lenable_paging
247
248 movl pa(mmu_cr4_features),%eax
249 movl %eax,%cr4
250
251 testb $X86_CR4_PAE, %al
252 jz .Lenable_paging
253
254
255 movl $0x80000000, %eax
256 cpuid
257
258 subl $0x80000001, %eax
259 cmpl $(0x8000ffff-0x80000001), %eax
260 ja .Lenable_paging
261
262
263 call verify_cpu
264
265 mov $0x80000001, %eax
266 cpuid
267
268 btl $(X86_FEATURE_NX & 31), %edx
269 jnc .Lenable_paging
270
271
272 movl $MSR_EFER, %ecx
273 rdmsr
274
275 btsl $_EFER_NX, %eax
276
277 wrmsr
278
279.Lenable_paging:
280
281
282
283
284 movl $pa(initial_page_table), %eax
285 movl %eax,%cr3
286 movl $CR0_STATE,%eax
287 movl %eax,%cr0
288 ljmp $__BOOT_CS,$1f
2891:
290
291 addl $__PAGE_OFFSET, %esp
292
293
294
295
296
297 movl setup_once_ref,%eax
298 andl %eax,%eax
299 jz 1f
300 call *%eax
3011:
302
303
304
305
306 movb $4,X86
307 cmpl $-1,X86_CPUID
308 je .Lis486
309
310
311 xorl %eax,%eax
312 cpuid
313 movl %eax,X86_CPUID
314 movl %ebx,X86_VENDOR_ID
315 movl %edx,X86_VENDOR_ID+4
316 movl %ecx,X86_VENDOR_ID+8
317
318 orl %eax,%eax
319 je .Lis486
320
321 movl $1,%eax
322 cpuid
323 movb %al,%cl
324 andb $0x0f,%ah
325 movb %ah,X86
326 andb $0xf0,%al
327 shrb $4,%al
328 movb %al,X86_MODEL
329 andb $0x0f,%cl
330 movb %cl,X86_STEPPING
331 movl %edx,X86_CAPABILITY
332
333.Lis486:
334 movl $0x50022,%ecx
335 movl %cr0,%eax
336 andl $0x80000011,%eax
337 orl %ecx,%eax
338 movl %eax,%cr0
339
340 lgdt early_gdt_descr
341 ljmp $(__KERNEL_CS),$1f
3421: movl $(__KERNEL_DS),%eax
343 movl %eax,%ss
344
345 movl $(__USER_DS),%eax
346 movl %eax,%ds
347 movl %eax,%es
348
349 movl $(__KERNEL_PERCPU), %eax
350 movl %eax,%fs
351
352 movl $(__KERNEL_STACK_CANARY),%eax
353 movl %eax,%gs
354
355 xorl %eax,%eax
356 lldt %ax
357
358 call *(initial_code)
3591: jmp 1b
360SYM_FUNC_END(startup_32_smp)
361
362#include "verify_cpu.S"
363
364
365
366
367
368
369
370
371__INIT
372setup_once:
373#ifdef CONFIG_STACKPROTECTOR
374
375
376
377
378
379 movl $gdt_page,%eax
380 movl $stack_canary,%ecx
381 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
382 shrl $16, %ecx
383 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
384 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
385#endif
386
387 andl $0,setup_once_ref
388 ret
389
390SYM_FUNC_START(early_idt_handler_array)
391
392
393
394
395 i = 0
396 .rept NUM_EXCEPTION_VECTORS
397 .if ((EXCEPTION_ERRCODE_MASK >> i) & 1) == 0
398 pushl $0
399 .endif
400 pushl $i
401 jmp early_idt_handler_common
402 i = i + 1
403 .fill early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
404 .endr
405SYM_FUNC_END(early_idt_handler_array)
406
407SYM_CODE_START_LOCAL(early_idt_handler_common)
408
409
410
411
412 cld
413
414 incl %ss:early_recursion_flag
415
416
417
418 cld
419 pushl %fs
420 pushl %es
421 pushl %ds
422 pushl %eax
423 pushl %ebp
424 pushl %edi
425 pushl %esi
426 pushl %edx
427 pushl %ecx
428 pushl %ebx
429
430
431 movl $(__KERNEL_DS), %ecx
432 movl %ecx, %ds
433 movl %ecx, %es
434
435
436 movl PT_GS(%esp), %edx
437
438
439 movw %gs, PT_GS(%esp)
440
441 movl %esp, %eax
442 call early_fixup_exception
443
444 popl %ebx
445 popl %ecx
446 popl %edx
447 popl %esi
448 popl %edi
449 popl %ebp
450 popl %eax
451 popl %ds
452 popl %es
453 popl %fs
454 popl %gs
455 decl %ss:early_recursion_flag
456 addl $4, %esp
457 iret
458SYM_CODE_END(early_idt_handler_common)
459
460
461SYM_FUNC_START(early_ignore_irq)
462 cld
463#ifdef CONFIG_PRINTK
464 pushl %eax
465 pushl %ecx
466 pushl %edx
467 pushl %es
468 pushl %ds
469 movl $(__KERNEL_DS),%eax
470 movl %eax,%ds
471 movl %eax,%es
472 cmpl $2,early_recursion_flag
473 je hlt_loop
474 incl early_recursion_flag
475 pushl 16(%esp)
476 pushl 24(%esp)
477 pushl 32(%esp)
478 pushl 40(%esp)
479 pushl $int_msg
480 call printk
481
482 call dump_stack
483
484 addl $(5*4),%esp
485 popl %ds
486 popl %es
487 popl %edx
488 popl %ecx
489 popl %eax
490#endif
491 iret
492
493hlt_loop:
494 hlt
495 jmp hlt_loop
496SYM_FUNC_END(early_ignore_irq)
497
498__INITDATA
499 .align 4
500SYM_DATA(early_recursion_flag, .long 0)
501
502__REFDATA
503 .align 4
504SYM_DATA(initial_code, .long i386_start_kernel)
505SYM_DATA(setup_once_ref, .long setup_once)
506
507#ifdef CONFIG_PAGE_TABLE_ISOLATION
508#define PGD_ALIGN (2 * PAGE_SIZE)
509#define PTI_USER_PGD_FILL 1024
510#else
511#define PGD_ALIGN (PAGE_SIZE)
512#define PTI_USER_PGD_FILL 0
513#endif
514
515
516
517__PAGE_ALIGNED_BSS
518 .align PGD_ALIGN
519#ifdef CONFIG_X86_PAE
520.globl initial_pg_pmd
521initial_pg_pmd:
522 .fill 1024*KPMDS,4,0
523#else
524.globl initial_page_table
525initial_page_table:
526 .fill 1024,4,0
527#endif
528 .align PGD_ALIGN
529initial_pg_fixmap:
530 .fill 1024,4,0
531.globl swapper_pg_dir
532 .align PGD_ALIGN
533swapper_pg_dir:
534 .fill 1024,4,0
535 .fill PTI_USER_PGD_FILL,4,0
536.globl empty_zero_page
537empty_zero_page:
538 .fill 4096,1,0
539EXPORT_SYMBOL(empty_zero_page)
540
541
542
543
544#ifdef CONFIG_X86_PAE
545__PAGE_ALIGNED_DATA
546
547 .align PGD_ALIGN
548SYM_DATA_START(initial_page_table)
549 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0
550
551 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0
552 .long pa(initial_pg_pmd+PGD_IDENT_ATTR+0x1000),0
553 .long pa(initial_pg_pmd+PGD_IDENT_ATTR+0x2000),0
554
555 .long 0,0
556 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0
557 .long pa(initial_pg_pmd+PGD_IDENT_ATTR+0x1000),0
558
559 .long 0,0
560 .long 0,0
561 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0
562# else
563
564# endif
565 .align PAGE_SIZE
566
567#ifdef CONFIG_PAGE_TABLE_ISOLATION
568
569
570
571
572
573 .fill 1024, 4, 0
574#endif
575
576SYM_DATA_END(initial_page_table)
577#endif
578
579.data
580.balign 4
581
582
583
584
585SYM_DATA(initial_stack,
586 .long init_thread_union + THREAD_SIZE -
587 SIZEOF_PTREGS - TOP_OF_KERNEL_STACK_PADDING)
588
589__INITRODATA
590int_msg:
591 .asciz "Unknown interrupt or fault at: %p %p %p\n"
592
593#include "../../x86/xen/xen-head.S"
594
595
596
597
598
599
600
601
602 .data
603 ALIGN
604
605 .word 0
606SYM_DATA_START_LOCAL(boot_gdt_descr)
607 .word __BOOT_DS+7
608 .long boot_gdt - __PAGE_OFFSET
609SYM_DATA_END(boot_gdt_descr)
610
611
612 .word 0
613SYM_DATA_START(early_gdt_descr)
614 .word GDT_ENTRIES*8-1
615 .long gdt_page
616SYM_DATA_END(early_gdt_descr)
617
618
619
620
621
622 .align L1_CACHE_BYTES
623SYM_DATA_START(boot_gdt)
624 .fill GDT_ENTRY_BOOT_CS,8,0
625 .quad 0x00cf9a000000ffff
626 .quad 0x00cf92000000ffff
627SYM_DATA_END(boot_gdt)
628