Source to include/mach/vm.h


0001  #ifndef _MACHVM_H
0002  #define _MACHVM_H
0003  /*
0004   * vm.h
0005   *	Machine-dependent VM stuff
0006   *
0007   * Some basic facts to keep in mind.  On i386, a two-level page table
0008   * organization is used.  Each top slot (known as a level 1 PTE) points
0009   * down to a page of level 2 PTEs.  Each top slot is responsible for
0010   * 4 Mb of virtual address space; each level 2 PTE handles 4K of that.
0011   *
0012   * Our boot loader has arranged for the kernel text to reside at 0 (the
0013   * first page is invalid, so references to vaddr 0 will trap).  It has
0014   * filled in a couple slots of the L1PTEs, pushed the page frame number
0015   * (PFN) of the next free page on the stack, and called us.  See locore.s
0016   * for details on initial boot.
0017   *
0018   * On boot, the root page table is layed out as:
0019   * 0000: 1:1/text
0020   * 0001: data remapping
0021   * 0002: CR3 (so at 8 Mb you will see the page table memory linearly)
0022   * 0003: empty, but L2PTEs are present
0023   *
0024   * We convert slot 3 to be our utility mapping area.  We then map 0004 and
0025   * up to be a 1:1 mapping of all physical memory.
0026   *
0027   * To avoid the cost of swapping page table roots when entering the
0028   * kernel, we share a root page table with our user-mode threads.  The
0029   * user's segments are tweaked to map vaddr 0 to paddr 2 Gb.  The user's
0030   * stack(s) start at the top of his 2 Gb.  So indices 512 and 1023 of
0031   * our L1PTEs will be filled in.  Perhaps 513 and 1022, etc. if the
0032   * process is big enough.
0033   */
0034  #include <sys/param.h>
0035  #include <mach/pte.h>
0036  
0037  #define BYTES_L1PT (1024*NBPG)		/* Bytes mapped per L1PTE */
0038  
0039  #define L1PT_TEXT 0			/* Indices for L1PTE slots */
0040  #define L1PT_DATA 1
0041  #define L1PT_CR3 2		/* For addressing L2PTEs */
0042  #define L1PT_UTIL 3		/* For vmap */
0043  #define L1PT_FREE 4		/* 1:1 mapping of memory will start here */
0044  #define L1PT_UTEXT 512
0045  #define L1PT_USTACK 1023
0046  
0047  /*
0048   * Layout of Global Descriptor Table:
0049   *
0050   * We don't use the LDT; all gates and such are via the GDT or IDT.
0051   */
0052  #define GDT_NULL (0 << 3)
0053  #define GDT_KDATA (1 << 3)
0054  #define GDT_KTEXT (2 << 3)
0055  #define GDT_BOOT32 (3 << 3)
0056  #define GDT_UDATA (5 << 3)
0057  #define GDT_UTEXT (6 << 3)
0058  #define NGDT 7			/* # entries in GDT */
0059  #define GDTIDX(i) ((i) >> 3)
0060  
0061  /*
0062   * Fixed locations in user's virtual address space.  Note that from
0063   * the kernel's linear perspective, the user resides in quandrants
0064   * 2 and 3; from the user's perspective, he resides in 0 and 1.
0065   * The following addresses are from the user perspective; this is
0066   * what is used for pview vaddrs and such.
0067   * UBASE--what user thinks is his lowest virtual address
0068   * UOFF--offset to convert from user to kernel perspective
0069   * USTACKADDR--base address at which stack starts.  esp will start
0070   *  at the top of this, and grow downwards.
0071   */
0072  #define UBASE (0x0)
0073  #define UOFF (0x80000000)
0074  #define USTACKADDR (0x80000000-UMAXSTACK)
0075  
0076  /*
0077   * Address of utility map used by hat_attach() on i386
0078   */
0079  #define VMAP_BASE (0x40000000)	/* Map area starts at 1 Gb */
0080  #define VMAP_SIZE (0x20000000)	/*  ...for 1/2 Gb */
0081  
0082  /*
0083   * Address of attach point for shared libraries
0084   */