home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / s / s001 / 1.ddi / TS / ASM / OISR.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-08-08  |  3.9 KB  |  161 lines

  1. ;                ************
  2. ;                * OISR.asm *
  3. ;               *******************************************
  4. ;               * Copyright TimeSlice, Inc. 1985, 86, 87. *
  5. ;               *******************************************
  6. ;
  7. include ts.inc
  8. ;
  9. start_data            ;to define DGROUP properly
  10. ;
  11. end_data
  12. ;
  13. start_code
  14. ;
  15. ;
  16. ;*********
  17. ;* OISR( INTLST, REGOFF, REGSEG ) - This function is called within an 
  18. ;* attached ISR to invoke the original ISR
  19. ;*********
  20. start_struct
  21. mbr    isrobp        d_int        ;saved BP
  22. ifdef MICROSOFT
  23. mbr    isrodi        d_int        ;save SI,DI
  24. mbr    isrosi        d_int    
  25. endif
  26. mbr    isroflg        d_int        ;saved flags
  27. mbr    isroret        d_ret        ;return address to ISR code
  28. mbr    isroilp        d_ptr        ;ptr to ISR's INTLST
  29. mbr    isrorof        d_int        ;ptr to ISR' INTSTATE
  30. mbr    isrorsg        d_int        ; "  "    "      "
  31. end_struct isrostk
  32. ;
  33. start_struct
  34. mbr    osavsp        d_int        ;current SP in itsk (really BP)
  35. mbr    osavss        d_int        ;current SS
  36. mbr    osavipi        d_int        ;ISR's IP
  37. mbr    osavcsi        d_int        ;ISR's CS
  38. mbr    osavipa        d_int        ;intrpted appl. IP
  39. mbr    osavcsa        d_int        ;intrpted appl. CS
  40. mbr    osavfl        d_int        ;flags
  41. end_struct isrosav
  42. ;
  43. routine    oisr
  44.     pushf            ;and flags
  45.     push_sdi        ;save    SI, DI
  46.     push    bp        ;save BP
  47.     mov    bp,sp
  48.      cli            ;hold interrupts
  49. ;
  50. ;    set address of OISR in call instruction
  51. ;
  52.     ldptr    es,si,[bp].isroilp,d
  53.     mov    di,offset oisr0
  54.     ldint    ax,es:[si].oisrip
  55.     mov    cs:[di],ax
  56.     ldint    ax,es:[si].oisrcs
  57.     mov    cs:[di+2],ax
  58. ;
  59. ;    allocate on ISTK space to save a OISRSAV structure
  60. ;
  61.     mov    di,_istop.off
  62.     sub    di,isrosav
  63.     mov    _istop.off,di
  64. ;
  65. ;    save FlagCsIpCsIp information in [di] (small space just allocated)
  66. ;
  67.     mov    ax,ds            ;make sure ES contains DGROUP
  68.     mov    es,ax
  69.     mov    [di].osavsp,bp
  70.     mov    ax,ss
  71.     mov    [di].osavss,ax
  72.     add    di,4            ;make di point at isripi
  73.     mov    si,[bp].isrorof        ;DS:SI <- isr's intstate
  74.     mov    ax,[bp].isrorsg
  75.     mov    ds,ax
  76.     add    si,intstate - isrosav + osavipi ;addr of FCICI
  77.     mov    cx,(isrosav - osavipi) / 2
  78.      cld
  79.     repz movsw
  80.     mov    ax,es            ;restore DS to DGROUP
  81.     mov    ds,ax
  82. ;
  83. ;    switch stack to interrupted code stack
  84. ;
  85.     ldint    ax,[bp].isrorof
  86.     ldint    bx,[bp].isrorsg
  87.     mov    sp,ax
  88.     mov    ss,bx
  89. ;
  90. ;    load CPU flags with interrupted code's flags, and also set cli bit
  91. ;    in flags left on stack. That is necessary to avoid interrupts being
  92. ;    enabled (temporarily) after the original ISR's IRET.
  93. ;
  94.     mov    bp,sp
  95.     ldint    ax,[bp].isflags    ;AX <= flags as pushed on stack by int
  96.     and    ax,0FDFFH    ;cli interrupt enable bit in ax
  97.     stint    [bp].isflags,ax    ;cli the flags with wich origISR does the IRET
  98. ;
  99. ;    restore all registers as upon entry and leave only flags (CLIed) and
  100. ;    simulate the rest of the INT with a call.
  101. ;
  102.     popa            ;restore regs as upon entry
  103.     add    sp,8        ;leave only flags on stack (real and CLIed)
  104.     popf
  105.     pushf
  106. ;
  107. ;    call original ISR    
  108. ;
  109.     db    CALLFAR        ;simulate interrupt
  110. oisr0:    dw    0        ;real destination is updated 3 lines above
  111.     dw    0
  112. ;
  113. ;    now that original ISR has executed prepare to go back to calling ISR
  114. ;    by reseting the stack the way it was when OISR() was called.
  115. ;
  116.     pushf            ;put back flags
  117.     cli            ;because some %#@%!! BIOS ROUTINES modify stack flags
  118.     sub    sp,8        ;restore interpted code's INTSTATE
  119.     pusha
  120.     mov    ax,DGROUP    ;restore data segment
  121.     mov    ds,ax
  122.     mov    bp,sp        ;[bp] <-- return address of intmgr
  123.     mov    di,bp        ;set DI to point at bottom of FCICI
  124.     add    di,intstate - isrosav + osavipi
  125.     mov    ax,ss        ;restore to interrupt stack segment
  126.     mov    es,ax        ;ES <- interptd stack segment
  127.     mov    si,_istop.off    ;Restore information saved below istk
  128.     mov    sp,[si].osavsp
  129.     mov    ax,[si].osavss
  130.     mov    ss,ax
  131.     add    si,osavipi        ;make si point to osavipi
  132.     cld
  133.     mov    cx,(osavfl - osavipi) / 2 ;restore CICI only to INTSTATE
  134.     repz    movsw
  135. ;
  136. ;    make sure to restore interrupt flag
  137. ;
  138.     mov    ax,[si]        ;DS:SI points at the interrupt code flags
  139.     and    ax,200H
  140.     jnz    oisr1
  141.     and    es:[di],0FDFFH
  142.     jmp    oisr2
  143. oisr1:  or    es:[di], 0200H
  144. oisr2:    add    _istop.off,isrosav  ;restore _istop
  145. ;
  146. ;    restore flags and bp
  147. ;
  148.     pop    bp
  149.     pop_sdi
  150. if not ldata
  151.     push    ds
  152.     pop    es
  153. endif
  154.     popf
  155. return    oisr
  156. ;
  157. end_code
  158.  
  159.  
  160.  
  161.