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

  1. /*
  2.  *    @(#) sysmacros.h 2.2 88/05/18 
  3.  *
  4.  *    Copyright (C) The Santa Cruz Operation, 1984, 1985, 1986, 1987, 1988.
  5.  *    Copyright (C) Microsoft Corporation, 1984, 1985, 1986, 1987, 1988.
  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. /*
  12.  * Some macros for units conversion
  13.  */
  14. /* Core clicks to segments and vice versa */
  15. #define ctos(x) ((x+(NCPS-1))/NCPS)
  16. #define    stoc(x) ((x)*NCPS)
  17.  
  18. /* Core clicks to disk blocks */
  19. #ifdef    NCPD
  20. #define    ctod(x) ((x+(NCPD-1))/NCPD)
  21. #else
  22. #define ctod(x)    ((x) * NDPC)
  23. #endif
  24.  
  25. /* inumber to disk address */
  26. #ifdef INOSHIFT
  27. #define    itod(x)    (daddr_t)(((unsigned)x+(2*INOPB-1))>>INOSHIFT)
  28. #else
  29. #define    itod(x)    (daddr_t)(((unsigned)x+(2*INOPB-1))/INOPB)
  30. #endif
  31.  
  32. /* inumber to disk offset */
  33. #ifdef INOSHIFT
  34. #define    itoo(x)    (int)(((unsigned)x+(2*INOPB-1))&(INOPB-1))
  35. #else
  36. #define    itoo(x)    (int)(((unsigned)x+(2*INOPB-1))%INOPB)
  37. #endif
  38.  
  39. /* clicks to bytes */
  40. #ifdef BPCSHIFT
  41. #define    ctob(x)    (((long) x) << BPCSHIFT)
  42. #else
  43. #define    ctob(x)    (((long) x) * NBPC)
  44. #endif
  45.  
  46. /* bytes to clicks */
  47. #ifdef BPCSHIFT
  48. #define    btoc(x)    (((unsigned)(x)+(NBPC-1))>>BPCSHIFT)
  49. #define    btoct(x)    ((unsigned)(x)>>BPCSHIFT)
  50. #else
  51. #define    btoc(x)    (((unsigned)(x)+(NBPC-1))/NBPC)
  52. #define    btoct(x)    ((unsigned)(x)/NBPC)
  53. #endif
  54.  
  55. /* major part of a device */
  56. #define    major(x)    (int)((unsigned)x>>8)
  57. #define    bmajor(x)    (int)(((unsigned)x>>8)&037)
  58. #define    brdev(x)    (x&0x1fff)
  59.  
  60. /* minor part of a device */
  61. #define    minor(x)    (int)(x&0377)
  62.  
  63. /* make a device number */
  64. #define    makedev(x,y)    (dev_t)(((x)<<8) | (y))
  65.  
  66.  
  67.  
  68. #ifndef M_I386
  69. /* far pointer (faddr_t) to segment (int) (get high 16 bits of faddr_t) */
  70. #define    ftoseg(x)        ((unsigned)((long)(x) >> 16))
  71.  
  72. /* far pointer (faddr_t) to offset (int) */
  73. #define    ftooff(x)        ((unsigned)((long)(x)))
  74.  
  75. /* real mode far pointer to physical address */
  76. #define ftop(x) \
  77.     ((paddr_t)((((long)(x) >> 12) & 0x000ffff0L) + (ushort)(x)))
  78.  
  79. /* seg off to far pointer (faddr_t) */
  80. #define sotofar(seg, off) \
  81.     (((char far *) (((long)(unsigned) (seg)) << 16)) + (unsigned) (off))
  82.  
  83. /* real mode seg, off to physical address */
  84. #define sotop(seg, off) \
  85.     ((((paddr_t) (ushort) (seg)) << 4) + (ushort) (off))
  86.  
  87. /* physical address to real mode far pointer */
  88. #define ptofar(p) \
  89.     ((char far *) ((((p) << 12) & 0xffff0000) + ((p) & 0x0000000f)))
  90.  
  91. /* physical address to real mode seg, off */
  92. #define ptoseg(p)    ((ushort) ((p) >> 4))
  93. #define ptooff(p)    ((ushort) (p) & 0x000f)
  94.  
  95. #define FADDR(seg, off)        off, seg
  96.  
  97. /* Memory location to real mode far pointer */
  98. #define mltofar(x)    ((char far *) ((long)(x) << 16 ))
  99.  
  100. /* Memory location to logical address */
  101. #define mltoa(x) ((paddr_t) (x) << LMMPGSZ)
  102.  
  103. /* address (long (32 bit)) to page count (int)*/
  104. #define    atoml(x)    ((int)(((paddr_t)(x)+(MMPGSZ-1))>>LMMPGSZ))
  105.  
  106. /* address (long (32 bit)) to page number (int)*/
  107. #define    atomlt(x)    ((int)(((paddr_t)(x))>>LMMPGSZ))
  108.  
  109. #define DSHFT      (BSHIFT-LMMPGSZ)
  110.  
  111. #define    mstod(x)  ((unsigned)((x) + BSIZE/MMPGSZ - 1) >> DSHFT)
  112. #define    dtoms(x)  ((x) << DSHFT)
  113.  
  114. #define    mstob(x)    ((x)<<LMMPGSZ)
  115.  
  116.  
  117.  
  118. #ifdef M_I8086
  119. /* bytes to mem size - this macro rounds up to a disk block boundary */
  120. /* process memory is allocated only in BSIZE chunks */
  121. #define btoms(x)  (msize_t)((x) ? (((((x)-1) | BMASK) >> LMMPGSZ) + 1) : 0)
  122.  
  123. /* bytes to pages */
  124. #define btop(x)    (((((unsigned)(x) - 1) | MMPGMASK) + 1) >> LMMPGSZ)
  125.  
  126. /* pages to bytes */
  127. #define ptob(x)    ((x) << LMMPGSZ)
  128. #endif
  129.  
  130. #ifdef M_I286
  131. /* bytes to mem size */
  132. #define    btoms(x)      ((unsigned) (((long)(x) + (MMPGSZ-1)) >> LMMPGSZ))
  133.  
  134. /* selector number to table index */
  135. #define stoi(sel)        ((sel)/SELSZ)
  136. #endif
  137.  
  138. #endif
  139.  
  140. /*    Calculate user process priority.  */
  141.  
  142. #ifdef VPIX
  143. #define calcppri(p)    ((p->p_cpu) >> 1) +  p->p_nice + (PUSER - NZERO)
  144. #endif
  145.