home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / DDJ9403A.ZIP / UC394.ZIP / CGATEVXD.ASM < prev    next >
Assembly Source File  |  1993-12-06  |  4KB  |  140 lines

  1. ;*********************************************************************
  2. ; CGATEVXD.ASM - Call Gate Virtual Device
  3. ; by Alex Shmidt. Nov, 1993
  4. ;*********************************************************************
  5. .386p
  6. .xlist
  7.         include vmm.inc
  8.         include v86mmgr.inc
  9.         include dosmgr.inc
  10.         include int2fapi.inc
  11.         include shell.inc
  12.         include debug.inc
  13.         include cgatevxd.inc
  14. .list
  15.  
  16. if1
  17.  ifdef DEBUG
  18.    %out  Debugging version
  19.  endif
  20.  ifdef WINICE
  21.    %out  SOFT-ICE/W version
  22.  endif
  23. endif
  24.  
  25. Declare_Virtual_Device CGATE, 1, 0, CGATE_Control, Undefined_Device_ID, \
  26.                        Undefined_Init_Order
  27.  
  28. VxD_IDATA_SEG
  29. VxD_IDATA_ENDS
  30.  
  31. VxD_DATA_SEG
  32. CALLGATE32      dw      0               ; callgate GDT selector
  33. VXD_FIRST       dd      0               ; pointer to VMM_DDB
  34. OLD_2F_OFFSET   dd      0
  35. OLD_2F_SEL      dw      0
  36. GATENAME        db      'CallGate',0
  37. VxD_DATA_ENDS
  38.  
  39. VxD_LOCKED_CODE_SEG
  40. Begin_Control_Dispatch CGATE
  41.         Control_Dispatch Sys_Critical_Init, CGATE_Sys_Critical_Init
  42. End_Control_Dispatch CGATE
  43. VxD_LOCKED_CODE_ENDS
  44.  
  45. VxD_ICODE_SEG
  46.  
  47. BeginProc       CGATE_Sys_Critical_Init
  48.         mov     ax, 2fh
  49.         VMMCall Get_PM_Int_Vector
  50.         mov     [OLD_2F_OFFSET],edx
  51.         mov     [OLD_2F_SEL],cx
  52.         mov     esi, offset32 CGate_2F_Handler
  53.         VMMCall Allocate_PM_Call_Back
  54.         movzx   edx, ax
  55.         shr     eax, 16
  56.         mov     ecx, eax
  57.         mov     ax, 2fh
  58.         VMMCall Set_PM_Int_Vector
  59.         clc
  60.         ret
  61. EndProc         CGATE_Sys_Critical_Init
  62.  
  63. VxD_ICODE_ENDS
  64.  
  65. VxD_CODE_SEG
  66. Private_JmpTable        label   dword
  67. dd      offset32 CreateGDTCallGate
  68. dd      offset32 DestroyGDTCallGate
  69.  
  70. BeginProc       CGate_2F_Handler
  71.         cmp     [ebp].Client_AX, 168Ah
  72.         je      short @f
  73. dispatch_2f:
  74.         mov     edx,[OLD_2F_OFFSET]
  75.         mov     cx,[OLD_2F_SEL]
  76.         VMMCall Simulate_Far_Jmp
  77. finish_2f:
  78.         clc
  79.         ret
  80. @@:
  81.         Client_Ptr_Flat edi, ds, si
  82.         mov     esi, offset32 GATENAME
  83.         cld
  84. @@:
  85.         cmpsb
  86.         jnz     short dispatch_2f
  87.         cmp     byte ptr [edi-1], 0
  88.         jnz     short @b
  89.         VMMcall Simulate_Iret
  90.         movzx   eax,[ebp].CLient_DX
  91.         cmp     eax,LAST_PRIVATE
  92.         ja      short @f
  93.         call    dword ptr Private_JmpTable[eax*4]
  94. @@:
  95.         jmp     short finish_2f
  96. EndProc         CGate_2F_Handler
  97.  
  98. ;Client_ES:DI -> ring3 function
  99. ;Client_CL = # of params
  100. ;       returns Client_DX = callgate
  101. BeginProc       CreateGDTCallGate
  102.         movzx   ecx, [ebp].Client_CL
  103.         or      cx, GATE32_RING3
  104.         Client_Ptr_Flat edx,es,di
  105.         mov     [ebp].Client_CX,dx
  106.         ror     edx,16
  107.         mov     [ebp].Client_BX,dx
  108.         ror     edx,16
  109.         mov     ax, cs
  110.         call    BuildCallGate
  111.         VMMCall _Allocate_GDT_Selector,<edx,eax,20000000h>
  112.         mov     [ebp].Client_DX,ax
  113.         mov     [ebp].Client_AX,0
  114.         ret
  115. EndProc         CreateGDTCallGate
  116.  
  117. ;client_cx = cgate to destroy
  118. BeginProc       DestroyGDTCallGate
  119.         movzx   eax,[ebp].Client_CX
  120.         VMMCall _Free_GDT_Selector,<eax,0>
  121.         ret
  122. EndProc         DestroyGDTCallGate
  123.  
  124. ;       On Entry:       ax  = Gate Selector
  125. ;                       edx = Gate Offset
  126. ;                       cx  = gate type | Dword Count
  127. ;
  128. ;       returns:        edx = hi desc dword
  129. ;                       eax = lo dess dword
  130. BeginProc       BuildCallGate
  131.         movzx   eax, ax
  132.         shl     eax, 16
  133.         mov     ax, dx
  134.         mov     dx, cx
  135.         ret
  136. EndProc         BuildCallGate
  137.  
  138. VxD_CODE_ENDS
  139.         end
  140.