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.

1249 lines
29 KiB

  1. ;/*
  2. ; * Microsoft Confidential
  3. ; * Copyright (C) Microsoft Corporation 1991
  4. ; * All Rights Reserved.
  5. ; */
  6. ;===========================================================================
  7. ;
  8. ; FILE: .ASM
  9. ;
  10. ;===========================================================================
  11. ;===========================================================================
  12. ;Declaration of include files
  13. ;===========================================================================
  14. debug equ 0
  15. .xlist
  16. INCLUDE DOSEQUS.INC
  17. INCLUDE DOSMAC.INC
  18. INCLUDE SYSCALL.INC
  19. INCLUDE ERROR.INC
  20. INCLUDE DIRENT.INC
  21. INCLUDE BPB.INC
  22. INCLUDE FOREQU.INC
  23. INCLUDE FORMACRO.INC
  24. .list
  25. ;
  26. ;---------------------------------------------------------------------------
  27. ;
  28. ; M029 : Remove the assumption that COMSPEC= has an absolute path name.
  29. ; and build the file name (COMMAND.COM) in a different buffer
  30. ; other than the buffer in which COMSPEC was stored.
  31. ;
  32. ;---------------------------------------------------------------------------
  33. ;
  34. ;===========================================================================
  35. ; Data segment
  36. ;===========================================================================
  37. DATA SEGMENT PUBLIC PARA 'DATA'
  38. ;===========================================================================
  39. ; Declarations for all publics in other modules used by this module
  40. ;===========================================================================
  41. ;Bytes
  42. EXTRN DriveLetter :BYTE
  43. EXTRN SystemDriveLetter :BYTE
  44. EXTRN Extended_Error_Msg :BYTE
  45. EXTRN BiosFile :BYTE
  46. EXTRN AltBiosFile :BYTE
  47. EXTRN AltBiosLen :ABS
  48. EXTRN MsdosFile :BYTE
  49. EXTRN MsdosRemark :BYTE
  50. EXTRN MsdosRemarkLen :ABS
  51. IFDEF DBLSPACE_HOOKS
  52. EXTRN fDblSpace :BYTE
  53. ENDIF
  54. ;Words
  55. EXTRN mStart :WORD
  56. EXTRN mSize :WORD
  57. EXTRN Environ_Segment :WORD
  58. EXTRN PSP_Segment :WORD
  59. ;Pointers
  60. ;Structures
  61. EXTRN Bios :BYTE
  62. EXTRN dos :BYTE
  63. EXTRN command :BYTE
  64. IFDEF DBLSPACE_HOOKS
  65. EXTRN DblSpaceBin :BYTE
  66. ENDIF
  67. BiosAttributes equ attr_hidden + attr_system + attr_read_only
  68. DosAttributes equ attr_hidden + attr_system + attr_read_only
  69. IFDEF DBLSPACE_HOOKS
  70. DblSpaceAttributes equ attr_hidden + attr_system + attr_read_only
  71. ENDIF
  72. CommandAttributes equ 0
  73. CommandFile db "X:\COMMAND.COM",0
  74. db (128 - 15) DUP (0) ; M012
  75. Comspec_ID db "COMSPEC=",00 ; Comspec target
  76. ; DOS status bits in FileStat are unused.
  77. ; Starting with Chicago, IO.SYS and MSDOS.SYS have been combined.
  78. ; For our purposes, the single file will be referred to as BIOS.
  79. FileStat db ? ; In memory Status of files
  80. ; XXXXXX00B BIOS not in
  81. ; XXXXXX01B BIOS partly in
  82. ; XXXXXX10B BIOS all in
  83. ; XXXX00XXB DOS not in
  84. ; XXXX01XXB DOS partly in
  85. ; XXXX10XXB DOS all in
  86. ; XX00XXXXB COMMAND not in
  87. ; XX01XXXXB COMMAND partly in
  88. ; XX10XXXXB COMMAND all in
  89. Command_Com DB "X:\COMMAND.COM",0 ; M029
  90. IFDEF DBLSPACE_HOOKS
  91. DblSpaceFile db "X:\DRVSPACE.BIN",0 ;full path to source copy
  92. db 64 DUP (0) ; of DRVSPACE.bin
  93. DblSpaceTargetName db "X:\" ;target DRVSPACE.bin name
  94. DblSpaceBase db "DRVSPACE.BIN",0 ;base name used to srch PATH
  95. ENDIF
  96. DOS_BUFFER db 45 dup (?) ; Find First/Next buffer
  97. TempHandle dw ?
  98. IOCNT dd ?
  99. DATA ENDS
  100. ;===========================================================================
  101. ; Executable code segment
  102. ;===========================================================================
  103. CODE SEGMENT PUBLIC PARA 'CODE'
  104. ASSUME CS:CODE, DS:DATA, ES:DATA
  105. ;===========================================================================
  106. ; Declarations for all publics in other modules used by this module
  107. ;===========================================================================
  108. ;Functions
  109. EXTRN SysPrm :NEAR
  110. EXTRN TargPrm :NEAR
  111. EXTRN Get_PSP_Parms :NEAR
  112. EXTRN Cap_Char :NEAR
  113. ;Labels
  114. EXTRN FatalExit :NEAR
  115. EXTRN Find_Path_In_Environment:NEAR
  116. EXTRN Path_Crunch :NEAR
  117. EXTRN Search :NEAR
  118. ;===========================================================================
  119. ; Declarations for all publics in this module
  120. ;===========================================================================
  121. PUBLIC ReadDos
  122. PUBLIC WriteDos
  123. PUBLIC CommandFile
  124. IFDEF DBLSPACE_HOOKS
  125. PUBLIC DblSpaceFile
  126. ENDIF
  127. PUBLIC FileStat
  128. ; ==========================================================================
  129. ; Copy WINBOOT.SYS, COMMAND.COM, and DRVSPACE.BIN (if present) into
  130. ; data area.
  131. ; Carry set if problems
  132. ; M011; SystemDriveLetter=Drive to Try
  133. ; ==========================================================================
  134. ReadDos:
  135. ;M011 - begin
  136. xor ax, ax
  137. mov Bios.FileSizeInParagraphs, ax ; Initialize file sizes
  138. mov Command.FileSizeInParagraphs, ax
  139. IFDEF DBLSPACE_HOOKS
  140. mov DblSpaceBin.FileSizeInParagraphs, ax
  141. ENDIF
  142. mov AL,SystemDriveLetter
  143. mov [BiosFile],AL ; Stuff it in file specs.
  144. mov [CommandFile],AL
  145. IFDEF DBLSPACE_HOOKS
  146. mov [DblSpaceFile], al
  147. ENDIF
  148. call Get_Bios
  149. jnc RdFils
  150. ;M011 - end
  151. return
  152. RdFils:
  153. mov BYTE PTR [FileStat],0
  154. mov BX,[Bios.fileHandle]
  155. mov AX,[mStart]
  156. mov DX,AX
  157. add DX,[mSize] ; CX first bad para
  158. mov [Bios.fileStartSegment],AX
  159. mov CX,[Bios.fileSizeInParagraphs]
  160. add AX,CX
  161. cmp AX,DX
  162. jbe GotBios
  163. mov BYTE PTR [FileStat],00000001B ; Got part of Bios
  164. mov SI,[mSize]
  165. xor DI,DI
  166. call DISIX4
  167. push DS
  168. mov DS,[Bios.fileStartSegment]
  169. assume DS:NOTHING
  170. call ReadFile
  171. pop DS
  172. assume DS:data
  173. jc ClsAll
  174. xor DX,DX
  175. mov CX,DX
  176. mov AX,(LSEEK shl 8) OR 1
  177. int 21H
  178. mov WORD PTR [Bios.fileOffset],AX
  179. mov WORD PTR [Bios.fileOffset+2],DX
  180. FilesDone:
  181. clc
  182. ClsAll:
  183. pushF
  184. call FILE_CLS
  185. popF
  186. return
  187. ; ==========================================================================
  188. GotBios:
  189. mov BYTE PTR [FileStat],00000010B ; Got all of Bios
  190. push ES
  191. les SI,[Bios.fileSizeInBytes]
  192. mov DI,ES
  193. pop ES
  194. push DS
  195. mov DS,[Bios.fileStartSegment]
  196. assume DS:nothing
  197. call ReadFile
  198. pop DS
  199. assume DS:data
  200. jc ClsAll
  201. push AX
  202. push DX
  203. call File_Cls
  204. call Get_DOS
  205. pop DX
  206. pop AX
  207. ClsAllJ:
  208. jnc notClsAll
  209. jmp ClsAll
  210. NotClsAll:
  211. push AX
  212. push DX
  213. call Get_Command_Path ; get path of COMMAND.COM
  214. call Get_Command ; Point to COMMAND and read it
  215. pop DX
  216. pop AX
  217. jnc Found_Command
  218. return
  219. ; ==========================================================================
  220. Found_COMMAND:
  221. mov BX,[command.fileHandle]
  222. mov [command.fileStartSegment],AX
  223. cmp AX,DX ; No room left?
  224. jz ClsAllJ ; Yes
  225. mov CX,[command.fileSizeInParagraphs]
  226. add AX,CX
  227. cmp AX,DX
  228. jbe GotCom
  229. or BYTE PTR [FileStat],00010000B ; Got part of COMMAND
  230. sub DX,[command.fileStartSegment]
  231. mov SI,DX
  232. xor DI,DI
  233. call DISIX4
  234. push DS
  235. mov DS,[command.fileStartSegment]
  236. assume DS:nothing
  237. call ReadFile
  238. pop DS
  239. assume DS:data
  240. jc ClsAllJ
  241. xor DX,DX
  242. mov CX,DX
  243. mov AX,(LSEEK shl 8) OR 1
  244. int 21h
  245. mov WORD PTR [command.fileOffset],AX
  246. mov WORD PTR [command.fileOffset+2],DX
  247. jmp FilesDone
  248. GotCom:
  249. or BYTE PTR [FileStat],00100000B ; Got all of COMMAND
  250. push ES
  251. les SI,[command.fileSizeInBytes]
  252. mov DI,ES
  253. pop ES
  254. push DS
  255. mov DS,[command.fileStartSegment]
  256. assume DS:nothing
  257. call ReadFile
  258. pop DS
  259. assume DS:data
  260. jc ClsAllJ
  261. IFDEF DBLSPACE_HOOKS
  262. ; Attempt to locate dblspace.bin
  263. push ax
  264. push dx
  265. call File_cls ; close COMMAND.COM
  266. call Get_DblSpace
  267. pop dx
  268. pop ax
  269. jnc Found_DblSpace
  270. ; DblSpace.bin is nowhere to be found! This isn't fatal, clear
  271. ; carry and return.
  272. clc
  273. return
  274. ; ==========================================================================
  275. ; DblSpace.bin has been located, will it fit in memory?
  276. ; AX has next free location in memory buffer, DX has
  277. ; (just past) end of buffer address.
  278. Found_DblSpace:
  279. mov bx, [DblSpaceBin.fileHandle]
  280. mov [DblSpaceBin.fileStartSegment], ax
  281. cmp ax, dx ; any room left?
  282. jz ClsAllJ2 ; no!
  283. mov cx, [DblSpaceBin.fileSizeInParagraphs]
  284. add ax, cx
  285. cmp ax, dx
  286. jbe GotDblSpace
  287. ;
  288. ; No mem for dblspace driver. Lets not count its size towards SysSiz
  289. ;
  290. mov word ptr [DblSpaceBin.fileSizeInBytes], 0
  291. mov word ptr [DblSpaceBin.fileSizeInBytes].2, 0
  292. ;
  293. ; BUGBUG :: Display a warning message
  294. ;
  295. ClsAllJ2: ; insufficient memory, skip
  296. jmp ClsAll ; DRVSPACE.bin (CY is clear)
  297. GotDblSpace:
  298. mov [fDblSpace], TRUE ; got it!
  299. mov si, word ptr [DblSpaceBin.fileSizeInBytes]
  300. mov di, word ptr [DblSpaceBin.fileSizeInBytes+2] ; di:si = size
  301. push ds
  302. mov ds, [DblSpaceBin.fileStartSegment] ; ds:0 = addr
  303. assume ds:nothing
  304. call ReadFile ; load it
  305. pop ds
  306. assume ds:data
  307. ENDIF
  308. jmp ClsAll
  309. ; ==========================================================================
  310. ; Write Bios DOS COMMAND to the newly formatted disk.
  311. ; ==========================================================================
  312. ASSUME DS:DATA
  313. WriteDos:
  314. mov CX,BiosAttributes
  315. mov DX,OFFSET BiosFile ; DS:DX --> ASCIIZ pathname
  316. push ES
  317. les SI,[Bios.fileSizeInBytes]
  318. mov DI,ES ; DI:SI is file size
  319. pop ES
  320. call MakeFil ; create & open file in dest. drive
  321. retc
  322. mov [TempHandle],BX ; save file handle
  323. test BYTE PTR FileStat,00000010B ; is BIOS all in already?
  324. jnz GotAllBio ; yes, write it out
  325. call Get_Bios ; no, read it in
  326. jnc Got_WBios ; check for error
  327. ret
  328. ; ==========================================================================
  329. Got_WBios:
  330. push ES
  331. LES SI,[Bios.fileOffset]
  332. mov DI,ES ; DI:SI is file pointer
  333. pop ES
  334. mov WORD PTR [IOCNT],SI
  335. mov WORD PTR [IOCNT+2],DI
  336. mov BP,OFFSET Bios ; BP --> parameter block for BIOS file
  337. call GotTArg
  338. retc
  339. jmp SHORT BiosDone
  340. GotAllBio:
  341. push ES
  342. LES SI,[Bios.fileSizeInBytes]
  343. mov DI,ES ; DI:SI is BIOS file size
  344. pop ES
  345. push DS
  346. mov DS,[Bios.fileStartSegment] ; DS:0 --> start of BIOS in memory
  347. assume DS:nothing
  348. call WriteFile ; write BIOS to disk
  349. pop DS
  350. assume DS:data
  351. BiosDone:
  352. mov BX,[TempHandle]
  353. mov CX,Bios.fileTime
  354. mov DX,Bios.fileDate
  355. call CloseTarg ; close BIOS file on target disk
  356. cmp [MsdosFile],0
  357. je skip_msdos
  358. mov CX,DosAttributes
  359. mov DX,OFFSET MsdosFile ; DS:DX --> ASCIIZ pathname
  360. sub si,si
  361. sub di,di ; DI:SI is file size
  362. call MakeFil ; create & open file in dest. drive
  363. jc skip_msdos
  364. call Get_Dos
  365. mov dx,offset MsdosRemark
  366. mov cx,word ptr [dos.fileSizeInBytes]
  367. mov ah,WRITE
  368. int 21h
  369. mov CX,Bios.fileTime
  370. mov DX,Bios.fileDate
  371. call CloseTarg ; close dummy MSDOS file on target disk
  372. skip_msdos:
  373. mov CX,CommandAttributes
  374. ;M029 call Command_Root ;adjust path for
  375. ;M029 ;COMMAND.COM creation
  376. mov DX,OFFSET Command_Com ; M029
  377. push ES
  378. les SI,[command.fileSizeInBytes]
  379. mov DI,ES
  380. pop ES
  381. call MakeFil
  382. retc
  383. mov [TempHandle],BX
  384. test BYTE PTR FileStat,00100000B
  385. jnz GotAllCom
  386. call Get_COMMAND
  387. jnc Got_WCOM
  388. ret
  389. Got_WCOM:
  390. mov BP,OFFSET command ; BP --> parameter block for COMMAND file
  391. test BYTE PTR FileStat,00010000B
  392. jnz PartCom
  393. mov WORD PTR [command.fileOffset],0
  394. mov WORD PTR [command.fileOffset+2],0
  395. call GETSYS3
  396. retc
  397. jmp SHORT ComDone
  398. PartCom:
  399. push ES
  400. LES SI,[command.fileOffset]
  401. mov DI,ES
  402. pop ES
  403. mov WORD PTR [IOCNT],SI
  404. mov WORD PTR [IOCNT+2],DI
  405. call GotTArg
  406. retc
  407. jmp SHORT ComDone
  408. GotAllCom:
  409. push ES
  410. les SI,[command.fileSizeInBytes]
  411. mov DI,ES
  412. pop ES
  413. push DS
  414. mov DS,[command.fileStartSegment]
  415. assume DS:nothing
  416. call WriteFile
  417. pop DS
  418. assume DS:data
  419. ComDone:
  420. mov BX,[TempHandle]
  421. mov CX,command.fileTime
  422. mov DX,command.fileDate
  423. call CloseTarg
  424. IFDEF DBLSPACE_HOOKS
  425. ; Write dblspace.bin to target disk if it was located and loaded
  426. ; into memory.
  427. cmp [fDblSpace], TRUE ;Have it?
  428. jne WriteDosDone ; no...
  429. mov cx, DblSpaceAttributes ;Create file on
  430. mov dx, offset DblSpaceTargetName ; target disk
  431. mov si, word ptr [DblSpaceBin.fileSizeInBytes]
  432. mov di, word ptr [DblSpaceBin.fileSizeInBytes+2]
  433. call MakeFil
  434. retc
  435. mov [TempHandle], bx
  436. mov si, word ptr [DblSpaceBin.fileSizeInBytes]
  437. mov di, word ptr [DblSpaceBin.fileSizeInBytes+2]
  438. push ds
  439. mov ds, [DblSpaceBin.fileStartSegment]
  440. assume ds:nothing
  441. call WriteFile ;Write dblspace.bin image
  442. pop ds
  443. assume ds:data
  444. mov bx, [TempHandle] ;Set time/date, close
  445. mov cx, [DblSpaceBin.fileTime] ; DblSpace.bin
  446. mov dx, [DblSpaceBin.fileDate]
  447. call ClosetArg
  448. WriteDosDone:
  449. ENDIF
  450. clc
  451. return
  452. ; ==========================================================================
  453. ; Create a file on target disk
  454. ; CX = attributes, DX points to name
  455. ; DI:SI is size file is to have
  456. ;
  457. ; There is a bug in DOS 2.00 and 2.01 having to do with writes
  458. ; from the end of memory. In order to circumvent it this routine
  459. ; must create files with the length in DI:SI
  460. ;
  461. ; On return BX is handle, carry set if problem
  462. ; ==========================================================================
  463. MakeFil:
  464. mov BX,DX ; BX --> ASCIIZ pathname
  465. push WORD PTR [BX] ; save drive letter in pathname
  466. mov AL,DriveLetter
  467. mov [BX],AL ; set new drive letter in pathname
  468. mov AH,CREAT
  469. int 21H ; create the file on disk
  470. pop WORD PTR [BX] ; restore original drive letter in pathname
  471. mov BX,AX ; save handle in BX
  472. jc CheckMany
  473. mov CX,DI
  474. mov DX,SI ; CX:DX is size of file
  475. mov AX,LSEEK shl 8
  476. int 21H ; Seek to eventual EOF
  477. xor CX,CX
  478. mov AH,WRITE
  479. int 21H ; Set size of file to position
  480. xor CX,CX
  481. mov DX,CX
  482. mov AX,LSEEK shl 8
  483. int 21H ; Seek back to start
  484. return
  485. ; ==========================================================================
  486. ; Examine error code in AX to see if it is too-many-open-files.
  487. ; If it is, we abort right here. Otherwise we return.
  488. ; ==========================================================================
  489. CheckMany:
  490. cmp AX,error_too_many_open_files
  491. retnz
  492. Extended_Message
  493. jmp FatalExit
  494. ;*********************************************
  495. ; Close a file on the target disk
  496. ; CX/DX is time/date, BX is handle
  497. CloseTarg:
  498. mov AX,(FILE_TIMES shl 8) OR 1
  499. int 21H
  500. mov AH,CLOSE
  501. int 21H
  502. return
  503. ;****************************************
  504. ; Transfer system files
  505. ; BP points to data structure for file involved
  506. ; offset is set to current amount read in
  507. ; Start set to start of file in buffer
  508. ; TempHandle is handle to write to on target
  509. IoLoop:
  510. mov AL,[SystemDriveLetter]
  511. cmp AL,[DriveLetter]
  512. jnz GotTArg
  513. mov AH,DISK_RESET
  514. int 21H
  515. call TargPrm ;Get target disk
  516. ; ==========================================================================
  517. ; Enter here if some of file is already in buffer, IOCNT must be set
  518. ; to size already in buffer.
  519. ; ==========================================================================
  520. ASSUME DS:DATA
  521. GotTArg:
  522. mov BX,[TempHandle]
  523. mov SI,WORD PTR [IOCNT]
  524. mov DI,WORD PTR [IOCNT+2]
  525. push DS
  526. mov DS,DS:[BP.fileStartSegment]
  527. assume DS:nothing
  528. call WriteFile ; Write next part
  529. pop DS
  530. assume DS:data
  531. retc
  532. push ES
  533. LES AX,DS:[BP.fileOffset]
  534. cmp AX,WORD PTR DS:[BP.fileSizeInBytes] ; has all the file been written?
  535. jnz GETSYS3 ; no, read rest in
  536. mov AX,ES
  537. cmp AX,WORD PTR DS:[BP.fileSizeInBytes+2]
  538. jnz GETSYS3
  539. pop ES
  540. return ; Carry clear from cmp
  541. GETSYS3:
  542. ; ==========================================================================
  543. ; Enter here if none of file is in buffer
  544. ; (or none of what remains to be written is in buffer)
  545. ; ==========================================================================
  546. pop ES
  547. mov AH,DISK_RESET
  548. int 21H
  549. mov AX,[mStart] ; Furthur IO done start here
  550. mov DS:[BP.fileStartSegment],AX ; point to start of buffer
  551. mov AL,[SystemDriveLetter] ; see if we have system disk
  552. cmp AL,[DriveLetter]
  553. jnz TestSys
  554. gSys:
  555. ; Need to prompt for system disk
  556. ; call File_Cls ;SA; close file that was opened
  557. mov AH,DISK_RESET
  558. int 21H
  559. call SysPrm ; Prompt for system disk
  560. ; inc NeedSysDisk ;SA;signal need for sys disk
  561. ; stc ;SA;force return to caller
  562. ; ret ;SA;handle SysPrm in WriteSysFiles
  563. TestSys:
  564. ; call TestSysDISK
  565. jc gSys ; repeat prompt if needed
  566. mov BX,WORD PTR DS:[BP.fileHandle] ; CS over ARR 2.30
  567. push ES
  568. LES DX,dWORD PTR DS:[BP.fileOffset] ; CS over ARR 2.30
  569. mov CX,ES ; CX:DX = required offset in file
  570. pop ES
  571. push DX
  572. mov AX,LSEEK shl 8
  573. int 21H
  574. pop DX
  575. push ES
  576. LES SI,dWORD PTR DS:[BP.fileSizeInBytes] ; CS over
  577. mov DI,ES ; put high word in di
  578. pop ES
  579. SUB SI,DX ; get low word value
  580. SBB DI,CX ; DI:SI is #bytes to go
  581. push DI
  582. push SI
  583. add SI,15 ; round up 1 para
  584. ADC DI,0 ; pick up carry
  585. call DISID4 ; div 16 to get para count
  586. mov AX,SI ; put para count in AX
  587. pop SI ; restore bytes remaining
  588. pop DI ; restore bytes remaining
  589. cmp AX,[mSize] ; enough memory for remainder?
  590. jbe GOTSIZ2 ; yes
  591. mov SI,[mSize]
  592. xor DI,DI
  593. call DISIX4
  594. GOTSIZ2:
  595. mov WORD PTR [IOCNT],SI ; save byte count for read
  596. mov WORD PTR [IOCNT+2],DI
  597. push DS
  598. mov DS,[mStart]
  599. assume DS:nothing
  600. call ReadFile
  601. pop DS
  602. assume DS:data
  603. jnc GetOffs
  604. call ClsAll
  605. jmp gSys
  606. GetOffs:
  607. xor DX,DX ; clear DX
  608. mov CX,DX ; clear CX
  609. mov AX,(LSEEK shl 8) OR 1
  610. int 21H
  611. mov WORD PTR DS:[BP.fileOffset],AX
  612. mov WORD PTR DS:[BP.fileOffset+2],DX
  613. jmp IoLoop
  614. ; ==========================================================================
  615. ; Test to see if correct system disk. Open handles
  616. ; ==========================================================================
  617. CRET12:
  618. stc
  619. return
  620. ; ==========================================================================
  621. ; TestSysDISK:
  622. ; ==========================================================================
  623. Get_Bios:
  624. mov AX,OPEN shl 8
  625. mov DX,OFFSET BiosFile ; DS:DX --> ASCIIZ pathname
  626. int 21H
  627. jnc SetBios
  628. push es
  629. push ds
  630. pop es
  631. mov cx,AltBiosLen
  632. lea si,AltBiosFile
  633. mov di,dx
  634. mov al,[di]
  635. mov [MsdosFile],al
  636. add di,3
  637. cld
  638. rep movsb
  639. pop es
  640. mov AX,OPEN shl 8
  641. int 21H
  642. jnc SetBios
  643. jmp CheckMany
  644. SetBios:
  645. mov [Bios.fileHandle],AX ; save file handle
  646. mov BX,AX ; BX = file handle
  647. call GetFsiz
  648. cmp [Bios.fileSizeInParagraphs],0
  649. jz SetBioSize
  650. cmp [Bios.fileSizeInParagraphs],AX
  651. jz SetBioSize
  652. BiosCls:
  653. mov AH,CLOSE
  654. mov BX,[Bios.fileHandle]
  655. int 21h
  656. ret
  657. ; ==========================================================================
  658. SetBioSize:
  659. mov [Bios.fileSizeInParagraphs],AX
  660. mov WORD PTR [Bios.fileSizeInBytes],SI
  661. mov WORD PTR [Bios.fileSizeInBytes+2],DI
  662. mov [Bios.fileDate],DX
  663. mov [Bios.fileTime],CX
  664. clc
  665. ret
  666. ; ==========================================================================
  667. Get_COMMAND:
  668. mov AX,OPEN shl 8
  669. mov DX,OFFSET CommandFile
  670. int 21H
  671. jnc GotComHand
  672. jmp CheckMany
  673. Get_DOS:
  674. mov WORD PTR [dos.fileSizeInBytes],MsdosRemarkLen
  675. mov WORD PTR [dos.fileSizeInBytes+2],0
  676. ret
  677. GotComHand:
  678. mov [command.fileHandle],AX
  679. mov BX,AX
  680. call GetFsiz
  681. cmp [command.fileSizeInParagraphs],0
  682. jz SetComSize
  683. cmp [command.fileSizeInParagraphs],AX
  684. jz SetComSize
  685. ComCls:
  686. mov AH,CLOSE
  687. mov BX,[command.fileHandle]
  688. int 21H
  689. ret
  690. ; ==========================================================================
  691. SetComSize:
  692. mov [command.fileSizeInParagraphs],AX
  693. mov WORD PTR [command.fileSizeInBytes],SI
  694. mov WORD PTR [command.fileSizeInBytes+2],DI
  695. mov [command.fileDate],DX
  696. mov [command.fileTime],CX
  697. CLC
  698. return
  699. IFDEF DBLSPACE_HOOKS
  700. ; ==========================================================================
  701. Get_DblSpace:
  702. mov AX,OPEN shl 8
  703. mov DX,OFFSET DblSpaceFile
  704. int 21H
  705. jnc GotDblHand
  706. ; We didn't locate DblSpace.bin in the root directory, look for
  707. ; it along the PATH
  708. call Find_DblSpace_on_Path ; sets CY if not found
  709. retc
  710. mov AX,OPEN shl 8 ; open the copy found
  711. mov DX,OFFSET DblSpaceFile
  712. int 21H
  713. retc
  714. GotDblHand:
  715. mov [DblSpaceBin.fileHandle],AX
  716. mov BX,AX
  717. call GetFsiz
  718. mov [DblSpaceBin.fileSizeInParagraphs],AX
  719. mov WORD PTR [DblSpaceBin.fileSizeInBytes],SI
  720. mov WORD PTR [DblSpaceBin.fileSizeInBytes+2],DI
  721. mov [DblSpaceBin.fileDate],DX
  722. mov [DblSpaceBin.fileTime],CX
  723. CLC
  724. return
  725. ENDIF
  726. ; ==========================================================================
  727. FILE_CLS:
  728. mov AH,CLOSE
  729. int 21H
  730. ret
  731. ; ==========================================================================
  732. ; Handle in BX, return file size in para in AX
  733. ; File size in bytes DI:SI, file date in DX, file
  734. ; time in CX.
  735. ; ==========================================================================
  736. GetFsiz:
  737. mov AX,(LSEEK shl 8) OR 2
  738. xor CX,CX
  739. mov DX,CX
  740. int 21h
  741. mov SI,AX
  742. mov DI,DX
  743. add AX,15 ; Para round up
  744. adc DX,0
  745. and DX,0fH ; If file is larger than this
  746. ; it is bigger than the 8086
  747. ; address space!
  748. mov CL,12
  749. shl DX,CL
  750. mov CL,4
  751. shr AX,CL
  752. or AX,DX
  753. push AX
  754. mov AX,LSEEK shl 8
  755. xor CX,CX
  756. mov DX,CX
  757. int 21H
  758. mov AX,FILE_TIMES shl 8
  759. int 21H
  760. pop AX
  761. return
  762. ; ==========================================================================
  763. ; Read/Write file
  764. ; DS:0 is Xaddr
  765. ; DI:SI is byte count to I/O
  766. ; BX is handle
  767. ; Carry set if screw up
  768. ;
  769. ; I/O SI bytes
  770. ; I/O 64K - 1 bytes DI times
  771. ; I/O DI bytes
  772. ; ==========================================================================
  773. ReadFile: ; Must preserve AX,DX
  774. push AX
  775. push DX
  776. push BP
  777. mov BP,READ shl 8
  778. call FilIo
  779. pop BP
  780. pop DX
  781. pop AX
  782. return
  783. WriteFile:
  784. push BP
  785. mov BP,WRITE shl 8
  786. call FilIo
  787. pop BP
  788. return
  789. FilIo:
  790. xor DX,DX
  791. mov CX,SI
  792. jCXZ K64IO
  793. mov AX,BP
  794. int 21H
  795. retc
  796. add DX,AX
  797. cmp AX,CX ; If not =, AX<CX, carry set.
  798. retnz
  799. call Normalize
  800. K64IO:
  801. CLC
  802. mov CX,DI
  803. jCXZ IoRet
  804. mov AX,BP
  805. int 21H
  806. retc
  807. add DX,AX
  808. cmp AX,CX ; If not =, AX<CX, carry set.
  809. retnz
  810. call Normalize
  811. mov CX,DI
  812. K64M1:
  813. push CX
  814. xor AX,AX
  815. OR DX,DX
  816. jz NormIo
  817. mov CX,10H
  818. SUB CX,DX
  819. mov AX,BP
  820. int 21H
  821. jc IoRetP
  822. add DX,AX
  823. cmp AX,CX ; If not =, AX<CX, carry set.
  824. jnz IoRetP
  825. call Normalize
  826. NormIo:
  827. mov CX,0FFFFH
  828. SUB CX,AX
  829. mov AX,BP
  830. int 21H
  831. jc IoRetP
  832. add DX,AX
  833. cmp AX,CX ; If not =, AX<CX, carry set.
  834. jnz IoRetP
  835. call Normalize ; Clears carry
  836. pop CX
  837. LOOP K64M1
  838. push CX
  839. IoRetP:
  840. pop CX
  841. IoRet:
  842. return
  843. ; ==========================================================================
  844. ; Shift DI:SI left 4 bits
  845. ; ==========================================================================
  846. DISIX4:
  847. mov CX,4
  848. @@:
  849. shl SI,1
  850. rcl DI,1
  851. loop @B
  852. return
  853. ; ==========================================================================
  854. ; Shift DI:SI right 4 bits
  855. ; ==========================================================================
  856. DISID4:
  857. mov CX,4
  858. @@:
  859. shr DI,1
  860. rcr SI,1
  861. loop @B
  862. return
  863. ; ==========================================================================
  864. ; Normalize DS:DX
  865. ; ==========================================================================
  866. Normalize:
  867. push DX
  868. push AX
  869. SHR DX,1
  870. SHR DX,1
  871. SHR DX,1
  872. SHR DX,1
  873. mov AX,DS
  874. add AX,DX
  875. mov DS,AX
  876. pop AX
  877. pop DX
  878. and DX,0FH ; Clears carry
  879. return
  880. ;=========================================================================
  881. ; Get_Command_Path : This routine finds the path where
  882. ; COMMAND.COM resides based on the
  883. ; environmental vector. Once the
  884. ; path is found it is copied to
  885. ; CommandFile.
  886. ;
  887. ; Inputs : Exec_Block.Segment_Env - Segment of environmental vector
  888. ; Comspec_ID - "COMSPEC="
  889. ;
  890. ; Outputs : CommandFile - Holds path to COMMAND.COM
  891. ;=========================================================================
  892. Procedure Get_Command_Path
  893. push DS
  894. push ES
  895. Set_Data_Segment ; DS,ES = Data
  896. call Get_PSP_Parms ; Gets PSP info.
  897. cld ; Clear direction
  898. mov AX,ES:Environ_Segment ; Get seg. of
  899. ; Environ. vector
  900. mov DS,AX ; Put it in DS
  901. assume DS:nothing
  902. xor SI,SI ; Clear SI
  903. ;M012 - begin
  904. GCP_WhileNotFound:
  905. mov BX,SI ; Save SI
  906. cmp byte ptr DS:[SI],0
  907. jz GCP_NotFound
  908. mov DI,offset Comspec_ID
  909. mov CX,8 ; Loop 8 times
  910. repe cmpsb ; "COMSPEC=" ?
  911. jnz GCP_NotThisLine ; "COMSPEC=" not found
  912. ; "COMSPEC=" found
  913. mov DI,offset ES:CommandFile
  914. lodsb ; Priming read
  915. ; Copy COMSPEC even if COMSPEC drive != boot drive
  916. ; mov DL,AL ; Prepare for capitalization
  917. ; call Cap_Char ; Capitalize character in DL
  918. ; cmp DL,ES:CommandFile ; COMSPEC same as boot Drive?
  919. ; jne GCP_NotFound ; COMSPEC drive != boot drive
  920. GCP_GetPath: ; While AL not = 0
  921. stosb ; Save it
  922. or al,al ; At end?
  923. je GCP_Done ; Yes
  924. lodsb ; Get character
  925. jmp SHORT GCP_GetPath
  926. GCP_NotThisLine:
  927. mov SI,BX ; Restore SI
  928. GCP_Find0Terminator:
  929. lodsb ; Loop until past the first 0.
  930. or al,al
  931. jnz GCP_Find0Terminator
  932. jmp GCP_WhileNotFound
  933. GCP_NotFound:
  934. ; Nothing to do
  935. ; since commandfile is
  936. ; already patched to try
  937. ; in the root of the
  938. ; default or boot drive
  939. GCP_Done:
  940. ;M012 - end
  941. pop ES
  942. pop DS
  943. ret
  944. Get_Command_Path ENDP
  945. comment ^ ; M029
  946. ;
  947. ; This routine is no longer required ; M029
  948. ;
  949. ;=========================================================================
  950. ; Command_Root : This routine sets up CommandFile so that the
  951. ; COMMAND.COM will be written to the root.
  952. ; It does this by copying at offset 3 of CommandFile
  953. ; the literal COMMAND.COM. This effectively
  954. ; overrides the original path, but maintains the
  955. ; Drive letter that is to be written to.
  956. ;
  957. ; Inputs : CommandFile - Holds full path to default COMMAND.COM
  958. ; Outputs : CommandFile - Holds modified path to new COMMAND.COM
  959. ; on target Drive.
  960. ;=========================================================================
  961. Procedure Command_Root
  962. push DS
  963. push ES
  964. push DI
  965. push SI
  966. push CX
  967. Set_Data_Segment
  968. mov DI,offset CommandFile+3 ; Point to path past drive spec
  969. mov SI,offset Command_Com ; Holds the literal COMMAND.COM
  970. mov CX,000ch ; Len. of literal
  971. rep movsb ; Move it
  972. pop CX
  973. pop SI
  974. pop DI
  975. pop ES
  976. pop DS
  977. ret
  978. Command_Root ENDP
  979. endcomment ^ ; M029
  980. IFDEF DBLSPACE_HOOKS
  981. ;******************* START OF SPECIFICATIONS ***********************************
  982. ;Routine name: Find_DblSpace_on_Path
  983. ;*******************************************************************************
  984. ;
  985. ;Description: Search Path for DRVSPACE.bin
  986. ;
  987. ;Output: no error - CF = 0 DblSpaceFile filled in with
  988. ; full path to DRVSPACE.bin
  989. ; error - CF = 1 Dblspace.bin not found
  990. ;
  991. ; Cut and pasted from SYS command code: 12/07/92 JEM
  992. ;
  993. ;******************* END OF SPECIFICATIONS *************************************
  994. Find_DblSpace_on_Path PROC NEAR
  995. push es
  996. push ds ; save our segments
  997. push si ; save DTA address
  998. mov ax, PSP_Segment
  999. mov es, ax ; get our PSP to ES
  1000. call Find_Path_In_Environment ; returns ptr to path string in ES:DI
  1001. jc fdp_exit ; no path, can't find DRVSPACE.bin
  1002. assume es:nothing
  1003. mov ax,ds ; swap DS and ES
  1004. push es
  1005. pop ds
  1006. assume ds:nothing
  1007. mov si,di ; DS:SI ==> Path string
  1008. mov es,ax
  1009. assume es:data
  1010. fdp_path_loop:
  1011. mov bh,';' ; path separator character
  1012. mov dx,offset DblSpaceBase ; base file name
  1013. mov di,offset DblSpaceFile ; buffer to stick full path in
  1014. call Path_Crunch ; concatenate name and path
  1015. pushf ; save result
  1016. push ds ; save segment of Path
  1017. push es
  1018. pop ds
  1019. assume ds:data
  1020. mov dx,offset DblSpaceFile ; buffer with full path name
  1021. mov bx,offset DOS_BUFFER ; DMA buffer for finds
  1022. mov al,1 ; extension is specified
  1023. call Search
  1024. or al,al ; found the file?
  1025. pop ds ; recover path segment
  1026. assume ds:nothing
  1027. pop ax ; recover flags in AX
  1028. jnz fdp_exit ; found it!
  1029. xchg ah,al
  1030. sahf ; check Path_Crunch result
  1031. jnc fdp_path_loop
  1032. fdp_exit:
  1033. pop si
  1034. pop ds
  1035. pop es
  1036. assume ds:data
  1037. ret
  1038. Find_DblSpace_on_Path ENDP
  1039. ENDIF
  1040. CODE ENDS
  1041. END
  1042.