home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / dmkit / flat / vector.asm < prev    next >
Encoding:
Assembly Source File  |  1993-12-31  |  4.6 KB  |  148 lines

  1. ;; This is the biggest damned hack I've ever seen under DPMI.  As if there
  2. ;; aren't enough hacks as it is.  Since it is required that we be able
  3. ;; to execute some real-mode code (like DIGPAK and MIDPAK) even though
  4. ;; we are in proteted mode, it is necessary to get into real-mode.
  5. ;; The problem is that DIGPAK and MIDPAK are initialized and de-initialized
  6. ;; through a indirect far call to a jump table.  Normal funtion 301h of
  7. ;; the DPMI services int 31h would take care of this.  But the 4GW 'royalty
  8. ;; free' DOS extender that comes with Watcom doesn't support this most basic
  9. ;; function.  Meaning there is no way, from protected mode, that we can call
  10. ;; a real-mode far procedure.  Therefor I have created, as a place holder, the
  11. ;; 'vector manager'.  This attaches to the INT 66h vector PRIOR!!!! to any
  12. ;; DIGPAK/MIDPAK installation.          This is accomplished by stomping on the INT
  13. ;; 66h vector and simulating a real-mode interrupt, which 4GW supports.
  14. ;; However, even this method of installing the interupt is dangerous.
  15. ;; It is only a placeholder until a better system can be devised.  Once
  16. ;; installed the VECTOR manager now provides a service that will let us
  17. ;; peform a far real-mode procedure call.
  18. ;; The vector manager requires the presence of VECTOR.COM in the directory
  19. ;; which is the tiny real-mode interrupt vector hook.  This is all black
  20. ;; boxed and handled by the LOADER.C program which handles dynamically
  21. ;; loading and unloading DIGPAK and MIDPAK drivers.
  22. ;; Note: both DIGPAK and MIDPAK are capable of operating as a DOS real-mode
  23. ;; TSR.  If LOADER finds both DIGPAK and MIDPAK in memory as a TSR it will
  24. ;; use the resident portion rather than trying to dynamicall load the
  25. ;; versions specified.
  26. ;; extern int cdecl InstallVector(char *vect); // Install far call vector manager.
  27. ;; extern int cdecl RemoveVector(void); // Remove vector manager.
  28. ;;                                                                                                                                                     */
  29. ;;        Written by John W. Ratcliff (c) 1994
  30. ;;             Compuserve: 70253,3237
  31. ;;             Genie: J.RATCLIFF3
  32. ;;             BBS: 1-314-939-0200
  33. ;;             Addresss:
  34. ;;                747 Napa Lane
  35. ;;                St. Charles, MO 63304
  36. ;;                                                                                                                                                     */
  37.  
  38.     IDEAL
  39.     P386
  40.     JUMPS
  41.     MODEL FLAT,C
  42.  
  43. Struc   PREGS
  44.  
  45. R_EDI   dd      ?       ; The EDI register.
  46. R_ESI   dd      ?       ; The ESI register.
  47. R_EBP   dd      ?       ; The EBP register.
  48. R_RESERVED dd   ?       ; reserved, should be zero.
  49. R_EBX   dd      ?       ; The EBX register.
  50. R_EDX   dd      ?       ; The EDX register.
  51. R_ECX   dd      ?       ; The ECX register.
  52. R_EAX   dd      ?       ; The EAX register.
  53. R_FLAGS dw      ?       ; The CPU flags register.
  54. R_ES    dw      ?       ; The ES register.
  55. R_DS    dw      ?       ; The DS register.
  56. R_FS    dw      ?       ; The FS register.
  57. R_GS    dw      ?       ; The GS register.
  58. R_IP    dw      ?       ; Reserved
  59. R_CS    dw      ?       ; Reserved
  60. R_SP    dw      ?       ; Stack pointer
  61. R_SS    dw      ?       ; Stack segment.
  62.  
  63.         Ends
  64.  
  65.  
  66.     CODESEG
  67.  
  68.     public    InstallVector
  69.     public    RemoveVector
  70.  
  71. SIMREGS PREGS <>
  72.  
  73. OLDOFF    dw    0
  74. OLDSEG    dw    0
  75.  
  76. Proc    C    InstallVector
  77.     ARG    VECTOR:DWORD
  78.     uses    ebx,ecx,esi,edi
  79.  
  80.     lea    edi,[SIMREGS]        ; Get the address of the registers
  81.     mov    ecx,size SIMREGS    ; for size of the register region.
  82.     xor    eax,eax
  83.     rep    stosb            ; Zero out register region.
  84.  
  85.     mov    ebx,[VECTOR]    ; Get the address of the 'supposed' DIGPAK.
  86.     cmp    [byte ebx+3],'V'        ; Does it say digpak?
  87.     jne    @@FREE
  88.     cmp    [byte ebx+4],'E'        ;
  89.     jne    @@FREE
  90.     cmp    [byte ebx+5],'C'
  91.     jne    @@FREE
  92.     cmp    [byte ebx+6],'T'
  93.     jne    @@FREE
  94.     cmp    [byte ebx+7],'O'
  95.     jne    @@FREE
  96.     cmp    [byte ebx+8],'R'
  97.     jne    @@FREE
  98. ;; Ok, it SAY's VECTOR.
  99.     shr    ebx,4        ; segment.
  100.     sub    bx,10h        ; less 10 paragraphs.
  101.  
  102.     push    ebx
  103.     mov    ebx,66h
  104.     mov    eax,200h
  105.     int    31h
  106.     mov    [OLDSEG],cx    ; Save original segment
  107.     mov    [OLDOFF],dx    ; Save original offset.
  108.     pop    ebx
  109.  
  110.     mov    ecx,ebx     ; CX=segment.
  111.     mov    edx,200h    ; Offset.
  112.     mov    ebx,66h     ; Install interrupt.
  113.     mov    eax,201h    ; Intall real-mode interrupt vector.
  114.     int    31h        ; install it.
  115.  
  116.     lea    edi,[SIMREGS]    ; Get address.
  117.     xor    ecx,ecx     ; Don't copy anything on the stack.
  118.     xor    ebx,ebx     ; Zero out flags.
  119.     mov    eax,0300h    ; simulate realmode interrupt
  120.     mov    bl,66h
  121.     int    31h        ; Do it!
  122.     jc    @@FREE        ; Failed.
  123.     mov    ax,1        ; Worked!
  124. @@RET:
  125.     ret
  126. @@FREE:
  127.     xor    ax,ax    ; Zero failed return code
  128.     jmp short @@RET
  129.     endp
  130.  
  131. Proc    C    RemoveVector
  132.     uses    ebx,ecx,edx
  133.     cmp    [OLDSEG],0
  134.     je    @@NOTIN
  135.     movsx    ecx,[OLDSEG]    ; CX=segment.
  136.     movsx    edx,[OLDOFF]    ; Offset.
  137.     mov    ebx,66h     ; Install interrupt.
  138.     mov    eax,201h    ; Intall real-mode interrupt vector.
  139.     int    31h        ; install it.
  140.     mov    [OLDSEG],0
  141.     mov    [OLDOFF],0
  142. @@NOTIN:
  143.     ret
  144.     endp
  145.  
  146.     ends
  147.     end
  148.