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.

558 lines
15 KiB

  1. page ,132
  2. if 0
  3. /*++
  4. Copyright (c) 1991 Microsoft Corporation
  5. Module Name:
  6. redir.asm
  7. Abstract:
  8. This module contains the stub redir TSR code for NT VDM net support
  9. Author:
  10. Richard L Firth (rfirth) 05-Sep-1991
  11. Environment:
  12. Dos mode only
  13. Revision History:
  14. 05-Sep-1991 rfirth
  15. Created
  16. --*/
  17. endif
  18. ;
  19. ; DOS include files
  20. ;
  21. .xlist
  22. .xcref
  23. include dossym.inc ; includes MS-DOS version etc
  24. include pdb.inc ; PSP defines
  25. include syscall.inc ; AssignOper
  26. include enumapis.inc ; Local_API_GetRedirVersion, etc.
  27. include segorder.inc ; load order of 'redir' segments
  28. include rdrsvc.inc ; BOP and SVC macros/dispatch codes
  29. include rdrmisc.inc ; miscellaneous definitions
  30. include debugmac.inc ; debug display macros
  31. include asmmacro.inc ; jumps which may be short or near
  32. include int5c.inc ; Int to be used for pseudo network adapter
  33. .cref
  34. .list
  35. ;
  36. ; Misc. local manifests
  37. ;
  38. LOAD_STACK_SIZE equ 256
  39. ;
  40. ; Define externals in resident code and data
  41. ;
  42. ResidentCodeStart
  43. extrn OldMultHandler:dword
  44. extrn MultHandler:near
  45. extrn Old2aHandler:dword
  46. extrn Int2aHandler:near
  47. extrn Old5cHandler:dword
  48. extrn Int5cHandler:near
  49. extrn OldNetworkHandler:dword
  50. extrn IntNetworkHandler:near
  51. extrn dwPostRoutineAddress:dword
  52. if DEBUG
  53. extrn Old21Handler:dword
  54. extrn CheckInt21Function5e:near
  55. endif
  56. ResidentCodeEnd
  57. ResidentDataStart
  58. extrn LanRootLength:word
  59. extrn LanRoot:byte
  60. ResidentDataEnd
  61. InitStack segment stack para 'stack'
  62. dw LOAD_STACK_SIZE dup (?)
  63. top_of_stack equ $
  64. InitStack ends
  65. InitDataStart
  66. ;
  67. ; pull in messages. Kept in a separate file to make internationalisation easier
  68. ;
  69. include redirmsg.inc
  70. public ComputerName
  71. ComputerName db LM20_CNLEN + 1 dup (?)
  72. DefaultLanRoot db "C:\LANMAN.DOS",0
  73. DEFAULT_LANROOT_LENGTH equ $-DefaultLanRoot
  74. InitDataEnd
  75. InitCodeStart
  76. assume cs:InitCode
  77. assume ds:nothing
  78. assume es:nothing
  79. assume ss:nothing
  80. public start
  81. start proc near
  82. ;
  83. ; when we start up we could be on any old PC - even an original, so don't
  84. ; assume anything other than a model-T processor
  85. ;
  86. .8086
  87. ;
  88. ; let's do the decent thing and create a stack. This way we're covered
  89. ;
  90. mov dx,InitStack
  91. mov ss,dx ; disables ints until after next ins.
  92. mov sp,offset top_of_stack
  93. assume ss:InitStack
  94. ;
  95. ; may as well set the data segment while we're at it - all paths set it sooner
  96. ; or later. NOTE: es will point to the PSP until we change it!
  97. ;
  98. mov dx,InitData
  99. mov ds,dx
  100. assume ds:InitData
  101. ;
  102. ; first off, get the DOS version. If we're not running on NT (VDM) then this
  103. ; TSR's not going to do much, so exit. Exit using various methods, depending
  104. ; on the DOS version (don't you hate compatibility?)
  105. ;
  106. mov ah,30h
  107. int 21h
  108. jc ancient_version ; version not even supported, forcrissake
  109. ;
  110. ; version is 2.0 or higher. Check it out. al = major#, ah = minor#
  111. ;
  112. cmp al,major_version
  113. jne invalid_version
  114. ;
  115. ; what do you know? We're actually running on NT (unless some evil programmer
  116. ; has pinched int 21h/30h and done something execrable with it!). We'd better
  117. ; do something...
  118. ; Also: at this point we know we're on at a 386, so lets enable some 286
  119. ; instructions to be generated. Eh? you justifiably ponder - is this a typo?
  120. ; Unfortunately, SoftPc only emulates the lowly 286 processor. We need to wait
  121. ; until Microsoft has paid Insignia lots of money before they can afford some
  122. ; new brains who will then dutifully provide us with full 386+ emulation (maybe)
  123. ;
  124. .286c
  125. mov ax,(AssignOper SHL 8) + Local_API_RedirGetVersion
  126. int 21h ; is redir already loaded?
  127. jnc already_here ; yep
  128. ;
  129. ; OK, the redir is not already loaded - we're in business. Get and set the
  130. ; various interrupt vectors, Calculate the amount of space we want to keep,
  131. ; free up any unused space (like the environment segment), display a message
  132. ; in the DEBUG version, then terminate and stay resident. Remember: at this
  133. ; point we expect ES to point at the PSP
  134. ;
  135. @@: call InstallInterruptHandlers
  136. ; OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
  137. ;;
  138. ;; Initialize VDM DOS memory window address (in virtual DLC driver).
  139. ;; The memory window is used for the async Netbios, DLC and
  140. ;; named pipe post routines.
  141. ;;
  142. ;
  143. ; push es ; PSP
  144. ; mov bx,ResidentCode
  145. ; mov es,bx
  146. ;
  147. ; assume es:ResidentCode
  148. ;
  149. ;;
  150. ;; now that VDMREDIR support is a DLL, we can fail initialization on the 32-bit
  151. ;; side if the DLL cannot be loaded, or the entry points not found. In this case
  152. ;; we will fail to load redir.exe, rather than constantly returning
  153. ;; ERROR_NOT_SUPPORTED every time we make a redir BOP
  154. ;;
  155. ;
  156. ; mov bx,offset dwPostRoutineAddress
  157. ; SVC SVC_VDM_WINDOW_INIT
  158. ; pop es ; es back to PSP
  159. ; jmpc initialization_error
  160. ; OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
  161. assume es:nothing
  162. ;
  163. ; free the environment segment
  164. ;
  165. mov es,es:[PDB_environ]
  166. mov ah,49h
  167. int 21h ; free environment segment
  168. if DEBUG
  169. ifdef PROLIX
  170. DbgPrintString <"Redir successfully loaded",13,10>
  171. endif
  172. endif
  173. ; OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
  174. ;;
  175. ;; now perform the BOP which will let the 32-bit redir support know that the
  176. ;; DOS redirector TSR is successfully loaded. This must be the last action -
  177. ;; we cannot fail installation after this point (unless we call the BOP to
  178. ;; uninitialize 32-bit VDM redir support
  179. ;;
  180. ;
  181. ; mov bx,seg ComputerName
  182. ; mov es,bx
  183. ;
  184. ; assume es:seg ComputerName
  185. ;
  186. ; mov bx,offset ComputerName ; initialization returns the computer name
  187. ; mov cx,size ComputerName ; which will be gettable using int 21/ah=5e
  188. ; SVC SVC_RDRINITIALIZE
  189. ; jmpc initialization_error ; 32-bit DLL failed (?)
  190. ; OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
  191. ; DbgBreakPoint ; check computer name returned
  192. ;
  193. ; set the computer name returned from the 32-bit side
  194. ;
  195. if DEBUG
  196. ifdef PROLIX
  197. DbgPrintString <"Set computer name here",13,10>
  198. endif
  199. endif
  200. if 0
  201. mov ax,5e01h ; set machine name
  202. xor cx,cx ; cx is 'user num'
  203. int 21h
  204. endif
  205. ;
  206. ; do initialisation things - set the lanroot to the default if not otherwise
  207. ; specified
  208. ;
  209. mov ax,InitData
  210. mov ds,ax
  211. assume ds:InitData
  212. mov ax,ResidentData
  213. mov es,ax
  214. assume es:ResidentData
  215. mov LanRootLength,DEFAULT_LANROOT_LENGTH
  216. mov si,offset DefaultLanRoot
  217. mov di,offset LanRoot
  218. cld
  219. mov cx,DEFAULT_LANROOT_LENGTH/2
  220. rep movsw
  221. if (DEFAULT_LANROOT_LENGTH and 1)
  222. movsb
  223. endif
  224. ;
  225. ; finally terminate and stay resident
  226. ;
  227. mov dx,ResidentEnd
  228. sub dx,ResidentStart ; number of paragraphs in resident code
  229. add dx,10h ; additional for PSP (PDB)
  230. ; DbgBreakPoint
  231. if DEBUG
  232. ifdef PROLIX
  233. DbgPrintString "Staying resident with "
  234. DbgPrintHexWord dx
  235. DbgPrintString " paragraphs. Load seg is ",NOBANNER
  236. mov ah,62h
  237. int 21h
  238. DbgPrintHexWord bx
  239. DbgPrintString " current seg is ",NOBANNER
  240. DbgPrintHexWord cs
  241. DbgCrLf
  242. endif
  243. endif
  244. mov ax,3100h
  245. int 21h ; terminate and stay resident
  246. ;
  247. ; here if the MS-DOS version check (Ah=30h) call is not supported
  248. ;
  249. ancient_version:
  250. mov dx,InitData
  251. mov ds,dx
  252. assume ds:InitData
  253. mov dx,offset bad_ver_msg
  254. mov ah,9 ; cp/m-style write to output
  255. int 21h
  256. ;
  257. ; safe exit: what we really want to do here is INT 20H, but when you do this,
  258. ; CS must be the segment of the PSP of this program. Knowing that CD 20 is
  259. ; embedded at the start of the PSP, the most foolproof way of doing this is
  260. ; to jump (using far return) to the start of the PSP
  261. ;
  262. push es
  263. xor ax,ax
  264. push ax
  265. retf ; terminate
  266. ;
  267. ; we are running on a version of DOS >= 2.00, but its not NT, so we still can't
  268. ; help. Display the familiar message and exit, but using a less programmer-
  269. ; hostile mechanism
  270. ;
  271. invalid_version:
  272. mov dx,offset bad_ver_msg
  273. mov cx,BAD_VER_MSG_LEN
  274. jmp short print_error_message_and_exit
  275. ; OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
  276. ;;
  277. ;; if we cannot initialize 32-bit support (because we can't find/load the DLL)
  278. ;; then put back the hooked interrupt vectors as they were when this TSR started,
  279. ;; display a message and fail to load the redir TSR
  280. ;;
  281. ;
  282. ;initialization_error:
  283. ; call RestoreInterruptHandlers
  284. ; mov dx,offset cannot_load_msg
  285. ; mov cx,CANNOT_LOAD_MSG_LEN
  286. ; jmps print_error_message_and_exit
  287. ; OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
  288. ;
  289. ; The DOS version's OK, but this TSR is already loaded
  290. ;
  291. already_here:
  292. mov dx,offset already_loaded_msg
  293. mov cx,ALREADY_LOADED_MSG_LEN
  294. print_error_message_and_exit:
  295. mov bx,1 ; bx = stdout handle
  296. mov ah,40h ; write to handle
  297. int 21h ; write (cx) bytes @ (ds:dx) to stdout
  298. mov ax,4c01h ; terminate program
  299. int 21h ; au revoir, cruel environment
  300. start endp
  301. ;*******************************************************************************
  302. ;*
  303. ;* InstallInterruptHandlers
  304. ;*
  305. ;* Sets the interrupt handlers for all the ints we use - 2a, 2f, 5c
  306. ;* and NETWORK_INTERRUPT (0b)
  307. ;*
  308. ;* ENTRY es = PSP segment
  309. ;* ds =
  310. ;*
  311. ;* EXIT OldMultHandler contains the original interrupt 2f vector
  312. ;* Old2aHandler contains the original interrupt 2a vector
  313. ;* Old5cHandler contains the original interrupt 5c vector
  314. ;* OldNetworkHandler contains the original interrupt 0e vector
  315. ;*
  316. ;* RETURNS nothing
  317. ;*
  318. ;* ASSUMES
  319. ;*
  320. ;*******************************************************************************
  321. InstallInterruptHandlers proc
  322. push es ; PSP segment - destroyed by INT 21/35h
  323. push ds
  324. ;
  325. ; note: if we use ResidentCode here, explicitly, instead of seg OldMultHandler,
  326. ; then we can leave out an extraneous load of ds for the ISR address
  327. ;
  328. mov dx,ResidentCode
  329. mov ds,dx
  330. assume ds:ResidentCode
  331. mov ax,352fh ; get current INT 2Fh vector
  332. int 21h
  333. mov word ptr OldMultHandler,bx
  334. mov word ptr OldMultHandler+2,es
  335. mov dx,offset ResidentCode:MultHandler
  336. mov ax,252fh
  337. int 21h ; set INT 2Fh vector to our handler
  338. ;
  339. ; we have to pinch int 2a too - certain parts of the net libraries perform a
  340. ; net check using a presence check on 2ah
  341. ;
  342. mov ax,352ah
  343. int 21h
  344. mov word ptr Old2aHandler,bx
  345. mov word ptr Old2aHandler+2,es
  346. mov dx,offset ResidentCode:Int2aHandler
  347. mov ax,252ah
  348. int 21h
  349. ;
  350. ; we have to pinch int 5c for Netbios and DLC
  351. ;
  352. mov ax,355ch
  353. int 21h
  354. mov word ptr Old5cHandler,bx
  355. mov word ptr Old5cHandler+2,es
  356. mov dx,offset ResidentCode:Int5cHandler
  357. mov ax,255ch
  358. int 21h
  359. ;
  360. ; we have to pinch int NETWORK_INTERRUPT for Netbios and DLC
  361. ;
  362. mov ax,3500h OR NETWORK_VECTOR
  363. int 21h
  364. mov word ptr OldNetworkHandler,bx
  365. mov word ptr OldNetworkHandler+2,es
  366. mov dx,offset ResidentCode:IntNetworkHandler
  367. mov ax,2500h OR NETWORK_VECTOR
  368. int 21h
  369. ;if DEBUG
  370. ;;
  371. ;; get the int 21 handler too so we can find out if anyone's calling the
  372. ;; (unsupported) int 21/ah=5e
  373. ;;
  374. ;
  375. ; mov ax,3521h
  376. ; int 21h
  377. ; mov word ptr Old21Handler,bx
  378. ; mov word ptr Old21Handler+2,es
  379. ; mov dx,offset ResidentCode:CheckInt21Function5e
  380. ; mov ax,2521h
  381. ; int 21h
  382. ;endif
  383. pop ds ; restore segment registers
  384. pop es
  385. ret
  386. InstallInterruptHandlers endp
  387. ;*******************************************************************************
  388. ;*
  389. ;* RestoreInterruptHandlers
  390. ;*
  391. ;* Resets the interrupt handlers for all the ints we use - 2a, 2f, 5c
  392. ;* and NETWORK_INTERRUPT (0b). Called in the event we cannot complete
  393. ;* installation
  394. ;*
  395. ;* ENTRY OldMultHandler, Old2aHandler, Old5cHandler, OldNetworkHandler
  396. ;* contain the interrupt vectors from before redir.exe was loaded
  397. ;*
  398. ;* EXIT Original interrupt vectors are restored
  399. ;*
  400. ;* RETURNS nothing
  401. ;*
  402. ;* ASSUMES
  403. ;*
  404. ;*******************************************************************************
  405. RestoreInterruptHandlers proc
  406. push ds
  407. assume ds:nothing
  408. push es
  409. mov dx,ResidentCode
  410. mov es,dx
  411. assume es:ResidentCode
  412. lds dx,OldMultHandler
  413. mov ax,252fh
  414. int 21h ; set INT 2Fh vector to previous handler
  415. lds dx,Old2aHandler
  416. mov ax,252ah
  417. int 21h
  418. lds dx,Old5cHandler
  419. mov ax,255ch
  420. int 21h
  421. lds dx,OldNetworkHandler
  422. mov ax,2500h OR NETWORK_VECTOR
  423. int 21h
  424. ;if DEBUG
  425. ; lds dx,Old21Handler
  426. ; mov ax,2521h
  427. ; int 21h
  428. ;endif
  429. pop es
  430. pop ds
  431. ret
  432. RestoreInterruptHandlers endp
  433. InitCodeEnd
  434. end start