Source code of Windows XP (NT5)
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.

947 lines
24 KiB

  1. ;/*
  2. ; * Microsoft Confidential
  3. ; * Copyright (C) Microsoft Corporation 1991
  4. ; * All Rights Reserved.
  5. ; */
  6. ;===========================================================================
  7. ;
  8. ; FILE: GLBLINIT.ASM
  9. ;
  10. ;===========================================================================
  11. ;===========================================================================
  12. ;Declaration of include files
  13. ;===========================================================================
  14. ;
  15. ;---------------------------------------------------------------------------
  16. ;
  17. ; M024 : B#5495. Added "Insufficient memory" message when FORMAT cannot
  18. ; allocate memory for FAT, Directory... etc
  19. ;
  20. ;---------------------------------------------------------------------------
  21. ;
  22. debug equ 0
  23. .xlist
  24. INCLUDE BPB.INC
  25. INCLUDE DOSEQUS.INC
  26. INCLUDE DOSMAC.INC
  27. INCLUDE SYSCALL.INC
  28. INCLUDE FOREQU.INC
  29. INCLUDE FORMACRO.INC
  30. INCLUDE IOCTL.INC
  31. INCLUDE FORSWTCH.INC
  32. INCLUDE SAFEDEF.INC
  33. INCLUDE SYSVAR.INC
  34. .list
  35. ;===========================================================================
  36. ; Data segment
  37. ;===========================================================================
  38. DATA SEGMENT PUBLIC PARA 'DATA'
  39. SECTORS_FOR_MIRROR EQU 7 ; # extra buffer sectors
  40. ; required by Mirror utility,
  41. ; apart from FAT & Root Dir
  42. ;===========================================================================
  43. ; Declarations for all publics in other modules used by this module
  44. ;===========================================================================
  45. ;Bytes
  46. EXTRN msgCrLF :BYTE
  47. EXTRN DriveToFormat :BYTE
  48. EXTRN ClustBound_Flag :BYTE
  49. EXTRN FileStat :BYTE
  50. EXTRN SystemDriveLetter :BYTE
  51. EXTRN SecPerClus :BYTE
  52. EXTRN CMCDDFlag :BYTE
  53. ;Words
  54. EXTRN SwitchMap :WORD
  55. EXTRN mSize :WORD
  56. EXTRN mStart :WORD
  57. EXTRN ClustBound_Buffer_Seg :WORD
  58. EXTRN Paras_per_fat :WORD
  59. ;Pointers and DWORDs
  60. EXTRN DirectorySector :DWORD
  61. EXTRN FatSpace :DWORD
  62. EXTRN FatSector :DWORD
  63. EXTRN DirBuf :DWORD
  64. EXTRN TotalClusters :DWORD
  65. ;Messages
  66. EXTRN msgFormatNotSupported :BYTE
  67. EXTRN msgCantZThisDrive :BYTE
  68. EXTRN msgCantZWithQ :BYTE
  69. EXTRN msgCantZFAT16 :BYTE
  70. EXTRN msgCantZFAT32 :BYTE
  71. EXTRN msgZFAT32Huge :BYTE
  72. EXTRN msgZFAT32TooHuge :BYTE
  73. EXTRN msgOutOfMemory :BYTE
  74. EXTRN msgInsufficientMemory :BYTE
  75. IFNDEF OPKBLD
  76. EXTRN msgNoSysSwitch :BYTE
  77. ENDIF ;OPKBLD
  78. ;Structures
  79. EXTRN SavedParams :BYTE
  80. EXTRN DeviceParameters :BYTE
  81. EXTRN IsExtRAWIODrv :BYTE
  82. EXTRN Bios :BYTE
  83. EXTRN dos :BYTE
  84. EXTRN Command :BYTE
  85. IFDEF DBLSPACE_HOOKS
  86. EXTRN DblSpaceBin :BYTE
  87. ENDIF
  88. PUBLIC FATNotAllInMem
  89. PUBLIC FATSecCntInMem
  90. FATNotAllInMem db 0
  91. FATSecCntInMem dd 0
  92. ifdef NEC_98
  93. AllocSectorSize DW ? ; fixed #16585
  94. endif
  95. DATA ENDS
  96. ;===========================================================================
  97. ; Executable code segment
  98. ;===========================================================================
  99. CODE SEGMENT PUBLIC PARA 'CODE'
  100. ASSUME CS:CODE, DS:DATA, ES:DATA
  101. ;===========================================================================
  102. ; Declarations for all publics in other modules used by this module
  103. ;===========================================================================
  104. ;Functions
  105. ;Labels
  106. EXTRN FatalExit :NEAR
  107. EXTRN ReadDos :NEAR
  108. EXTRN SysPrm :NEAR
  109. EXTRN exclusive_access_failed :NEAR
  110. EXTRN IsLockErr? :NEAR
  111. EXTRN Calc_Big32_Fat :NEAR
  112. EXTRN Calc_Big16_Fat :NEAR
  113. EXTRN GetTotalClusters :NEAR
  114. EXTRN Yes? :NEAR
  115. ;===========================================================================
  116. ; Declarations for all publics in this module
  117. ;===========================================================================
  118. PUBLIC Global_Init
  119. PUBLIC GetDeviceParameters
  120. PUBLIC ModifyDevPrmsForZSwich
  121. ; for debug
  122. PUBLIC Copy_Device_Parameters
  123. PUBLIC Alloc_Dir_Buf
  124. PUBLIC Alloc_Fat_Buf
  125. PUBLIC Alloc_Fat_Sec_Buf
  126. PUBLIC Alloc_DirBuf2
  127. PUBLIC Alloc_Cluster_Buf
  128. IFDEF OPKBLD
  129. PUBLIC Do_Switch_S
  130. ENDIF ;OPKBLD
  131. ;===========================================================================
  132. ;
  133. ; Global_Init : This procedure first gets the default drive parameters.
  134. ; It then allocates buffer space for the root directory
  135. ; sector, FAT,a fat sector, a file header and first
  136. ; root DIR sector based on these parameters. It
  137. ; then checks for the /s switch and if this is present,
  138. ; a buffer is allocated for the system files and these
  139. ; are read into memory. A prompt to insert the system
  140. ; disk will be given in the case of removable media.
  141. ;
  142. ;===========================================================================
  143. Global_Init proc near
  144. lea DX, DeviceParameters ; Get the default drive parameters
  145. mov DeviceParameters.DP_SpecialFunctions, 0
  146. .errnz EDP_SPECIALFUNCTIONS NE DP_SPECIALFUNCTIONS
  147. call GetDeviceParameters
  148. jnc GotDeviceParameters
  149. call IsLockErr?
  150. jnc @f
  151. jmp exclusive_access_failed
  152. @@:
  153. Message msgFormatNotSupported
  154. stc ; Let the jump to FatalExit be made
  155. ret ; in the main routine, upon returning
  156. GotDeviceParameters:
  157. ifdef NEC_98 ; fixed #16585
  158. cmp DeviceParameters.DP_DeviceType,DEV_HARDDISK
  159. je @f
  160. cmp DeviceParameters.DP_DeviceType,DEV_OPTICAL
  161. je @f
  162. mov AllocSectorSize,0400h
  163. jmp short Set_ok
  164. @@:
  165. push bx
  166. mov bx, DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  167. mov AllocSectorSize,bx
  168. pop bx
  169. Set_ok:
  170. endif ; fixed #16585
  171. call Copy_Device_Parameters ; Save the device parameters
  172. ; for when we exit
  173. cmp SecPerClus,0
  174. je NoZSwtch
  175. mov ax,1 ; Noisy version
  176. call ModifyDevPrmsForZSwich
  177. jc gi_err
  178. NoZSwtch:
  179. ifdef NEC_98
  180. ; If 3.5"MO, allcate memory after updating default BPB
  181. cmp DeviceParameters.DP_DeviceType, DEV_HARDDISK ; Hard disk?
  182. .errnz EDP_DEVICETYPE NE DP_DEVICETYPE
  183. jne @F ; No
  184. test DeviceParameters.DP_DeviceAttributes, 1 ; Removable?
  185. .errnz EDP_DEVICEATTRIBUTES NE DP_DEVICEATTRIBUTES
  186. jz $$IF100 ; Yes
  187. @@:
  188. endif
  189. call Alloc_Dir_Buf ; Allocate root directory buffer
  190. jc gi_memerr
  191. call Alloc_Fat_Buf ; Allocate FAT buffer
  192. jc gi_memerr
  193. call Alloc_Fat_Sec_Buf ; Allocate fat sector buffer
  194. jc gi_memerr
  195. call Alloc_DirBuf2 ; Allocate 1-sector buffer DirBuf (general-
  196. ; purpose use)
  197. jc gi_memerr
  198. call Alloc_Cluster_Buf ; get room for retry buffer
  199. IFDEF OPKBLD
  200. call Do_Switch_S ; Load system files if needed
  201. ELSE
  202. test SwitchMap,SWITCH_S
  203. jz NoS1 ; Carry clear if jump
  204. Message msgNoSysSwitch
  205. jmp short gi_err
  206. NoS1:
  207. ENDIF ;OPKBLD
  208. ; carry flag determined by Do_Switch_S
  209. ifdef NEC_98
  210. $$IF100:
  211. endif
  212. ret
  213. gi_memerr:
  214. Message msgInsufficientMemory
  215. gi_err:
  216. stc
  217. ret
  218. Global_Init endp
  219. ; =========================================================================
  220. ;
  221. ; ModifyDevPrmsForZSwich:
  222. ; Modify the device parameters for a different sec/clus value
  223. ;
  224. ; Input:
  225. ; DeviceParameters set
  226. ; AX != 0 for noisy version (do the message thing)
  227. ; Output:
  228. ; carry set if problem.
  229. ;
  230. ; =========================================================================
  231. ModifyDevPrmsForZSwich proc near
  232. push ax ; Save noisy switch on stack
  233. .386
  234. movzx cx,SecPerClus
  235. .8086
  236. or cx,cx
  237. jz MFZDoneJ ; Carry clear if jump
  238. cmp CMCDDFlag, Yes
  239. jne DrvOk1
  240. DispErrMsg:
  241. mov dx,offset data:msgCantZThisDrive
  242. DispErrMsgSet:
  243. pop ax
  244. push ax
  245. or ax,ax
  246. jz MFZDoneErrJ
  247. call Display_Interface
  248. MFZDoneErrJ:
  249. stc
  250. MFZDoneJ:
  251. jmp MFZDone
  252. DrvOk1:
  253. ;;
  254. ;; This used to ignore things if you weren't actually making a change.
  255. ;; This is now out as it is important to poke Mr. User if he is making
  256. ;; a huge FAT drive.
  257. ;;
  258. ;; cmp cl,DeviceParameters.DP_BPB.oldBPB.BPB_SectorsPerCluster
  259. ;; je MFZDoneJ ; Carry clear if jump
  260. ;;;;
  261. mov dx,offset data:msgCantZWithQ
  262. test SwitchMap,SWITCH_Q ; Check for quick format
  263. jnz DispErrMsgSet
  264. mov DeviceParameters.DP_BPB.oldBPB.BPB_SectorsPerCluster,cl
  265. cmp DeviceParameters.DP_BPB.oldBPB.BPB_SectorsPerFAT,0
  266. je IsFAT32
  267. call Calc_Big16_Fat
  268. mov dx,0002h
  269. xor ax,ax ; DX:AX = 128k bytes
  270. mov cx,DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  271. div cx ; AX = Sectors in 128k
  272. cmp ax,DeviceParameters.DP_BPB.oldBPB.BPB_SectorsPerFAT
  273. jb Bad16
  274. .386
  275. ja MFZDone ; Carry clear if jump
  276. .8086
  277. call GetTotalClusters
  278. .386
  279. cmp TotalClusters,0000FFF0h
  280. .8086
  281. cmc ; Change "JB Is-OK" to "JNC Is-OK"
  282. jnc MFZDone
  283. Bad16:
  284. mov dx,offset data:msgCantZFAT16
  285. jmp short DispErrMsgSet
  286. IsFAT32:
  287. call Calc_Big32_Fat
  288. call GetTotalClusters
  289. .386
  290. cmp TotalClusters,65536-10
  291. .8086
  292. mov dx,offset data:msgCantZFAT32
  293. jb DispErrMsgSet
  294. .386
  295. mov eax,TotalClusters
  296. inc eax ; EAX now count including clus 0 and 1
  297. ;
  298. ; GUI SCANDISK is a 16-bit windows app. GlobalAlloc in 16-bit windows is
  299. ; limited to 16Meg-64k per block. Check if we have made a drive with a huge FAT
  300. ; that may result in slow disk util perf.
  301. ;
  302. cmp eax, ((16 * 1024 * 1024) - (64 * 1024)) / 4
  303. je short MFZDone ; carry clear if jump
  304. cmc ; Turn carry around so clear if below limit
  305. jnc short MFZDone
  306. .8086
  307. pop ax
  308. push ax
  309. or ax,ax ; Noisy?
  310. jz MFZDone ; No, Carry clear if jump
  311. Message msgZFAT32Huge
  312. call Yes? ; Carry clear if YES, set if NO
  313. pushf
  314. Message msgCrlf
  315. popf
  316. MFZDone:
  317. pop ax
  318. ret
  319. ModifyDevPrmsForZSwich endp
  320. ; =========================================================================
  321. ;
  322. ; GetDeviceParameters:
  323. ; Get the device parameters
  324. ;
  325. ; Input:
  326. ; DriveToFormat
  327. ; DX - pointer to device parameters
  328. ; =========================================================================
  329. GetDeviceParameters proc near
  330. mov AX, (IOCTL shl 8) or GENERIC_IOCTL
  331. mov bl, DriveToFormat
  332. inc bl
  333. mov CX, (EXTRAWIO shl 8) or GET_DEVICE_PARAMETERS
  334. int 21H
  335. jc TryOldForm
  336. mov IsExtRAWIODrv,1
  337. DoRet:
  338. jc realdoret
  339. push bx
  340. mov bx,dx
  341. cmp [bx.DP_BPB.oldBPB.BPB_TotalSectors],0
  342. je realdoretP
  343. ;
  344. ; the WORD total sectors field is non-zero, make sure the DWORD
  345. ; total sectors field is 0. Having BigTotalSectors be a DWORD
  346. ; version of TotalSectors in this case is SUPPOSED to be perfectly
  347. ; ok but it turns out that several apps (mostly SETUP apps) get
  348. ; upset about this (on floppies in particular).
  349. ;
  350. mov [bx.DP_BPB.oldBPB.BPB_BigTotalSectors],0
  351. mov [bx.DP_BPB.oldBPB.BPB_BigTotalSectors+2],0
  352. realdoretP:
  353. pop bx
  354. clc
  355. realdoret:
  356. return
  357. TryOldForm:
  358. mov IsExtRAWIODrv,0
  359. mov AX, (IOCTL shl 8) or GENERIC_IOCTL
  360. mov bl, DriveToFormat
  361. inc bl
  362. mov CX, (RAWIO shl 8) or GET_DEVICE_PARAMETERS
  363. int 21H
  364. jmp short DoRet
  365. GetDeviceParameters endp
  366. ;==========================================================================
  367. ;
  368. ; Copy_Device_Parameters : This procedure saves a copy of the original
  369. ; device parameters in the structure
  370. ; SavedParams.
  371. ;
  372. ;==========================================================================
  373. Copy_Device_Parameters proc near
  374. lea SI, DeviceParameters
  375. lea DI, SavedParams
  376. mov CX, size EA_DeviceParameters
  377. push DS
  378. pop ES
  379. rep movsb
  380. ret
  381. Copy_Device_Parameters endp
  382. ;==========================================================================
  383. ;
  384. ; Alloc_Dir_Buf : This procedure allocates a memory block for the root
  385. ; directory buffer, based on the device parameters only.
  386. ;
  387. ; Inputs : DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  388. ; Outputs : CY CLEAR - DirectorySector pointer to buffer
  389. ; CY SET - failure
  390. ; Modifies : AX, BX, DirectorySector
  391. ;
  392. ;==========================================================================
  393. Alloc_Dir_Buf proc near
  394. ; DirectorySector =
  395. ; malloc( Bytes Per Sector )
  396. ifdef NEC_98 ; fixed #16585
  397. mov BX, AllocSectorSize
  398. else
  399. mov BX, DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  400. endif
  401. .errnz EDP_BPB NE DP_BPB
  402. add BX, 0fH
  403. .386
  404. shr bx, 4 ; Divide by 16 to get #paragraphs
  405. .8086
  406. mov AH, Alloc
  407. int 21h
  408. jc Exit_Alloc_Dir_Buf
  409. ; Base address of newly allocated
  410. ; block is AX:0000
  411. mov WORD PTR DirectorySector+2,AX
  412. xor AX,AX
  413. mov WORD PTR DirectorySector,AX
  414. Exit_Alloc_Dir_Buf:
  415. ret
  416. Alloc_Dir_Buf endp
  417. ;==========================================================================
  418. ;
  419. ; Alloc_Fat_Buf : This procedure allocates a memory block for the FAT
  420. ; buffer, based on the device parameters only. In order
  421. ; to ensure there is enough buffer space for the Mirror
  422. ; utility, the FatSpace buffer is initially allocated
  423. ; with size:
  424. ; FAT + RootDir + 6 sectors + 1 surplus sector
  425. ; which is all the buffer space required by Mirror.
  426. ;
  427. ; Inputs : DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  428. ; DeviceParameters.DP_BPB.oldBPB.BPB_SectorsPerFat
  429. ; DeviceParameters.DP_BPB.BGBPB_BigSectorsPerFat
  430. ; DeviceParameters.DP_BPB.oldBPB.BPB_RootEntries
  431. ;
  432. ; Outputs : CY CLEAR - FatSpace pointer to buffer
  433. ; CY SET - failure
  434. ;
  435. ; Modifies : AX, BX, DX, FatSpace
  436. ;
  437. ;==========================================================================
  438. Alloc_Fat_Buf proc near
  439. xor ax,ax
  440. mov FATNotAllInMem,al ; Assume FAT will fit in mem
  441. .386
  442. ifdef NEC_98 ; fixed #16585
  443. cmp DeviceParameters.DP_DeviceType, DEV_3INCH1440KB
  444. jne short $$IF101
  445. cmp DeviceParameters.DP_BPB.oldBPB.BPB_TotalSectors, 0
  446. je short $$IF101
  447. movzx EAX, AllocSectorSize
  448. jmp short $$EN101
  449. $$IF101:
  450. movzx EAX, DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  451. $$EN101:
  452. else
  453. movzx EAX, DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  454. endif
  455. .errnz EDP_BPB NE DP_BPB
  456. add EAX, 0fH ; round up for next para
  457. shr eax, 4 ; convert to paras
  458. movzx ebx,DeviceParameters.DP_BPB.oldBPB.BPB_SectorsPerFat
  459. or bx,bx
  460. jnz short GotFSz
  461. mov ebx,dword ptr DeviceParameters.DP_BPB.BGBPB_BigSectorsPerFat
  462. GotFSz:
  463. mul ebx
  464. or edx,edx
  465. jz short NotHi
  466. GotBigFat:
  467. mov FATNotAllInMem,1
  468. mov eax,128*1024
  469. movzx ebx,DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  470. xor edx,edx
  471. div ebx
  472. mov FATSecCntInMem,eax
  473. mov ax,(128*1024)/16
  474. jmp short SetRestFatBuf
  475. NotHi:
  476. cmp eax,(128*1024)/16 ; FAT bigger than 128k?
  477. ja short GotBigFat ; Yes
  478. SetRestFatBuf:
  479. .8086
  480. mov BX,AX ; Save FAT size in paras in BX
  481. mov Paras_per_fat,BX ; Set paras_per_fat here, to
  482. ; avoid having to calculate it later
  483. ; Now add on root dir + extra sectors
  484. mov AX,DeviceParameters.DP_BPB.oldBPB.BPB_RootEntries
  485. ;; shl ax,5 ; * 32 bytes per dor entry
  486. ;; shr ax,4 ; / 16 bytes per para
  487. ;; Combine above two shifts....
  488. shl AX,1 ; AX = para size of root dir
  489. add BX,AX ; BX = FAT + root dir
  490. ifdef NEC_98 ; fixed #16585
  491. cmp DeviceParameters.DP_DeviceType, DEV_3INCH1440KB
  492. jne $$IF102
  493. cmp DeviceParameters.DP_BPB.oldBPB.BPB_TotalSectors, 0
  494. je $$IF102
  495. mov AX, AllocSectorSize
  496. jmp short $$EN102
  497. $$IF102:
  498. mov AX, DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  499. $$EN102:
  500. else
  501. mov AX, DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  502. endif
  503. add AX, 0fH ; round up for next para
  504. .386
  505. shr AX, 4 ; convert to paras
  506. .8086
  507. mov CX,SECTORS_FOR_MIRROR ; CX = # additional sectors needed by Mirror
  508. mul CX ; AX = total extra sector size in paras
  509. add BX,AX ; BX = FAT + root dir + extra sectors
  510. ; in paras
  511. mov AH,Alloc
  512. int 21h
  513. jc Exit_Alloc_Fat_Buf
  514. mov WORD PTR FatSpace+2,AX
  515. xor AX,AX
  516. mov WORD PTR FatSpace,AX
  517. Exit_Alloc_Fat_Buf:
  518. ret
  519. Alloc_Fat_Buf endp
  520. ;==========================================================================
  521. ;
  522. ; Alloc_Fat_Sec_Buf : This procedure allocates a memory block for the fat
  523. ; sector buffer which is used when copying chains from
  524. ; the old FAT to the new FAT.
  525. ;
  526. ; Inputs : DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  527. ; Outputs : CY CLEAR - FatSector pointer to buffer
  528. ; CY SET - failure
  529. ; Modifies : AX, BX, FatSector
  530. ;
  531. ;==========================================================================
  532. Alloc_Fat_Sec_Buf proc near
  533. ; FatSector =
  534. ; malloc( Bytes Per Sector )
  535. ifdef NEC_98 ; fixed #16585
  536. mov BX, AllocSectorSize
  537. else
  538. mov BX, DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  539. endif
  540. .errnz EDP_BPB NE DP_BPB
  541. add BX, 0fH
  542. .386
  543. shr BX, 4 ; Divide by 16 to get #paragraphs
  544. .8086
  545. mov AH, Alloc
  546. int 21h
  547. jc Exit_Alloc_Fat_Sec_Buf
  548. ; Base address of newly allocated
  549. ; block is AX:0000
  550. mov WORD PTR FatSector+2,AX
  551. xor AX,AX
  552. mov WORD PTR FatSector,AX
  553. Exit_Alloc_Fat_Sec_Buf:
  554. ret
  555. Alloc_Fat_Sec_Buf endp
  556. ;==========================================================================
  557. ;
  558. ; Alloc_DirBuf2 : This procedure allocates a memory block for a 1-sector
  559. ; buffer. This buffer is used when reading in the boot
  560. ; sector in Phase1.
  561. ;
  562. ; Inputs : DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  563. ; Outputs : CY CLEAR - DirBuf pointer to buffer
  564. ; CY SET - failure
  565. ; Modifies : AX, BX, DirBuf
  566. ;
  567. ;==========================================================================
  568. Alloc_DirBuf2 proc near
  569. ; DirBuf =
  570. ; malloc( Bytes Per Sector )
  571. ifdef NEC_98 ; fixed #16585
  572. mov BX, AllocSectorSize
  573. else
  574. mov BX, DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  575. endif
  576. .errnz EDP_BPB NE DP_BPB
  577. add BX, 0fH
  578. .386
  579. shr BX, 4 ; Divide by 16 to get #paragraphs
  580. .8086
  581. mov AH, Alloc
  582. int 21h
  583. jc Exit_Alloc_DirBuf2
  584. ; Base address of newly allocated
  585. ; block is AX:0000
  586. mov WORD PTR DirBuf+2,AX
  587. xor AX,AX
  588. mov WORD PTR DirBuf,AX
  589. Exit_Alloc_DirBuf2:
  590. ret
  591. Alloc_DirBuf2 endp
  592. ;=========================================================================
  593. ; Alloc_Cluster_Buf : This routine will allocate a buffer
  594. ; based on a cluster's size. If enough
  595. ; space does not exist, a cluster will
  596. ; be redefined to a smaller size for
  597. ; purposes of sector retries.
  598. ; Note: This buffer is used only for bad
  599. ; tracks on hard disks.
  600. ;
  601. ; Inputs : DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  602. ; DeviceParameters.DP_BPB.oldBPB.BPB_SectorsPerCluster
  603. ;
  604. ; Outputs : ClustBound_Flag - True (space available)
  605. ; False(not enough space)
  606. ; ClustBound_Buffer_Seg - Pointer to buffer
  607. ;=========================================================================
  608. Procedure Alloc_Cluster_Buf
  609. push AX ; Save regs
  610. push BX
  611. mov AX,(Alloc shl 8) ; Allocate memory
  612. mov BX,0ffffh ; Get available memory
  613. int 21h
  614. ifdef NEC_98 ; fixed #16585
  615. mov AX, AllocSectorSize
  616. else
  617. mov AX, DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  618. endif
  619. .errnz EDP_BPB NE DP_BPB
  620. add AX, 0fH
  621. .386
  622. shr AX, 4
  623. .8086
  624. mul DeviceParameters.DP_BPB.oldBPB.BPB_SectorsPerCluster
  625. cmp BX,AX ; Enough room
  626. jna $$IF137 ; Yes
  627. mov BX,AX ; Allocate needed memory
  628. mov AX,(Alloc shl 8)
  629. int 21h
  630. mov ClustBound_Buffer_Seg,AX ; Save pointer to buffer
  631. mov ClustBound_Flag,True ; Signal space available
  632. jmp SHORT $$EN137 ; Not enough room
  633. $$IF137:
  634. mov ClustBound_Flag,False ; Signal not enough space
  635. $$EN137:
  636. pop BX ; Restore regs
  637. pop AX
  638. ret
  639. Alloc_Cluster_Buf ENDP
  640. IFDEF OPKBLD
  641. ;=========================================================================
  642. ;
  643. ; DO_SWITCH_S : This procedure will load the system files into
  644. ; memory (if there's space) if the /s switch is
  645. ; specified.
  646. ;
  647. ; CALLS : ReadDos
  648. ; SysPrm
  649. ; CALLED BY : Global_Init
  650. ; STRATEGY : The largest block of memory available is first
  651. ; determined. The program is aborted if this is zero.
  652. ; This block is then allocated, and the system files
  653. ; are read into it. A prompt for the system disk
  654. ; will be given if the system files are not found.
  655. ;
  656. ;=========================================================================
  657. Do_Switch_S proc near
  658. test SwitchMap,SWITCH_S
  659. .386
  660. jz End_Do_Switch_S ; System files not required
  661. ; allocate memory for system files
  662. .8086
  663. mov BX,0ffffh ; This call will actually fail
  664. mov AH,Alloc ; so that BX returns max block avlbl
  665. int 21h
  666. or BX,BX
  667. jz MemErr ; No memory
  668. mov [mSize],BX ; Now allocate the largest block
  669. mov AH,alloc
  670. int 21h
  671. jnc Mem_OK
  672. MemErr:
  673. mov AX, seg data ; Check for memory allocation error
  674. mov DS, AX
  675. Message msgOutOfMemory ; call PrintString
  676. stc ; Let the jump to FatalExit be made
  677. jmp End_Do_Switch_S ; in the main routine, upon returning
  678. Mem_OK:
  679. mov [mStart],AX ; Save the starting paragraph
  680. ; =========================================================================
  681. ; This call to ReadDos may not be able to read in all of the DOS files if
  682. ; there is insufficient memory available. In that case the files will
  683. ; be read in after the disk is formatted. If the Drive being formatted is
  684. ; also the boot Drive this function will read the files from that
  685. ; Drive if there is enough memory. If there is insufficent memory it will
  686. ; force the files to be read from Drive A: if the Drive being formatted
  687. ; is also the boot Drive
  688. ; M011; Wrong: Try Boot, Then Default, Then sysprm (usually "A").
  689. ; If not enough memory at boot time, we fail.
  690. ; =========================================================================
  691. RdFrst:
  692. mov AH,GET_DEFAULT_Drive ; Find out default Drive
  693. int 21h
  694. push AX ; save default Drive
  695. mov ax, 3305h ; get startup drive
  696. int 21h
  697. mov al,dl
  698. add AL,40h ; Make it ASCII
  699. pop BX ; restore default Drive
  700. ifndef NEC_98
  701. cmp AL,41h ; Q: Booted from Drive A?
  702. jnz go_get_Bios ; N: Not a special case
  703. cmp bl,1 ; Q: is B: current Drive
  704. jnz go_get_Bios ; N: Not a special case
  705. jmp short check_default ; check default Drive
  706. endif
  707. go_get_Bios: ; Here to check booted
  708. call Get_Host_Drive ; Translate to DblSpace host
  709. mov SystemDriveLetter,AL ; (if necessary)
  710. call ReadDos
  711. jnc CheckAllFilesIn
  712. check_default: ; Here to check default
  713. mov AH,GET_DEFAULT_Drive ; Find out default Drive
  714. int 21h
  715. add AL,41h ; Make it ASCII, 1 based
  716. call Get_Host_Drive ; Translate to DblSpace host
  717. mov SystemDriveLetter,AL
  718. TryThisOne:
  719. call ReadDos ; Read BIOS and DOS
  720. jnc CheckAllFilesIn ; Files read in OK
  721. NeedSys:
  722. call SysPrm ; Prompt for system disk
  723. jmp TryThisOne ; Try again
  724. CheckAllFilesIn:
  725. ; abort program here if all system files
  726. ; have not been read into memory, since
  727. ; program fails when trying to read them
  728. ; in after formatting is complete
  729. and FileStat,3fh ; zero out 2 msb
  730. cmp FileStat,22h ; BIOS and COMMAND in memory?
  731. jne MemErr ; no - abort program
  732. ;
  733. ; Now we have all of the files in memory, SETBLOCK the allocation
  734. ; block down to the amount required.
  735. ;
  736. .386
  737. mov bx,[dos.fileStartSegment]
  738. mov eax,[dos.fileSizeInBytes]
  739. cmp bx,[bios.fileStartSegment]
  740. ja short Skip1
  741. mov bx,[bios.fileStartSegment]
  742. mov eax,[bios.fileSizeInBytes]
  743. Skip1:
  744. cmp bx,[command.fileStartSegment]
  745. ja short Skip2
  746. mov bx,[command.fileStartSegment]
  747. mov eax,[command.fileSizeInBytes]
  748. Skip2:
  749. IFDEF DBLSPACE_HOOKS
  750. cmp bx,[DblSpaceBin.fileStartSegment]
  751. ja short Skip3
  752. mov bx,[DblSpaceBin.fileStartSegment]
  753. mov eax,[DblSpaceBin.fileSizeInBytes]
  754. Skip3:
  755. ENDIF
  756. add eax,15
  757. shr eax,4 ; AX = # of paras from SEG BX
  758. .8086
  759. add bx,ax ; SEG after end of sys files
  760. sub bx,[mStart] ; SIZE of sys area
  761. mov es,[mStart]
  762. mov AH,setblock
  763. int 21h
  764. clc ; yes
  765. End_Do_Switch_S:
  766. ret
  767. Do_Switch_S ENDP
  768. ;******************* START OF SPECIFICATIONS ***********************************
  769. ;Routine name: Get_Host_Drive
  770. ;*******************************************************************************
  771. ;
  772. ;Description: Given a drive letter in AL, check to see if it is a dblspace
  773. ; drive, and if so, translate the drive letter to the host
  774. ; drive letter.
  775. ;
  776. ;Called Procedures: None
  777. ;
  778. ;Input: ASCII drive letter in AL
  779. ;
  780. ;Output: drive letter in AL
  781. ;
  782. ;Change History: Created 11/21/92 MD
  783. ; Cut and paste from SYS command 12/07/92 JEM
  784. ;
  785. ;******************* END OF SPECIFICATIONS *************************************
  786. public Get_Host_Drive
  787. Get_Host_Drive PROC NEAR
  788. push ax
  789. mov ax,4a11h ; DBLSPACE multiplex number
  790. xor bx,bx ; inquire version number
  791. int 2fh
  792. or ax,ax ; error?
  793. jnz not_dblspace
  794. cmp bx,'DM' ; stamp returned correctly?
  795. jnz not_dblspace
  796. ; DBLSPACE.BIN is loaded. At this time:
  797. ;
  798. ; (dx & 0x7fff) == driver internal version number
  799. ; high bit of DH set of driver has not yet been permanently placed
  800. ; cl == first disk letter reserved for DBLSPACE
  801. ; ch == number of disk letters reserved for DBLSPACE
  802. mov ax,4a11h ; DBLSPACE multiplex number
  803. mov bx,1 ; inquire drive map
  804. pop dx
  805. push dx
  806. sub dl, 'A' ; convert drv letter to 0 based drv number
  807. int 2fh
  808. test bl,80h ; COMPRESSED bit true?
  809. jz not_dblspace
  810. ; Drive is compressed. At this time:
  811. ;
  812. ; (bl & 0x7f) == host drive's CURRENT drive number
  813. ; bh == CVF extension number
  814. ;
  815. mov al,bl
  816. and al,7Fh
  817. add al, 'A' ; convert drv number to drv letter
  818. cbw
  819. pop dx
  820. push ax
  821. not_dblspace:
  822. pop ax
  823. ret
  824. Get_Host_Drive ENDP
  825. ENDIF ;OPKBLD
  826. CODE ENDS
  827. END
  828.