locore.s revision 111299
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: head/sys/i386/i386/locore.s 111299 2003-02-23 09:45:50Z jake $ 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_compat.h" 48#include "opt_nfsroot.h" 49 50#include <sys/syscall.h> 51#include <sys/reboot.h> 52 53#include <machine/asmacros.h> 54#include <machine/cputypes.h> 55#include <machine/psl.h> 56#include <machine/pmap.h> 57#include <machine/specialreg.h> 58 59#include "assym.s" 60 61/* 62 * XXX 63 * 64 * Note: This version greatly munged to avoid various assembler errors 65 * that may be fixed in newer versions of gas. Perhaps newer versions 66 * will have more pleasant appearance. 67 */ 68 69/* 70 * PTmap is recursive pagemap at top of virtual address space. 71 * Within PTmap, the page directory can be found (third indirection). 72 * 73 * NOTE: PTDpde, PTmap, and PTD are being defined as address symbols. 74 * In C you access them directly, and not with a '*'. Storage is not being 75 * allocated. They will magically address the correct locations in KVM 76 * which C will treat as normal variables of the type they are defined in 77 * machine/pmap.h, i.e. PTDpde = XX ; to set a PDE entry, NOT *PTDpde = XX; 78 */ 79 .globl PTmap,PTD,PTDpde 80 .set PTmap,(PTDPTDI << PDRSHIFT) 81 .set PTD,PTmap + (PTDPTDI * PAGE_SIZE) 82 .set PTDpde,PTD + (PTDPTDI * PDESIZE) 83 84/* 85 * APTmap, APTD is the alternate recursive pagemap. 86 * It's used when modifying another process's page tables. 87 * See the note above. It is true here as well. 88 */ 89 .globl APTmap,APTD,APTDpde 90 .set APTmap,APTDPTDI << PDRSHIFT 91 .set APTD,APTmap + (APTDPTDI * PAGE_SIZE) 92 .set APTDpde,PTD + (APTDPTDI * PDESIZE) 93 94#ifdef SMP 95/* 96 * Define layout of per-cpu address space. 97 * This is "constructed" in locore.s on the BSP and in mp_machdep.c 98 * for each AP. DO NOT REORDER THESE WITHOUT UPDATING THE REST! 99 */ 100 .globl SMP_prvspace, lapic 101 .set SMP_prvspace,(MPPTDI << PDRSHIFT) 102 .set lapic,SMP_prvspace + (NPTEPG-1) * PAGE_SIZE 103#endif /* SMP */ 104 105/* 106 * Compiled KERNBASE location 107 */ 108 .globl kernbase 109 .set kernbase,KERNBASE 110 111/* 112 * Globals 113 */ 114 .data 115 ALIGN_DATA /* just to be sure */ 116 117 .globl HIDENAME(tmpstk) 118 .space 0x2000 /* space for tmpstk - temporary stack */ 119HIDENAME(tmpstk): 120 121 .globl bootinfo 122bootinfo: .space BOOTINFO_SIZE /* bootinfo that we can handle */ 123 124 .globl KERNend 125KERNend: .long 0 /* phys addr end of kernel (just after bss) */ 126physfree: .long 0 /* phys addr of next free page */ 127 128#ifdef SMP 129 .globl cpu0prvpage 130cpu0pp: .long 0 /* phys addr cpu0 private pg */ 131cpu0prvpage: .long 0 /* relocated version */ 132 133 .globl SMPpt 134SMPptpa: .long 0 /* phys addr SMP page table */ 135SMPpt: .long 0 /* relocated version */ 136#endif /* SMP */ 137 138 .globl IdlePTD 139IdlePTD: .long 0 /* phys addr of kernel PTD */ 140 141#ifdef SMP 142 .globl KPTphys 143#endif 144KPTphys: .long 0 /* phys addr of kernel page tables */ 145 146 .globl proc0uarea, proc0kstack 147proc0uarea: .long 0 /* address of proc 0 uarea space */ 148proc0kstack: .long 0 /* address of proc 0 kstack space */ 149p0upa: .long 0 /* phys addr of proc0's UAREA */ 150p0kpa: .long 0 /* phys addr of proc0's STACK */ 151 152vm86phystk: .long 0 /* PA of vm86/bios stack */ 153 154 .globl vm86paddr, vm86pa 155vm86paddr: .long 0 /* address of vm86 region */ 156vm86pa: .long 0 /* phys addr of vm86 region */ 157 158#ifdef PC98 159 .globl pc98_system_parameter 160pc98_system_parameter: 161 .space 0x240 162#endif 163 164/********************************************************************** 165 * 166 * Some handy macros 167 * 168 */ 169 170#define R(foo) ((foo)-KERNBASE) 171 172#define ALLOCPAGES(foo) \ 173 movl R(physfree), %esi ; \ 174 movl $((foo)*PAGE_SIZE), %eax ; \ 175 addl %esi, %eax ; \ 176 movl %eax, R(physfree) ; \ 177 movl %esi, %edi ; \ 178 movl $((foo)*PAGE_SIZE),%ecx ; \ 179 xorl %eax,%eax ; \ 180 cld ; \ 181 rep ; \ 182 stosb 183 184/* 185 * fillkpt 186 * eax = page frame address 187 * ebx = index into page table 188 * ecx = how many pages to map 189 * base = base address of page dir/table 190 * prot = protection bits 191 */ 192#define fillkpt(base, prot) \ 193 shll $PTESHIFT,%ebx ; \ 194 addl base,%ebx ; \ 195 orl $PG_V,%eax ; \ 196 orl prot,%eax ; \ 1971: movl %eax,(%ebx) ; \ 198 addl $PAGE_SIZE,%eax ; /* increment physical address */ \ 199 addl $PTESIZE,%ebx ; /* next pte */ \ 200 loop 1b 201 202/* 203 * fillkptphys(prot) 204 * eax = physical address 205 * ecx = how many pages to map 206 * prot = protection bits 207 */ 208#define fillkptphys(prot) \ 209 movl %eax, %ebx ; \ 210 shrl $PAGE_SHIFT, %ebx ; \ 211 fillkpt(R(KPTphys), prot) 212 213 .text 214/********************************************************************** 215 * 216 * This is where the bootblocks start us, set the ball rolling... 217 * 218 */ 219NON_GPROF_ENTRY(btext) 220 221#ifdef PC98 222 /* save SYSTEM PARAMETER for resume (NS/T or other) */ 223 movl $0xa1400,%esi 224 movl $R(pc98_system_parameter),%edi 225 movl $0x0240,%ecx 226 cld 227 rep 228 movsb 229#else /* IBM-PC */ 230/* Tell the bios to warmboot next time */ 231 movw $0x1234,0x472 232#endif /* PC98 */ 233 234/* Set up a real frame in case the double return in newboot is executed. */ 235 pushl %ebp 236 movl %esp, %ebp 237 238/* Don't trust what the BIOS gives for eflags. */ 239 pushl $PSL_KERNEL 240 popfl 241 242/* 243 * Don't trust what the BIOS gives for %fs and %gs. Trust the bootstrap 244 * to set %cs, %ds, %es and %ss. 245 */ 246 mov %ds, %ax 247 mov %ax, %fs 248 mov %ax, %gs 249 250 call recover_bootinfo 251 252/* Get onto a stack that we can trust. */ 253/* 254 * XXX this step is delayed in case recover_bootinfo needs to return via 255 * the old stack, but it need not be, since recover_bootinfo actually 256 * returns via the old frame. 257 */ 258 movl $R(HIDENAME(tmpstk)),%esp 259 260#ifdef PC98 261 /* pc98_machine_type & M_EPSON_PC98 */ 262 testb $0x02,R(pc98_system_parameter)+220 263 jz 3f 264 /* epson_machine_id <= 0x0b */ 265 cmpb $0x0b,R(pc98_system_parameter)+224 266 ja 3f 267 268 /* count up memory */ 269 movl $0x100000,%eax /* next, talley remaining memory */ 270 movl $0xFFF-0x100,%ecx 2711: movl 0(%eax),%ebx /* save location to check */ 272 movl $0xa55a5aa5,0(%eax) /* write test pattern */ 273 cmpl $0xa55a5aa5,0(%eax) /* does not check yet for rollover */ 274 jne 2f 275 movl %ebx,0(%eax) /* restore memory */ 276 addl $PAGE_SIZE,%eax 277 loop 1b 2782: subl $0x100000,%eax 279 shrl $17,%eax 280 movb %al,R(pc98_system_parameter)+1 2813: 282 283 movw R(pc98_system_parameter+0x86),%ax 284 movw %ax,R(cpu_id) 285#endif 286 287 call identify_cpu 288 289/* clear bss */ 290/* 291 * XXX this should be done a little earlier. 292 * 293 * XXX we don't check that there is memory for our bss and page tables 294 * before using it. 295 * 296 * XXX the boot program somewhat bogusly clears the bss. We still have 297 * to do it in case we were unzipped by kzipboot. Then the boot program 298 * only clears kzipboot's bss. 299 * 300 * XXX the gdt and idt are still somewhere in the boot program. We 301 * depend on the convention that the boot program is below 1MB and we 302 * are above 1MB to keep the gdt and idt away from the bss and page 303 * tables. 304 */ 305 movl $R(end),%ecx 306 movl $R(edata),%edi 307 subl %edi,%ecx 308 xorl %eax,%eax 309 cld 310 rep 311 stosb 312 313 call create_pagetables 314 315/* 316 * If the CPU has support for VME, turn it on. 317 */ 318 testl $CPUID_VME, R(cpu_feature) 319 jz 1f 320 movl %cr4, %eax 321 orl $CR4_VME, %eax 322 movl %eax, %cr4 3231: 324 325/* Now enable paging */ 326 movl R(IdlePTD), %eax 327 movl %eax,%cr3 /* load ptd addr into mmu */ 328 movl %cr0,%eax /* get control word */ 329 orl $CR0_PE|CR0_PG,%eax /* enable paging */ 330 movl %eax,%cr0 /* and let's page NOW! */ 331 332 pushl $begin /* jump to high virtualized address */ 333 ret 334 335/* now running relocated at KERNBASE where the system is linked to run */ 336begin: 337 /* set up bootstrap stack */ 338 movl proc0kstack,%eax /* location of in-kernel stack */ 339 /* bootstrap stack end location */ 340 leal (KSTACK_PAGES*PAGE_SIZE-PCB_SIZE)(%eax),%esp 341 342 xorl %ebp,%ebp /* mark end of frames */ 343 344 movl IdlePTD,%esi 345 movl %esi,(KSTACK_PAGES*PAGE_SIZE-PCB_SIZE+PCB_CR3)(%eax) 346 347 pushl physfree /* value of first for init386(first) */ 348 call init386 /* wire 386 chip for unix operation */ 349 350 /* 351 * Clean up the stack in a way that db_numargs() understands, so 352 * that backtraces in ddb don't underrun the stack. Traps for 353 * inaccessible memory are more fatal than usual this early. 354 */ 355 addl $4,%esp 356 357 call mi_startup /* autoconfiguration, mountroot etc */ 358 /* NOTREACHED */ 359 addl $0,%esp /* for db_numargs() again */ 360 361/* 362 * Signal trampoline, copied to top of user stack 363 */ 364NON_GPROF_ENTRY(sigcode) 365 calll *SIGF_HANDLER(%esp) 366 leal SIGF_UC(%esp),%eax /* get ucontext */ 367 pushl %eax 368 testl $PSL_VM,UC_EFLAGS(%eax) 369 jne 1f 370 movl UC_GS(%eax),%gs /* restore %gs */ 3711: 372 movl $SYS_sigreturn,%eax 373 pushl %eax /* junk to fake return addr. */ 374 int $0x80 /* enter kernel with args */ 375 /* on stack */ 3761: 377 jmp 1b 378 379#ifdef COMPAT_FREEBSD4 380 ALIGN_TEXT 381freebsd4_sigcode: 382 calll *SIGF_HANDLER(%esp) 383 leal SIGF_UC4(%esp),%eax /* get ucontext */ 384 pushl %eax 385 testl $PSL_VM,UC4_EFLAGS(%eax) 386 jne 1f 387 movl UC4_GS(%eax),%gs /* restore %gs */ 3881: 389 movl $344,%eax /* 4.x SYS_sigreturn */ 390 pushl %eax /* junk to fake return addr. */ 391 int $0x80 /* enter kernel with args */ 392 /* on stack */ 3931: 394 jmp 1b 395#endif 396 397#ifdef COMPAT_43 398 ALIGN_TEXT 399osigcode: 400 call *SIGF_HANDLER(%esp) /* call signal handler */ 401 lea SIGF_SC(%esp),%eax /* get sigcontext */ 402 pushl %eax 403 testl $PSL_VM,SC_PS(%eax) 404 jne 9f 405 movl SC_GS(%eax),%gs /* restore %gs */ 4069: 407 movl $103,%eax /* 3.x SYS_sigreturn */ 408 pushl %eax /* junk to fake return addr. */ 409 int $0x80 /* enter kernel with args */ 4100: jmp 0b 411#endif /* COMPAT_43 */ 412 413 ALIGN_TEXT 414esigcode: 415 416 .data 417 .globl szsigcode 418szsigcode: 419 .long esigcode-sigcode 420#ifdef COMPAT_FREEBSD4 421 .globl szfreebsd4_sigcode 422szfreebsd4_sigcode: 423 .long esigcode-freebsd4_sigcode 424#endif 425#ifdef COMPAT_43 426 .globl szosigcode 427szosigcode: 428 .long esigcode-osigcode 429#endif 430 .text 431 432/********************************************************************** 433 * 434 * Recover the bootinfo passed to us from the boot program 435 * 436 */ 437recover_bootinfo: 438 /* 439 * This code is called in different ways depending on what loaded 440 * and started the kernel. This is used to detect how we get the 441 * arguments from the other code and what we do with them. 442 * 443 * Old disk boot blocks: 444 * (*btext)(howto, bootdev, cyloffset, esym); 445 * [return address == 0, and can NOT be returned to] 446 * [cyloffset was not supported by the FreeBSD boot code 447 * and always passed in as 0] 448 * [esym is also known as total in the boot code, and 449 * was never properly supported by the FreeBSD boot code] 450 * 451 * Old diskless netboot code: 452 * (*btext)(0,0,0,0,&nfsdiskless,0,0,0); 453 * [return address != 0, and can NOT be returned to] 454 * If we are being booted by this code it will NOT work, 455 * so we are just going to halt if we find this case. 456 * 457 * New uniform boot code: 458 * (*btext)(howto, bootdev, 0, 0, 0, &bootinfo) 459 * [return address != 0, and can be returned to] 460 * 461 * There may seem to be a lot of wasted arguments in here, but 462 * that is so the newer boot code can still load very old kernels 463 * and old boot code can load new kernels. 464 */ 465 466 /* 467 * The old style disk boot blocks fake a frame on the stack and 468 * did an lret to get here. The frame on the stack has a return 469 * address of 0. 470 */ 471 cmpl $0,4(%ebp) 472 je olddiskboot 473 474 /* 475 * We have some form of return address, so this is either the 476 * old diskless netboot code, or the new uniform code. That can 477 * be detected by looking at the 5th argument, if it is 0 478 * we are being booted by the new uniform boot code. 479 */ 480 cmpl $0,24(%ebp) 481 je newboot 482 483 /* 484 * Seems we have been loaded by the old diskless boot code, we 485 * don't stand a chance of running as the diskless structure 486 * changed considerably between the two, so just halt. 487 */ 488 hlt 489 490 /* 491 * We have been loaded by the new uniform boot code. 492 * Let's check the bootinfo version, and if we do not understand 493 * it we return to the loader with a status of 1 to indicate this error 494 */ 495newboot: 496 movl 28(%ebp),%ebx /* &bootinfo.version */ 497 movl BI_VERSION(%ebx),%eax 498 cmpl $1,%eax /* We only understand version 1 */ 499 je 1f 500 movl $1,%eax /* Return status */ 501 leave 502 /* 503 * XXX this returns to our caller's caller (as is required) since 504 * we didn't set up a frame and our caller did. 505 */ 506 ret 507 5081: 509 /* 510 * If we have a kernelname copy it in 511 */ 512 movl BI_KERNELNAME(%ebx),%esi 513 cmpl $0,%esi 514 je 2f /* No kernelname */ 515 movl $MAXPATHLEN,%ecx /* Brute force!!! */ 516 movl $R(kernelname),%edi 517 cmpb $'/',(%esi) /* Make sure it starts with a slash */ 518 je 1f 519 movb $'/',(%edi) 520 incl %edi 521 decl %ecx 5221: 523 cld 524 rep 525 movsb 526 5272: 528 /* 529 * Determine the size of the boot loader's copy of the bootinfo 530 * struct. This is impossible to do properly because old versions 531 * of the struct don't contain a size field and there are 2 old 532 * versions with the same version number. 533 */ 534 movl $BI_ENDCOMMON,%ecx /* prepare for sizeless version */ 535 testl $RB_BOOTINFO,8(%ebp) /* bi_size (and bootinfo) valid? */ 536 je got_bi_size /* no, sizeless version */ 537 movl BI_SIZE(%ebx),%ecx 538got_bi_size: 539 540 /* 541 * Copy the common part of the bootinfo struct 542 */ 543 movl %ebx,%esi 544 movl $R(bootinfo),%edi 545 cmpl $BOOTINFO_SIZE,%ecx 546 jbe got_common_bi_size 547 movl $BOOTINFO_SIZE,%ecx 548got_common_bi_size: 549 cld 550 rep 551 movsb 552 553#ifdef NFS_ROOT 554#ifndef BOOTP_NFSV3 555 /* 556 * If we have a nfs_diskless structure copy it in 557 */ 558 movl BI_NFS_DISKLESS(%ebx),%esi 559 cmpl $0,%esi 560 je olddiskboot 561 movl $R(nfs_diskless),%edi 562 movl $NFSDISKLESS_SIZE,%ecx 563 cld 564 rep 565 movsb 566 movl $R(nfs_diskless_valid),%edi 567 movl $1,(%edi) 568#endif 569#endif 570 571 /* 572 * The old style disk boot. 573 * (*btext)(howto, bootdev, cyloffset, esym); 574 * Note that the newer boot code just falls into here to pick 575 * up howto and bootdev, cyloffset and esym are no longer used 576 */ 577olddiskboot: 578 movl 8(%ebp),%eax 579 movl %eax,R(boothowto) 580 movl 12(%ebp),%eax 581 movl %eax,R(bootdev) 582 583 ret 584 585 586/********************************************************************** 587 * 588 * Identify the CPU and initialize anything special about it 589 * 590 */ 591identify_cpu: 592 593 /* Try to toggle alignment check flag; does not exist on 386. */ 594 pushfl 595 popl %eax 596 movl %eax,%ecx 597 orl $PSL_AC,%eax 598 pushl %eax 599 popfl 600 pushfl 601 popl %eax 602 xorl %ecx,%eax 603 andl $PSL_AC,%eax 604 pushl %ecx 605 popfl 606 607 testl %eax,%eax 608 jnz try486 609 610 /* NexGen CPU does not have aligment check flag. */ 611 pushfl 612 movl $0x5555, %eax 613 xorl %edx, %edx 614 movl $2, %ecx 615 clc 616 divl %ecx 617 jz trynexgen 618 popfl 619 movl $CPU_386,R(cpu) 620 jmp 3f 621 622trynexgen: 623 popfl 624 movl $CPU_NX586,R(cpu) 625 movl $0x4778654e,R(cpu_vendor) # store vendor string 626 movl $0x72446e65,R(cpu_vendor+4) 627 movl $0x6e657669,R(cpu_vendor+8) 628 movl $0,R(cpu_vendor+12) 629 jmp 3f 630 631try486: /* Try to toggle identification flag; does not exist on early 486s. */ 632 pushfl 633 popl %eax 634 movl %eax,%ecx 635 xorl $PSL_ID,%eax 636 pushl %eax 637 popfl 638 pushfl 639 popl %eax 640 xorl %ecx,%eax 641 andl $PSL_ID,%eax 642 pushl %ecx 643 popfl 644 645 testl %eax,%eax 646 jnz trycpuid 647 movl $CPU_486,R(cpu) 648 649 /* 650 * Check Cyrix CPU 651 * Cyrix CPUs do not change the undefined flags following 652 * execution of the divide instruction which divides 5 by 2. 653 * 654 * Note: CPUID is enabled on M2, so it passes another way. 655 */ 656 pushfl 657 movl $0x5555, %eax 658 xorl %edx, %edx 659 movl $2, %ecx 660 clc 661 divl %ecx 662 jnc trycyrix 663 popfl 664 jmp 3f /* You may use Intel CPU. */ 665 666trycyrix: 667 popfl 668 /* 669 * IBM Bluelighting CPU also doesn't change the undefined flags. 670 * Because IBM doesn't disclose the information for Bluelighting 671 * CPU, we couldn't distinguish it from Cyrix's (including IBM 672 * brand of Cyrix CPUs). 673 */ 674 movl $0x69727943,R(cpu_vendor) # store vendor string 675 movl $0x736e4978,R(cpu_vendor+4) 676 movl $0x64616574,R(cpu_vendor+8) 677 jmp 3f 678 679trycpuid: /* Use the `cpuid' instruction. */ 680 xorl %eax,%eax 681 cpuid # cpuid 0 682 movl %eax,R(cpu_high) # highest capability 683 movl %ebx,R(cpu_vendor) # store vendor string 684 movl %edx,R(cpu_vendor+4) 685 movl %ecx,R(cpu_vendor+8) 686 movb $0,R(cpu_vendor+12) 687 688 movl $1,%eax 689 cpuid # cpuid 1 690 movl %eax,R(cpu_id) # store cpu_id 691 movl %ebx,R(cpu_procinfo) # store cpu_procinfo 692 movl %edx,R(cpu_feature) # store cpu_feature 693 rorl $8,%eax # extract family type 694 andl $15,%eax 695 cmpl $5,%eax 696 jae 1f 697 698 /* less than Pentium; must be 486 */ 699 movl $CPU_486,R(cpu) 700 jmp 3f 7011: 702 /* a Pentium? */ 703 cmpl $5,%eax 704 jne 2f 705 movl $CPU_586,R(cpu) 706 jmp 3f 7072: 708 /* Greater than Pentium...call it a Pentium Pro */ 709 movl $CPU_686,R(cpu) 7103: 711 ret 712 713 714/********************************************************************** 715 * 716 * Create the first page directory and its page tables. 717 * 718 */ 719 720create_pagetables: 721 722/* Find end of kernel image (rounded up to a page boundary). */ 723 movl $R(_end),%esi 724 725/* Include symbols, if any. */ 726 movl R(bootinfo+BI_ESYMTAB),%edi 727 testl %edi,%edi 728 je over_symalloc 729 movl %edi,%esi 730 movl $KERNBASE,%edi 731 addl %edi,R(bootinfo+BI_SYMTAB) 732 addl %edi,R(bootinfo+BI_ESYMTAB) 733over_symalloc: 734 735/* If we are told where the end of the kernel space is, believe it. */ 736 movl R(bootinfo+BI_KERNEND),%edi 737 testl %edi,%edi 738 je no_kernend 739 movl %edi,%esi 740no_kernend: 741 742 addl $PAGE_MASK,%esi 743 andl $~PAGE_MASK,%esi 744 movl %esi,R(KERNend) /* save end of kernel */ 745 movl %esi,R(physfree) /* next free page is at end of kernel */ 746 747/* Allocate Kernel Page Tables */ 748 ALLOCPAGES(NKPT) 749 movl %esi,R(KPTphys) 750 751/* Allocate Page Table Directory */ 752 ALLOCPAGES(1) 753 movl %esi,R(IdlePTD) 754 755/* Allocate UPAGES */ 756 ALLOCPAGES(UAREA_PAGES) 757 movl %esi,R(p0upa) 758 addl $KERNBASE, %esi 759 movl %esi, R(proc0uarea) 760 761 ALLOCPAGES(KSTACK_PAGES) 762 movl %esi,R(p0kpa) 763 addl $KERNBASE, %esi 764 movl %esi, R(proc0kstack) 765 766 ALLOCPAGES(1) /* vm86/bios stack */ 767 movl %esi,R(vm86phystk) 768 769 ALLOCPAGES(3) /* pgtable + ext + IOPAGES */ 770 movl %esi,R(vm86pa) 771 addl $KERNBASE, %esi 772 movl %esi, R(vm86paddr) 773 774#ifdef SMP 775/* Allocate cpu0's private data page */ 776 ALLOCPAGES(1) 777 movl %esi,R(cpu0pp) 778 addl $KERNBASE, %esi 779 movl %esi, R(cpu0prvpage) /* relocated to KVM space */ 780 781/* Allocate SMP page table page */ 782 ALLOCPAGES(1) 783 movl %esi,R(SMPptpa) 784 addl $KERNBASE, %esi 785 movl %esi, R(SMPpt) /* relocated to KVM space */ 786#endif /* SMP */ 787 788/* Map read-only from zero to the end of the kernel text section */ 789 xorl %eax, %eax 790 xorl %edx,%edx 791 movl $R(etext),%ecx 792 addl $PAGE_MASK,%ecx 793 shrl $PAGE_SHIFT,%ecx 794 fillkptphys(%edx) 795 796/* Map read-write, data, bss and symbols */ 797 movl $R(etext),%eax 798 addl $PAGE_MASK, %eax 799 andl $~PAGE_MASK, %eax 800 movl $PG_RW,%edx 801 movl R(KERNend),%ecx 802 subl %eax,%ecx 803 shrl $PAGE_SHIFT,%ecx 804 fillkptphys(%edx) 805 806/* Map page directory. */ 807 movl R(IdlePTD), %eax 808 movl $1, %ecx 809 fillkptphys($PG_RW) 810 811/* Map proc0's UPAGES in the physical way ... */ 812 movl R(p0upa), %eax 813 movl $(UAREA_PAGES), %ecx 814 fillkptphys($PG_RW) 815 816/* Map proc0's KSTACK in the physical way ... */ 817 movl R(p0kpa), %eax 818 movl $(KSTACK_PAGES), %ecx 819 fillkptphys($PG_RW) 820 821/* Map ISA hole */ 822 movl $ISA_HOLE_START, %eax 823 movl $ISA_HOLE_LENGTH>>PAGE_SHIFT, %ecx 824 fillkptphys($PG_RW) 825 826/* Map space for the vm86 region */ 827 movl R(vm86phystk), %eax 828 movl $4, %ecx 829 fillkptphys($PG_RW) 830 831/* Map page 0 into the vm86 page table */ 832 movl $0, %eax 833 movl $0, %ebx 834 movl $1, %ecx 835 fillkpt(R(vm86pa), $PG_RW|PG_U) 836 837/* ...likewise for the ISA hole */ 838 movl $ISA_HOLE_START, %eax 839 movl $ISA_HOLE_START>>PAGE_SHIFT, %ebx 840 movl $ISA_HOLE_LENGTH>>PAGE_SHIFT, %ecx 841 fillkpt(R(vm86pa), $PG_RW|PG_U) 842 843#ifdef SMP 844/* Map cpu0's private page into global kmem (4K @ cpu0prvpage) */ 845 movl R(cpu0pp), %eax 846 movl $1, %ecx 847 fillkptphys($PG_RW) 848 849/* Map SMP page table page into global kmem FWIW */ 850 movl R(SMPptpa), %eax 851 movl $1, %ecx 852 fillkptphys($PG_RW) 853 854/* Map the private page into the SMP page table */ 855 movl R(cpu0pp), %eax 856 movl $0, %ebx /* pte offset = 0 */ 857 movl $1, %ecx /* one private page coming right up */ 858 fillkpt(R(SMPptpa), $PG_RW) 859 860/* ... and put the page table table in the pde. */ 861 movl R(SMPptpa), %eax 862 movl $MPPTDI, %ebx 863 movl $1, %ecx 864 fillkpt(R(IdlePTD), $PG_RW) 865 866/* Fakeup VA for the local apic to allow early traps. */ 867 ALLOCPAGES(1) 868 movl %esi, %eax 869 movl $(NPTEPG-1), %ebx /* pte offset = NTEPG-1 */ 870 movl $1, %ecx /* one private pt coming right up */ 871 fillkpt(R(SMPptpa), $PG_RW) 872#endif /* SMP */ 873 874/* install a pde for temporary double map of bottom of VA */ 875 movl R(KPTphys), %eax 876 xorl %ebx, %ebx 877 movl $NKPT, %ecx 878 fillkpt(R(IdlePTD), $PG_RW) 879 880/* install pde's for pt's */ 881 movl R(KPTphys), %eax 882 movl $KPTDI, %ebx 883 movl $NKPT, %ecx 884 fillkpt(R(IdlePTD), $PG_RW) 885 886/* install a pde recursively mapping page directory as a page table */ 887 movl R(IdlePTD), %eax 888 movl $PTDPTDI, %ebx 889 movl $1,%ecx 890 fillkpt(R(IdlePTD), $PG_RW) 891 892 ret 893