home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR4 / V12N16.ZIP / FINDIR.ZIP / FINASM.ZIP / IRQISR.ASM < prev    next >
Assembly Source File  |  1993-08-24  |  11KB  |  280 lines

  1. ;---------------------------------------------------------------    
  2. ;irqisr.asm - Interrupt service routines for FINDIRQ Utility   |
  3. ;--------------------------------------------------------------|
  4. ;FINDIRQ Copyright (c) 1993                                    |
  5. ;                                                              |
  6. ;Rick Knoblaugh All rights reserved.                           |
  7. ;First Appeared in PC MAGAZINE, US Edition,                    |
  8. ;September 28, 1993                                            |
  9. ;--------------------------------------------------------------|
  10. ; 4/25/93                      Rick Knoblaugh                  |
  11. ;--------------------------------------------------------------|
  12. ;include files                                                 |
  13. ;---------------------------------------------------------------    
  14.                 include irqequ.inc
  15.                 include irqstruc.inc
  16.  
  17. code            segment public  'CODE'
  18.                 assume cs:code, ds:code, es:code
  19. ;--------------------------------------------------------------
  20. ;Externals                                                    |
  21. ;--------------------------------------------------------------
  22.                 extrn   put_to_disk:near                ;irqsupt.asm
  23.                 extrn   start_util:near                 ;irqmain.asm
  24.                 extrn   int_table:byte                  ;irqmain.asm
  25.                 extrn   get_set_int:near                ;irqsupt.asm        
  26.  
  27.  
  28. ;--------------------------------------------------------------
  29. ;Publics                                                      |
  30. ;--------------------------------------------------------------
  31.                 public  int_1c_isr, int_28_isr, int_2f_isr
  32.                 public  old_1c_isr, old_28_isr, old_2f_isr 
  33.                 public  atclassf, pic_mask                       
  34.                 public  read_pic_masks
  35.                 public  startup
  36.  
  37.                 org     100h             
  38. startup:
  39.                 jmp     start_util
  40.  
  41.  
  42. ;--------------------------------------------------------------
  43. ;Variables                                                    |
  44. ;--------------------------------------------------------------
  45.                 even
  46. irq_stack       dw      IRQ_STACK_SIZE dup('SS')
  47. irq_stack_ptr   label   word
  48.  
  49. old_1c_isr      dd      ?
  50. old_28_isr      dd      ?
  51. old_2f_isr      dd      ?
  52. old_stack_ptr   dw      ?
  53. old_stack_seg   dw      ?
  54.  
  55.  
  56.  
  57. tick_count      dw      0
  58. need_to_write   db      FALSE           ;TRUE if need to update file
  59. atclassf        db      TRUE            ;default to AT class machine
  60. pic_mask        dw      ?               ;mask value for master and slave PICs
  61.  
  62. ;--------------------------------------------------------------
  63. ;int_1c_isr - user timer isr.  Count the tick.  If it's       |
  64. ;             time to check PIC mask, read the values.        |
  65. ;             If any new IRQs have been enabled (other than   |
  66. ;             any we have already seen since monitoring       |
  67. ;             began), set flag to write new hold file values. |
  68. ;                                                             |
  69. ;          Enter:                                             |
  70. ;                                                             |
  71. ;           Exit:                                             |
  72. ;                      tick_count updated                     |
  73. ;                                                             |
  74. ;                   need_to_write=TRUE if new enables found   |
  75. ;                       pic_mask updated                      |
  76. ;                                                             |
  77. ;                                                             |
  78. ;--------------------------------------------------------------
  79. int_1c_isr      proc    near
  80.                 pushf
  81.                 cmp     cs:tick_count, CK_EVERY_UNIT
  82.                 jb      int_1c999
  83.                 push    ax
  84.                 push    bx
  85.                 push    dx
  86.                 push    ds
  87.  
  88.                 push    cs
  89.                 pop     ds                      ;get ds=local data seg
  90.  
  91.                 mov     tick_count, 0           ;reset tick count
  92.  
  93.  
  94.                 call    read_pic_masks
  95.  
  96. int_1c_800:
  97.                 pop     ds
  98.                 pop     dx
  99.                 pop     bx
  100.                 pop     ax
  101.  
  102. int_1c999:
  103.                 inc     cs:tick_count
  104.                 popf
  105.                 jmp     dword ptr cs:old_1c_isr
  106. int_1c_isr      endp        
  107.  
  108.  
  109.  
  110. read_pic_masks  proc    near
  111.  
  112.                 mov     ah, pic_mask.d_master 
  113.                 mov     dx, MASTER_PIC_MASK     ;port for master mask reg
  114.                 call    ck_port
  115.                 jz      read_pic100
  116.                 mov     pic_mask.d_master, ah
  117. read_pic100:
  118.                 cmp     atclassf, TRUE          ;AT machine?
  119.                 jne     read_pic900             ;if not, only 1 8259
  120.                 mov     ah, pic_mask.d_slave
  121.                 mov     dx, SLAVE_PIC_MASK      ;port for slave mask reg
  122.                 call    ck_port
  123.                 jz      read_pic900
  124.                 mov     pic_mask.d_slave, ah
  125. read_pic900:
  126.                 ret
  127. read_pic_masks  endp
  128.  
  129.  
  130. ;--------------------------------------------------------------
  131. ;ck_port - Check PIC mask register.  See if any IRQs have     |
  132. ;          been enabled that we don't know about yet.         |
  133. ;                                                             |
  134. ;          Enter:                                             |
  135. ;                  dx=i/o port for mask register              |
  136. ;                  ah=mask value we have been keeping         |
  137. ;                  ds=local data segment                      |
  138. ;                                                             |
  139. ;           Exit:                                             |
  140. ;                   need_to_write=TRUE if new enables found   |
  141. ;                  ah=updated PIC mask values                 |
  142. ;                  ZR if no change from last reading          |
  143. ;                                                             |
  144. ;--------------------------------------------------------------
  145. ck_port         proc    near
  146.                 mov     bh, ah          ;save original mask value
  147.                 in      al, dx          ;read mask regsiter
  148.                 and     ah, al          ;compare with old value
  149.                 cmp     ah, bh          ;any new ones enabled?
  150.                 je      ck_port999
  151.                 mov     need_to_write, TRUE ;indicate we should update
  152. ck_port999:
  153.                 ret
  154. ck_port         endp
  155.  
  156. ;--------------------------------------------------------------
  157. ; int_28_isr - if flag set for updating file, do it.          |
  158. ;                                                             |
  159. ;          Enter:                                             |
  160. ;                 cs:need_to_write=TRUE if update pending     |
  161. ;                                                             |
  162. ;           Exit:                                             |
  163. ;                 cs:need_to_write=FALSE if do update         |
  164. ;                                                             |
  165. ;--------------------------------------------------------------
  166. int_28_isr      proc    near
  167.                 pushf
  168.                 cmp     cs:need_to_write, TRUE    ;should update file?
  169.                 jne     int_28_999
  170.                 cli               
  171.                 mov     cs:old_stack_ptr, sp    ;save existing stack        
  172.                 mov     cs:old_stack_seg, ss
  173.                 mov     sp, cs                  ;setup our stack
  174.                 mov     ss, sp
  175.                 mov     sp, offset cs:irq_stack_ptr
  176.                 sti
  177.  
  178.                 push    ax                      ;ensure all preserved
  179.                 push    bx
  180.                 push    cx
  181.                 push    dx 
  182.                 push    di
  183.                 push    si
  184.                 push    bp
  185.                 push    ds
  186.                 push    es
  187.                 
  188.                 push    cs
  189.                 pop     ds                      ;get ds=local data
  190.  
  191.                 mov     need_to_write, FALSE    ;reset flag
  192.  
  193.                 mov     di, offset old_int24 
  194.                 mov     al, 24h                 ;int 24h critical error handler
  195.                 mov     dx, offset irq_int24    ;our minimal handler
  196.                 call    get_set_int
  197.  
  198.                 mov     ah, DOS_GET_PSP         ;get program segment prefix
  199.                 int     21h
  200.  
  201.                 push    bx                      ;save current PSP
  202.                 mov     bx, cs                  ;.COM file, this is our PSP
  203.                 mov     ah, DOS_SET_PSP
  204.                 int     21h
  205.                 call    put_to_disk
  206.                 pop     bx                      
  207.  
  208.                 mov     ah, DOS_SET_PSP
  209.                 int     21h
  210.  
  211.                 mov     dx, old_int24.d_offset
  212.                 mov     ax, old_int24.d_segment
  213.                 mov     ds, ax
  214.                 mov     al, 24h
  215.                 mov     ah, DOS_SET_INT         
  216.                 int     21h                     ;restore int 24h handler
  217.  
  218.                 pop     es
  219.                 pop     ds
  220.                 pop     bp
  221.                 pop     si
  222.                 pop     di
  223.                 pop     dx
  224.                 pop     cx
  225.                 pop     bx
  226.                 pop     ax
  227.                 
  228.                 cli
  229.                 mov     sp, cs:old_stack_ptr
  230.                 mov     ss, cs:old_stack_seg
  231.                 sti
  232.  
  233. int_28_999:
  234.                 popf
  235.                 jmp     dword ptr cs:old_28_isr
  236. int_28_isr      endp        
  237.  
  238. old_int24       dd      ?
  239.  
  240.  
  241. irq_int24       proc    far
  242.                 mov     ax, 3                   ;fail the operation
  243.                 iret
  244. irq_int24       endp
  245.  
  246.  
  247.  
  248. ;--------------------------------------------------------------
  249. ;int_2f_isr - respond to get installed state function and     |
  250. ;             the next higher function for our id.            |
  251. ;                                                             |
  252. ;--------------------------------------------------------------
  253. int_2f_isr      proc    near
  254.                 cmp     ah, FINDIRQ_ID          ;our id?
  255.                 jne     int_2f_900              ;if not, must be for old int
  256.                 cmp     al, GET_INST_STATE + 1  ;the 2 functions we know?
  257.                 je      int_2f_100
  258.                 jnb     int_2f_900              ;must not be for us
  259.                 mov     al, TRUE                ;indicate we are installed
  260.                 jmp     short int_2f_999
  261. int_2f_100:
  262.                 cmp     cx, 'Q!'                ;extra sure it's us    
  263.                 jne     int_2f_900              ;if not, must be for old int
  264.                 mov     byte ptr [bx], TRUE     ;let other code know it's us
  265.                 mov     dx, offset int_table    ;also pass this back
  266.                 mov     ax, cs
  267.                 jmp     short int_2f_999
  268. int_2f_900:
  269.                 jmp     dword ptr cs:old_2f_isr
  270. int_2f_999:
  271.                 iret
  272. int_2f_isr      endp        
  273.  
  274.  
  275.  
  276.  
  277. code            ends
  278.                 end
  279.  
  280.