home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 4 Drivers / 04-Drivers.zip / cs0929a.zip / irq.lst < prev    next >
File List  |  1999-09-29  |  14KB  |  415 lines

  1.  
  2. Module: D:\dev\csrc\os2dd\scd\irq.c
  3. Group: 'DGROUP' CONST,CONST2,_DATA,_BSS
  4.  
  5. Segment: _TEXT  PARA   0000014b bytes  
  6.  
  7. //
  8. // irq.c
  9. // 30-Jan-99
  10. //
  11. // VOID __far __loadds irqHandler(VOID);
  12. // USHORT irqEnable(USHORT irqNo);
  13. // USHORT irqDisable(USHORT irqNo);
  14.  
  15. #include "cs40.h"
  16.  
  17. static USHORT irqEnabled = 0;   // count enables, grab IRQ when 0->1, release IRQ when back to 0
  18. static USHORT irqLevel = 0;
  19.  
  20. // -----------
  21. // in: n/a
  22. //out: clc=okay, stc=bad
  23. //nts: gets called by kernel to handle interrupt (interrupt context)
  24. //
  25. //     A new logical device might post an interrupt request while we are
  26. //     in service (such as a CAPTURE that is running along with a PLAY).
  27. //
  28. //     OS/2 2.1 and later save all regs (so documented, not 100% sure on extended regs (eax))
  29. //     interrupts are disabled on entry since not a shared IRQ
  30. //     probably should not be using cli/sti here, and
  31.  
  32. VOID __far __loadds irqHandler(VOID) {
  33.  
  34.  WAVESTREAM *wsPtr;
  35.  STREAM *streamPtr;
  36.  USHORT times;
  37.  
  38. // !!! ---------
  39. //static USHORT cnt = 0;
  40. // ddprintf("at IRQ, cnt=%u\n",cnt);
  41.  
  42.  
  43.  0000  1e                irqHandler_     push    ds
  44.  0001  b8 00 00                          mov     ax,seg L21
  45.  0004  8e d8                             mov     ds,ax
  46.  0006  53                                push    bx
  47.  0007  51                                push    cx
  48.  0008  52                                push    dx
  49.  
  50.  sti();         // sure, let higher-priority interrupts through
  51.  
  52. //cnt++;
  53. //if (cnt > 99) {
  54. //   if ((cnt % 100) == 0) ddprintf("at IRQ, cnt=%u\n",cnt);
  55. //   if (cnt > 1023) cnt = 0;
  56. //   chipsetIntReset(AUDIOHW_WAVE_PLAY);
  57. //   cli();
  58. //   DevHelp_EOI(irqLevel);
  59. //   clc();
  60. //   return;
  61. //}
  62.  
  63. #ifdef TRACE_IRQ
  64.  0009  fb                                sti     
  65.  
  66.  tracePerf(TRACE_IRQ_IN,_IF());
  67. #endif
  68.  
  69.  000a  9c                                pushf   
  70.  000b  58                                pop     ax
  71.  000c  25 00 02                          and     ax,0200H
  72.  000f  99                                cwd     
  73.  0010  89 c3                             mov     bx,ax
  74.  0012  89 d1                             mov     cx,dx
  75.  0014  b8 40 00                          mov     ax,0040H
  76.  0017  e8 00 00                          call    tracePerf_
  77.  001a  8b 1e 00 00                       mov     bx,_irqEnabled
  78.  
  79.  for (times = 0; times < irqEnabled; times++) {
  80.  
  81.  001e  31 d2                             xor     dx,dx
  82.  0020  85 db                             test    bx,bx
  83.  0022  0f 86 88 00                       jbe     L8
  84.  
  85.     if (chipsetIntPending(AUDIOHW_WAVE_PLAY)) {
  86.  0026  b8 11 00          L1              mov     ax,0011H
  87.  0029  e8 00 00                          call    chipsetIntPending_
  88.  002c  85 c0                             test    ax,ax
  89.  002e  74 18                             je      L3
  90.  
  91.        streamPtr = streamFindActive(STREAM_WAVE_PLAY);
  92.  0030  b8 11 00                          mov     ax,0011H
  93.  0033  e8 00 00                          call    streamFindActive_
  94.  0036  89 c3                             mov     bx,ax
  95.  
  96.        if (streamPtr) {
  97.  0038  85 c0                             test    ax,ax
  98.  003a  74 06                             je      L2
  99.  
  100.           wsPtr = streamPtr->wsParentPtr;
  101.  
  102. #ifdef TRACE_PROCESS
  103.  tracePerf(TRACE_PROCESS_IN,_IF());
  104. #endif
  105.  
  106.  003c  8b 47 24                          mov     ax,[bx+24H]
  107.  
  108.           wavestreamProcess(wsPtr);
  109.  
  110. #ifdef TRACE_PROCESS
  111.  tracePerf(TRACE_PROCESS_OUT,_IF());
  112. #endif
  113.  
  114.        }
  115.  003f  e8 00 00                          call    wavestreamProcess_
  116.  
  117.        chipsetIntReset(AUDIOHW_WAVE_PLAY);
  118.     }
  119.  
  120.  0042  b8 11 00          L2              mov     ax,0011H
  121.  0045  e8 00 00                          call    chipsetIntReset_
  122.  
  123.     if (chipsetIntPending(AUDIOHW_WAVE_CAPTURE)) {
  124. //ddprintf("at IRQ, capture, cnt=%u\n",cnt++);
  125.  0048  b8 10 00          L3              mov     ax,0010H
  126.  004b  e8 00 00                          call    chipsetIntPending_
  127.  004e  85 c0                             test    ax,ax
  128.  0050  74 18                             je      L5
  129.  
  130.        streamPtr = streamFindActive(STREAM_WAVE_CAPTURE);
  131.  0052  b8 10 00                          mov     ax,0010H
  132.  0055  e8 00 00                          call    streamFindActive_
  133.  0058  89 c3                             mov     bx,ax
  134.  
  135.        if (streamPtr) {
  136.  005a  85 c0                             test    ax,ax
  137.  005c  74 06                             je      L4
  138.  
  139.           wsPtr = streamPtr->wsParentPtr;
  140.  005e  8b 47 24                          mov     ax,[bx+24H]
  141.  
  142.           wavestreamProcess(wsPtr);
  143.        }
  144.  0061  e8 00 00                          call    wavestreamProcess_
  145.  
  146.        chipsetIntReset(AUDIOHW_WAVE_CAPTURE);
  147.     }
  148.  
  149.  0064  b8 10 00          L4              mov     ax,0010H
  150.  0067  e8 00 00                          call    chipsetIntReset_
  151.  
  152.     if (chipsetIntPending(AUDIOHW_TIMER)) {
  153. //ddprintf("at IRQ, timer, cnt=%u\n",cnt++);
  154.  006a  b8 80 00          L5              mov     ax,0080H
  155.  006d  e8 00 00                          call    chipsetIntPending_
  156.  0070  85 c0                             test    ax,ax
  157.  0072  74 06                             je      L6
  158.  
  159.        chipsetIntReset(AUDIOHW_TIMER);
  160.     }
  161.  
  162.  
  163.     // check if anymore
  164.  
  165.  0074  b8 80 00                          mov     ax,0080H
  166.  0077  e8 00 00                          call    chipsetIntReset_
  167.  
  168.     if (chipsetIntPending(-1) == 0) {
  169.  
  170. #ifdef TRACE_IRQ
  171.  007a  b8 ff ff          L6              mov     ax,0ffffH
  172.  007d  e8 00 00                          call    chipsetIntPending_
  173.  0080  85 c0                             test    ax,ax
  174.  0082  75 1f                             jne     L7
  175.  
  176.  tracePerf(TRACE_IRQ_OUT,_IF());
  177. #endif
  178.  
  179.  0084  9c                                pushf   
  180.  0085  58                                pop     ax
  181.  0086  25 00 02                          and     ax,0200H
  182.  0089  99                                cwd     
  183.  008a  89 c3                             mov     bx,ax
  184.  008c  89 d1                             mov     cx,dx
  185.  008e  b8 40 80                          mov     ax,8040H
  186.  0091  e8 00 00                          call    tracePerf_
  187.  
  188.        cli();
  189.  0094  fa                                cli     
  190.  
  191.        DevHelp_EOI(irqLevel);
  192.  0095  a1 00 00                          mov     ax,_irqLevel
  193.  0098  b2 31                             mov     dl,31H
  194.  009a  ff 1e 00 00                       call    dword ptr _Device_Help
  195.  009e  29 c0                             sub     ax,ax
  196.  
  197.        clc();
  198.  00a0  f8                                clc     
  199.  
  200.        return;
  201.     }
  202.  
  203.  00a1  eb 17                             jmp     L9
  204.  
  205.  }
  206. //ddprintf("at IRQ, stc()\n");
  207.  
  208. #ifdef TRACE_IRQ
  209.  00a3  8b 0e 00 00       L7              mov     cx,_irqEnabled
  210.  00a7  42                                inc     dx
  211.  00a8  39 ca                             cmp     dx,cx
  212.  00aa  0f 82 78 ff                       jb      L1
  213.  
  214.  tracePerf(TRACE_IRQ_OUT,0x9999);
  215. #endif
  216.  
  217.  00ae  bb 99 99          L8              mov     bx,9999H
  218.  00b1  b8 40 80                          mov     ax,8040H
  219.  00b4  31 c9                             xor     cx,cx
  220.  00b6  e8 00 00                          call    tracePerf_
  221.  
  222.  stc();
  223.  
  224.  return;        // back to kernel with bad news
  225.  00b9  f9                                stc     
  226.  
  227. }
  228.  
  229.  
  230. // ---------
  231. // in: irqNo
  232. //out: 0=okay 1=fail (or other rc error)
  233. //nts: if 0->1 grab IRQ
  234. //     ds must be set correctly since checked by kernel when unsetting
  235. //     if irq already set, inc count (error if irqNo differs from irqLevel)
  236.  
  237.  00ba  5a                L9              pop     dx
  238.  00bb  59                                pop     cx
  239.  00bc  5b                                pop     bx
  240.  00bd  1f                                pop     ds
  241.  00be  cb                                retf    
  242.  00bf  fc                                cld     
  243.  
  244. USHORT irqEnable(USHORT irqNo) {
  245.  
  246.  00c0  53                irqEnable_      push    bx
  247.  00c1  51                                push    cx
  248.  00c2  52                                push    dx
  249.  00c3  8b 0e 00 00                       mov     cx,_irqEnabled
  250.  
  251.  USHORT rc = 0;
  252.  
  253.  00c7  31 db                             xor     bx,bx
  254.  
  255.  if (irqEnabled && (irqNo != irqLevel)) return 1;
  256.  
  257.  00c9  85 c9                             test    cx,cx
  258.  00cb  74 0b                             je      L10
  259.  00cd  3b 06 00 00                       cmp     ax,_irqLevel
  260.  00d1  74 05                             je      L10
  261.  00d3  b8 01 00                          mov     ax,0001H
  262.  00d6  eb 21                             jmp     L14
  263.  
  264.  if (irqEnabled == 0) {
  265.  00d8  85 c9             L10             test    cx,cx
  266.  00da  75 16                             jne     L12
  267.  
  268.     irqLevel = irqNo;
  269.  00dc  a3 00 00                          mov     _irqLevel,ax
  270.  00df  89 c3                             mov     bx,ax
  271.  
  272.     rc = DevHelp_SetIRQ((NPFN)irqHandler, irqLevel, 0); // rc =1 if already owned
  273.  
  274. // !!!
  275. //ddprintf("@SetIRQ (#%u), rc=%u\n",irqNo,rc);
  276.  
  277.  }
  278.  00e1  30 f6                             xor     dh,dh
  279.  00e3  b8 00 00                          mov     ax,offset irqHandler_
  280.  00e6  b2 1b                             mov     dl,1bH
  281.  00e8  ff 1e 00 00                       call    dword ptr _Device_Help
  282.  00ec  72 02                             jb      L11
  283.  00ee  29 c0                             sub     ax,ax
  284.  00f0  89 c3             L11             mov     bx,ax
  285.  
  286.  if (rc == 0) irqEnabled++;
  287.  
  288.  00f2  85 db             L12             test    bx,bx
  289.  00f4  75 01                             jne     L13
  290.  00f6  41                                inc     cx
  291.  
  292.  return rc;
  293.  00f7  89 d8             L13             mov     ax,bx
  294.  
  295. }
  296.  
  297.  
  298. // ---------
  299. // in: irqNo
  300. //out: 0=okay, 1=errro
  301. //nts: if 1->0 release IRQ
  302. //     ds must be set to owner
  303.  
  304.  00f9  89 0e 00 00       L14             mov     _irqEnabled,cx
  305.  00fd  5a                                pop     dx
  306.  00fe  59                                pop     cx
  307.  00ff  5b                                pop     bx
  308.  0100  c3                                ret     
  309.  0101  89 c0                             mov     ax,ax
  310.  0103  fc                                cld     
  311.  
  312. USHORT irqDisable(USHORT irqNo) {
  313.  
  314.  0104  53                irqDisable_     push    bx
  315.  0105  51                                push    cx
  316.  0106  52                                push    dx
  317.  0107  8b 0e 00 00                       mov     cx,_irqEnabled
  318.  
  319.  USHORT rc = 0;
  320.  
  321.  010b  31 db                             xor     bx,bx
  322.  
  323.  if (irqEnabled == 0) return 1;
  324.  010d  85 c9                             test    cx,cx
  325.  010f  75 05                             jne     L15
  326.  0111  b8 01 00                          mov     ax,0001H
  327.  0114  eb 2d                             jmp     L20
  328.  
  329.  if (irqNo != irqLevel) return 1;
  330.  0116  8b 16 00 00       L15             mov     dx,_irqLevel
  331.  011a  39 d0                             cmp     ax,dx
  332.  011c  74 0b                             je      L16
  333.  011e  b8 01 00                          mov     ax,0001H
  334.  0121  89 0e 00 00                       mov     _irqEnabled,cx
  335.  0125  5a                                pop     dx
  336.  0126  59                                pop     cx
  337.  0127  5b                                pop     bx
  338.  0128  c3                                ret     
  339.  
  340.  if (irqEnabled == 1) {
  341.  0129  83 f9 01          L16             cmp     cx,0001H
  342.  012c  75 0e                             jne     L18
  343.  
  344.     rc = DevHelp_UnSetIRQ(irqNo);  // rc=1 if not owner of IRQ based on DS
  345.  
  346. // !!!
  347. //ddprintf("@UnSetIRQ (#%u), rc=%u\n",irqNo,rc);
  348.  
  349.  }
  350.  012e  89 d3                             mov     bx,dx
  351.  0130  b2 1c                             mov     dl,1cH
  352.  0132  ff 1e 00 00                       call    dword ptr _Device_Help
  353.  0136  72 02                             jb      L17
  354.  0138  29 c0                             sub     ax,ax
  355.  013a  89 c3             L17             mov     bx,ax
  356.  
  357.  if (rc == 0) irqEnabled--;
  358.  
  359.  013c  85 db             L18             test    bx,bx
  360.  013e  75 01                             jne     L19
  361.  0140  49                                dec     cx
  362.  
  363.  return 0;
  364.  0141  31 c0             L19             xor     ax,ax
  365.  
  366. }
  367.  
  368.  
  369.  0143  89 0e 00 00       L20             mov     _irqEnabled,cx
  370.  0147  5a                                pop     dx
  371.  0148  59                                pop     cx
  372.  0149  5b                                pop     bx
  373.  014a  c3                                ret     
  374.  
  375. No disassembly errors
  376.  
  377. List of external symbols
  378.  
  379. Symbol
  380. ----------------
  381. tracePerf_       000000b7 00000092 00000018
  382. _irqEnabled      00000145 00000123 00000109 000000fb 000000c5 000000a5 0000001c
  383. chipsetIntPending_ 
  384.                  0000007e 0000006e 0000004c 0000002a
  385. streamFindActive_ 
  386.                  00000056 00000034
  387. wavestreamProcess_ 
  388.                  00000062 00000040
  389. chipsetIntReset_ 
  390.                  00000078 00000068 00000046
  391. _irqLevel        00000118 000000dd 000000cf 00000096
  392. _Device_Help     00000134 000000ea 0000009c
  393. irqHandler_      000000e4
  394. ------------------------------------------------------------
  395.  
  396. Segment: _DATA  WORD   00000004 bytes  
  397.  0000  00 00                   _irqEnabled     - ..
  398.  0002  00 00                   _irqLevel       - ..
  399.  
  400. No disassembly errors
  401.  
  402. ------------------------------------------------------------
  403. List of public symbols
  404.  
  405. SYMBOL          GROUP           SEGMENT          ADDRESS
  406. ---------------------------------------------------------
  407. _irqEnabled     DGROUP          _DATA            00000000
  408. _irqLevel       DGROUP          _DATA            00000002
  409. irqDisable_                     _TEXT            00000104
  410. irqEnable_                      _TEXT            000000c0
  411. irqHandler_                     _TEXT            00000000
  412.  
  413. ------------------------------------------------------------
  414.  
  415.