home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / microcode / intrpt.h < prev    next >
C/C++ Source or Header  |  2000-12-05  |  5KB  |  134 lines

  1. /* -*-C-*-
  2.  
  3. $Id: intrpt.h,v 1.21 2000/12/05 21:23:45 cph Exp $
  4.  
  5. Copyright (c) 1987-2000 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. /* Interrupt manipulation utilities. */
  23.  
  24. /* Interrupt bits -- scanned from LSB (1) to MSB (16) */
  25.  
  26. #define INT_Stack_Overflow    1    /* Local interrupt */
  27. #define INT_Global_GC        2
  28. #define INT_GC            4    /* Local interrupt */
  29. #define INT_Global_1        8
  30. #define INT_Character        16    /* Local interrupt */
  31. #define INT_AFTER_GC        32    /* Local interrupt */
  32. #define INT_Timer        64    /* Local interrupt */
  33. #define INT_Global_3        128
  34. #define INT_Suspend        256    /* Local interrupt */
  35. #define INT_Global_Mask        \
  36.   (INT_Global_GC | INT_Global_1 | INT_Global_3)
  37.  
  38. /* Descartes profiling interrupts */
  39.  
  40. #define INT_IPPB_Flush        512    /* Local interrupt */
  41. #define INT_IPPB_Extend           1024    /* Local interrupt */
  42. #define INT_PCBPB_Flush           2048    /* Local interrupt */
  43. #define INT_PCBPB_Extend       4096    /* Local interrupt */
  44. #define INT_HCBPB_Flush           8192    /* Local interrupt */
  45. #define INT_HCBPB_Extend      16384    /* Local interrupt */
  46.  
  47. #define INT_Step_CC          32768        
  48.  
  49. #define Global_GC_Level        1
  50. #define Global_1_Level        3
  51. #define Global_3_Level        7
  52. #define MAX_INTERRUPT_NUMBER   15    /* 2^15 = INT_Step_CC */
  53.  
  54. #define INT_Mask        ((1 << (MAX_INTERRUPT_NUMBER + 1)) - 1)
  55.  
  56. /* Utility macros. */
  57.  
  58. #define PENDING_INTERRUPTS()                        \
  59.   ((FETCH_INTERRUPT_MASK ()) & (FETCH_INTERRUPT_CODE ()))
  60.  
  61. #define INTERRUPT_QUEUED_P(mask) (((FETCH_INTERRUPT_CODE ()) & (mask)) != 0)
  62.  
  63. #define INTERRUPT_ENABLED_P(mask) (((FETCH_INTERRUPT_MASK ()) & (mask)) != 0)
  64.  
  65. #define INTERRUPT_PENDING_P(mask) (((PENDING_INTERRUPTS ()) & (mask)) != 0)
  66.  
  67. #define COMPILER_SETUP_INTERRUPT() do                    \
  68. {                                    \
  69.   (Registers[REGBLOCK_MEMTOP]) =                    \
  70.     (((PENDING_INTERRUPTS ()) != 0)                    \
  71.      ? ((SCHEME_OBJECT) -1)                        \
  72.      : (INTERRUPT_ENABLED_P (INT_GC))                    \
  73.      ? ((SCHEME_OBJECT) (ADDR_TO_SCHEME_ADDR (MemTop)))            \
  74.      : ((SCHEME_OBJECT) (ADDR_TO_SCHEME_ADDR (Heap_Top))));        \
  75.   (Registers[REGBLOCK_STACK_GUARD]) =                    \
  76.     ((INTERRUPT_ENABLED_P (INT_Stack_Overflow))                \
  77.      ? ((SCHEME_OBJECT) (ADDR_TO_SCHEME_ADDR (Stack_Guard)))        \
  78.      : ((SCHEME_OBJECT) (ADDR_TO_SCHEME_ADDR (Stack_Bottom))));        \
  79. } while (0)
  80.  
  81. #define FETCH_INTERRUPT_MASK() ((long) (Registers[REGBLOCK_INT_MASK]))
  82.  
  83. #define SET_INTERRUPT_MASK(mask)                    \
  84. {                                    \
  85.   GRAB_INTERRUPT_REGISTERS ();                        \
  86.   (Registers[REGBLOCK_INT_MASK]) = ((SCHEME_OBJECT) (mask));        \
  87.   COMPILER_SETUP_INTERRUPT ();                        \
  88.   RELEASE_INTERRUPT_REGISTERS ();                    \
  89. }
  90.  
  91. #define FETCH_INTERRUPT_CODE() ((long) (Registers[REGBLOCK_INT_CODE]))
  92.  
  93. #define REQUEST_INTERRUPT(code)                        \
  94. {                                    \
  95.   GRAB_INTERRUPT_REGISTERS ();                        \
  96.   (Registers[REGBLOCK_INT_CODE]) =                    \
  97.     ((SCHEME_OBJECT) ((FETCH_INTERRUPT_CODE ()) | (code)));        \
  98.   COMPILER_SETUP_INTERRUPT ();                        \
  99.   RELEASE_INTERRUPT_REGISTERS ();                    \
  100. }
  101.  
  102. #define CLEAR_INTERRUPT_NOLOCK(code)                    \
  103. {                                    \
  104.   (Registers[REGBLOCK_INT_CODE]) =                    \
  105.     ((SCHEME_OBJECT) ((FETCH_INTERRUPT_CODE ()) &~ (code)));        \
  106.   COMPILER_SETUP_INTERRUPT ();                        \
  107. }
  108.  
  109. #define CLEAR_INTERRUPT(code)                        \
  110. {                                    \
  111.   GRAB_INTERRUPT_REGISTERS ();                        \
  112.   CLEAR_INTERRUPT_NOLOCK (code);                    \
  113.   RELEASE_INTERRUPT_REGISTERS ();                    \
  114. }
  115.  
  116. #define INITIALIZE_INTERRUPTS()                        \
  117. {                                    \
  118.   GRAB_INTERRUPT_REGISTERS ();                        \
  119.   (Registers[REGBLOCK_INT_MASK]) = ((SCHEME_OBJECT) INT_Mask);        \
  120.   (Registers[REGBLOCK_INT_CODE]) = ((SCHEME_OBJECT) 0);            \
  121.   COMPILER_SETUP_INTERRUPT ();                        \
  122.   RELEASE_INTERRUPT_REGISTERS ();                    \
  123. }
  124.  
  125. #if defined(__OS2__) || defined(__WIN32__)
  126.    extern void OS_grab_interrupt_registers (void);
  127.    extern void OS_release_interrupt_registers (void);
  128. #  define GRAB_INTERRUPT_REGISTERS() OS_grab_interrupt_registers ()
  129. #  define RELEASE_INTERRUPT_REGISTERS() OS_release_interrupt_registers ()
  130. #else
  131. #  define GRAB_INTERRUPT_REGISTERS()
  132. #  define RELEASE_INTERRUPT_REGISTERS()
  133. #endif
  134.