home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 202.img / SCO386N2.TD0 / usr / include / sys / mmu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-18  |  8.3 KB  |  287 lines

  1. /*
  2.  *    @(#) mmu.h 2.3 88/05/18 
  3.  *
  4.  *    Copyright (C) The Santa Cruz Operation, 1984, 1985, 1986, 1987.
  5.  *    Copyright (C) Microsoft Corporation, 1984, 1985, 1986, 1987.
  6.  *    This Module contains Proprietary Information of
  7.  *    The Santa Cruz Operation, Microsoft Corporation
  8.  *    and AT&T, and should be treated as Confidential.
  9.  */
  10.  
  11. #ifdef M_I386
  12.  
  13. #define    MMUERR ((int)-1)
  14.  
  15. #define INVALID ((caddr_t)-1)
  16.  
  17. /* bytes to memory size (page/click) */
  18. #define btoms(x)    btoc(x)
  19.  
  20. /* memory size (click/page) to bytes */
  21. #define mstob(x)    ctob(x)
  22. #define mltoa(x)    ctob(x)
  23.  
  24. /* number of pages in a segment (used for setting baseaddr of 286 ldts) */
  25. #define NPGS        17
  26.  
  27. /* memory size to disk blocks */
  28. #define mstod(x)    (ctob(x)/BSIZE)
  29.  
  30. /* convert segment:offset 8086 far pointer to address */
  31. #define ftop(x)    (((x & 0xffff0000) >> 12) + (x & 0xffff))
  32.  
  33. /*
  34.  * defines for 286 compatibility
  35.  */
  36. #define    MMPGSZ    512        /* bytes/page in the MMU */
  37. #define    LMMPGSZ    9        /* log2(MMPGSZ) */
  38. #define NPAGEPS    128        /* 64k/MMPGSZ = number of pages per segment */
  39.  
  40. /* mem size to bytes */
  41. #define    mstob286(x)    ((x)<<LMMPGSZ)
  42.  
  43. /* bytes to mem size */
  44. #define    btoms286(x)      ((unsigned) (((long)(x) + (MMPGSZ-1)) >> LMMPGSZ))
  45.  
  46. #else
  47.  
  48. /*
  49.  * mmu.h
  50.  *    Memory Management Definitions
  51.  *
  52.  * used by mmu.c
  53.  * param.h has basic page-size/etc definitions.
  54.  *
  55.  * definitions for 286/8086 memory managment model
  56.  *
  57.  */
  58.  
  59. #ifdef M_I8086
  60. extern short mm_size;        /* #mem pages initialized to NCOREL */
  61.  
  62. #define    RO    0
  63. #define    RW    1
  64.  
  65. #define    MMUERR    -1        /* error return from MMU routines */
  66. #define    MMUOK    0        /* normal return from MMU routines */
  67.  
  68. #define    SEGKD    0
  69.  
  70. #define    SEGUD    (u.u_usegs[0])
  71. #define    SEGUI    (u.u_usegs[1])
  72. #endif /* M_I8086 */
  73.  
  74. #define NDSEGS    3    /* number of data segments the kernel may have*/
  75. #define NCSEGS    7    /* number of text segments the kernel may have*/
  76.  
  77. #include "relsym86.h"
  78.  
  79. #define SELSZ        sizeof(struct desctab)
  80.  
  81. #ifdef M_I286
  82.  
  83. #define    NBUFSEL    16    /* number of selectors for mapped out buffers */
  84.  
  85. /*
  86.  * descriptor table defines
  87.  * NOTE: the RPL in USEG_SEL and ULDT_SEL is 0. This
  88.  *     does not ENFORCE protection
  89.  */
  90. #define    NULL_SEL    0    /* 'invalid' selector */
  91. /* 
  92.  * portable gdt defines
  93.  * WARNING - these must agree with the layout of the gdt in oem.c
  94.  */
  95. #define    GDT_SEL        0x8    /* selector for GDT alias */
  96. #define    IDT_SEL        0x10    /* selector for IDT alias */
  97. #define KDS_SEL        0x18    /* 1st kernel data seg selector */
  98. #define    KCS_SEL        0x30    /* 1st kernel code seg selector */
  99. #define    KSS_SEL        0x68    /* kernel stack seg selector */
  100. #define    KTSS        0x70    /* kernel TSS selector */
  101. #define    SFTSS        0x78    /* stack fault TSS selector */
  102. #define    KWORK0        0x80    /* work segment selector */
  103. #define    KWORK1        0x88    /* work segment selector */
  104. #define    KWORK2        0x90    /* work segment selector */
  105. #define    MAPWKSEL    0x98    /* selector for map work */
  106. #define COPY_SEL    0xA0    /* selector for copyio */
  107. #define    CLDT_SEL    0xA8    /* current process' ldt selector */
  108. #define    KENTRY        0xB0    /* kernel entry selector (call gate) */
  109.                 /* 0xB8 and 0xC0 reserved */
  110. #define BUF_SEL        0xC8    /* 1st of 16 selectors to map buffers */
  111. #define    SWAP1_SEL    0x148    /* work segment selector - swap */
  112. #define    SWAP2_SEL    0x150    /* work segment selector - swap */
  113. #define    SWAP3_SEL    0x158    /* work segment selector - swap */
  114. #define    SWAP4_SEL    0x160    /* work segment selector - swap */
  115. #define FREE_SEL    0x168    /* 1st dscralloc() selector */
  116.  
  117. #define NGDT    (stoi(FREE_SEL)+1 + 40)       /*  86 ; 40 dscralloc() selectors */
  118.  
  119. /* 
  120.  * ldt defines 
  121.  * These selector definitions should not be touched - they are chip
  122.  * and linker defined
  123.  */
  124. #define    USEG_SEL    0x04    /* LDT based U seg selector */
  125. #define    ULDT_SEL    0x0C    /* ldt based, ldt alias */
  126. #define    ULINFO_SEL    0x14    /* used for ldt info array */
  127. #define UEXEC_SEL    0x1C    /* used during an exec */
  128. #define    ULDTTMP_SEL    0x24    /* used for execing and in mmu routines */
  129. #define    UTEMP_SEL    0x2C    /* used for swapping, etc */
  130. #define    UOVRLY_SEL    0x34    /* used with overlay files */
  131. #define    FIRSTU_SEL    0x3F    /* user's initial selector */
  132.  
  133. #define LDTPAD        8    /* number extra ldt slots allocated per proc */                    /* size of an ldt entry in bytes (8) */
  134. #define MAXLDT        8192    /* maximum number of entries in an ldt */
  135. #define KERNLDT         7    /* number of kernel reserved ldts */
  136.  
  137. #define IDTSZ        256            /* number of entries in idt */
  138. #define IDTLIM        (IDTSZ * SELSZ) -1    /* idt limit */
  139.  
  140. /*
  141.  * Descriptor Types
  142.  */
  143. #define    DST_ATASK    0x1    /* avail task */
  144. #define    DST_TABLE    0x2    /* descriptor table */
  145. #define    DST_BTASK    0x3    /* busy task */
  146. #define    DST_CGATE    0x4    /* call gate */
  147. #define    DST_TAGATE    0x5    /* task context gate */
  148. #define    DST_IGATE    0x6    /* interrupt gate */
  149. #define    DST_TRGATE    0x7    /* trap gate */
  150.  
  151. /*
  152.  * access byte fields (DSA_*) are defined in relsym86.h
  153.  */
  154.  
  155.  
  156. /*
  157.  * tss structure
  158.  */
  159.  
  160. struct tss {
  161.     unsigned    t_link;        /* previous tss selector */
  162.     unsigned    t_sp0;        /* stack for level 0 */
  163.     unsigned    t_ss0;
  164.     unsigned    t_sp1;        /* stack for level 1 */
  165.     unsigned    t_ss1;
  166.     unsigned    t_sp2;        /* stack for level 2 */
  167.     unsigned    t_ss2;
  168.     unsigned    t_ip;        /* task state - ip */
  169.     unsigned    t_flags;    /* task state - flags */
  170.     unsigned    t_ax;        /* task state - ax */
  171.     unsigned    t_cx;        /* task state - cx */
  172.     unsigned    t_dx;        /* task state - dx */
  173.     unsigned    t_bx;        /* task state - bx */
  174.     unsigned    t_sp;        /* task state - sp */
  175.     unsigned    t_bp;        /* task state - bp */
  176.     unsigned    t_si;        /* task state - si */
  177.     unsigned    t_di;        /* task state - di */
  178.     unsigned    t_es;        /* task state - es */
  179.     unsigned    t_cs;        /* task state - cs */
  180.     unsigned    t_ss;        /* task state - ss */
  181.     unsigned    t_ds;        /* task state - ds */
  182.     unsigned    t_ldt;        /* task ldt selector */
  183. };
  184.  
  185. #define TSSLIM        (sizeof(struct tss) - 1)     /* tss limit */
  186.  
  187. /*
  188.  * flag register bits
  189.  */
  190. #define    FL_NCX        0x4000    /* nested context */
  191. #define    FL_IOPL        0x3000    /* I/O priv level */
  192. #define    FL_OFLOW    0x800    /* overflow bit */
  193. #define    FL_DIR        0x400    /* direction of string ops */
  194. #define    FL_INTEN    0x200    /* interrupt enable */
  195. #define    FL_TRAP        0x100    /* single step flag */
  196. #define    FL_SIGN        0x80    /* sign bit */
  197. #define    FL_ZERO        0x40    /* zero bit */
  198. #define    FL_AUXCARRY    0x10    /* auxillary carry */
  199. #define    FL_PARITY    0x4    /* parity bit */
  200. #define    FL_CARRY    0x1    /* carry bit */
  201.  
  202. /*
  203.  * parts of a selector see relsym86.h
  204.  */
  205. #define    SEL_TI        SEL_LDT    /* table indicator (0-gdt,1-ldt) */
  206.  
  207. /*
  208.  * descriptor table structure: see relsym86.h
  209.  */
  210. #define NPSEGM    0        /* no segments */
  211.  
  212. /*
  213.  * Misc constants.
  214.  */
  215. #define OFFMASK    (MMPGSZ-1)    /* develop offset within page from addr */
  216.  
  217. #define RO (DSA_CODE|DSA_RING3) /* tells mmuset to setup code to make */
  218. #define RW (DSA_DATA|DSA_RING3) /* kernel access read-only, or rd/wr */
  219.  
  220. #define    MMUOK    ((mloc_t) 0)
  221. #define    MMUERR    ((mloc_t) -1)
  222.  
  223. struct ldtinf {
  224.     unsigned short flag;
  225.     union {
  226.         unsigned short psize;    /* used for exec */
  227.         unsigned short swapbn;    /* block # on swapper */
  228.         unsigned short dupsel;    /* sel this sel is dup of, if LT_DUP */
  229.     } si;
  230. };
  231.  
  232. /* 
  233.  * ldtinf flag values indicating the type of segment represented
  234.  */
  235.  
  236. #define LT_OWN        0x0001        /* maps user-owned, private memory */
  237. #define LT_ALLOC    0x0002        /* swapper must allocate mem for exec */
  238. #define LT_EXPAND    0x0004        /* expanding segment -used by swapper */
  239. #define LT_ITER        0x0008        /* iterated data or text segment */
  240. #define LT_SD        0x0010        /* shared data segment */
  241. #define LT_ABS        0x0020        /* maps fixed location (i.e. screen) */
  242. #define LT_DUP        0x0040        /* duplicate mapping */
  243. #define LT_EXEC        0x0080        /* executable segment */
  244. #define LT_RO        0x0100        /* read-only segment */
  245. #define LT_HUGE        0x0200        /* allocated as HUGE seg by brkctl */
  246. #define LT_CONTIG    0x0400        /* maps a segment in a series */
  247.                     /*  of physically contiguous segments */
  248. #define LT_FCONTIG    0x0800        /* first in a series of physically */
  249.                     /* contiguous segments */
  250.  
  251. extern fdesc_t *ldt;            /* ULDT_SEL:0 */
  252. #define    flinf_t        struct ldtinf far    /* far ldt info array entry */
  253. extern flinf_t *ldtinfo;        /* ULINFO_SEL:0 */
  254. #ifndef NOEXTGDT
  255. extern struct desctab gdt[];
  256. #endif
  257.  
  258. extern mloc_t mmupget();
  259. extern mloc_t mmuget();
  260.  
  261. /*
  262.  * LDTDESCR initializes an ldt entry
  263.  */
  264. #define LDTDESCR(sel, addr, limit, access)    \
  265. if (1) {                    \
  266.     int xacc = access;            \
  267.     fdesc_t *_p = &ldt[sel/SELSZ];        \
  268.     _p->d_limit = limit;            \
  269.     _p->d_paddr = addr;            \
  270.     _p->d_acc = xacc;            \
  271. } else
  272.  
  273. /*
  274.  * GDTDESCR initializes a gdt entry
  275.  */
  276. #define GDTDESCR(sel, addr, limit, access)    \
  277. if (1) {                    \
  278.     int xacc = access;            \
  279.     struct desctab *_p = &gdt[sel/SELSZ];    \
  280.     _p->d_limit = limit;            \
  281.     _p->d_paddr = addr;            \
  282.     _p->d_acc = xacc;            \
  283. } else
  284.  
  285. #endif /* M_I286 */
  286. #endif /* M_I386 */
  287.