]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i386/i386/locore.s
Move most of the contents of opt_compat.h to opt_global.h.
[FreeBSD/FreeBSD.git] / sys / i386 / i386 / locore.s
1 /*-
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * William Jolitz.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *      from: @(#)locore.s      7.3 (Berkeley) 5/13/91
33  * $FreeBSD$
34  *
35  *              originally from: locore.s, by William F. Jolitz
36  *
37  *              Substantially rewritten by David Greenman, Rod Grimes,
38  *                      Bruce Evans, Wolfgang Solfrank, Poul-Henning Kamp
39  *                      and many others.
40  */
41
42 #include "opt_bootp.h"
43 #include "opt_nfsroot.h"
44 #include "opt_pmap.h"
45
46 #include <sys/reboot.h>
47
48 #include <machine/asmacros.h>
49 #include <machine/cputypes.h>
50 #include <machine/psl.h>
51 #include <machine/pmap.h>
52 #include <machine/specialreg.h>
53
54 #include "assym.inc"
55
56 /*
57  *      XXX
58  *
59  * Note: This version greatly munged to avoid various assembler errors
60  * that may be fixed in newer versions of gas. Perhaps newer versions
61  * will have more pleasant appearance.
62  */
63
64 /*
65  * PTmap is recursive pagemap at top of virtual address space.
66  * Within PTmap, the page directory can be found (third indirection).
67  */
68         .globl  PTmap,PTD,PTDpde
69         .set    PTmap,(PTDPTDI << PDRSHIFT)
70         .set    PTD,PTmap + (PTDPTDI * PAGE_SIZE)
71         .set    PTDpde,PTD + (PTDPTDI * PDESIZE)
72
73 /*
74  * Compiled KERNBASE location and the kernel load address
75  */
76         .globl  kernbase
77         .set    kernbase,KERNBASE
78         .globl  kernload
79         .set    kernload,KERNLOAD
80
81 /*
82  * Globals
83  */
84         .data
85         ALIGN_DATA                      /* just to be sure */
86
87         .space  0x2000                  /* space for tmpstk - temporary stack */
88 tmpstk:
89
90         .globl  bootinfo
91 bootinfo:       .space  BOOTINFO_SIZE   /* bootinfo that we can handle */
92
93                 .globl KERNend
94 KERNend:        .long   0               /* phys addr end of kernel (just after bss) */
95 physfree:       .long   0               /* phys addr of next free page */
96
97         .globl  IdlePTD
98 IdlePTD:        .long   0               /* phys addr of kernel PTD */
99
100 #if defined(PAE) || defined(PAE_TABLES)
101         .globl  IdlePDPT
102 IdlePDPT:       .long   0               /* phys addr of kernel PDPT */
103 #endif
104
105         .globl  KPTmap
106 KPTmap:         .long   0               /* address of kernel page tables */
107
108         .globl  KPTphys
109 KPTphys:        .long   0               /* phys addr of kernel page tables */
110
111         .globl  proc0kstack
112 proc0kstack:    .long   0               /* address of proc 0 kstack space */
113 p0kpa:          .long   0               /* phys addr of proc0's STACK */
114
115 vm86phystk:     .long   0               /* PA of vm86/bios stack */
116
117         .globl  vm86paddr, vm86pa
118 vm86paddr:      .long   0               /* address of vm86 region */
119 vm86pa:         .long   0               /* phys addr of vm86 region */
120
121 /**********************************************************************
122  *
123  * Some handy macros
124  *
125  */
126
127 #define R(foo) ((foo)-KERNBASE)
128
129 #define ALLOCPAGES(foo) \
130         movl    R(physfree), %esi ; \
131         movl    $((foo)*PAGE_SIZE), %eax ; \
132         addl    %esi, %eax ; \
133         movl    %eax, R(physfree) ; \
134         movl    %esi, %edi ; \
135         movl    $((foo)*PAGE_SIZE),%ecx ; \
136         xorl    %eax,%eax ; \
137         cld ; \
138         rep ; \
139         stosb
140
141 /*
142  * fillkpt
143  *      eax = page frame address
144  *      ebx = index into page table
145  *      ecx = how many pages to map
146  *      base = base address of page dir/table
147  *      prot = protection bits
148  */
149 #define fillkpt(base, prot)               \
150         shll    $PTESHIFT,%ebx          ; \
151         addl    base,%ebx               ; \
152         orl     $PG_V,%eax              ; \
153         orl     prot,%eax               ; \
154 1:      movl    %eax,(%ebx)             ; \
155         addl    $PAGE_SIZE,%eax         ; /* increment physical address */ \
156         addl    $PTESIZE,%ebx           ; /* next pte */ \
157         loop    1b
158
159 /*
160  * fillkptphys(prot)
161  *      eax = physical address
162  *      ecx = how many pages to map
163  *      prot = protection bits
164  */
165 #define fillkptphys(prot)                 \
166         movl    %eax, %ebx              ; \
167         shrl    $PAGE_SHIFT, %ebx       ; \
168         fillkpt(R(KPTphys), prot)
169
170         .text
171 /**********************************************************************
172  *
173  * This is where the bootblocks start us, set the ball rolling...
174  *
175  */
176 NON_GPROF_ENTRY(btext)
177
178 /* Tell the bios to warmboot next time */
179         movw    $0x1234,0x472
180
181 /* Set up a real frame in case the double return in newboot is executed. */
182         pushl   %ebp
183         movl    %esp, %ebp
184
185 /* Don't trust what the BIOS gives for eflags. */
186         pushl   $PSL_KERNEL
187         popfl
188
189 /*
190  * Don't trust what the BIOS gives for %fs and %gs.  Trust the bootstrap
191  * to set %cs, %ds, %es and %ss.
192  */
193         mov     %ds, %ax
194         mov     %ax, %fs
195         mov     %ax, %gs
196
197 /*
198  * Clear the bss.  Not all boot programs do it, and it is our job anyway.
199  *
200  * XXX we don't check that there is memory for our bss and page tables
201  * before using it.
202  *
203  * Note: we must be careful to not overwrite an active gdt or idt.  They
204  * inactive from now until we switch to new ones, since we don't load any
205  * more segment registers or permit interrupts until after the switch.
206  */
207         movl    $R(end),%ecx
208         movl    $R(edata),%edi
209         subl    %edi,%ecx
210         xorl    %eax,%eax
211         cld
212         rep
213         stosb
214
215         call    recover_bootinfo
216
217 /* Get onto a stack that we can trust. */
218 /*
219  * XXX this step is delayed in case recover_bootinfo needs to return via
220  * the old stack, but it need not be, since recover_bootinfo actually
221  * returns via the old frame.
222  */
223         movl    $R(tmpstk),%esp
224
225         call    identify_cpu
226         call    create_pagetables
227
228 /*
229  * If the CPU has support for VME, turn it on.
230  */ 
231         testl   $CPUID_VME, R(cpu_feature)
232         jz      1f
233         movl    %cr4, %eax
234         orl     $CR4_VME, %eax
235         movl    %eax, %cr4
236 1:
237
238 /* Now enable paging */
239 #if defined(PAE) || defined(PAE_TABLES)
240         movl    R(IdlePDPT), %eax
241         movl    %eax, %cr3
242         movl    %cr4, %edx
243         orl     $CR4_PAE, %edx
244         movl    %edx, %cr4
245 #else
246         movl    R(IdlePTD), %eax
247         movl    %eax,%cr3               /* load ptd addr into mmu */
248 #endif
249         movl    %cr0,%edx               /* get control word */
250         orl     $CR0_PE|CR0_PG,%edx     /* enable paging */
251         movl    %edx,%cr0               /* and let's page NOW! */
252
253         pushl   $begin                  /* jump to high virtualized address */
254         ret
255
256 begin:
257         /*
258          * Now running relocated at KERNBASE where the system is linked to run.
259          *
260          * Remove the lowest part of the double mapping of low memory to get
261          * some null pointer checks.
262          */
263         movl    $0,PTD
264         movl    %eax,%cr3               /* invalidate TLB */
265
266         /* set up bootstrap stack */
267         movl    proc0kstack,%eax        /* location of in-kernel stack */
268
269         /*
270          * Only use bottom page for init386().  init386() calculates the
271          * PCB + FPU save area size and returns the true top of stack.
272          */
273         leal    PAGE_SIZE(%eax),%esp
274
275         xorl    %ebp,%ebp               /* mark end of frames */
276
277         pushl   physfree                /* value of first for init386(first) */
278         call    init386                 /* wire 386 chip for unix operation */
279
280         /*
281          * Clean up the stack in a way that db_numargs() understands, so
282          * that backtraces in ddb don't underrun the stack.  Traps for
283          * inaccessible memory are more fatal than usual this early.
284          */
285         addl    $4,%esp
286
287         /* Switch to true top of stack. */
288         movl    %eax,%esp
289
290         call    mi_startup              /* autoconfiguration, mountroot etc */
291         /* NOTREACHED */
292         addl    $0,%esp                 /* for db_numargs() again */
293
294 /**********************************************************************
295  *
296  * Recover the bootinfo passed to us from the boot program
297  *
298  */
299 recover_bootinfo:
300         /*
301          * This code is called in different ways depending on what loaded
302          * and started the kernel.  This is used to detect how we get the
303          * arguments from the other code and what we do with them.
304          *
305          * Old disk boot blocks:
306          *      (*btext)(howto, bootdev, cyloffset, esym);
307          *      [return address == 0, and can NOT be returned to]
308          *      [cyloffset was not supported by the FreeBSD boot code
309          *       and always passed in as 0]
310          *      [esym is also known as total in the boot code, and
311          *       was never properly supported by the FreeBSD boot code]
312          *
313          * Old diskless netboot code:
314          *      (*btext)(0,0,0,0,&nfsdiskless,0,0,0);
315          *      [return address != 0, and can NOT be returned to]
316          *      If we are being booted by this code it will NOT work,
317          *      so we are just going to halt if we find this case.
318          *
319          * New uniform boot code:
320          *      (*btext)(howto, bootdev, 0, 0, 0, &bootinfo)
321          *      [return address != 0, and can be returned to]
322          *
323          * There may seem to be a lot of wasted arguments in here, but
324          * that is so the newer boot code can still load very old kernels
325          * and old boot code can load new kernels.
326          */
327
328         /*
329          * The old style disk boot blocks fake a frame on the stack and
330          * did an lret to get here.  The frame on the stack has a return
331          * address of 0.
332          */
333         cmpl    $0,4(%ebp)
334         je      olddiskboot
335
336         /*
337          * We have some form of return address, so this is either the
338          * old diskless netboot code, or the new uniform code.  That can
339          * be detected by looking at the 5th argument, if it is 0
340          * we are being booted by the new uniform boot code.
341          */
342         cmpl    $0,24(%ebp)
343         je      newboot
344
345         /*
346          * Seems we have been loaded by the old diskless boot code, we
347          * don't stand a chance of running as the diskless structure
348          * changed considerably between the two, so just halt.
349          */
350          hlt
351
352         /*
353          * We have been loaded by the new uniform boot code.
354          * Let's check the bootinfo version, and if we do not understand
355          * it we return to the loader with a status of 1 to indicate this error
356          */
357 newboot:
358         movl    28(%ebp),%ebx           /* &bootinfo.version */
359         movl    BI_VERSION(%ebx),%eax
360         cmpl    $1,%eax                 /* We only understand version 1 */
361         je      1f
362         movl    $1,%eax                 /* Return status */
363         leave
364         /*
365          * XXX this returns to our caller's caller (as is required) since
366          * we didn't set up a frame and our caller did.
367          */
368         ret
369
370 1:
371         /*
372          * If we have a kernelname copy it in
373          */
374         movl    BI_KERNELNAME(%ebx),%esi
375         cmpl    $0,%esi
376         je      2f                      /* No kernelname */
377         movl    $MAXPATHLEN,%ecx        /* Brute force!!! */
378         movl    $R(kernelname),%edi
379         cmpb    $'/',(%esi)             /* Make sure it starts with a slash */
380         je      1f
381         movb    $'/',(%edi)
382         incl    %edi
383         decl    %ecx
384 1:
385         cld
386         rep
387         movsb
388
389 2:
390         /*
391          * Determine the size of the boot loader's copy of the bootinfo
392          * struct.  This is impossible to do properly because old versions
393          * of the struct don't contain a size field and there are 2 old
394          * versions with the same version number.
395          */
396         movl    $BI_ENDCOMMON,%ecx      /* prepare for sizeless version */
397         testl   $RB_BOOTINFO,8(%ebp)    /* bi_size (and bootinfo) valid? */
398         je      got_bi_size             /* no, sizeless version */
399         movl    BI_SIZE(%ebx),%ecx
400 got_bi_size:
401
402         /*
403          * Copy the common part of the bootinfo struct
404          */
405         movl    %ebx,%esi
406         movl    $R(bootinfo),%edi
407         cmpl    $BOOTINFO_SIZE,%ecx
408         jbe     got_common_bi_size
409         movl    $BOOTINFO_SIZE,%ecx
410 got_common_bi_size:
411         cld
412         rep
413         movsb
414
415 #ifdef NFS_ROOT
416 #ifndef BOOTP_NFSV3
417         /*
418          * If we have a nfs_diskless structure copy it in
419          */
420         movl    BI_NFS_DISKLESS(%ebx),%esi
421         cmpl    $0,%esi
422         je      olddiskboot
423         movl    $R(nfs_diskless),%edi
424         movl    $NFSDISKLESS_SIZE,%ecx
425         cld
426         rep
427         movsb
428         movl    $R(nfs_diskless_valid),%edi
429         movl    $1,(%edi)
430 #endif
431 #endif
432
433         /*
434          * The old style disk boot.
435          *      (*btext)(howto, bootdev, cyloffset, esym);
436          * Note that the newer boot code just falls into here to pick
437          * up howto and bootdev, cyloffset and esym are no longer used
438          */
439 olddiskboot:
440         movl    8(%ebp),%eax
441         movl    %eax,R(boothowto)
442         movl    12(%ebp),%eax
443         movl    %eax,R(bootdev)
444
445         ret
446
447
448 /**********************************************************************
449  *
450  * Identify the CPU and initialize anything special about it
451  *
452  */
453 identify_cpu:
454
455         /* Try to toggle alignment check flag; does not exist on 386. */
456         pushfl
457         popl    %eax
458         movl    %eax,%ecx
459         orl     $PSL_AC,%eax
460         pushl   %eax
461         popfl
462         pushfl
463         popl    %eax
464         xorl    %ecx,%eax
465         andl    $PSL_AC,%eax
466         pushl   %ecx
467         popfl
468
469         testl   %eax,%eax
470         jnz     try486
471
472         /* NexGen CPU does not have aligment check flag. */
473         pushfl
474         movl    $0x5555, %eax
475         xorl    %edx, %edx
476         movl    $2, %ecx
477         clc
478         divl    %ecx
479         jz      trynexgen
480         popfl
481         movl    $CPU_386,R(cpu)
482         jmp     3f
483
484 trynexgen:
485         popfl
486         movl    $CPU_NX586,R(cpu)
487         movl    $0x4778654e,R(cpu_vendor)       # store vendor string
488         movl    $0x72446e65,R(cpu_vendor+4)
489         movl    $0x6e657669,R(cpu_vendor+8)
490         movl    $0,R(cpu_vendor+12)
491         jmp     3f
492
493 try486: /* Try to toggle identification flag; does not exist on early 486s. */
494         pushfl
495         popl    %eax
496         movl    %eax,%ecx
497         xorl    $PSL_ID,%eax
498         pushl   %eax
499         popfl
500         pushfl
501         popl    %eax
502         xorl    %ecx,%eax
503         andl    $PSL_ID,%eax
504         pushl   %ecx
505         popfl
506
507         testl   %eax,%eax
508         jnz     trycpuid
509         movl    $CPU_486,R(cpu)
510
511         /*
512          * Check Cyrix CPU
513          * Cyrix CPUs do not change the undefined flags following
514          * execution of the divide instruction which divides 5 by 2.
515          *
516          * Note: CPUID is enabled on M2, so it passes another way.
517          */
518         pushfl
519         movl    $0x5555, %eax
520         xorl    %edx, %edx
521         movl    $2, %ecx
522         clc
523         divl    %ecx
524         jnc     trycyrix
525         popfl
526         jmp     3f              /* You may use Intel CPU. */
527
528 trycyrix:
529         popfl
530         /*
531          * IBM Bluelighting CPU also doesn't change the undefined flags.
532          * Because IBM doesn't disclose the information for Bluelighting
533          * CPU, we couldn't distinguish it from Cyrix's (including IBM
534          * brand of Cyrix CPUs).
535          */
536         movl    $0x69727943,R(cpu_vendor)       # store vendor string
537         movl    $0x736e4978,R(cpu_vendor+4)
538         movl    $0x64616574,R(cpu_vendor+8)
539         jmp     3f
540
541 trycpuid:       /* Use the `cpuid' instruction. */
542         xorl    %eax,%eax
543         cpuid                                   # cpuid 0
544         movl    %eax,R(cpu_high)                # highest capability
545         movl    %ebx,R(cpu_vendor)              # store vendor string
546         movl    %edx,R(cpu_vendor+4)
547         movl    %ecx,R(cpu_vendor+8)
548         movb    $0,R(cpu_vendor+12)
549
550         movl    $1,%eax
551         cpuid                                   # cpuid 1
552         movl    %eax,R(cpu_id)                  # store cpu_id
553         movl    %ebx,R(cpu_procinfo)            # store cpu_procinfo
554         movl    %edx,R(cpu_feature)             # store cpu_feature
555         movl    %ecx,R(cpu_feature2)            # store cpu_feature2
556         rorl    $8,%eax                         # extract family type
557         andl    $15,%eax
558         cmpl    $5,%eax
559         jae     1f
560
561         /* less than Pentium; must be 486 */
562         movl    $CPU_486,R(cpu)
563         jmp     3f
564 1:
565         /* a Pentium? */
566         cmpl    $5,%eax
567         jne     2f
568         movl    $CPU_586,R(cpu)
569         jmp     3f
570 2:
571         /* Greater than Pentium...call it a Pentium Pro */
572         movl    $CPU_686,R(cpu)
573 3:
574         ret
575
576
577 /**********************************************************************
578  *
579  * Create the first page directory and its page tables.
580  *
581  */
582
583 create_pagetables:
584
585 /* Find end of kernel image (rounded up to a page boundary). */
586         movl    $R(_end),%esi
587
588 /* Include symbols, if any. */
589         movl    R(bootinfo+BI_ESYMTAB),%edi
590         testl   %edi,%edi
591         je      over_symalloc
592         movl    %edi,%esi
593         movl    $KERNBASE,%edi
594         addl    %edi,R(bootinfo+BI_SYMTAB)
595         addl    %edi,R(bootinfo+BI_ESYMTAB)
596 over_symalloc:
597
598 /* If we are told where the end of the kernel space is, believe it. */
599         movl    R(bootinfo+BI_KERNEND),%edi
600         testl   %edi,%edi
601         je      no_kernend
602         movl    %edi,%esi
603 no_kernend:
604
605         addl    $PDRMASK,%esi           /* Play conservative for now, and */
606         andl    $~PDRMASK,%esi          /* ... round up to PDR boundary */
607         movl    %esi,R(KERNend)         /* save end of kernel */
608         movl    %esi,R(physfree)        /* next free page is at end of kernel */
609
610 /* Allocate Kernel Page Tables */
611         ALLOCPAGES(NKPT)
612         movl    %esi,R(KPTphys)
613         addl    $(KERNBASE-(KPTDI<<(PDRSHIFT-PAGE_SHIFT+PTESHIFT))),%esi
614         movl    %esi,R(KPTmap)
615
616 /* Allocate Page Table Directory */
617 #if defined(PAE) || defined(PAE_TABLES)
618         /* XXX only need 32 bytes (easier for now) */
619         ALLOCPAGES(1)
620         movl    %esi,R(IdlePDPT)
621 #endif
622         ALLOCPAGES(NPGPTD)
623         movl    %esi,R(IdlePTD)
624
625 /* Allocate KSTACK */
626         ALLOCPAGES(TD0_KSTACK_PAGES)
627         movl    %esi,R(p0kpa)
628         addl    $KERNBASE, %esi
629         movl    %esi, R(proc0kstack)
630
631         ALLOCPAGES(1)                   /* vm86/bios stack */
632         movl    %esi,R(vm86phystk)
633
634         ALLOCPAGES(3)                   /* pgtable + ext + IOPAGES */
635         movl    %esi,R(vm86pa)
636         addl    $KERNBASE, %esi
637         movl    %esi, R(vm86paddr)
638
639 /*
640  * Enable PSE and PGE.
641  */
642 #ifndef DISABLE_PSE
643         testl   $CPUID_PSE, R(cpu_feature)
644         jz      1f
645         movl    $PG_PS, R(pseflag)
646         movl    %cr4, %eax
647         orl     $CR4_PSE, %eax
648         movl    %eax, %cr4
649 1:
650 #endif
651 #ifndef DISABLE_PG_G
652         testl   $CPUID_PGE, R(cpu_feature)
653         jz      2f
654         movl    $PG_G, R(pgeflag)
655         movl    %cr4, %eax
656         orl     $CR4_PGE, %eax
657         movl    %eax, %cr4
658 2:
659 #endif
660
661 /*
662  * Initialize page table pages mapping physical address zero through the
663  * (physical) end of the kernel.  Many of these pages must be reserved,
664  * and we reserve them all and map them linearly for convenience.  We do
665  * this even if we've enabled PSE above; we'll just switch the corresponding
666  * kernel PDEs before we turn on paging.
667  *
668  * XXX: We waste some pages here in the PSE case!
669  *
670  * This and all other page table entries allow read and write access for
671  * various reasons.  Kernel mappings never have any access restrictions.
672  */
673         xorl    %eax, %eax
674         movl    R(KERNend),%ecx
675         shrl    $PAGE_SHIFT,%ecx
676         fillkptphys($PG_RW)
677
678 /* Map page table pages. */
679         movl    R(KPTphys),%eax
680         movl    $NKPT,%ecx
681         fillkptphys($PG_RW)
682
683 /* Map page directory. */
684 #if defined(PAE) || defined(PAE_TABLES)
685         movl    R(IdlePDPT), %eax
686         movl    $1, %ecx
687         fillkptphys($PG_RW)
688 #endif
689
690         movl    R(IdlePTD), %eax
691         movl    $NPGPTD, %ecx
692         fillkptphys($PG_RW)
693
694 /* Map proc0's KSTACK in the physical way ... */
695         movl    R(p0kpa), %eax
696         movl    $(TD0_KSTACK_PAGES), %ecx
697         fillkptphys($PG_RW)
698
699 /* Map ISA hole */
700         movl    $ISA_HOLE_START, %eax
701         movl    $ISA_HOLE_LENGTH>>PAGE_SHIFT, %ecx
702         fillkptphys($PG_RW)
703
704 /* Map space for the vm86 region */
705         movl    R(vm86phystk), %eax
706         movl    $4, %ecx
707         fillkptphys($PG_RW)
708
709 /* Map page 0 into the vm86 page table */
710         movl    $0, %eax
711         movl    $0, %ebx
712         movl    $1, %ecx
713         fillkpt(R(vm86pa), $PG_RW|PG_U)
714
715 /* ...likewise for the ISA hole */
716         movl    $ISA_HOLE_START, %eax
717         movl    $ISA_HOLE_START>>PAGE_SHIFT, %ebx
718         movl    $ISA_HOLE_LENGTH>>PAGE_SHIFT, %ecx
719         fillkpt(R(vm86pa), $PG_RW|PG_U)
720
721 /*
722  * Create an identity mapping for low physical memory, including the kernel.
723  * This is only used to map the 2 instructions for jumping to 'begin' in
724  * locore (we map everything to avoid having to determine where these
725  * instructions are).  ACPI resume will transiently restore the first PDE in
726  * this mapping (and depend on this PDE's page table created here not being
727  * destroyed).  See pmap_bootstrap() for more details.
728  *
729  * Note:  There are errata concerning large pages and physical address zero,
730  * so a PG_PS mapping should not be used for PDE 0.  Our double mapping
731  * avoids this automatically by not using PG_PS for PDE #KPDI so that PAT
732  * bits can be set at the page level for i/o pages below 1 MB.
733  */
734         movl    R(KPTphys), %eax
735         xorl    %ebx, %ebx
736         movl    $NKPT, %ecx
737         fillkpt(R(IdlePTD), $PG_RW)
738
739 /*
740  * Install PDEs for PTs covering enough kva to bootstrap.  Then for the PSE
741  * case, replace the PDEs whose coverage is strictly within the kernel
742  * (between KERNLOAD (rounded up) and KERNend) by large-page PDEs.
743  */
744         movl    R(KPTphys), %eax
745         movl    $KPTDI, %ebx
746         movl    $NKPT, %ecx
747         fillkpt(R(IdlePTD), $PG_RW)
748         cmpl    $0,R(pseflag)
749         je      done_pde
750
751         movl    R(KERNend), %ecx
752         movl    $(KERNLOAD + PDRMASK) & ~PDRMASK, %eax
753         subl    %eax, %ecx
754         shrl    $PDRSHIFT, %ecx
755         movl    $KPTDI + ((KERNLOAD + PDRMASK) >> PDRSHIFT), %ebx
756         shll    $PDESHIFT, %ebx
757         addl    R(IdlePTD), %ebx
758         orl     $(PG_V|PG_RW|PG_PS), %eax
759 1:      movl    %eax, (%ebx)
760         addl    $(1 << PDRSHIFT), %eax
761         addl    $PDESIZE, %ebx
762         loop    1b
763
764 done_pde:
765 /* install a pde recursively mapping page directory as a page table */
766         movl    R(IdlePTD), %eax
767         movl    $PTDPTDI, %ebx
768         movl    $NPGPTD,%ecx
769         fillkpt(R(IdlePTD), $PG_RW)
770
771 #if defined(PAE) || defined(PAE_TABLES)
772         movl    R(IdlePTD), %eax
773         xorl    %ebx, %ebx
774         movl    $NPGPTD, %ecx
775         fillkpt(R(IdlePDPT), $0x0)
776 #endif
777
778         ret
779
780 #ifdef XENHVM
781 /* Xen Hypercall page */
782         .text
783 .p2align PAGE_SHIFT, 0x90       /* Hypercall_page needs to be PAGE aligned */
784
785 NON_GPROF_ENTRY(hypercall_page)
786         .skip   0x1000, 0x90    /* Fill with "nop"s */
787 #endif