home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_05 / 3n05027a < prev    next >
Text File  |  1991-12-30  |  11KB  |  231 lines

  1.         ;*************************************************************
  2.         ; Title         PIPE.ASM - Pipe Virtual Device Driver
  3.         ; Version:      3.00                                           
  4.         ; Author:       Thomas W. Olsen                                
  5.         ; Assembler:    Microsoft Macro Assembler 5.10B
  6.         ; Linker:       Microsoft Linear-Executable Linker 1.00.058
  7.         ;               masm5 -p -w2 -Mx -Zd pipe;
  8.         ;               link386 pipe.obj,pipe.386 /NOI /NOD /NOP,,,pipe.def;
  9.         ;               addhdr pipe.386
  10.         ;*************************************************************
  11.  
  12.         .386p
  13.         INCLUDE VMM.Inc
  14.  
  15.         PIPE_DEVICE_ID         EQU 2020H
  16.         PIPE_MAJOR_VERSION     EQU 03
  17.         PIPE_MINOR_VERSION     EQU 00
  18.         PIPE_VERSION_NO        EQU (PIPE_MAJOR_VERSION * 256 + PIPE_MINOR_VERSION)
  19.         GET_VERSION            EQU 0
  20.         REGISTER_CALLBACK      EQU 1
  21.         UNREGISTER_CALLBACK    EQU 2
  22.         ALLOCATE_GDT_SELECTOR  EQU 3
  23.         FREE_GDT_SELECTOR      EQU 4
  24.         CALL_WINDOWS_PROCEDURE EQU 5
  25.  
  26.         ;*************************************************************
  27.         ;                       Device Header
  28.         ;*************************************************************
  29.  
  30. Declare_Virtual_Device  PIPE, PIPE_MAJOR_VERSION, PIPE_MINOR_VERSION,       \
  31.                         PIPE_CONTROL, PIPE_DEVICE_ID, Undefined_Init_Order, \
  32.                         PIPE_API, PIPE_API
  33.  
  34.         ;*************************************************************
  35.         ;                    Virtual Machine Data
  36.         ;*************************************************************
  37.         VM_Control_Block_Data struc
  38.                 msgNo           dw ?            ;Client_AX
  39.                 wParam          dw ?            ;Client_BX
  40.                 lParamLo        dw ?            ;Client_CX
  41.                 lParamHi        dw ?            ;Client_DX
  42.         VM_Control_Block_Data ends
  43.  
  44.         ;*************************************************************
  45.         ;                       Local Data 
  46.         ;*************************************************************
  47. VxD_DATA_SEG
  48.  
  49.         VM_Control_Block_Offset dd ?
  50.         WinProc_Installed       dw 0
  51.         WinProc_hWnd            dw ?
  52.         WinProc_Callback_CS     dw ?
  53.         WinProc_Callback_IP     dw ?
  54.  
  55.         EXPORT_TABLE            label dword
  56.                                 dd offset32 PIPE_Get_Version
  57.                                 dd offset32 PIPE_Register_CallBack
  58.                                 dd offset32 PIPE_Unregister_CallBack
  59.                                 dd offset32 PIPE_Allocate_GDT_Selector
  60.                                 dd offset32 PIPE_Free_GDT_Selector
  61.                                 dd offset32 PIPE_Call_Windows_Procedure
  62.         NO_OF_EXPORTS           EQU ($ - EXPORT_TABLE) / 4
  63.  
  64. VxD_DATA_ENDS
  65.  
  66.         ;*************************************************************
  67.         ;                      Control Procedures
  68.         ;*************************************************************
  69. VxD_LOCKED_CODE_SEG
  70.         BeginProc PIPE_Device_Init
  71.                 VMMcall _Allocate_Device_CB_Area, <<SIZE VM_Control_Block_Data>, 0>
  72.                 mov     [VM_Control_Block_Offset], eax
  73.                 clc
  74.                 ret
  75.         EndProc PIPE_Device_Init
  76.  
  77.         BeginProc PIPE_Control
  78.                 Control_Dispatch Device_Init,   PIPE_Device_Init
  79.                 clc
  80.                 ret
  81.         EndProc PIPE_Control
  82. VxD_LOCKED_CODE_ENDS
  83.         
  84.         ;*************************************************************
  85.         ;                           APIs
  86.         ;*************************************************************
  87. VxD_CODE_SEG
  88.  
  89.         ;*************************************************************
  90.         ;On Entry:  AX = Function Number to Execute
  91.         ;*************************************************************
  92.         BeginProc PIPE_API,PUBLIC
  93.             and    [ebp].Client_Flags, CF_Mask
  94.                 movzx   eax, [ebp].Client_AX
  95.                 cmp     ax, NO_OF_EXPORTS
  96.                 jae     short @@A99
  97.                 jmp     EXPORT_TABLE[eax * 4]
  98.         @@A99:
  99.                 ret
  100.         EndProc PIPE_API
  101.  
  102.         ;*************************************************************
  103.         ;On Exit:   AX = Version Number
  104.         ;*************************************************************
  105.         BeginProc PIPE_Get_Version,PUBLIC
  106.                 mov     [ebp].Client_AX, PIPE_VERSION_NO
  107.             and    [ebp].Client_Flags, NOT CF_Mask
  108.                 ret
  109.         EndProc PIPE_Get_Version
  110.  
  111.         ;*************************************************************
  112.         ;On Entry:  CX:DX = Windows Proc CS:IP EntryPoint
  113.         ;           BX    = Window Handle
  114.         ;*************************************************************
  115.         BeginProc PIPE_Register_CallBack,PUBLIC
  116.                 mov     WinProc_Installed, 1
  117.                 mov     cx,[ebp].Client_CX
  118.                 mov     WinProc_Callback_CS, cx
  119.                 mov     dx,[ebp].Client_DX
  120.                 mov     WinProc_Callback_IP, dx
  121.                 mov     bx,[ebp].Client_BX
  122.                 mov     WinProc_hWnd, bx
  123.             and    [ebp].Client_Flags, NOT CF_Mask
  124.                 ret
  125.         EndProc PIPE_Register_CallBack
  126.  
  127.         ;*************************************************************
  128.         ;On Entry:  None
  129.         ;*************************************************************
  130.         BeginProc PIPE_Unregister_CallBack,PUBLIC
  131.                 mov     WinProc_Installed, 0
  132.             and    [ebp].Client_Flags, NOT CF_Mask
  133.                 ret
  134.         EndProc PIPE_Unregister_CallBack
  135.  
  136.         ;*************************************************************
  137.         ;On Entry:  BX = Real Mode Segment Register
  138.         ;On Exit:   AX = Protected Mode Selector
  139.         ;*************************************************************
  140.         BeginProc PIPE_Allocate_GDT_Selector,PUBLIC
  141.                 Client_Ptr_Flat eax, bx   ;Map a Selector to DOS partition using [ebp].Client_DS
  142.                 VMMCall _BuildDescriptorDWORDs, <eax, 0FFFFh, RW_Data_Type, <D_GRAN_BYTE or D_DEF16>, 0>
  143.                 VMMCall _Allocate_GDT_Selector, <edx, eax, 0>
  144.                 mov     [ebp].Client_AX, ax
  145.             and    [ebp].Client_Flags, NOT CF_Mask
  146.                 ret
  147.         EndProc PIPE_Allocate_GDT_Selector
  148.         
  149.         ;*************************************************************
  150.         ;On Entry:  BX    = Protected Mode Selector
  151.         ;*************************************************************
  152.         BeginProc PIPE_Free_GDT_Selector,PUBLIC
  153.                 mov     bx, [ebp].Client_BX
  154.                 movzx   ebx, bx
  155.                 VMMCall _Free_GDT_Selector, <ebx, 0>    ;EBX = GDT Selector
  156.             and    [ebp].Client_Flags, NOT CF_Mask
  157.                 ret
  158.         EndProc PIPE_Free_GDT_Selector
  159.  
  160.         ;*************************************************************
  161.         ;On Entry:  BX    = (WORD) msgNo 
  162.         ;           SI    = (WORD) wParam
  163.         ;           CX:DX = (LONG) lParam
  164.         ;*************************************************************
  165.         BeginProc PIPE_Call_Windows_Procedure,PUBLIC
  166.                 cmp     WinProc_Installed, 0            ;If Not Installed, Abort
  167.                 je      short @@C2
  168.                 mov     esi, ebx                        ;EBX = VM Handle
  169.                 add     esi, [VM_Control_Block_Offset]  ; point to that VM's area
  170.                 mov     ax, [ebp].Client_BX
  171.                 mov     [esi].msgNo, ax
  172.                 mov     ax, [ebp].Client_SI
  173.                 mov     [esi].wParam, ax
  174.                 mov     ax, [ebp].Client_CX
  175.                 mov     [esi].lParamHi, ax
  176.                 mov     ax, [ebp].Client_DX
  177.                 mov     [esi].lParamLo, ax
  178.  
  179.                 VMMcall Test_Sys_VM_Handle              ;Are We in the System VM?
  180.                 jnz     short @@C1
  181.                 VMMcall Get_Crit_Section_Status         ;Is Something Critical Happening?
  182.                 jc      short @@C1
  183.                 mov     edx, ebx                        ;EDX = Current VM Handle
  184.                 mov     esi, offset32 PIPE_EventProcedure
  185.                 VMMcall Call_When_VM_Ints_Enabled       ;Call Event Procedure Now
  186.                 jmp     short @@C2
  187.         @@C1:
  188.                 mov     edx, ebx                        ;EDX = Current VM Handle
  189.                 VMMcall Get_Sys_VM_Handle               ;EBX = System VM Handle
  190.                 mov     eax, High_Pri_Device_Boost      ;EAX = Priority Boost
  191.                 mov     ecx, PEF_Wait_For_STI or PEF_Wait_Not_Crit ;ECX = Flags
  192.                 mov     esi, offset32 PIPE_EventProcedure   ;ESI = Offset of Event Procedure
  193.                 VMMcall Call_Priority_VM_Event          ;Post Event in Task Queue
  194.         @@C2:
  195.                 ret
  196.         EndProc PIPE_Call_Windows_Procedure
  197.  
  198.         ;*************************************************************
  199.         ;On Entry:  EDX = Current VM Handle
  200.         ;*************************************************************
  201.         BeginProc PIPE_EventProcedure, PUBLIC
  202.                 Push_Client_State
  203.                 mov     esi, edx                        ;EDX = Current VM Handle
  204.                 add     esi, VM_Control_Block_Offset
  205.                 VMMCall Begin_Nest_Exec                 ;Setup Call Frame
  206.  
  207.                 mov     ax, WinProc_hWnd                ;Push Parms onto Stack
  208.                 VMMcall Simulate_Push                   ;Using PASCAL Convention (4,3,2,1)
  209.                 mov     ax, [esi].msgNo                 
  210.                 VMMcall Simulate_Push                   
  211.                 mov     ax, [esi].wParam
  212.                 VMMcall Simulate_Push
  213.                 mov     ax, [esi].lParamHi
  214.                 VMMcall Simulate_Push
  215.                 mov     ax, [esi].lParamLo
  216.                 VMMcall Simulate_Push
  217.                 mov     cx, WinProc_Callback_CS
  218.                 mov     dx, WinProc_Callback_IP
  219.                 movzx   edx, dx
  220.                 VMMCall Simulate_Far_Call               ;Push Address Onto Stack
  221.  
  222.                 VMMCall Resume_Exec                     ;Call Windows Procedure
  223.                 VMMcall End_Nest_Exec
  224.                 Pop_Client_State
  225.                 ret
  226.         EndProc   PIPE_EventProcedure
  227.  
  228. VxD_CODE_ENDS
  229.  
  230. END
  231.