home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / APR94_2.ZIP / LISTINST / LISTINST.ASM < prev    next >
Assembly Source File  |  1994-03-01  |  26KB  |  742 lines

  1. ;ListInst.ASM 
  2. ;from Dr. Dobbs Journal,April 1994
  3. ;Copyright (c) 1994 Klaus Mueller.  All rights reserved.
  4.  
  5. OPTION M510
  6.  
  7. .386p
  8.  
  9. INCLUDE VMM.INC
  10. INCLUDE INT2FAPI.INC
  11. INCLUDE WIN386.INC
  12. Create_ListInst_Service_Table   EQU     1   ;service table created
  13. INCLUDE LISTINST.INC
  14.  
  15. ;*****************************************************************************
  16. ;        V I R T U A L   D E V I C E   D E C L A R A T I O N
  17. ;*****************************************************************************
  18.  
  19. Declare_Virtual_Device  ListInst, 1, 0, ListInst_VxD_Control, \
  20.                         ListInst_Device_ID,ListInst_Init_Order, \
  21.                         ListInst_V86_API
  22.     
  23.  
  24. ;*****************************************************************************
  25. ;           R E A L   M O D E   I N I T I A L I Z A T I O N
  26. ;*****************************************************************************
  27.  
  28. VXD_REAL_INIT_SEG
  29.  
  30. real_init proc near
  31.     push edx
  32.     mov ah, 9
  33.     mov dx, offset copyright
  34.     int 21h
  35.     xor ax, ax           
  36.     xor bx, bx          
  37.     xor si, si
  38.     pop edx
  39.     ret
  40. real_init endp
  41.  
  42. copyright   db  'ListInst.386 -- provides structures of the Instance Data'
  43.             db  ' Manager.',0dh,0ah
  44.  
  45.             db  'Copyright (c) 1994 Klaus Mueller. All Rights Reserved.'
  46.             db  0dh,0ah,'$'
  47.  
  48. VXD_REAL_INIT_ENDS
  49.  
  50. VxD_ICODE_SEG
  51.  
  52.  
  53. BeginProc ListInst_Sys_Critical_Init
  54.  
  55.         ;int 3
  56.         movzx eax,dx                            ;real mode offset of ref data from 
  57.         and edx,0ffff0000h                      ;VxDLoad TSR
  58.         shr edx,0ch                             ;segment
  59.         add edx,eax                             ;linear address
  60.         mov w386_sis_tbl,edx
  61.         mov Data_Buf_Size,1000h
  62. ;allocate 1 page for the InstDataStrucs from the hooked _AddInstanceItem call
  63.         VMMcall _PageAllocate <1, PG_SYS, 0, 0, 0, 0, 0, PAGEFIXED+PAGEZEROINIT>
  64.         cmp eax,0
  65.         je allocerr
  66.         mov Data_Buf_Handle,eax
  67.         mov Data_Buf_Addr,edx
  68.         int 3
  69.  
  70. ;Instancing of the first byte in the 1st MB in order to get all calls to 
  71. ;_AddInstanceItem befor ListInst_Sys_Critical_Init. The _AddInstanceItem
  72. ;service chains the InstDataStrucs together to a sorted double linked list
  73. ;via InstLinkF and instLinkB.
  74. ;If the LinkF field is -1, no other calls were made.
  75. ;If LinkF <> -1, then it represents a call to _AddInstanceItem caused by an
  76. ;system.ini - entry "LOCALTSRS= tsr_name". The VMM instances the hole TSR,
  77. ;the first 16 Byte represents the MCB of the PSP. So we can determine the name
  78. ;of the fully instanced TSR. 
  79.  
  80.         mov KM_Instance.InstLinAddr,0
  81.         mov KM_Instance.InstSize,1
  82.         mov KM_Instance.InstType,ALWAYS_FIELD
  83.         mov esi,offset32 KM_Instance
  84.         VMMcall _AddInstanceItem <esi,0>       
  85.         cmp KM_Instance.InstLinkF,-1            ;any LOCALTSRS ?
  86.         je nolocal
  87.         mov esi,KM_Instance.InstLinkF           ;yes, get it
  88. loclp:  mov Inst_Struc_Ptr,esi
  89.         mov calladr,'LTSR'
  90.         call addinst                            ;add instance item to our list
  91.         mov esi,[esi.InstDataStruc.InstLinkF]   ;get next InstDataStruc
  92.         cmp esi,-1                              ;no more strucs?
  93.         jne loclp
  94. nolocal:mov eax,_AddInstanceItem
  95.         mov esi,offset32 myhook
  96.         VMMcall Hook_Device_Service
  97.         mov [oldservice],esi
  98.         ;int 3                                  ;uncomment this for debug
  99.         clc                                     ;no error
  100.         ret                     
  101. allocerr:
  102.         stc
  103.         ret
  104. EndProc ListInst_Sys_Critical_Init
  105.  
  106.         
  107.  
  108. VxD_ICODE_ENDS
  109.  
  110. ;*****************************************************************************
  111. ;           L O C K E D   C O D E   S E G M E N T
  112. ;*****************************************************************************
  113.  
  114. VxD_LOCKED_CODE_SEG
  115.  
  116. BeginProc ListInst_VxD_Control
  117.  
  118.     Control_Dispatch Sys_Critical_Init, ListInst_Sys_Critical_Init
  119. ;   Control_Dispatch Init_Complete,     ListInst_Init_Complete
  120.     clc
  121.     ret
  122.  
  123. EndProc ListInst_VxD_Control
  124.  
  125. VxD_LOCKED_CODE_ENDS
  126.  
  127. ;*****************************************************************************
  128. ;               O N L Y   D A T A   S E G M E N T
  129. ;*****************************************************************************
  130.  
  131. VxD_DATA_SEG
  132.  
  133. w386_sis_tbl    dd  0
  134. oldservice      dd  0
  135. count           dd  0
  136. ddbpointer      dd  0   
  137. Inst_Struc_Ptr  dd  0
  138. calladr         dd  0
  139. init_done       dd  0
  140. Inst_Data_Count dd  0
  141. inst_count      dd  0
  142. desc_count      dd  0
  143. VMCB_PG_Table   dd  0
  144. SYS_PG_Table    dd  0
  145. win4_flag       dd  0
  146. w4_pres_count   dd  0
  147. w4_npres_count  dd  0
  148. w4_cur_handle   dd  0
  149. Inst_Desc_Buf   dd  0
  150. Inst_Buf_Handle dd  0
  151. Inst_Buf_Size   dd  0                       
  152. bit_array       dd  0
  153. Data_Buf_Handle dd  0
  154. Data_Buf_Addr   dd  0
  155. Data_Buf_Size   dd  0
  156. hook_err        dd  0
  157. string_buf      dd  0
  158. string_buf_handle dd    0
  159. string_buf_size   dd    0
  160. int_2f_string   db  'VMM:Create_Int_2F_Inst_Tbl:        ',0 
  161. localtsr_string db  'VMM:Instance_LOCALTSRS    :        ',0
  162. dos_sys_string  db  'SYS DRV '
  163. nostring        db  '????'
  164. cur_inst        dd  0
  165.  
  166. KM_Instance     InstDataStruc {}
  167.  
  168. VxD_DATA_ENDS
  169.  
  170. VxD_CODE_SEG
  171.  
  172. BeginProc   Hooked_AddInstanceItem
  173. ;The AddInstanceItem Hook stores the callers address and the instance data
  174. ;pointer in the Inst_Data_Buf buffer.
  175. myhook: 
  176.         ;int 3                                  ;uncomment this for debug
  177.         push ebp
  178.         mov ebp,esp
  179.         push [ebp+0ch]                          ;Flags
  180.         push [ebp+8]                            ;Instance Structure Pointer
  181.         push [ebp+8]
  182.         pop Inst_Struc_Ptr
  183.         push [ebp+4]                            ;Callers returnaddress
  184.         pop calladr
  185.         call [oldservice]                       ;call old handler
  186.         add esp,8
  187.         pop ebp
  188.         ;int 3
  189.         cmp eax,0                               ;error in AddInstanceItem ?
  190.         je exit
  191.         call addinst                            ;add Instance Item to our list
  192. exit:   ;int 3
  193.         ret
  194.  
  195. ;*****************************************************************************
  196. ;addinst - adds a instance item to our list.
  197. ;INPUT:     calladr - address of caller of _AddInstanceItem
  198. ;           Inst_Struc_Ptr - address of InstDataStruc
  199. ;OUTPUT:    hookerr = -1 - error growing Data_Buf
  200. ;           hookerr = 0 - all O.K.
  201. ;*****************************************************************************
  202.  
  203. addinst:push edi
  204.         push esi
  205.         push ecx
  206.         push eax
  207. hook2:  mov edi,Data_Buf_Addr
  208.         mov ecx,Inst_Data_Count
  209.         imul ecx,sizeof KM_InstData
  210.         add edi,ecx
  211.         push edi
  212.         add edi,sizeof KM_InstData
  213.         mov ecx,Data_Buf_Addr
  214.         add ecx,Data_Buf_Size
  215.         cmp edi,ecx
  216.         pop edi
  217.         jl hook1
  218.         mov ecx,Data_Buf_Size
  219.         add ecx,1000h
  220.         shr ecx,0ch
  221.         mov edx,Data_Buf_Handle
  222.         VMMcall _PageReAllocate <EDX, ECX, PAGEZEROINIT>          
  223.         cmp eax,0
  224.         je hookerr
  225.         add Data_Buf_Size,1000h
  226.         mov Data_Buf_Handle,eax
  227.         mov Data_Buf_Addr,edx
  228.         jmp hook2
  229. hook1:  mov eax,calladr                         ;save callers address in buffer
  230.         stosd
  231.         mov esi,Inst_Struc_Ptr
  232.         mov ecx,(sizeof InstDataStruc)/4
  233.         rep movsd                               ;save instance data struc
  234.         inc Inst_Data_Count
  235. hookret:pop eax                                 ;next offset pair
  236.         pop ecx
  237.         pop esi
  238.         pop edi
  239.         ret
  240. hookerr:mov hook_err,-1
  241.         jmp hookret
  242.  
  243. EndProc   Hooked_AddInstanceItem
  244.  
  245. BeginProc ListInst_Get_Instance_Desc_Buffer, Service
  246.  
  247.         cmp Inst_Desc_Buf,0
  248.         jne getdes
  249.         call descr                              ;build Instance Description Buf
  250.         jc getderr                              ;error in decr buf build
  251. getdes: mov esi,Inst_Desc_Buf                   ;return address of buffer
  252.         clc
  253. getderr:ret
  254.  
  255. EndProc ListInst_Get_Instance_Desc_Buffer
  256.  
  257.  
  258.  
  259. BeginProc ListInst_V86_API
  260.         ;int 3
  261.         cmp [ebp.Client_AX],Inst_Map
  262.         je instmap
  263.         cmp [ebp.Client_AX],Inst_Ownership
  264.         je instown
  265.         cmp [ebp.Client_AX],Desc_Buf_Size
  266.         je descsize
  267.         cmp [ebp.Client_AX],Inst_Map_Size
  268.         je mapsize
  269. v86err: or [ebp.Client_FLAGS],1                 ;set carry
  270.         ret
  271. descsize:
  272.         call descr
  273.         jc v86err
  274.         mov eax,Inst_Buf_Size
  275.         Client_Ptr_Flat edi, DS, BX
  276.         stosd
  277.         ret 
  278. mapsize:mov eax,Inst_Data_Count                 ;# of inst strucs
  279.         imul eax, sizeof Inst_Hook_Struc
  280.         Client_Ptr_Flat edi, DS, BX
  281.         stosd
  282.         ret 
  283.             
  284.  
  285. ;V86 API, determine instance page ownership
  286.  
  287. instown:;int 3
  288.         VMMcall Get_VMM_Version
  289.         cmp ah,3
  290.         je win3
  291.         cmp ah,4
  292.         je win4
  293.         or [ebp.Client_FLAGS],1
  294.         ret
  295. win3:   cmp ecx,0                               ;debug VMM ?
  296.         je nodeb3                               ;no, retail VMM
  297.         mov VMCB_PG_Table,CB_PT_Deb31_Off       ;debug VMM loaded
  298.         jmp vm1
  299. nodeb3: mov VMCB_PG_Table,CB_PT_Ret31_Off       ;get offset for retail VMM
  300.         jmp vm1
  301. win4:   cmp ecx,0                               ;debug VMM ?
  302.         je nodeb4
  303.         or [ebp.Client_FLAGS],1                 ;yes, cannot handle
  304.         ret
  305. nodeb4: mov win4_flag,-1
  306.         mov VMCB_PG_Table,CB_PT_Ret40_Off
  307. vm1:    VMMcall Get_Sys_VM_Handle
  308.         mov ecx,110h
  309.         mov edi,VMCB_PG_Table
  310.         mov edx,[ebx+edi]                       ;get page table of SYS VM
  311.         mov SYS_PG_Table,edx
  312. ownloop:mov eax,[edx]                           ;get page entry
  313.         mov esi,eax
  314.         cmp win4_flag,-1
  315.         jne w3loop
  316.         and esi,P_WRITE
  317.         jz nextpg    
  318.         jmp gotinst
  319. w3loop: and esi,PG_Type                         ;filter "Avail" field of entry
  320.         cmp esi,PgT_INSTANCE                    ;instanced page found ?
  321.         je gotinst
  322. nextpg: add edx,4                               ;no, test next page
  323. lp1:    loop ownloop
  324. done:   cmp Inst_Desc_Buf,0
  325.         jne done1
  326.         call descr                              ;build Instance Description Buf
  327.         jnc done1                               ;error in decr buf build
  328.         Client_Ptr_Flat edi,DS,BX               ;get callers buffer
  329.         mov edi,[edi]                           ;get far pointer
  330.         call v862lin
  331.         mov eax,0
  332.         mov ecx,(sizeof Inst_Desc_Struc)/4
  333.         rep stosd
  334.         jmp done2
  335. done1:  mov ecx,Inst_Buf_Size
  336.         shr ecx,2                               ;copy dword
  337.         mov esi,Inst_Desc_Buf
  338.         Client_Ptr_Flat edi,DS,BX               ;get callers buffer
  339.         mov edi,[edi]                           ;get far pointer
  340.         call v862lin
  341.         rep movsd                               ;copy Instance Description Buf
  342. done2:  Client_Ptr_Flat edi,DS,DX               ;get callers buffer
  343.         mov edi,[edi]                           ;get far pointer
  344.         call v862lin
  345.         mov esi,inst_count
  346.         imul esi,sizeof Inst_Ownership_Struc    
  347.         add edi,esi
  348.         mov eax,Last_Entry
  349.         stosd
  350.         mov inst_count,0
  351.         ret                                     ;walked all VM's
  352. gotinst:and eax,P_PRES                          ;page present ?
  353.         jnz gotpres
  354. got1:   cmp win4_flag,-1
  355.         jne got31
  356.         inc w4_npres_count  
  357. got31:  VMMcall Get_Next_VM_Handle              ;SYS VM does not own Inst Pg
  358.         VMMCall Test_Sys_VM_Handle              ;check all others
  359.         jnz nextvm                              ;Z=1 if SYS VM
  360.         cmp win4_flag,-1
  361.         jne lp3
  362.         cmp w4_pres_count,1
  363.         jne lp4
  364.         cmp w4_npres_count,0
  365.         je lp4
  366.         mov eax,110h
  367.         sub eax,ecx
  368.         cmp eax,0a0h
  369.         jl got4 
  370.         cmp eax,0c8h                            ;exclude screen mem 
  371.         jl lp4                                  
  372. got4:   push ebx
  373.         mov ebx,w4_cur_handle
  374.         call storepg                            ;write instance page to V86 buf
  375.         pop ebx                                 ;restore current VM handle
  376. lp4:    mov w4_pres_count,0
  377.         mov w4_npres_count,0            
  378. lp3:    add edx,4                               ;next page table entry
  379.         jmp lp1
  380. nextvm: push edx
  381.         sub edx,SYS_PG_Table                    ;current offset into page table
  382.         mov eax,edx
  383.         mov edi,VMCB_PG_Table
  384.         mov edx,[ebx+edi]                       ;get page table of next VM
  385.         add edx,eax                             ;current entry
  386.         mov eax,[edx]                           ;get current entry
  387.         pop edx                                 ;current entry from SYS_VM
  388.         jmp gotinst
  389. gotpres:cmp win4_flag,-1
  390.         jne gotpr3
  391.         inc w4_pres_count 
  392.         mov w4_cur_handle,ebx
  393.         jmp got31                               ;test next entry
  394. gotpr3: call storepg                            ;store page number in V86 buffer
  395.         jmp got31                               ;test next entry
  396.  
  397. ;Storepg - Writes number of instanced page and VM handle, flags, ID
  398. ;to V86 buffer in DS:DX
  399. ;INPUT: EBX = VM handle
  400. ;       EBP = Client_Ptr
  401. ;       ECX = current pagecount (<110h)
  402.         
  403. storepg:push eax
  404.         push esi
  405.         push edi
  406.         mov eax,110h
  407.         sub eax,ecx                                 ;eax = number of inst page
  408.         Client_Ptr_Flat edi,DS,DX                   ;get callers buffer
  409.         mov edi,[edi]                               ;get far pointer
  410.         call v862lin
  411.         mov esi,inst_count
  412.         imul esi,sizeof Inst_Ownership_Struc    
  413.         add edi,esi
  414.         mov [edi.Inst_PG_No],eax                    ;store number of instanced page
  415.         mov [edi.Owner_VM_Handle],ebx               ;store VM_Handle
  416.         mov eax,[ebx.CB_VM_Status]
  417.         mov [edi.Owner_VM_Flags],eax
  418.         mov eax,[ebx.CB_VMID]                       ;get VMID
  419.         mov [edi.Owner_VM_ID],eax                   ;store ID
  420.         inc inst_count
  421.         pop edi
  422.         pop esi
  423.         pop eax
  424.         ret
  425.  
  426. ;Create the Instance Description Buffer with data from hooked _AddInstanceItem
  427.  
  428. ;Since 140 Kb are not a big problem in win386, I simply allocate a bit array.
  429. ;Every bit stands for a Byte in the first 10fh pages.
  430. ;A bit is set if the corresponding byte is marked instanced in an InstData
  431. ;struc. In this way I must not handle the overlapping (left, right, lower,
  432. ;upper) instance items for building the Instance Description Buffer.
  433. ;If you ever inspect the code from the VMM, which generates the VMM 
  434. ;Instance Description Buffer, you will be astonished how a different approach
  435. ;can avoid al lot of programming work. 
  436.  
  437. descr:  ;int 3
  438.         pushad
  439.         cmp hook_err,-1                         ;error in _AddInstanceItemhook?
  440.         je deserr
  441.         mov eax,110000h
  442.         shr eax,3
  443.         mov ecx,eax
  444.         push ecx
  445.         VMMcall _HeapAllocate <eax,0>
  446.         pop ecx
  447.         cmp eax,0
  448.         je deserr
  449.         mov edi,eax
  450.         mov bit_array,eax
  451.         shr ecx,2
  452.         mov eax,0
  453.         push edi
  454.         rep stosd                                   ;perform ZeroInit
  455.         pop edi
  456.         mov Inst_Buf_Size,1000h                     ;size in dword
  457.         VMMcall _PageAllocate <1,PG_SYS,0,0,0,0,0,PAGEFIXED+PAGEZEROINIT>
  458.         mov Inst_Desc_Buf,edx                       ;store address  
  459.         mov Inst_Buf_Handle,eax                     ;store handle
  460.         mov ebx,8
  461.         mov esi,Data_Buf_Addr
  462.         mov ecx,Inst_Data_Count                     ;# of InstData strucs
  463.         ;int 3
  464. desclp: push ecx
  465.         mov eax,[esi.KM_InstData.InstType]
  466.         cmp eax,ALWAYS_Field
  467.         je blp1
  468.         cmp eax,INDOS_Field
  469.         jnz skiplp
  470. blp1:   mov eax,[esi.KM_InstData.InstLinaddr]       ;get VM linear address
  471.         mov ecx,[esi.KM_InstData.InstSize]
  472. bitlp:  bts [edi],eax                               ;386 power!,set bit in array
  473.         inc eax
  474.         loop bitlp
  475. skiplp: add esi,sizeof KM_InstData                  ;next InstData Struc
  476.         pop ecx                                     ;current Inst_Data_Count
  477.         loop desclp     
  478.         mov ecx,110000h
  479.         mov ebx,Inst_Desc_Buf                       ;all bits set
  480.         mov eax,0                                   ;begin with bit 0
  481.         mov esi,0                                   ;size of last item
  482. tstlp:  bt [edi],eax                                ;test bit
  483.         inc eax
  484.         jc bitset                               
  485.         loop tstlp
  486. desret: mov eax,bit_array
  487.         VMMcall _HeapFree <eax, 0>
  488.         clc
  489.         popad
  490.         ret                                         ;all bits tested
  491. itemend:mov [ebx.Inst_Desc_Struc.Item_Size],edx
  492.         cmp edx,4
  493.         push edx
  494.         jb item5
  495.         mov edx,[ebx.Inst_Desc_Struc.VM_Lin_Address]
  496.         test edx,3
  497.         jz item2
  498.         and edx,3
  499.         sub edx,4
  500.         neg edx
  501.         push eax
  502.         mov eax,[ebx.Inst_Desc_Struc.Item_Size]
  503.         sub eax,edx
  504.         cmp eax,4
  505.         jb item4
  506.         mov eax,esi
  507.         and eax,3
  508.         sub eax,4
  509.         neg eax
  510.         cmp eax,edx
  511.         jz item4
  512.         ja item3
  513.         add esi,eax
  514.         add esi,4
  515.         sub esi,edx
  516.         jmp item4
  517. item3:  sub eax,edx
  518.         add esi,eax
  519. item4:  pop eax
  520.         jmp item5
  521. item2:  add esi,3                                   ;last Inst_Buf_Off
  522.         and esi,not 3       
  523. item5:  ;int 3
  524.         mov [ebx.Inst_Desc_Struc.Inst_Buf_Off],esi  ;offset in Inst Buf
  525.         pop edx
  526.         add esi,edx                                 ;Inst_Buf_Off for next item
  527.         add ebx,sizeof Inst_Desc_Struc              ;next entry
  528.         push ebx
  529.         mov edx,Inst_Desc_Buf
  530.         add edx,Inst_Buf_Size
  531.         add ebx,sizeof Inst_Desc_Struc              ;next entry
  532.         cmp ebx,edx
  533.         pop ebx
  534.         jl item1
  535.         sub ebx,Inst_Desc_Buf
  536.         push ebx
  537.         push eax
  538.         push ecx
  539.         mov ecx,Inst_Buf_Size
  540.         add ecx,1000h
  541.         shr ecx,0ch
  542.         mov edx,Inst_Buf_Handle
  543.         VMMcall _PageReAllocate <EDX, ECX, PAGEZEROINIT>          
  544.         cmp eax,0
  545.         je deserr
  546.         add Inst_Buf_Size,1000h
  547.         mov Inst_Buf_Handle,eax
  548.         mov Inst_Desc_Buf,edx
  549.         pop ecx
  550.         pop eax
  551.         pop ebx
  552.         add ebx,Inst_Desc_Buf
  553. item1:  dec ecx
  554.         jnz tstlp
  555.         jmp desret                                  ;all bits tested
  556. bitset: dec ecx
  557.         mov edx,1                                   ;instanced byte counter
  558.         dec eax
  559.         mov [ebx.Inst_Desc_Struc.VM_Lin_Address],eax
  560.         inc eax
  561. itemlp: bt [edi],eax                                ;test following bit
  562.         inc eax                                     ;next bit
  563.         jnc itemend
  564.         inc edx                                     ;instanced byte counter++ 
  565.         loop itemlp
  566.         jmp desret                                  ;all bits tested
  567. deserr: stc                                         ;signal error
  568.         popad
  569.         ret     
  570.  
  571. ;V86 API, result of _AddInstanceItem hook
  572.  
  573. instmap:;int 3
  574.         cmp hook_err,-1         ;errore during -AddInstanceItem hook ?
  575.         jne hookok
  576.         or [ebp.Client_Flags],1                     ;signal error
  577.         ret
  578. hookok: cmp string_buf,0                            ;already build ?
  579.         je instgo
  580.         jmp instcpy 
  581. instgo: mov eax,Inst_Data_Count
  582.         imul eax,sizeof Inst_Hook_Struc
  583.         cmp eax,1000h
  584.         ja instgo1
  585.         mov eax,1
  586.         jmp instgo2
  587. instgo1:add eax,1000h
  588.         and eax,0fffh
  589.         shr eax,0ch
  590. instgo2:VMMcall _PageAllocate <eax, PG_SYS, 0, 0, 0, 0, 0, PAGEFIXED+PAGEZEROINIT>
  591.         cmp eax,0
  592.         je inster1
  593.         mov string_buf_handle,eax
  594.         mov string_buf,edx
  595.  
  596.         mov ecx,Inst_Data_Count
  597. instlp: push ecx
  598.         mov esi,count
  599.         imul esi,sizeof KM_InstData
  600.         add esi,Data_Buf_Addr
  601.         ;int 3                                  
  602.         mov edi,[esi.KM_InstData.AddInst_Caller]    
  603.         mov cur_inst,esi
  604.         cmp edi,'LTSR'          ;instance struc from LOCALTSRS entry ?
  605.         je locadd 
  606.         VxDcall VxDQuery_Address_to_VxDName
  607.         jc insterr
  608. isVxD:  push edi                ;points to VxDname received from VxDQuery
  609.         ;int 3
  610.         mov edi,w386_sis_tbl                        ;first Win386_KM_SIS
  611. nextsis:mov ebx,[edi.KM_SIS.SIS_Instance_Data_Ptr]
  612.         cmp ebx,0               ;any instance data in current Win386_KM_SIS ?
  613.         jne idata
  614. endlst: cmp [edi.KM_SIS.SIS_Next_Ptr],0             ;last SIS ?
  615.         je no2f
  616.         add edi,sizeof KM_SIS                       ;next Win386_KM_SIS
  617.         jmp nextsis
  618. idata:  mov esi,ebx                                 ;Seg:Off of inst data list
  619.         movzx eax,si                                ;offset of inst data list
  620.         and esi,0ffff0000h
  621.         shr esi,0ch                                 ;linear address of segment
  622.         add esi,eax                                 ;linadr of inst data list        
  623. nextiis:int 3
  624.         mov ebx,[esi.IIS_Ptr]                       ;Seg:Off of instance item
  625.         cmp ebx,0                                   ;no more items ?
  626.         je endlst
  627.         movzx eax,bx                                ;offset of Instance Item
  628.         and ebx,0ffff0000h
  629.         shr ebx,0ch                                 ;linear address of segment
  630.         add ebx,eax                                 ;linadr of instance item     
  631.         mov eax,cur_inst                            ;current Instance struc
  632.         ;current instance item from int_2f_inst_table ?
  633.         cmp ebx,[eax.KM_InstData.InstLinAddr]
  634.         je inst2f
  635.         add esi,sizeof Instance_Item_Struc          ;next Instance_Item_Struc
  636.         jmp nextiis
  637. ;InstDataStruc of DOS-TSR via int 2f
  638. inst2f: add esp,4                                   ;forget name from VxDQuery
  639.         ;int 3
  640.         mov esi,offset32 int_2f_string
  641.         mov ebx,edi                                 ;current Win386_KM_SIS
  642. inst2f1:mov edi,[count]
  643.         imul edi,sizeof Inst_Hook_Struc
  644.         add edi,string_buf
  645.         push edi                                    ;current Inst_Hook_Struc
  646.         mov ecx,string_len/4
  647.         rep movsd               ;copy "Create_Int_2F_Inst_Table" string
  648.         sub edi,9
  649.         mov esi,ebx                                 ;points to Win386_KM_SIS
  650.         add esi,offset KM_SIS.Tsr_Name              ;points to name of DOS TSR
  651.         cmp byte ptr [esi],'S'
  652.         jne inst1
  653.         cmp byte ptr[esi+1],'D'
  654.         jne inst1
  655.         mov esi,offset32 dos_sys_string  
  656.         movsd                                       ;copy "CONFIG DRV" string
  657.         movsd
  658.         jmp endname
  659. inst1:  movsd
  660.         movsd                                       ;copy name of DOS TSR
  661.         sub edi,8
  662.         mov ecx,9
  663.         mov al,0
  664.         repne scasb
  665.         jne endname
  666.         mov al,20h
  667.         dec edi
  668.         rep stosb                                   ;fill up with spaces
  669.         jmp endname
  670. ;InstDataStruc of a LOCALTSR via system.ini entry
  671. locadd: ;int 3                  ;uncomment this for debug
  672.         mov esi,offset32 localtsr_string
  673.         mov edi,[count]
  674.         imul edi,sizeof Inst_Hook_Struc
  675.         add edi,string_buf
  676.         push edi                                    ;current Inst_Hook_Struc
  677.         mov ecx,string_len/4
  678.         rep movsd               ;copy "VMM: Instance_LOCALTSRS " string
  679.         sub edi,9
  680.         mov esi,cur_inst                            ;InstDataStruc
  681.         mov esi,[esi.KM_InstData.InstLinAddr]       ;esi = MCB of LOCALTSR      
  682.         add esi,offset MCB_Name                     ;points to name of DOS TSR
  683.         movsd
  684.         movsd                                       ;copy name of DOS TSR
  685.         sub edi,8
  686.         mov ecx,9
  687.         mov al,0
  688.         repne scasb
  689.         jne endname
  690.         mov al,20h
  691.         dec edi
  692.         rep stosb                                   ;fill up with spaces
  693.         jmp endname
  694. no2f:   pop edi
  695.         mov esi,edi                                 ;pointer to VxDName
  696.         mov edi,count
  697.         imul edi,sizeof Inst_Hook_Struc
  698.         add edi,string_buf
  699.         push edi
  700.         mov ecx,string_len/4
  701.         rep movsd                                   ;save VxDName in string_buf 
  702. endname:pop edi                                     ;current Inst_Hook_Struc
  703.         mov eax,cur_inst                            ;Instance struc
  704.         mov edx,[eax.KM_InstData.InstLinAddr]
  705.         mov [edi.Inst_Hook_Struc.Inst_Lin_Adr],edx
  706.         mov edx,[eax.KM_InstData.InstSize]
  707.         mov [edi.Inst_Hook_Struc.Inst_Size],edx
  708.         inc count
  709.         pop ecx
  710.         dec ecx
  711.         jnz instlp                  
  712. instcpy:Client_Ptr_Flat edi,DS,DX           ;address of callers ptr to buffer
  713.         mov edi,[edi]
  714.         call v862lin
  715.         mov esi,string_buf
  716.         mov ecx,Inst_Data_Count                     ;# of inst strucs
  717.         imul ecx, sizeof Inst_Hook_Struc
  718.         shr ecx,2
  719.         rep movsd                           ;copy data into callers V86 buffer
  720.         mov count,0
  721.         ret
  722. insterr:pop ecx
  723. inster1:or [ebp.Client_FLAGS],1                     ;set carry, error
  724.         ret
  725.  
  726. ;INPUT  edi = Seg:Offs V86
  727. ;OUTPUT edi = linadr
  728. v862lin:push edx
  729.         movzx edx,di
  730.         shr edi,10h
  731.         shl edi,4
  732.         add edi,edx
  733.         pop edx
  734.         ret
  735.  
  736.         
  737. EndProc   ListInst_V86_API
  738.  
  739. VxD_CODE_ENDS
  740.  
  741.     END
  742.