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