Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

418 lines
11 KiB

  1. page ,132
  2. if 0
  3. /*++
  4. Copyright (c) 1991 Microsoft Corporation
  5. Module Name:
  6. int5c.asm
  7. Abstract:
  8. This module contains the int 5c handler for the NT VDM redir TSR
  9. Author:
  10. Colin Watson (colinw) 5-Dec-1991
  11. Environment:
  12. Dos mode only
  13. Revision History:
  14. 05-Dec-1991 colinw
  15. Created
  16. --*/
  17. endif
  18. .xlist
  19. .xcref
  20. include debugmac.inc ; debug display macros
  21. include segorder.inc ; load order of 'redir' segments
  22. include rdrsvc.inc ; BOP and SVC macros/dispatch codes
  23. include int5c.inc ; Int to be used for pseudo network adapter
  24. include asmmacro.inc ; jumps which may be short or near
  25. include vrdlctab.inc ; VDM_REDIR_DOS_WINDOW
  26. .cref
  27. .list
  28. .286 ; all code in this module 286 compatible
  29. ;
  30. ; Misc. local manifests
  31. ;
  32. NETBIOS_STACK_SIZE equ 256
  33. ResidentDataStart
  34. NetbiosStack db NETBIOS_STACK_SIZE dup( 0 )
  35. NetbiosStackTop label word
  36. ResidentDataEnd
  37. pic1 equ 20h
  38. pic2 equ 0a0h
  39. ;
  40. ; The CCB1 definition
  41. ;
  42. CCB struc
  43. CCB_ADAPTER db ?
  44. CCB_COMMAND db ?
  45. CCB_RETCODE db ?
  46. CCB_WORK db ?
  47. CCB_POINTER dd ?
  48. CCB_CMD_CMPL dd ?
  49. CCB_PARM_TAB dd ?
  50. CCB ends
  51. ResidentCodeStart
  52. assume cs:ResidentCode
  53. assume ds:nothing
  54. assume es:nothing
  55. assume ss:nothing
  56. public Old5cHandler
  57. Old5cHandler dd ?
  58. public OldNetworkHandler
  59. OldNetworkHandler dd ?
  60. ; *** VDM REDIR INFO WINDOW
  61. ; *
  62. ; * ABSTRACT:
  63. ; * Used to share data structures between VDM device driver
  64. ; * in 32-bit mode and DOS-VDM. This data structure must be
  65. ; * excactly same as VDM_REDIR_DOS_WINDOW struct in vdmredir.h.
  66. ; *
  67. ; ***
  68. public dwPostRoutineAddress
  69. dwPostRoutineAddress: ; async post routine address
  70. VDM_REDIR_DOS_WINDOW <>
  71. ; *** Int5cHandler
  72. ; *
  73. ; * Handles int 5c requests, in which we redirect work to netapi.dll
  74. ; *
  75. ; * ENTRY es:bx = Address of NCB or DLC CCB, if the
  76. ; * first byte less than 10H.
  77. ; *
  78. ; * EXIT al = NCB_RETCODE for NCB's
  79. ; *
  80. ; * RETURNS nothing
  81. ; *
  82. ; * USES nothing
  83. ; *
  84. ; * ASSUMES nothing
  85. ; *
  86. ; ***
  87. public Int5cHandler
  88. Int5cHandler proc near
  89. ;
  90. ; Perform a BOP into 32 bit mode to process the request.
  91. ; It's DLC if the first byte in ES:BX is less than 10h.
  92. ;
  93. sti ; enable hw interrupts
  94. cmp byte ptr es:[bx], 10H
  95. jb call_dlc_5c
  96. ;
  97. ; deferred loading: if this call is from (presumably) DOSX checking to see if
  98. ; the 5C support is loaded, return the expected error without calling Netbios
  99. ; for real: this allows us to continue installation without having to load
  100. ; VDMREDIR.DLL until it is really required
  101. ;
  102. cmp byte ptr es:[bx],7fh ; NETBIOS presence check
  103. je @f
  104. cmp byte ptr es:[bx],0ffh ; async NETBIOS presence check
  105. je @f
  106. SVC SVC_NETBIOS5C
  107. iret
  108. @@: mov al,3 ; INVALID COMMAND error
  109. mov es:[bx].ncb_retcode,al ; returned in NCB_RETCODE && al
  110. mov es:[bx].ncb_cmd_cplt,al ; and NCB_CMD_CPLT
  111. iret
  112. ;
  113. ; call is for DLC. DLC does not return anything in registers. Command completion
  114. ; is either via an 'appendage' (call-back to you and me) or by the app polling
  115. ; the CCB_RETCODE field of the CCB in ES:BX for a change from 0xFF
  116. ;
  117. call_dlc_5c:
  118. ;
  119. ; BOP into 32-bit DOS DLC emulator. This will return in AL the status of the
  120. ; CCB request: 0xFF if the command will complete asynchronously, else a
  121. ; synchrnous completion code
  122. ;
  123. SVC SVC_DLC_5C
  124. ;
  125. ; if the CCB completed (synchronously) and there is an 'appendage' (who do IBM
  126. ; have writing this stuff?) then we must call it. We check the return code in
  127. ; AL since the return in the CCB may be the final code (ie already changed by
  128. ; the asynchronous completion thread in 32-bit DOS DLC emulator)
  129. ;
  130. cmp al,0ffh ; is the command active?
  131. je @f ; yes - return to the app
  132. ;
  133. ; the 32-bit DOS DLC emulator returned a synchronous completion code. We
  134. ; complete the CCB by calling the 'appendage'. The appendage is pointed at
  135. ; by the CCB_CMD_CMPL field in the CCB. If this field is 0:0 then the app
  136. ; has not provided an 'appendage' and will periodically look at the CCB_RETCODE
  137. ; field until the 32-bit emulator's asynchronous completion thread writes
  138. ; something there other than 0xFF
  139. ;
  140. pusha ; save caller's registers
  141. mov cx,word ptr es:[bx].CCB_CMD_CMPL
  142. or cx,word ptr es:[bx].CCB_CMD_CMPL[2]
  143. jz no_go
  144. ;
  145. ; we have an appendage. The manual says: cx=adapter #, es:bx=CCB, ss:sp=stack (!)
  146. ; cs=appendage cs (!!). Simulate an interrupt (ints off - that's what it says)
  147. ;
  148. mov cl,byte ptr es:[bx].CCB_ADAPTER
  149. xor ch,ch
  150. xor ah,ah
  151. pushf ; simulate INT
  152. cli ; all ints are off
  153. call dword ptr es:[bx].CCB_CMD_CMPL
  154. ;
  155. ; appendage irets here, we restore the caller's registers and wend our merry
  156. ; walker
  157. ;
  158. no_go: popa ; restore caller's context
  159. @@: iret
  160. Int5cHandler endp
  161. ; *** IntNetworkHandler
  162. ; *
  163. ; * Handles int Network requests, in which we redirect work to netapi.dll
  164. ; *
  165. ; * NOTE: !!! This routine is NOT re-entrant: it sets up a new stack !!!
  166. ; *
  167. ; * ENTRY nothing
  168. ; *
  169. ; * EXIT nothing
  170. ; *
  171. ; * RETURNS nothing
  172. ; *
  173. ; * USES nothing
  174. ; *
  175. ; * ASSUMES nothing
  176. ; *
  177. ; ***
  178. even
  179. InterruptedStack dd ?
  180. if DEBUG
  181. ReEntered db 0
  182. endif
  183. public IntNetworkHandler
  184. IntNetworkHandler proc near
  185. assume cs:ResidentCode
  186. assume ds:nothing
  187. assume es:nothing
  188. assume ss:nothing
  189. if DEBUG
  190. cmp ReEntered,0
  191. jne __re_entry
  192. inc ReEntered
  193. jmps @f
  194. __re_entry:
  195. DbgPrintString <"ERROR: IntNetworkHandler re-entered",13,10>
  196. push ds
  197. push es
  198. push ax
  199. sub ax,ax
  200. dec ax
  201. mov ds,ax ; ds = es = -1 signals re-entrancy
  202. mov es,ax
  203. DbgUnsupported
  204. DbgBreakPoint
  205. pop ax
  206. pop es
  207. pop ds
  208. @@:
  209. endif
  210. ;
  211. ; Switch stacks and call the post routine
  212. ;
  213. push ax ; interrupted ax on interrupted stack
  214. ; push dx ; dx
  215. mov word ptr InterruptedStack,sp
  216. mov word ptr InterruptedStack[2],ss
  217. mov ax,seg NetbiosStack
  218. mov ss,ax
  219. mov sp,offset NetbiosStackTop
  220. ;
  221. ; perform a BOP into 32 bit mode to process the request.
  222. ;
  223. ; 32 bit code returns:
  224. ;
  225. ; ZF = 0, CF = 0 nothing to do (2 jumps)
  226. ; ZF = 0, CF = 1 async named pipe post processing (1 jump)
  227. ; ZF = 1, CF = 0 DLC post processing (1 jump)
  228. ; ZF = 1, CF = 1 NCB post processing (0 jumps)
  229. ;
  230. ; CAVEAT: if we extend this interface to have >3 options + do nothing, then
  231. ; we need to change to setting a value in a (unused) register (bp?)
  232. ;
  233. pusha ; rest of interrupted registers on our stack
  234. push ds
  235. push es
  236. SVC SVC_NETBIOS5CINTERRUPT
  237. jmpne nothing_or_nmpipe
  238. jmpnc dlc_processing
  239. ;
  240. ; Call post routine, it returns with IRET => push flags to stack.
  241. ; We must not change any registers between BOP and post routine!
  242. ; Note: NCB post processing is currently on fastest path. May need
  243. ; to change to DLC. Check it out in performance phase
  244. ;
  245. pushf ; fake interrupt call
  246. call es:[bx].ncb_post
  247. jmps exit_IntNetworkHandler
  248. nothing_or_nmpipe:
  249. jmpnc exit_IntNetworkHandler
  250. ;
  251. ; default is async named-pipe processing. The BOP handler returns us the
  252. ; following:
  253. ; AL = 0 => ordinary (not AsyncNmPipe2) call
  254. ; AL != 0 => call is DosReadAsyncNmPipe2 or DosWriteAsyncNmPipe2
  255. ; CX:BX = address of ANR
  256. ; DS:SI = address of data buffer
  257. ; ES:DI = 'semaphore' handle for AsyncNmPipe2 call
  258. ;
  259. ; if the async name pipe function call didn't specify a semaphore, then don't
  260. ; push anything to stack since the ANR itself knows how many parameters will
  261. ; be on the stack. We expect it to ret n
  262. ;
  263. DbgPrintString <"AsyncNmPipe callback!", 13, 10>
  264. or al,al
  265. jz @f
  266. push es ; semaphore handle for type2 calls
  267. push di
  268. @@: push ds ; buffer address
  269. push si
  270. ;
  271. ; the ANR is a pascal function which will clean the stack before returning. We
  272. ; push the ANR address and fake a far call. The ANR will return to
  273. ; exit_IntNetworkHandler. We futz the stack anyway, so we may as well avoid
  274. ; an extra jump
  275. ;
  276. push cs ; store far return addr on the stack
  277. push offset exit_IntNetworkHandler
  278. push cx ; fake far call to ANR
  279. push bx
  280. retf
  281. ;
  282. ; DLC post processing: 32-bit code has set relevant registers and put post
  283. ; routine address in dwPostRoutineAddress. Must make sure that post address
  284. ; (ie 'appendage' address) is not 0:0
  285. ;
  286. dlc_processing:
  287. cmp word ptr dwPostRoutineAddress,0
  288. jne @f
  289. cmp word ptr dwPostRoutineAddress[2],0
  290. je exit_IntNetworkHandler ; huh?
  291. ;
  292. ; there is a non-zero post routine address set in the BOP. Simulate an
  293. ; interrupt into the post routine (appendage)
  294. ;
  295. @@: pushf ; fake interrupt call
  296. ; cli ; manual says ints off
  297. call dword ptr dwPostRoutineAddress
  298. ;
  299. ; restore the interrupted registers and stack
  300. ;
  301. exit_IntNetworkHandler:
  302. pop es
  303. pop ds
  304. popa
  305. mov ss,word ptr InterruptedStack[2]
  306. mov sp,word ptr InterruptedStack
  307. ; pop dx ; interrupted dx
  308. ;;
  309. ;; re-enable the 8259s
  310. ;;
  311. ;
  312. ; mov al,20h
  313. ;
  314. ;;
  315. ;; Edge triggered assuming interrupt on slave pic as per the AT
  316. ;;
  317. ;
  318. ; out pic2,al ; EOI pic 2
  319. ; out pic1,al ; EOI pic 1
  320. ;
  321. ;;
  322. ;; Level triggered assuming interrupt on slave pic
  323. ;;
  324. ;; out pic1,al ; EOI pic 1
  325. ;; out pic2,al ; EOI pic 2
  326. ;
  327. ;;
  328. ;; assuming interrupt on master pic
  329. ;; out pic1,al ; EOI pic 1
  330. ;;
  331. pop ax ; interrupted ax
  332. if DEBUG
  333. dec ReEntered
  334. endif
  335. SVC SVC_RDRINTACK2
  336. iret ; back to interrupted code
  337. ; jmp dword ptr OldNetworkHandler
  338. IntNetworkHandler endp
  339. ResidentCodeEnd
  340. end