home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / UNIX3862.ZIP / U386-06.ZIP / U386-6.TD0 / usr / include / sys / immu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-26  |  11.9 KB  |  393 lines

  1. /*    Copyright (c) 1984, 1986, 1987, 1988 AT&T    */
  2. /*      All Rights Reserved      */
  3.  
  4. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T    */
  5. /*    The copyright notice above does not evidence any       */
  6. /*    actual or intended publication of such source code.    */
  7.  
  8. /*    Copyright (c) 1987, 1988 Microsoft Corporation    */
  9. /*      All Rights Reserved    */
  10.  
  11. /*    This Module contains Proprietary Information of Microsoft  */
  12. /*    Corporation and should be treated as Confidential.       */
  13.  
  14. #ident    "@(#)head.sys:immu.h    1.6.1.3"
  15.  
  16. /*
  17.  * NOTE: Page Table entries are caled pde's (page descriptors)
  18.  *     and Page Directory entries are called pdte's. This is
  19.  *     not the best naming scheme but it minimizes the changes
  20.  *     required to the base source.
  21.  */
  22.  
  23. /*
  24.  * Page Table (descriptor) Entry Definitions
  25.  */
  26.  
  27. typedef union pde {    /*  page descriptor (table) entry  */
  28. /*                                                        */
  29. /*  +---------------------+---+--+--+--+-+-+--+-+-+-+  */
  30. /*  |        pfn          |lck|nr|cw|  |m|r|  |u|r|p|  */
  31. /*  +---------------------+---+--+--+--+-+-+--+-+-+-+  */
  32. /*             20            1  1  1  2 1 1  2 1 1 1   */
  33. /*                                                      */
  34.     struct {
  35.         uint pg_pres    :  1,    /* Page is present in memory */
  36.              pg_rw    :  1,    /* read/write */
  37.              pg_us    :  1,    /* user/supervisor */
  38.                      :  2,    /* Reserved by hardware.    */
  39.              pg_ref    :  1,    /* Page has been referenced */
  40.              pg_mod    :  1,    /* Page has been modified */
  41.                 :  2,    /* Reserved by hardware.    */
  42.              pg_cw    :  1,    /* Copy on write (fault    */
  43.              pg_ndref    :  1,    /* Needs reference (software).    */
  44.              pg_lock    :  1,    /* Lock in core (software) */
  45.              pg_pfn    : 20;    /* Physical page frame number */
  46.     } pgm;
  47.  
  48.     struct {
  49.         uint    pg_pde;        /* Full page table entry */
  50.     } pgi;
  51. } pde_t;
  52.  
  53. #define pg_v    pg_pres        /* present bit = valid bit */
  54.  
  55. /*
  56.  *    Page Table
  57.  */
  58.  
  59. #define NPGPT        1024        /* Nbr of pages per page table */
  60. typedef union ptbl {
  61.     int page[NPGPT];
  62. } ptbl_t;
  63.  
  64. /* Page table entry dependent constants */
  65.  
  66. #define    NBPP        4096        /* Number of bytes per page */
  67. #define    NBPPT        4096        /* Number of bytes per page table */
  68. #define    BPTSHFT        12         /* LOG2(NBPPT) if exact */
  69. #define NDPP            8               /* Number of disk blocks per page */
  70. #define DPPSHFT         3               /* Shift for disk blocks per page. */
  71. /* Following added because svid says ulimit works in 512 byte units, so we must
  72.   have something independent of the blocksize of the file system implementation
  73.  */
  74. #define NUPP        8        /* Number ulimit blocks per page    */
  75. #define UPPSHFT        3        /* Shift for ulimit blocks per page */
  76.  
  77. #define PNUMSHFT    12        /* Shift for page number from addr. */
  78. #define POFFMASK        0xFFF        /* Mask for offset into page. */
  79. #define    PTOFFMASK    0x3FF        /* Mask for offset into page table/dir*/
  80. #define    PNDXMASK    PTOFFMASK    /* Mask for offset into kptbl.*/
  81. #define PGFNMASK    0xFFFFF        /* Mask page frame nbr after shift. */
  82. #define PTNUMSHFT    22        /* Shift for page table num from addr */
  83.  
  84. #define    NPTPP        1        /* Nbr of page tables per page.    */
  85. #define    NPTPPSHFT    0        /* Shift for NPTPP. */
  86.  
  87. /* Page descriptor (table) entry field masks */
  88.  
  89. #define PG_ADDR        0xFFFFF000    /* physical page address */
  90. #define PG_LOCK        0x00000800    /* page lock bit (software) */
  91. #define PG_NDREF    0x00000400    /* need reference bit (software) */
  92. #define PG_COPYW    0x00000200    /* copy on write bit */
  93. #define PG_M        0x00000040    /* modify bit */
  94. #define PG_REF        0x00000020    /* reference bit */
  95. #define    PG_US        0x00000004    /* 0=supervisor, 1=user */
  96. #define    PG_RW        0x00000002    /* 0=read-only, 1=read/write */
  97. #define PG_P        0x00000001    /* page present bit */
  98. #define PTE_RW        (PG_RW|PG_US)
  99.  
  100. #define PTSIZE        4096        /* page table size in bytes */
  101. #define PTSZSHFT    12        /* page table size shift count */
  102.  
  103.  
  104. /* byte addr to virtual page */
  105.  
  106. #define pnum(X)   (((uint)(X) >> PNUMSHFT) & PTOFFMASK) 
  107.  
  108. /* page frame number */
  109.  
  110. #define pfnum(X) (((uint)(X) >> PNUMSHFT) & PGFNMASK)
  111.  
  112. /* page offset */
  113.  
  114. #define poff(X)   ((uint)(X) & POFFMASK)
  115.  
  116. /* page table num (page dir entry) */
  117.  
  118. #define ptnum(X)    ((uint)(X) >> PTNUMSHFT)
  119.  
  120. #define pgndx(X)    (((X) >> PNUMSHFT) & PNDXMASK)
  121.  
  122. /* Round up page table address */
  123.  
  124. #define ptround(p)    ((int *) (((int)p + PTSIZE-1) & ~(PTSIZE-1)))
  125.  
  126. /* Round down page table address */
  127.  
  128. #define ptalign(p)    ((int *) ((int)p & ~(PTSIZE-1)))
  129.  
  130. /* Following added because svid says ulimit works in 512 byte units, so we must
  131.   have something independent of the blocksize of the file system implementation
  132.  
  133.     Ulimit blocks (512 bytes each) and pages.
  134.  */
  135.  
  136. #define utop(UU)    (((UU) + NUPP -1) >> UPPSHFT)
  137.  
  138. /*    Disk blocks (sectors) and pages.
  139. */
  140.  
  141. #define    ptod(PP)    ((PP) << DPPSHFT)
  142. #define    dtop(DD)    (((DD) + NDPP - 1) >> DPPSHFT)
  143. #define dtopt(DD)    ((DD) >> DPPSHFT)
  144.  
  145. /*    Disk blocks (sectors) and bytes.
  146. */
  147.  
  148. #define    dtob(DD)    ((DD) << SCTRSHFT)
  149. #define    btod(BB)    (((BB) + NBPSCTR - 1) >> SCTRSHFT)
  150. #define    btodt(BB)    ((BB) >> SCTRSHFT)
  151.  
  152. /*    Page tables to pages.
  153. */
  154.  
  155. #define    pttopgs(X)    ((X + NPTPP - 1) >> NPTPPSHFT)
  156. #define    pttob(X)    ((X) << BPTSHFT)
  157. #define    btopt(X)    (((X) + NBPPT - 1) >> BPTSHFT)
  158.  
  159. union ptbl *getptbl();        /* page table allocator */
  160.  
  161. extern int        nptalloced;
  162. extern int        nptfree;
  163.  
  164. /* Form page descriptor (table) entry from modes and page frame
  165. ** number
  166. */
  167.  
  168. #define    mkpde(mode,pfn)    (mode | ((pfn) << PNUMSHFT))
  169.  
  170. /*    The following macros are used to check the value
  171.  *    of the bits in a page descriptor (table) entry 
  172.  */
  173.  
  174. #define pg_isvalid(pde)     ((pde)->pgm.pg_pres)
  175. #define pg_islocked(pde)    ((pde)->pgm.pg_lock)
  176. #define pg_iswriteable(pde)     ((pde)->pgm.pg_rw)
  177.  
  178. /*    The following macros are used to set the value
  179.  *    of the bits in a page table entry 
  180.  *
  181.  *    Atomic instruction is available to clear the present bit,
  182.  *    other bits are set or cleared in a word operation.
  183.  */
  184.  
  185. #define pg_setvalid(P)    ((P)->pgi.pg_pde |= PG_P) /* Set valid bit.    */
  186. #define pg_clrvalid(P)    ((P)->pgi.pg_pde &= ~PG_P) /* Clear valid bit.    */
  187.  
  188. #define pg_setndref(P)    ((P)->pgi.pg_pde |= PG_NDREF)
  189.                         /* Set need ref bit.    */
  190. #define pg_clrndref(P)    ((P)->pgi.pg_pde &= ~PG_NDREF)
  191.                         /* Clr need ref bit.    */
  192.  
  193. #define pg_setlock(P)    ((P)->pgi.pg_pde |= PG_LOCK)    
  194.                         /* Set lock bit.    */
  195. #define pg_clrlock(P)    ((P)->pgi.pg_pde &= ~PG_LOCK) /* Clear lock bit.    */
  196.  
  197. #define pg_setmod(P)    ((P)->pgi.pg_pde |= PG_M)    
  198.                         /* Set modify bit.    */
  199. #define pg_clrmod(P)    ((P)->pgi.pg_pde &= ~PG_M)    
  200.                         /* Clear modify bit.    */
  201.  
  202. #define pg_setcw(P)    ((P)->pgi.pg_pde |= PG_COPYW), \
  203.             ((P)->pgi.pg_pde &= ~PG_RW)
  204.                         /* Set copy on write
  205.                          * and clear r/w
  206.                          */
  207.  
  208. #define pg_clrcw(P)    ((P)->pgi.pg_pde &= ~PG_COPYW) /* Clr copy on write.*/
  209.  
  210. #define pg_setref(P)    ((P)->pgi.pg_pde |= PG_REF)     /* Set ref bit.    */
  211. #define pg_clrref(P)    ((P)->pgi.pg_pde &= ~PG_REF) /* Clear ref bit.    */
  212.  
  213. #define pg_setprot(P,b)    ((P)->pgi.pg_pde |= b)    /* Set r/w access */
  214.  
  215. #define    SOFFMASK    0x3FFFFF    /* Mask for page table alignment */
  216. #define    SGENDMASK    0x3FFFFC    /* Mask for page table end alignment */
  217.  
  218. /*  access modes  */
  219.  
  220. #define KNONE  (unsigned char)  0x00
  221. #define KEO    (unsigned char)  0x40    /* KRO on WE32000    */
  222. #define KRE    (unsigned char)  0x80
  223. #define KRWE   (unsigned char)  0xC0    /* KRW on WE32000    */
  224.  
  225. #define UNONE  (unsigned char)  0x00
  226. #define UEO    (unsigned char)  0x01    /* URO on WE32000    */
  227. #define URE    (unsigned char)  0x02
  228. #define URWE   (unsigned char)  0x03    /* URW on WE32000    */
  229.  
  230. #define UACCESS (unsigned char) 0x03
  231. #define KACCESS (unsigned char) 0xC0
  232.  
  233. #define SEG_RO    (KRWE|URE)
  234. #define SEG_RW    (KRWE|URWE)
  235.  
  236. /*    The following variables describe the memory managed by
  237. **    the kernel.  This includes all memory above the kernel
  238. **    itself.
  239. */
  240.  
  241. extern paddr_t    kpbase;        /* The address of the start of    */
  242.                 /* the first physical page of    */
  243.                 /* memory above the kernel.    */
  244.                 /* Physical memory from here to    */
  245.                 /* the end of physical memory    */
  246.                 /* is represented in the pfdat.    */
  247. extern int    syssegs[];    /* Start of the system segment    */
  248.                 /* from which kernel space is    */
  249.                 /* allocated.  The actual value    */
  250.                 /* is defined in the vuifile.    */
  251. extern int    win_ublk[];    /* A window into which a    */
  252.                 /* u-block can be mapped.    */
  253. extern pde_t    *kptbl;        /* Kernel page table.  Used to    */
  254.                 /* map sysseg.            */
  255. extern pde_t    *usertable;    /* Common page table.  Used to    */
  256.                 /* map the current ublock.    */
  257. extern int    maxmem;        /* Maximum available free    */
  258.                 /* memory.            */
  259. extern int    freemem;    /* Current free memory.        */
  260. extern int    availrmem;    /* Available resident (not    */
  261.                 /* swapable) memory in pages.    */
  262. extern int    availsmem;    /* Available swapable memory in    */
  263.                 /* pages.            */
  264.  
  265. /*    Conversion macros
  266. */
  267.  
  268. /*    Get page number from system virtual address.  */
  269.  
  270. #define svtop(vaddr)    ((paddr_t)((vaddr) - KVBASE) >> PNUMSHFT)
  271.  
  272. /*    Get system virtual address from page number.  */
  273.  
  274. #define ptosv(paddr)    (((paddr) << PNUMSHFT) + KVBASE)
  275.  
  276.  
  277. /*    These macros are used to map between kernel virtual
  278. **      and physical address.
  279. */
  280.  
  281. #define kvtophys(vaddr) ((paddr_t)svirtophys(vaddr))
  282. #define phystokv(paddr) ((paddr) + KVBASE)
  283.  
  284. /*    The xphystokv() macro works for all physical addresses
  285. **    which correspond to main (RAM) memory.  This differs from
  286. **    phystokv() in that it can handle the Olivetti's extra 384K.
  287. **    Normally, this isn't an issue, since this 384K is used for
  288. **    kernel text.
  289. */
  290.  
  291. #define xphystokv(paddr) (((paddr) & 0x80000000) ? \
  292.         (paddr) + (KVXBASE - 0x80000000) : (paddr) + KVBASE)
  293.  
  294. /*    Between kernel virtual address and physical page frame number.
  295. */
  296.  
  297. #define kvtopfn(vaddr) (kvtophys(vaddr) >> PNUMSHFT)
  298. #define pfntokv(pfn)   (phystokv ((pfn) << PNUMSHFT))
  299.  
  300. /*    Between kernel virtual addresses and the kernel page
  301. **    table.
  302. */
  303.  
  304. #define    kvtokptbl(X)    (&kptbl[pgndx((uint)(X) - (uint)syssegs)])
  305.  
  306. /*    The following routines are involved with the pfdat
  307. **    table described in pfdat.h
  308. */
  309.  
  310. #define    kvtopfdat(kv)    (&pfdat[kvtopfn(kv) - btoc(kpbase)])
  311. #define    pfntopfdat(pfn)    (&pfdat[pfn - btoc(kpbase)])
  312. #define    pfdattopfn(pfd)    (pfd - pfdat + btoc(kpbase))
  313.  
  314. #ifndef    MSDEBUGGER
  315. /*
  316.  * pde_t *
  317.  * vatopdte(v)
  318.  * returns the page directory entry location of v.
  319.  */
  320.  
  321. #define    vatopdte(v)    ((pde_t *)phystokv(_cr3()) + ptnum(v))
  322. #else
  323. #define    vatopdte(v)    ((pde_t *) db_vtopdte(v))
  324. #endif
  325.  
  326. /*
  327.  * pde_t *
  328.  * vatopde(v, pdte)
  329.  * returns the page table entry location of v.
  330.  */
  331.  
  332. #define    vatopde(v, pdte) ((pde_t *)phystokv(ctob(pdte->pgm.pg_pfn)) + pnum(v))
  333.  
  334. /*
  335.  * pde_t *
  336.  * svtopde(v)
  337.  * returns the pt entry location of v.
  338.  *
  339.  * This macro works only with paged virtual address.
  340.  *
  341.  */
  342.  
  343. #define svtopde(v) ((pde_t *)phystokv(ctob((uint)(vatopdte(v)->pgm.pg_pfn))) + pnum(v))
  344.  
  345. /*
  346.  * svtopfn(v)
  347.  */
  348.  
  349. #define svtopfn(v) (pfnum(svirtophys(v)))
  350.  
  351. /*    Page frame number to kernel pde.
  352. */
  353.  
  354. #define    pfntokptbl(P)    (kvtokptbl(pfntokv(P)))
  355.  
  356. /*    Convert segment:offset 8086 far pointer to address
  357. */
  358.  
  359. #define    ftop(x)    ((((x) & 0xffff0000) >> 12) + ((x) & 0xffff))
  360.  
  361. /* flags used in ptmemall() call
  362. */
  363.  
  364. #define PHYSCONTIG 02
  365. #define NOSLEEP    01
  366.  
  367. /*
  368.  *  User address space offsets
  369.  *
  370.  *****************************  NOTE - NOTE  *********************************
  371.  *
  372.  *     ANY CHANGES IN THE FOLLOWING DEFINES NEED TO BE REFLECTED IN
  373.  *        EITHER ml/misc.s, OR ml/ttrap.s, OR BOTH.
  374.  */
  375.  
  376. #define UVBASE          ((unsigned)0x00000000L)     /* main store virtual address    */
  377. #define UVSTACK         ((unsigned)0x7FFFFFFCL)     /* stack bottom virtual address  */
  378. #define UVSHM           ((unsigned)0x80000000L)     /* Shared memory address         */
  379. #define KVBASE          ((unsigned)0xC0000000L)     /* base of kernel memory map     */
  380. #define KVSBASE         ((unsigned)0xD0000000L)     /* base for kernel text, data + bss */
  381. #define KVXBASE         ((unsigned)0xD8000000L)     /* base for extended memory      */
  382. #define UVUBLK          ((unsigned)0xE0000000L)     /* ublock virtual address        */
  383.  
  384. #define UVTEXT          UVBASE          /* beginning addrss of user text    */
  385. #define MINUVADR        UVTEXT          /* minimum user virtual address.    */
  386. #define MAXUVADR        KVBASE          /* maximum user virtual address.    */
  387. #define MINKVADR        KVBASE          /* minimum kernel virtual address.  */
  388. #define MAXKVADR        UVUBLK          /* maximum kernel virtual address.  */
  389.  
  390. #define KADDR(v)        ((v) >= MINKVADR && (v) < MAXKVADR)
  391.  
  392. #define    SEL_RPL        0x03
  393.