home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 8.ddi / usr / include / sys / immu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  11.1 KB  |  373 lines

  1. /*    Copyright (c) 1990 UNIX System Laboratories, Inc.    */
  2. /*    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T    */
  3. /*      All Rights Reserved      */
  4.  
  5. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF         */
  6. /*    UNIX System Laboratories, Inc.                         */
  7. /*    The copyright notice above does not evidence any       */
  8. /*    actual or intended publication of such source code.    */
  9.  
  10. #ifndef _SYS_IMMU_H
  11. #define _SYS_IMMU_H
  12.  
  13. #ident    "@(#)/usr/include/sys/immu.h.sl 1.1 4.0 12/08/90 26902 AT&T-USL"
  14.  
  15. /*
  16.  * Page Table Entry Definitions
  17.  */
  18.  
  19. typedef union pte {    /*  page table entry  */
  20.  
  21. /*                                                 */
  22. /*                        DEBUG                    */
  23. /*                        only                     */
  24. /*  +---------------------+---+---+-+-+---+-+-+-+  */
  25. /*  |        pfn          |tag|   |m|r|   |u|r|p|  */
  26. /*  +---------------------+---+---+-+-+---+-+-+-+  */
  27. /*            20            3   2  1 1  2  1 1 1   */
  28. /*                                                 */
  29.     struct {
  30.         uint pg_v    :  1,    /* Page is valid, i.e. present */
  31.              pg_rw    :  1,    /* read/write */
  32.              pg_us    :  1,    /* user/supervisor */
  33.                      :  2,    /* Reserved by hardware.    */
  34.              pg_ref    :  1,    /* Page has been referenced */
  35.              pg_mod    :  1,    /* Page has been modified */
  36.                 :  2,    /* Reserved by hardware.    */
  37.              pg_tag    :  3,    /* Unused software bits.    */
  38.              pg_pfn    : 20;    /* Physical page frame number    */
  39.     } pgm;
  40.     uint    pg_pte;        /* Full page table entry    */
  41. } pte_t;
  42.  
  43. /*
  44.  *    Page Table
  45.  */
  46.  
  47. #define NPGPT        1024    /* Nbr of pages per page table (seg). */
  48.  
  49. typedef struct ptbl {
  50.     int page[NPGPT];
  51. } ptbl_t;
  52.  
  53. /* Page table entry dependent constants */
  54.  
  55. #define    NBPP        4096        /* Number of bytes per page */
  56. #define    NBPPT        4096        /* Number of bytes per page table */
  57. #define    BPTSHFT        12         /* LOG2(NBPPT) if exact */
  58. #define    NPTPP        1        /* Nbr of page tables per page.    */
  59. #define    NPTPPSHFT    0        /* Shift for NPTPP. */
  60.  
  61. /* Following added because svid says ulimit works in 512 byte units. so we must
  62.   have something independent of the blocksize of the file system implementation
  63.  */
  64. #define NUPP        8        /* Number ulimit blocks per page    */
  65. #define UPPSHFT        3        /* Shift for ulimit blocks per page */
  66.  
  67. #define PNUMSHFT    12        /* Shift for page number from addr. */
  68. #define PNUMMASK    0x3FF        /* Mask for index in page table */
  69. #define POFFMASK        0xFFF        /* Mask for offset into page. */
  70. #define    PTOFFMASK    0x3FF        /* Mask for offset into page table/dir*/
  71. #define    PNDXMASK    PTOFFMASK    /* Mask for offset into kptbl.*/
  72. #define PGFNMASK    0xFFFFF        /* Mask page frame nbr after shift. */
  73. #define PTNUMSHFT    22        /* Shift for page table num from addr */
  74. #define PTSIZE        4096        /* Page table size in bytes */
  75. #define    PTMASK        (PTSIZE - 1)    /* Mask for page table size */
  76. #define VPTSIZE        (1<<PTNUMSHFT)    /* Virtual bytes described by    */
  77.                     /* a page table.        */
  78.  
  79. /* Page descriptor (table) entry field masks */
  80.  
  81. #define PT_ADDR        0xFFC00000    /* physical page table address */
  82. #define PG_ADDR        0xFFFFF000    /* physical page address */
  83. #ifdef DEBUG
  84. #define PG_LOCKCNT    0x00000E00    /* mapping SOFTLOCK count (software) */
  85. #endif
  86. #define PG_M        0x00000040    /* modify bit */
  87. #define PG_REF        0x00000020    /* reference bit */
  88. #define    PG_US        0x00000004    /* 0=supervisor, 1=user */
  89. #define    PG_RW        0x00000002    /* 0=read-only, 1=read/write */
  90. #define PG_V        0x00000001    /* page valid bit */
  91. #define PG_P        PG_V        /* for source compatibility */
  92. #define PTE_RW        (PG_RW|PG_US)
  93. #define PTE_PROTMASK    PTE_RW
  94.  
  95. #define O_PG_LOCK    0x00000800    /* OBSOLETE; for binary compatibility */
  96. #define PG_LOCK        0        /* OBSOLETE; for source compatibility */
  97.  
  98. #define XMEM_BIT    0x80000000    /* bit to indicate 2GB extra mem */
  99.  
  100. /* The page number within a section. */
  101.  
  102. #define ptnum(X)    ((uint)(X) >> PTNUMSHFT)
  103.  
  104. #define pgndx(x)    (((x) >> PNUMSHFT) & PNDXMASK)
  105.  
  106. /* Round up page table address */
  107.  
  108. #define ptround(p)    ((int *) (((uint)(p) + PTSIZE-1) & ~(PTSIZE-1)))
  109.  
  110. /* Round down page table address */
  111.  
  112. #define pttrunc(p)    ((int *) ((uint)(p) & ~(PTSIZE-1)))
  113. #define ptalign(p)    pttrunc(p)
  114.  
  115. #define pnum(X)      (((uint)(X) >> PNUMSHFT) & PTOFFMASK) 
  116. #define pfnum(X)    (((uint)(X) >> PNUMSHFT) & PGFNMASK)
  117. #define PFNUM(X)    pfnum(X)
  118.  
  119. /* Following added because svid says ulimit works in 512 byte units, so we must
  120.    have something independent of the blocksize of the file system implementation
  121.  
  122.     Ulimit blocks (512 bytes each) and pages.
  123.  */
  124.  
  125. #define utop(UU)    (((UU) + NUPP -1) >> UPPSHFT)
  126.  
  127. /* Page tables (1024 entries == 4k bytes) to pages. */
  128.  
  129. #define    pttopgs(x)    (((x) + NPTPP - 1) >> NPTPPSHFT)
  130. #define    pttob(x)    ((x) << BPTSHFT)
  131. #define    btopt(x)    (((x) + NBPPT - 1) >> BPTSHFT)
  132.  
  133. /* Form page table entry from modes and page frame number */
  134.  
  135. #define    mkpte(mode,pfn)    (mode | ((uint)(pfn) << PNUMSHFT))
  136.  
  137. /*    The following macros are used to set/check the value
  138.  *    of the bits in a page descriptor (table) entry 
  139.  *
  140.  *    Atomic instruction is available to clear the present bit,
  141.  *    other bits are set or cleared in a word operation.
  142.  */
  143.  
  144. #define PG_ISVALID(pte)     ((pte)->pgm.pg_v)
  145. #define PG_SETVALID(pte)    ((pte)->pg_pte |= PG_V)
  146. #define PG_CLRVALID(pte)    ((pte)->pg_pte &= ~PG_V)
  147.  
  148. #define PG_SETMOD(pte)       ((pte)->pg_pte |= PG_M)    
  149. #define PG_CLRMOD(pte)       ((pte)->pg_pte &= ~PG_M)    
  150.  
  151. #define PG_SETREF(pte)        ((pte)->pg_pte |= PG_REF)
  152. #define PG_CLRREF(pte)        ((pte)->pg_pte &= ~PG_REF)
  153.  
  154. #define PG_ISWRITEABLE(pte)    ((pte)->pgm.pg_rw)
  155. #define PG_CLRW(pte)        ((pte)->pg_pte &= ~(PG_RW))
  156.  
  157. #define PG_SETPROT(pte,b)    ((pte)->pg_pte |= b)    /* Set r/w access */
  158. #define PG_CLRPROT(pte)        ((pte)->pg_pte &= ~(PTE_PROTMASK))
  159.  
  160. #ifdef DEBUG
  161.  
  162. /*
  163.  * Macros to keep track of SOFTLOCKs on a mapping.
  164.  */
  165.  
  166. #define PG_ISLOCKED(pte)    ((pte)->pgm.pg_tag)
  167. #define PG_SETLOCK(pte)        { \
  168.     if ((pte)->pgm.pg_tag == 7) \
  169.         cmn_err(CE_PANIC, "Too many SOFTLOCKs on mapping !\n"); \
  170.     ++(pte)->pgm.pg_tag; \
  171. }
  172. #define PG_CLRLOCK(pte)    { \
  173.     if ((pte)->pgm.pg_tag == 0) \
  174.         cmn_err(CE_PANIC, "SOFTUNLOCK on an unlocked mapping !\n"); \
  175.     --(pte)->pgm.pg_tag; \
  176. }
  177.  
  178. #else
  179.  
  180. #define PG_ISLOCKED(pte)
  181. #define PG_SETLOCK(pte)
  182. #define PG_CLRLOCK(pte)
  183.  
  184. #endif
  185.  
  186. #define SOFFMASK    0x3FFFFF    /* Mask for page table alignment */
  187. #define SGENDMASK    0x3FFFFC    /* Mask for page table end alignment */
  188.  
  189. /*  access modes  */
  190.  
  191. #define KNONE  (unsigned char)  0x00
  192. #define KEO    (unsigned char)  0x40    /* KRO on WE32000    */
  193. #define KRE    (unsigned char)  0x80
  194. #define KRWE   (unsigned char)  0xC0    /* KRW on WE32000    */
  195.  
  196. #define UNONE  (unsigned char)  0x00
  197. #define UEO    (unsigned char)  0x01    /* URO on WE32000    */
  198. #define URE    (unsigned char)  0x02
  199. #define URWE   (unsigned char)  0x03    /* URW on WE32000    */
  200.  
  201. #define UACCESS (unsigned char) 0x03
  202. #define KACCESS (unsigned char) 0xC0
  203.  
  204. #define SEG_RO    (KRWE|URE)
  205. #define SEG_RW    (KRWE|URWE)
  206.  
  207.  
  208. #define PAGNUM(x)   (((uint)(x) >> PNUMSHFT) & PNUMMASK)
  209. #define PAGOFF(x)   (((uint)(x)) & POFFMASK)
  210.  
  211.  
  212. /*    The following variables describe the memory managed by
  213. **    the kernel.  This includes all memory above the kernel
  214. **    itself.
  215. */
  216.  
  217. extern int    syssegs[];    /* Start of the system segment    */
  218.                 /* from which kernel space is    */
  219.                 /* allocated.  The actual value    */
  220.                 /* is defined in the vuifile.    */
  221. extern pte_t    *kptbl;        /* Kernel page table.  Used to    */
  222.                 /* map sysseg.            */
  223. extern pte_t    *usertable;    /* Common page table.  Used to    */
  224.                 /* map the current ublock.    */
  225. extern int    maxmem;        /* Maximum available free    */
  226.                 /* memory.            */
  227. extern int    freemem;    /* Current free memory.        */
  228. extern int    availrmem;    /* Available resident (not    */
  229.                 /* swapable) memory in pages.    */
  230. extern int    availsmem;    /* Available swapable memory in    */
  231.                 /* pages.            */
  232.  
  233. /*    Conversion macros
  234. */
  235.  
  236. /*    Get page number from system virtual address.  */
  237.  
  238.  
  239. /*    Between kernel virtual address and physical page frame number.
  240. */
  241.  
  242. #define svtop(vaddr)    ((((unsigned long) (vaddr) >= KVXBASE) ? \
  243.             ((vaddr) - KVXBASE) + X_MEMBIT : (vaddr) - KVBASE) \
  244.             >> PNUMSHFT)
  245.  
  246. /*    Get system virtual address from page number.  */
  247.  
  248. #define ptosv(pfn)   (phystokv((pfn) << PNUMSHFT))
  249.  
  250.  
  251. /*    These macros are used to map between kernel virtual
  252. **      and physical address.
  253. */
  254.  
  255. extern paddr_t    svirtophys(/* va */);
  256.  
  257. #define phystokv(paddr) xphystokv(paddr)
  258.  
  259. /*    The xphystokv() macro works for all physical addresses
  260. **    which correspond to main (RAM) memory.  This differs from
  261. **    phystokv() in that it can handle the Olivetti's extra 384K.
  262. **    Normally, this isn't an issue, since this 384K is used for
  263. **    kernel text.
  264. */
  265.  
  266. #define xphystokv(paddr) (((unsigned long)(paddr) & XMEM_BIT) ? \
  267.         (paddr) + (KVXBASE - XMEM_BIT) : (paddr) + KVBASE)
  268.  
  269. /*    Between kernel virtual address and physical page frame number.
  270. */
  271.  
  272. #define phystopfn(paddr)    ((u_int)(paddr) >> PNUMSHFT)
  273. #define pfntophys(pfn)      ((pfn) << PNUMSHFT)
  274. #define kvtopfn(vaddr)         (kvtophys(vaddr) >> PNUMSHFT)
  275. #define pfntokv(pfn)           (phystokv ((pfn) << PNUMSHFT))
  276.  
  277. /*    Between kernel virtual addresses and the kernel page
  278. **    table.
  279. */
  280.  
  281. #define    kvtokptbl(x)    (&kptbl[pgndx((uint)(x) - (uint)syssegs)])
  282.  
  283. /*
  284.  * pte_t *
  285.  * vatopdte(v)
  286.  * returns the page directory entry location of v.
  287.  */
  288.  
  289. #define    vatopdte(v)    (&kpd0[ptnum(v)])
  290.  
  291. /*
  292.  * pte_t *
  293.  * vatopte(v, pdte)
  294.  * returns the page table entry location of v.
  295.  */
  296.  
  297. #define    vatopte(v, pdte) ((pte_t *)phystokv(ctob(pdte->pgm.pg_pfn)) + pnum(v))
  298.  
  299. /*
  300.  * pte_t *
  301.  * svtopte(v)
  302.  * returns the pt entry location of v.
  303.  *
  304.  * This macro works only with paged virtual address.
  305.  *
  306.  */
  307.  
  308. #define svtopte(v) ((pte_t *)phystokv(ctob((uint)(vatopdte(v)->pgm.pg_pfn))) + pnum(v))
  309.  
  310. /*
  311.  * svtopfn(v)
  312.  */
  313.  
  314. #define svtopfn(v) (PAGNUM(svirtophys(v)))
  315.  
  316. /*    Page frame number to kernel pte.
  317. */
  318.  
  319. #define    pfntokptbl(p)    (kvtokptbl(pfntokv(p)))
  320.  
  321. /*    Convert segment:offset 8086 far pointer to address
  322. */
  323.  
  324. #define    ftop(x)    ((((x) & 0xffff0000) >> 12) + ((x) & 0xffff))
  325.  
  326.  
  327. /* flags used in ptmemall() call
  328. */
  329.  
  330. #define PHYSCONTIG 02
  331. #define NOSLEEP    01
  332.  
  333.  
  334. /*    Declarations for kernel variables
  335. */
  336.  
  337. #ifdef _KERNEL
  338.  
  339. extern pte_t    kpd0[];        /* Global system page directory */
  340.  
  341. #endif /* _KERNEL */
  342.  
  343.  
  344. /*
  345.  *  User address space offsets
  346.  *
  347.  *****************************  NOTE - NOTE  *********************************
  348.  *
  349.  *     ANY CHANGES IN THE FOLLOWING DEFINES NEED TO BE REFLECTED IN
  350.  *        EITHER ml/misc.s, OR ml/ttrap.s, OR BOTH.
  351.  */
  352.  
  353. #define UVBASE          ((unsigned)0x00000000L)     /* main store virtual address    */
  354. #define UVSTACK         ((unsigned)0x7FFFFFFCL)     /* stack bottom virtual address  */
  355. #define UVSHM           ((unsigned)0x80000000L)     /* Shared memory address         */
  356. #define KVBASE          ((unsigned)0xC0000000L)     /* base of kernel memory map     */
  357. #define KVXBASE         ((unsigned)0xC8000000L)     /* base for extended memory      */
  358. #define KVSBASE         ((unsigned)0xD0000000L)     /* base for kernel text, data + bss */
  359. #define UVUBLK          ((unsigned)0xE0000000L)     /* ublock virtual address        */
  360.  
  361. #define UVTEXT          UVBASE          /* beginning addrss of user text    */
  362. #define UVEND        KVBASE        /* end of user virtual address range */
  363. #define MINUVADR        UVTEXT          /* minimum user virtual address.    */
  364. #define MAXUVADR        KVBASE          /* maximum user virtual address.    */
  365. #define MINKVADR        KVBASE          /* minimum kernel virtual address.  */
  366. #define MAXKVADR        UVUBLK          /* maximum kernel virtual address.  */
  367.  
  368. #define KADDR(v)        ((v) >= MINKVADR)
  369.  
  370. #define    SEL_RPL        0x03
  371.  
  372. #endif    /* _SYS_IMMU_H */
  373.