home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v17n02 / 386bsd.292 next >
Encoding:
Text File  |  1991-12-17  |  3.4 KB  |  79 lines

  1. .po 0
  2. [LISTING ONE]
  3.  
  4.  
  5. /* [Excerpted from /sys/i386/include/param.h] */
  6.    ...
  7. #ifndef __ORPL__
  8. /* Interrupt Group Masks  */
  9. extern  u_short __highmask__;   /* interrupts masked with splhigh() */
  10. extern  u_short __ttymask__;    /* interrupts masked with spltty() */
  11. extern  u_short __biomask__;    /* interrupts masked with splbio() */
  12. extern  u_short __netmask__;    /* interrupts masked with splimp() */
  13. extern  u_short __protomask__;  /* interrupts masked with splnet() */
  14. extern  u_short __nonemask__;   /* interrupts masked with splnone() */
  15.  
  16. asm("   .set IO_ICU1, 0x20 ; .set IO_ICU2, 0xa0 "); 
  17.  
  18. /* adjust priority level to disable a group of interrupts */
  19. #define __ORPL__(m) ({ u_short oldpl, msk; \
  20.     msk = (msk); \
  21.     asm volatile (" \
  22.     cli ;                   /* modify interrupts atomically */ \
  23.     movw    %1, %%dx ;      /* get mask to OR in */ \
  24.     inb $ IO_ICU1+1, %%al ; /* get low order mask */ \
  25.     xchgb   %%dl, %%al ;    /* switch the old with the new */ \
  26.     orb %%dl, %%al ;        /* finally, OR both it in! */ \
  27.     outb    %%al, $ IO_ICU1+1 ;     /* and stuff it back where it came */ \
  28.     inb $ 0x84, %%al ;      /* post it & handle write recovery */ \
  29.     inb $ IO_ICU2+1, %%al ; /* next, get high order mask */ \
  30.     xchgb   %%dh, %%al ;    /* switch the old with the new */ \
  31.     orb %%dh, %%al ;        /* finally, or it in! */ \
  32.     outb    %%al, $ IO_ICU2+1 ;     /* and stuff it back where it came */ \
  33.     inb $ 0x84, %%al ;      /* post it & handle write recovery */ \
  34.     movw    %%dx, %0 ;      /* return old mask */ \
  35.     sti                     /* allow interrupts again */ " \
  36.     : "&=g" (oldpl)         /* return values */ \
  37.     : "g" ((m))             /* arguments */ \
  38.     : "ax", "dx"            /* registers used */ \
  39.     ); \
  40.     oldpl;                  /* return the "old" value */ \
  41. })
  42. /* force priority mask to a set value */
  43. #define __SETPL__(m)    ({ u_short oldpl, msk; \
  44.     msk = (msk); \
  45.     asm volatile (" \
  46.     cli ;                   /* modify interrupts atomically */ \
  47.     movw    %1, %%dx ;      /* get mask to OR in */ \
  48.     inb $ IO_ICU1+1, %%al ; /* get low order mask */ \
  49.     xchgb   %%dl, %%al ;    /* switch the old with the new */ \
  50.     outb    %%al, $ IO_ICU1+1 ;     /* and stuff it back where it came */ \
  51.     inb $ 0x84, %%al ;      /* post it & handle write recovery */ \
  52.     inb $ IO_ICU2+1, %%al ; /* next, get high order mask */ \
  53.     xchgb   %%dh, %%al ;    /* switch the old with the new */ \
  54.     outb    %%al, $ IO_ICU2+1 ;     /* and stuff it back where it came */ \
  55.     inb $ 0x84, %%al ;      /* post it & handle write recovery */ \
  56.     movw    %%dx, %0 ;      /* return old mask */ \
  57.     sti                     /* allow interrupts again */ " \
  58.     : "&=g" (oldpl)         /* return values */ \
  59.     : "g" ((m))             /* arguments */ \
  60.     : "ax", "dx"            /* registers used */ \
  61.     ); \
  62.     oldpl;                  /* return the "old" value */ \
  63. })
  64. #define splhigh()   __ORPL__(__highmask__)
  65. #define spltty()    __ORPL__(__ttymask__)
  66. #define splbio()    __ORPL__(__biomask__)
  67. #define splimp()    __ORPL__(__netmask__)
  68. #define splnet()    __ORPL__(__protomask__)
  69. #define splsoftclock()  __ORPL__(__protomask__)
  70. #define splx(v) ({ u_short val; \
  71.     val = (v); \
  72.     if (val == __nonemask__) (void) spl0(); /* zero is special */ \
  73.     else (void) __SETPL__(val); \
  74. })
  75. #endif __ORPL__
  76.    ...
  77.  
  78.  
  79.