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