home *** CD-ROM | disk | FTP | other *** search
- Page ,132
- Title 'Interrupt handler support for Lattice C Version 2.1x'
- ;;
- ; Author: Cheyenne Wills
- ; Addr: 12 West Locust St.
- ; Mechanicsburg Pa. 17055
- ;
- ; Compuserv [70376,555]
- ;
- ; December 1984
- ;
- ;Permission is granted to use, distribute and/or modify this code unless
- ;done for direct commercial profit.
- ;Author's name, address and this notice must be included in any copies.
- ;
- ;No guarantees or warranties of any kind: This code is distributed
- ;"AS IS" without any warranty. You are soley responsible for the
- ;selection of the program to achieve your intended results and for the
- ;results actually obtained.
- ;
- ;Any suggestions for improvements gratefully accepted
- ;
- ;;
- Include DOS.MAC
- DSEG
- Subttl 'XCINTBOO - Interrupt Boot Code'
- ;
- ; The following code is relocated into storage and
- ; is the "1st" level interrupt handler
- ;
- XCINTBOO Proc Far
- If COM
- Db 9Ah ;Long Call
- Dw XCINTCOM ;Ip
- FuncCCs Dw 0 ;And for the benifit of EXE2BIN...
- Else
- Call Far Ptr XCINTCOM
- Endif
- Iret
- FuncIp Dw ? ;IP for the C interrupt handler
- FuncCs Dw ? ;CS for the C interrupt handler
- FuncSs Dw ? ;SS for the C interrupt handler
- FuncDs Dw ? ;DS for the C interrupt handler
- Intrcl Equ $-XCINTBOO ;Length of above section..
- XCINTBOO Endp
- If S8086 Eq 0
- Intradr Dd XCINTBOO ;Segement/offset of above code
- Endif
- ENDDS
- Page ,132
- PSEG
- Subttl 'XCINTRIN - Interrupt Handler Initializer'
- Public XCINTRIN
- If LPROG
- XCINTRIN Proc Far
- Else
- XCINTRIN Proc Near
- Endif
- Push Bp
- Mov Bp,Sp
- ;------
- If S8086
- Mov Ax,[Bp+6] ;Get the pointer to the function
- Mov FuncIp,Ax ;Where Interserv will call to..
- Mov FuncCs,Cs ;Current CS..
- If COM
- Mov FuncCCs,Cs ;Com files don't relocate, (but we do..)
- Endif
- Mov FuncSs,Ss ;Save the Current stack segment address
- Mov FuncDs,Ds ;Save the Current data segment address
- ;
- Mov Di,[Bp+8] ;Get the pointer to the IBC area
- Lea Si,XCINTBOO ;Get the address to the actual code
- Mov Cx,Intrcl ;And the length of the code
- Cld ;Make sure we go in the right direction
- Rep Movsb ;And move it..
- ;
- Mov Bx,[Bp+4] ;Get the interrupt number..
- Mov Al,Bl ;Into Al
- Mov Ah,25h ;Subfunction 25
- Mov Dx,[Bp+8] ;Get the address of the IBC
- Int 21h ;And install it..
- EndIf
- If D8086
- Mov Ax,[Bp+6] ;Get the pointer to the function
- Mov Bx,[Bp+8]
- Mov FuncIp,Ax ;Where Interserv will call to..
- Mov FuncCs,Bx ;..
- Mov Ax,[Bp+12] ;We have a "New stack segment.."
- Mov FuncSs,Ax ;Save the Current stack segment address
- Mov FuncDs,Ds ;Save the Current data segment address
- ;
- Push Ds ;Save Ds..
- Les Di,[Bp+10] ;Move the code into
- Lds Si,Intradr ;the IBC area
- Mov Cx,Intrcl ;..
- Cld
- Rep Movsb
- ;
- Mov Bx,[Bp+4] ;Get the interrupt number..
- Mov Al,Bl ;Into Al
- Mov Ah,25h ;Subfunction 25
- Lds Dx,[Bp+10] ;Get the address of the IPC
- Int 21h ;And install it..
- Pop Ds
- EndIf
- If P8086
- Mov Ax,[Bp+8] ;Get the pointer to the function
- Mov Si,Ax ;...
- Mov Ax,[Si] ;...
- Mov Bx,[Si+2] ;...
- Mov FuncIp,Ax ;Where Interserv will call to..
- Mov FuncCs,Bx ;..
- Mov FuncSs,Ss ;Save the Current stack segment address
- Mov FuncDs,Ds ;Save the Current data segment address
- ;
- Mov Di,[Bp+10] ;Move into the IBC area..
- Mov Si,Offset XCINTBOO
- Mov Cx,Intrcl
- Cld
- Rep Movsb
- ;
- Mov Bx,[Bp+6] ;Get the interrupt number..
- Mov Al,Bl ;Into Al
- Mov Ah,25h ;Subfunction 25
- Mov Dx,[Bp+10] ;Get the address of the IPC
- Int 21h ;And install it..
- EndIf
- If L8086
- Mov Ax,[Bp+8] ;Get the pointer to the function
- Mov Bx,[Bp+10]
- Mov FuncIp,Ax ;Where Interserv will call to..
- Mov FuncCs,Bx ;..
- Mov Ax,[Bp+14] ;We have a "New stack segment.."
- Mov FuncSs,Ax ;Save the Current stack segment address
- Mov FuncDs,Ds ;Save the Current data segment address
- ;
- Push Ds
- Les Di,[Bp+12] ;Move into the IBC area
- Lds Si,Intradr
- Mov Cx,Intrcl
- Cld
- Rep Movsb
- ;
- Mov Bx,[Bp+6] ;Get the interrupt number..
- Mov Al,Bl ;Into Al
- Mov Ah,25h ;Subfunction 25
- Lds Dx,[Bp+12] ;Get the address of the IPC
- Int 21h ;And install it..
- Pop Ds
- EndIf
- Pop Bp
- Ret
- XCINTRIN Endp
- Page ,132
- Subttl XCINTCOM
- ; All interrupts that are being processed by a C routine will
- ; come through here.
- ; We will set up the conditions to run a C program.
- ;
- ; Stack on entry
- ; +------+ +------+
- ; = = = =
- ; SP-> +------+ +0 Bp-> +------+ +0
- ; | SP | | Bp |
- ; +------+ +2 +------+ +2
- ; | SS | +--- |oIBC@ |
- ; ICP--> +------+ +4 | +------+ +4
- ; |Call | | |sIBC@ |
- ; +------+ +5 | +------+
- ; |IP | |
- ; +------+ +7 |
- ; |CS | |
- ; oIBC@-> +------+ +9 <--+
- ; |IRET |
- ; +------+ +10
- ; |FUNCIP|
- ; +------+ +12
- ; |FUNCCS|
- ; +------+ +14
- ; |FUNCSS|
- ; +------+ +16
- ; |FUNCDS|
- ; +------+
- ;
- XCINTCOM Proc Far
- Push Bp ;Save
- Mov Bp,Sp ;So we can see the stack
- Push Es
- Push Ds
- Push Bx ;Save BX
- ;
- Cli
- Mov Es,[Bp+4] ;Set up ES to point to the ICP
- Mov Bx,[Bp+2] ;Get offset to the "IRET"
- Sub Bx,9 ;some room yet
- Mov Es:[Bx],Sp ;save stack seg
- Mov Es:[Bx+2],Ss ;and the stack pointer
- Mov Ss,Es:[Bx+14]
- Mov Ds,Es:[Bx+16]
- Mov Sp,Bx
- ;- Save all the other registers..
- Push Ax
- Push Bx
- Push Cx
- Push Dx
- Push Si
- Push Di
- Push Ds
- Push Es
- Push Bp
- PushF
- Mov Bp,Sp
- ;- Call the C function thats handles this interrupt
- If LPROG
- Call Dword Ptr Es:[Bx+10]
- Else
- Call Es:[Bx+10]
- Endif
- ;- Restore the callers environment
- Cli
- Mov Sp,Bp
- PopF
- Pop Bp
- Pop Es
- Pop Ds
- Pop Di
- Pop Si
- Pop Dx
- Pop Cx
- Pop Bx
- Pop Ax
- Mov Bx,Sp ;set up to restore stack
- Mov Sp,Es:[Bx]
- Mov Ss,Es:[Bx+2] ;stack restored
- ;- And return back to the IBC so it can return back to the caller..
- Pop Bx
- Pop Ds
- Pop Es
- Pop Bp
- Ret ;all done
- XCINTCOM Endp
- Page ,132
- Subttl '_ENAINT/_DISAINT Enable/Disable interrupts'
- Public _ENAINT,_DISAINT
- If LPROG
- _ENAINT Proc Far
- Else
- _ENAINT Proc Near
- Endif
- Sti
- Ret
- _ENAINT Endp
- If LPROG
- _DISAINT Proc Far
- Else
- _DISAINT Proc Near
- Endif
- Cli
- Ret
- _DISAINT Endp
- ENDPS
- End