home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / s / s001 / 1.ddi / TS / ASM / INTMGR.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-01-09  |  2.8 KB  |  112 lines

  1. ;                **************
  2. ;                * INTMGR.asm *
  3. ;               *******************************************
  4. ;               * Copyright TimeSlice, Inc. 1985, 86, 87. *
  5. ;               *******************************************
  6. ;
  7. ;
  8. include ts.inc
  9. ;
  10. start_data            ;to define DGROUP properly
  11. end_data
  12. ;
  13. start_code
  14. ;
  15. ;***
  16. ;* INTMGR is called automatically when an interrupt has a function attached
  17. ;* to it thru INTATT(). It saves all registers, then call the attached
  18. ;* function with two arguments : 
  19. ;*    1> a ptr to the intlst
  20. ;*    2> a ptr to the intstate
  21. ;* and returns to an IRET or a JUMP to the original interrupt vector.
  22. ;***
  23. public    intmgr
  24. routine intmgr
  25.     pusha            ;save all registers
  26.     cli            ;to compensate for the lack of cli in int86
  27. imgr0:    mov    ax,DGROUP    ;load ds and es with dgroup
  28.     mov    ds,ax
  29.     inc    _sslev        ;disable slicer (simulate ssleep)
  30. ;
  31. ;    set di to INTLST structure
  32. ;
  33.     mov    bp,sp        ;[bp] <-- return address of intmgr
  34.     mov    di,[bp].isimrip    ;es:[di] <-- intlist->dummy2
  35.     mov    ax,[bp].isimrcs
  36.     mov    es,ax
  37.     sub    di,dummy2 - next    ;[di] <-- intlist 
  38. ;
  39. ;    set stack for func
  40. ;
  41.     mov    bx,ss        ;bx <-- interrupted code's ss
  42.     mov    dx,sp        ;dx <-- interrupted code's sp
  43. ;
  44. ;    update _istop and ss and sp
  45. ;
  46. ifdef stkset
  47.     mov    si,_istop.off    ;SI <-- offset ptr to top of istack
  48.     mov    sp,es:[di].stksiz ;load sp with size of stack (cannonized ptr to top of stack)
  49.     sub    si,sp        ;compute offset of new istop
  50.     mov    _istop.off,si    ;update _istop
  51.     mov    cl,4        ;translate offset of new istop in segment
  52.     shr    si,cl
  53.     mov    ax,ds
  54.     add    ax,si
  55.      mov    ss,ax        ;SS:SP now contains pointer to cannonized stack
  56. else
  57.     mov    si,_istop.off    ;SI <-- offset ptr to top of istack
  58.     mov    ax,ds        ;static data is also stack seg.
  59.     mov    ss,ax
  60.     mov    sp,si
  61.     sub    si,es:[di].stksiz ;compute new _istop below stack for func
  62.     mov    _istop.off,si    ;update _istop
  63.     push    stk_base    ;save current _base
  64.     mov    stk_base,si    ;set it to bottom of ISR stack
  65. endif
  66.     push    bx        ;pass segment of interupted CPU Registers
  67.     push    dx        ;pass offset  of interupted CPU Registers
  68. ;
  69. ;    push intlst address as argument and call function
  70. ;
  71. if ldata
  72.     push    es
  73. endif
  74.     push    di        ;pass it to func
  75.     fncall    es:[di].func    ;execute function attached to interrupt
  76.     pop    di        ;pop func's argument
  77.     cli            ;make sure to hold int while changing sp,bp
  78.     dec    _sslev        ;decrement level of slicer sleep (simulate swake)
  79. ;
  80. ;    restore interrupt service stack
  81. ;
  82. if ldata
  83.     pop    es
  84. else
  85.     mov    ax,dgroup
  86.     mov    es,ax
  87. endif
  88.     pop    dx        ;dx <-- interrupted code's sp
  89.     pop    cx        ;cx <-- interrupted code's ss
  90. ifndef stkset
  91.     pop    stk_base    ;restore _base
  92. endif
  93.     mov    ss,cx        ;restore interrupted code's ss & sp
  94.     mov    sp,dx
  95.     mov    ax,es:[di].stksiz ;ES:DI -> INTLST
  96.     add    _istop.off,ax
  97. ;
  98. ;    restore flags (CLIed)
  99. ;
  100.     mov    bp,sp
  101.     mov    ax,[bp+1CH]
  102.     and    ax,0FDFFH
  103.     push    ax
  104.     popf
  105. ;
  106. ;    retore interupted code's stack
  107. ;
  108.     popa            ;restore all registers
  109. return    intmgr
  110. ;
  111. end_code
  112.