source: trunk/bootcode/regular/driveio.asm@ 175

Last change on this file since 175 was 175, checked in by Ben Rietbroek, 8 years ago

Reenable interrupts after disk i/o -- trac #11 [v1.1.1-testing]

Some old or quirky BIOSses return with interrupts disabled after INT13
and/or INT13X calls. That blocks the timer interrupt which makes
AiR-BOOT wait forever when building the BOOT-MENU.
This should fix trac issue #11:
http://trac.netlabs.org/air-boot/ticket/11

CAUTION:
This is a testbuild !
AirBoot uses the BIOS to access disks and a small coding error can trash
partition tables or other vital disk structures. You are advised to make
backups of TRACK0 and EBRs before using this testbuild. More info at:
https://rousseaux.github.io/netlabs.air-boot/pdf/AirBoot-v1.1.0-manual.pdf

File size: 75.1 KB
Line 
1; AiR-BOOT (c) Copyright 1998-2008 M. Kiewitz
2;
3; This file is part of AiR-BOOT
4;
5; AiR-BOOT is free software: you can redistribute it and/or modify it under
6; the terms of the GNU General Public License as published by the Free
7; Software Foundation, either version 3 of the License, or (at your option)
8; any later version.
9;
10; AiR-BOOT is distributed in the hope that it will be useful, but WITHOUT ANY
11; WARRANTY: without even the implied warranty of MERCHANTABILITY or FITNESS
12; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13; details.
14;
15; You should have received a copy of the GNU General Public License along with
16; AiR-BOOT. If not, see <http://www.gnu.org/licenses/>.
17;
18;---------------------------------------------------------------------------
19; AiR-BOOT / DRIVE I/O
20;---------------------------------------------------------------------------
21
22
23
24IFDEF MODULE_NAMES
25DB 'DRIVEIO',0
26ENDIF
27
28;
29; Check if INT13X extensions are supported.
30; AirBoot requires these extensions, and will halt if they are not available.
31; Modified: [CurIO_UseExtension]
32DriveIO_CheckFor13extensions Proc Near Uses ax bx cx dx
33 mov ah, 41h
34 mov bx, 55AAh
35 mov dl, [BIOS_BootDisk] ; We check using the boot-disk
36 int 13h
37 sti
38
39IFDEF AUX_DEBUG
40 IF 0
41 DBG_TEXT_OUT_AUX 'DriveIO_CheckFor13extensions:'
42 PUSHRF
43 call DEBUG_DumpRegisters
44 ;~ call AuxIO_DumpParagraph
45 ;~ call AuxIO_TeletypeNL
46 mov si, offset [Scratch]
47 mov word ptr [si], 50h
48 mov ah, 48h
49 int 13h
50 sti
51 call DEBUG_DumpRegisters
52 ;~ call AuxIO_DumpSector
53 POPRF
54 ENDIF
55ENDIF
56
57 jc PCCF13E_NotFound ; Error occured
58 cmp bx, 0AA55h
59 je PCCF13E_Found
60 PCCF13E_NotFound:
61 ret
62 PCCF13E_Found:
63 and cx, 1 ; Check 42h-44h,47h,48h supported
64 jz PCCF13E_NotFound ; Sig OK but no support, strange beast
65 mov byte ptr [CurIO_UseExtension], 1
66 ret
67DriveIO_CheckFor13extensions EndP
68
69
70; Note: Some routines set DS/ES to CS or even address via CS, even if its not
71; needed. This was done for SECURITY. So DO NOT remove it.
72; Its there to make sure the correct data is loaded/written to/from
73; harddrive.
74;
75; IF YOU MODIFY ANYTHING IN HERE, YOU MAY EASILY BREAK YOUR HARDDRIVE!
76
77; Will only load base-configuration, will NOT load IPT nor Hide-Config
78; Those are originally loaded on startup and will NOT get reloaded.
79DriveIO_LoadConfiguration Proc Near Uses ax bx cx dx es
80
81IFDEF AUX_DEBUG
82 IF 0
83 DBG_TEXT_OUT_AUX 'DriveIO_LoadConfiguration:'
84 PUSHRF
85 ;~ call DEBUG_DumpRegisters
86 ;~ call AuxIO_DumpParagraph
87 ;~ call AuxIO_TeletypeNL
88 POPRF
89 ENDIF
90ENDIF
91
92;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
93 mov ax, cs
94 mov es, ax
95 mov bx, offset Configuration
96 xor dh, dh
97 mov dl, [BIOS_BootDisk] ; Disk we booted from
98 mov cx, 0037h ; Sector 55 (CHS)
99 mov ax, 0201h ; Function 02, read 1 sector...
100 int 13h
101 sti ; Enable ints
102 jnc DIOLC_NoError
103 call MBR_LoadError ; Will Abort BootUp
104
105
106 DIOLC_NoError:
107 ret
108DriveIO_LoadConfiguration EndP
109
110DriveIO_SaveConfiguration Proc Near Uses ax bx cx dx ds es si
111
112IFDEF AUX_DEBUG
113 IF 0
114 DBG_TEXT_OUT_AUX 'DriveIO_SaveConfiguration:'
115 PUSHRF
116 call DEBUG_DumpRegisters
117 ;~ call AuxIO_DumpParagraph
118 ;~ call AuxIO_TeletypeNL
119 POPRF
120 ENDIF
121ENDIF
122
123 mov ax, cs
124 mov ds, ax
125 mov es, ax ; Safety first (CS==DS==ES)
126 ; --- Overwrite Floppy-Name with "FloppyDrive"
127 mov si, offset TXT_Floppy_Drive
128 mov di, offset PartitionTable
129 sub di, 30 ; Adjust to Floppy-Name
130 mov cx, 11
131 rep movsb
132 mov si, offset Configuration ; Calculate new checksum
133 xor bx, bx
134
135 ; Changed from 5 to calculated value (not here, see compat. issue below)
136 ; Fixes issue: #2987 -- "air-boot doesn't remember drive letter"
137 ; Size of the ab-configuration in 512 byte sectors
138 ;mov cx, (MBR_BackUpMBR - Configuration) / 200h
139
140 ; AB v1.07 stores a 5 sector configuration with a 5 sector checksum.
141 ; AB v1.0.8+ *should* stores a 7 sector configuration with a
142 ; 7 sector checksum.
143 ; Because 5 was hardcoded here, SET(A)BOOT v1.07 will see see an AB v1.0.8+
144 ; config as corrupted, while this is not the case.
145 ; So, for compatibility reasons, in v1.0.8+, the checksum stored is over
146 ; 5 sectors, to be compatible with v1.07.
147 ; This may change (be corrected) in future versions !
148 mov cx,5
149
150 mov dx, [CFG_CheckConfig]
151 mov [CFG_CheckConfig], bx
152 DIOSC_Loop:
153 call MBR_GetCheckOfSector
154 loop DIOSC_Loop
155 mov [CFG_CheckConfig], bx
156 ; --------------------------------------------------------------------
157 ; ES == CS
158 mov bx, offset Configuration
159 xor dh, dh
160 mov dl, [BIOS_BootDisk] ; Disk we booted from
161 mov cx, 0037h ; Sector 55 (CHS)
162
163 ; Changed from 5 to calculated value
164 ; Fixes issue: #2987 -- "air-boot doesn't remember drive letter"
165 ; Size of the ab-configuration in 512 byte sectors
166 mov al, (MBR_BackUpMBR - Configuration) / 200h
167 mov ah,03h
168;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
169 int 13h
170 sti
171 jnc DIOSC_NoError
172 call MBR_SaveError ; Will Abort BootUp
173 DIOSC_NoError:
174 ret
175DriveIO_SaveConfiguration EndP
176
177DriveIO_UpdateFloppyName Proc Near Uses bx cx dx ds si es di
178 mov ax, cs
179 mov ds, ax
180 mov es, ax
181
182 mov ah, 00h ; Function 0 - Reset Drive
183 xor dl, dl
184 int 13h
185 sti
186 xor dx, dx ; Cylinder=0, Head=0
187 mov cx, 1 ; Sector=1, Drive=0
188 mov bx, offset TmpSector ; ES:BX - TmpSector
189 mov ax, 0201h ; Function 2 - Load Sector
190 int 13h
191 jnc DIOUFN_AllFine
192
193 ; --- Overwrite Floppy-Name with "No Disc"
194 mov si, offset TXT_Floppy_NoDisc
195 xor ax, ax
196 DIOUFN_WriteFloppyName:
197 mov di, offset PartitionTable
198 sub di, 30 ; Adjust to Floppy-Name
199 mov cl, 11
200 rep movsb
201 ret ; AX=-1 -> GotDisc, =0 -> NoDisc
202
203 ; --- Floppy found and read, data in TempSector
204 DIOUFN_AllFine:
205 mov ax, -1
206 mov si, offset TXT_Floppy_NoName
207 cmp wptr es:[bx+54], 'AF'
208 jne DIOUFN_WriteFloppyName
209 cmp wptr es:[bx+56], '1T'
210 jne DIOUFN_WriteFloppyName
211 cmp bptr es:[bx+58], '2'
212 jne DIOUFN_WriteFloppyName
213 mov si, bx
214 add si, 43 ; FAT12 - Volume Label Location
215 jmp DIOUFN_WriteFloppyName
216DriveIO_UpdateFloppyName EndP
217
218; =============================================================================
219; HARDDRIVE / GENERAL ACCESS
220; =============================================================================
221; The following routines are used for harddisc/floppy access.
222; The access is done via INT 13h/CHS or INT 13h/LBA.
223; Access will be done prefered by INT 13h/CHS, because it's (I wonder!) much
224; faster, than the LBA-method. I don't know, why LBA is so slow. Perhaps BIOS.
225;
226; Internal access (to AiR-BOOT) is always done via INT 13h/CHS.
227
228DriveIO_GetHardDriveCount Proc Near Uses ds si
229 push ds
230 push si
231 push 0040h
232 pop ds
233 mov si, 0075h
234 mov dh, ds:[si] ; 40:75 -> POST: Total Harddiscs == DH
235 pop si
236 pop ds
237 mov [TotalHarddiscs], dh
238 ret
239DriveIO_GetHardDriveCount EndP
240
241
242; Fills our LBA-Usage table. It holds the LBA-address, where BIOS/CHS access is
243; stopped and BIOS/LBA access is started.
244; This is calculated by Sector*Heads. Comparing will get done with Bit 25-10
245; on LBA sectors, so we actually divide sector number by 1024.
246DriveIO_InitLBASwitchTable Proc Near Uses es di
247 mov di, offset LBASwitchTable
248 mov dh, [TotalHarddiscs]
249 mov dl, 80h ; First disk to process
250 DIOILUT_DriveLoop:
251 push dx
252 push di
253 mov ah, 08h
254 int 13h ; DISK - GET DRIVE PARAMETERS
255 sti ; Enable ints
256 mov ah, 0FBh ; Assume 255 heads/63 sectors, if error
257 jc DIOILUT_Error
258 and cl, 111111b ; Isolate lower 6 bits of CL -> sector count
259;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
260 ;movzx ax, cl
261 mov al,cl
262 mov ah,0
263
264 mov bl, dh ; DH -> max head number
265 mul bl ; AX = Sectors*Heads
266 shl ah, 1
267 shl ah, 1 ; Shift 2 bits, so we are able to compare to
268 ; bit 16-23 of the LBA address
269 DIOILUT_Error:
270 pop di
271 pop dx
272 mov bptr ds:[di], ah ; Save that value
273 inc di ; Go to next BYTE
274 inc dl ; Next disk
275 dec dh ; Decrease disks to process
276 jnz DIOILUT_DriveLoop ; Next disk if DH != 0
277 ret
278DriveIO_InitLBASwitchTable EndP
279
280; #########################################################################
281; Routine: Loads partition to ExecBase and checks for validity
282; #########################################################################
283; Calling : bx:ax - Absolute sector
284; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
285; Returns : Carry Set if invalid partition encountered
286; Preserve: all registers
287; #########################################################################
288DriveIO_LoadPartition Proc Near Uses si
289
290IFDEF AUX_DEBUG
291 IF 0
292 DBG_TEXT_OUT_AUX 'DriveIO_LoadPartition:'
293 PUSHRF
294 call DEBUG_DumpRegisters
295 ;~ call AuxIO_DumpParagraph
296 ;~ call AuxIO_TeletypeNL
297 POPRF
298 ENDIF
299ENDIF
300
301 mov wptr cs:[CurPartition_Location+0], ax
302 mov wptr cs:[CurPartition_Location+2], bx
303 mov wptr cs:[CurPartition_Location+4], dx
304 mov wptr cs:[CurPartition_Location+6], cx ; Saves the location
305 mov si, offset [PartitionSector] ; DS:SI - ExecBase
306
307
308;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
309 call DriveIO_LoadSector
310
311 clc
312 cmp wptr [si+LocBR_Magic], 0AA55h
313 je DIOLP_Success
314 ; We check, if we are scanning partitions. In that case, if CHS is not 0/0/1
315 ; we will display a "bad partition table" message and halt the system.
316 cmp cx, 0001h
317 jne DIOLP_Failed
318 or dh, dh
319 jnz DIOLP_Failed
320 stc ; Set carry, so no partition table
321 DIOLP_Success:
322
323
324
325 ret
326 DIOLP_Failed:
327 jmp DriveIO_GotLoadError
328DriveIO_LoadPartition EndP
329
330; #########################################################################
331; Routine: Writes a partition from ExecBase to its original sector
332; #########################################################################
333; Calling : none
334; Returns : none
335; Preserve: all registers
336; #########################################################################
337DriveIO_SavePartition Proc Near Uses ax bx cx dx si
338
339IFDEF AUX_DEBUG
340 IF 0
341 DBG_TEXT_OUT_AUX 'DriveIO_SavePartition:'
342 PUSHRF
343 call DEBUG_DumpRegisters
344 ;~ call AuxIO_DumpParagraph
345 ;~ call AuxIO_TeletypeNL
346 POPRF
347 ENDIF
348ENDIF
349
350 mov ax, wptr cs:[CurPartition_Location+0]
351 mov bx, wptr cs:[CurPartition_Location+2]
352 mov dx, wptr cs:[CurPartition_Location+4]
353 mov cx, wptr cs:[CurPartition_Location+6] ; Gets prev. saved location
354 mov si, offset PartitionSector ; DS:SI - ExecBase
355 cmp wptr [si+LocBR_Magic], 0AA55h ; Checks for signature, if not found
356 jne DIOSP_SevereError ; we assume a really bad error
357 call DriveIO_SaveSector
358 DIOSP_SevereError:
359 ret
360DriveIO_SavePartition EndP
361
362
363
364;##############################################################################
365;# The location of LVM sectors depends on the OS/2 geometry used when the disk
366;# was prepared. This geometry is present in the Master LVM sector, which has
367;# already been located if it exists. All partitions, whether primary or
368;# logical, have an entry in a partition table. For primary partitions this
369;# table is located in the MBR, while for logical partitions this table is
370;# located in the EBR for that logical partition. An LVM record is located
371;# LVM_SPT-1 sectors above an MBR or EBR. The Master LVM record contains the
372;# information for all primary partitions. For logical partitions, the LVM
373;# sector only has one entry, because EBRs are chained. The global LVM info,
374;# like disk-name, sectors per track, etc. is replicated between the Master
375;# LVM sector and LVM sectors corresponding to logical partitions. This info
376;# is kept in sync by the OS/2 LVM Engine.
377;##############################################################################
378;# ACTION : Attempts to load the corresponding LVM sector for a partition
379;# ----------------------------------------------------------------------------
380;# EFFECTS : Modifies DAP structure and fills or clears sector buffer
381;# ----------------------------------------------------------------------------
382;# IN : MEM - Location info is in [CurPartition_Location]
383;# ----------------------------------------------------------------------------
384;# OUT : CF=1 - failure, no valid LVM sector was loaded
385;# : SI - Points to the sector buffer ([LVMSector])
386;##############################################################################
387DriveIO_LoadLVMSector Proc Near Uses ax bx cx dx di
388
389IFDEF AUX_DEBUG
390 IF 0
391 DBG_TEXT_OUT_AUX 'DriveIO_LoadLVMSector:'
392 PUSHRF
393 call DEBUG_DumpRegisters
394 ;~ call AuxIO_DumpSector
395 ;~ call AuxIO_DumpParagraph
396 ;~ call AuxIO_TeletypeNL
397 POPRF
398 ENDIF
399ENDIF
400
401 ; Clear the sector buffer
402 mov si, offset [LVMSector]
403 call ClearSectorBuffer
404
405 ; Quit with CY if LVM is ignored in SETUP
406 test byte ptr [CFG_IgnoreLVM], 1 ; ZF=0 means ignore LVM
407 jnz DIOLLVMS_NoLVMSector ; Quit if so
408
409 ; Load the location of the current partition being acted upon.
410 ; Note that this is not the actual LBA of the partition, but the
411 ; sector that has the partition table that contains the entry
412 ; for the partition. In other words, for primary partitions the LBA
413 ; address points to the MBR while for extended partitions it points
414 ; to an EBR. In both cases the LVM sector is located LVM_SPT-1 above.
415 ; Also note that the BIOS CHS values (DH and CX) below are not used,
416 ; because we explicitly use LBA sector loading.
417 mov ax, wptr cs:[CurPartition_Location+0] ; LBA lo of MBR/EBR
418 mov bx, wptr cs:[CurPartition_Location+2] ; LBA hi of MBR/EBR
419 mov dx, wptr cs:[CurPartition_Location+4] ; BIOS disk num & head
420 mov cx, wptr cs:[CurPartition_Location+6] ; BIOS cyl & sec
421
422 ; Do the actual loading.
423 ; This is in a separate function so that LVM records can also be
424 ; loaded using the MBR/EBR LBA addresses from IPT entries.
425 call DriveIO_LoadLVMSectorXBR
426 jc DIOLLVMS_NoLVMSector
427
428 ; We're done, indicate success and return
429 clc
430 jmp DIOLLVMS_Done
431
432 DIOLLVMS_NoLVMSector:
433
434 ; Clear the sector buffer
435 mov si, offset [LVMSector]
436 call ClearSectorBuffer
437 mov bptr [si+LocLVM_SignatureStart], 0
438
439 ; Indicate no valid LVM sector was loaded
440 stc
441
442 DIOLLVMS_Done:
443
444 ret
445DriveIO_LoadLVMSector EndP
446
447
448
449
450
451;------------------------------------------------------------------------------
452; Attempts to load the corresponding LVM sector for a partition
453;------------------------------------------------------------------------------
454; IN : AX - LBA lo of MBR or EBR
455; : BX - LBA hi of MBR or EBR
456; ; DL - BIOS disk number
457; ; SI - Pointer to sector buffer (usually [LVMSec])
458; OUT : CF=0 - A valid LVM sector was loaded
459; NOTE : LocIPT_AbsolutePartTable and LocIPT_Drive can provide LBA and DISK
460;------------------------------------------------------------------------------
461DriveIO_LoadLVMSectorXBR Proc Near
462
463IFDEF AUX_DEBUG
464 IF 0
465 DBG_TEXT_OUT_AUX 'DriveIO_LoadLVMSectorXBR:'
466 PUSHRF
467 call DEBUG_DumpRegisters
468 ;~ call AuxIO_DumpSector
469 ;~ call AuxIO_DumpParagraph
470 ;~ call AuxIO_TeletypeNL
471 POPRF
472 ENDIF
473ENDIF
474
475 ; Save all registers
476 pusha
477
478 ; Calculate the entry in the DISKINFO array for this disk,
479 ; and put the LVM_SPT in DI
480 push bx
481 call DriveIO_CalcDiskInfoPointer
482 mov di, [bx+LocDISKINFO_LVM_Secs]
483 pop bx
484
485 ; If the LVM_SPT is ZERO, no LVM info is present and we quit with CY
486 test di, di ; See if it is 0
487 jz DriveIO_LoadLVMSectorXBR_no_lvm ; Quit if so
488
489 ; Adjust the location to point to the LVM sector
490 add ax, di ; Add the LVM sectors-per-track
491 adc bx, 0 ; Propagate LBA lo overflow to LBA hi
492 sub ax, 1 ; LVM sector is located one sector below
493 sbb bx, 0 ; Propagate borrow to LBA hi
494
495 ; Load the LVM sector into sector buffer pointed to by SI
496 mov di, ds ; Segment of that buffer
497 call DriveIO_ReadSectorLBA ; Read the LVM sector
498
499IFDEF AUX_DEBUG
500 IF 0
501 DBG_TEXT_OUT_AUX 'LVMSecLoaded'
502 PUSHRF
503 call DEBUG_DumpRegisters
504 ;~ call AuxIO_DumpSector
505 mov cx, 3
506 @@:
507 call AuxIO_DumpParagraph
508 call AuxIO_TeletypeNL
509 add si, 16
510 loop @B
511 ;~ call AuxIO_DumpParagraph
512 ;~ call AuxIO_TeletypeNL
513 POPRF
514 ENDIF
515ENDIF
516
517 jc DriveIO_LoadLVMSectorXBR_no_lvm ; Quit on error
518
519 ; Check the validity of the LVM sector, quit with CY if invalid
520 call LVM_ValidateSector ; Check signature and CRC
521 jnc DriveIO_LoadLVMSectorXBR_no_lvm ; Quit if not valid
522
523 ; We're done, indicate success and return
524 clc
525 jmp DriveIO_LoadLVMSectorXBR_done
526
527 DriveIO_LoadLVMSectorXBR_no_lvm:
528 ; Indicate no valid LVM sector was loaded
529 stc
530
531 DriveIO_LoadLVMSectorXBR_done:
532 ; Restore all registers
533 popa
534
535 ret
536DriveIO_LoadLVMSectorXBR EndP
537
538
539;##############################################################################
540;# The location of LVM sectors depends on the OS/2 geometry used when the disk
541;# was prepared. This geometry is present in the Master LVM sector, which has
542;# already been located if it exists. All partitions, whether primary or
543;# logical, have an entry in a partition table. For primary partitions this
544;# table is located in the MBR, while for logical partitions this table is
545;# located in the EBR for that logical partition. An LVM record is located
546;# LVM_SPT-1 sectors above an MBR or EBR. The Master LVM record contains the
547;# information for all primary partitions. For logical partitions, the LVM
548;# sector only has one entry, because EBRs are chained. The global LVM info,
549;# like disk-name, sectors per track, etc. is replicated between the Master
550;# LVM sector and LVM sectors corresponding to logical partitions. This info
551;# is kept in sync by the OS/2 LVM Engine.
552;##############################################################################
553;# ACTION : Attempts to save the corresponding LVM sector for a partition
554;# ----------------------------------------------------------------------------
555;# EFFECTS : Modifies DAP structure and writes LVM sector to disk
556;# ----------------------------------------------------------------------------
557;# IN : MEM - Location info is in [CurPartition_Location]
558;# : SI - Pointer to sector buffer
559;# ----------------------------------------------------------------------------
560;# OUT : CF=1 - failure, no valid LVM sector was saved
561;##############################################################################
562DriveIO_SaveLVMSector Proc Near Uses ax bx cx dx di
563
564IFDEF AUX_DEBUG
565 IF 0
566 DBG_TEXT_OUT_AUX 'DriveIO_SaveLVMSector:'
567 PUSHRF
568 call DEBUG_DumpRegisters
569 ;~ call AuxIO_DumpParagraph
570 ;~ call AuxIO_TeletypeNL
571 POPRF
572 ENDIF
573ENDIF
574
575 ; Quit with CY if LVM is ignored in SETUP
576 test byte ptr [CFG_IgnoreLVM], 1 ; ZF=0 means ignore LVM
577 jnz DIOSLVMS_NoLVMSector ; Quit if so
578
579 ; Load the location of the current partition being acted upon.
580 ; Note that this is not the actual LBA of the partition, but the
581 ; sector that has the partition table that contains the entry
582 ; for the partition. In other words, for primary partitions the LBA
583 ; address points to the MBR while for extended partitions it points
584 ; to an EBR. In both cases the LVM sector is located LVM_SPT-1 above.
585 ; Also note that the BIOS CHS values (DH and CX) below are not used,
586 ; because we explicitly use LBA sector loading.
587 mov ax, wptr cs:[CurPartition_Location+0] ; LBA lo of MBR/EBR
588 mov bx, wptr cs:[CurPartition_Location+2] ; LBA hi of MBR/EBR
589 mov dx, wptr cs:[CurPartition_Location+4] ; BIOS disk num & head
590 mov cx, wptr cs:[CurPartition_Location+6] ; BIOS cyl & sec
591
592 ; Do the actual saving.
593 ; This is in a separate function so that LVM records can also be
594 ; saved using the MBR/EBR LBA addresses from IPT entries.
595 call DriveIO_SaveLVMSectorXBR
596 jc DIOSLVMS_NoLVMSector
597
598 ; We're done, indicate success and return
599 clc
600 jmp DIOSLVMS_Done
601
602 DIOSLVMS_NoLVMSector:
603 ; Indicate no valid LVM sector was saved
604 stc
605
606 DIOSLVMS_Done:
607 ret
608DriveIO_SaveLVMSector EndP
609
610
611;------------------------------------------------------------------------------
612; Attempts to save the corresponding LVM sector for a partition
613;------------------------------------------------------------------------------
614; IN : AX - LBA lo of MBR or EBR
615; : BX - LBA hi of MBR or EBR
616; ; DL - BIOS disk number
617; ; SI - Pointer to sector buffer (usually [LVMSec])
618; OUT : CF=0 - A valid LVM sector was saved
619; NOTE : LocIPT_AbsolutePartTable and LocIPT_Drive can provide LBA and DISK
620;------------------------------------------------------------------------------
621DriveIO_SaveLVMSectorXBR Proc Near
622
623IFDEF AUX_DEBUG
624 IF 1
625 DBG_TEXT_OUT_AUX 'DriveIO_SaveLVMSectorXBR:'
626 PUSHRF
627 call DEBUG_DumpRegisters
628 call AuxIO_DumpSector
629 ;~ call AuxIO_DumpParagraph
630 ;~ call AuxIO_TeletypeNL
631 POPRF
632 ENDIF
633ENDIF
634
635 ; Save all registers
636 pusha
637
638 ; Check the validity of the LVM sector, quit with CY if invalid
639 push ax ; Save LBA lo
640 call LVM_ValidateSector ; Check signature and CRC
641 pop ax ; Restore LBA lo
642 jnc DriveIO_SaveLVMSectorXBR_no_lvm ; Quit if not valid
643
644 ; Calculate the entry in the DISKINFO array for this disk,
645 ; and put the LVM_SPT in DI
646 push bx
647 call DriveIO_CalcDiskInfoPointer
648 mov di, [bx+LocDISKINFO_LVM_Secs]
649 pop bx
650
651 ; If the LVM_SPT is ZERO, no LVM info is present and we quit with CY
652 test di, di ; See if it is 0
653 jz DriveIO_SaveLVMSectorXBR_no_lvm ; Quit if so
654
655 ; Adjust the location to point to the LVM sector
656 add ax, di ; Add the LVM sectors-per-track
657 adc bx, 0 ; Propagate LBA lo overflow to LBA hi
658 sub ax, 1 ; LVM sector is located one sector below
659 sbb bx, 0 ; Propagate borrow to LBA hi
660
661 ; Writing an LVM sector is always the result of modifications to a
662 ; previously loaded one. So, now that we have the LBA address of the
663 ; LVM sector, the one about to be overwritten should be there.
664 ; If it's not, something is seriously wrong and we quit immetiately.
665 pusha ; Push our context except the flags
666 mov si, offset [Scratch] ; Sector buffer to load the LVM sector
667 call ClearSectorBuffer ; Make sure no old LVM info is present
668 mov di, ds ; Segment of buffer
669 call DriveIO_ReadSectorLBA ; Load the old LVM sector
670 call LVM_ValidateSector ; CF=1 if valid
671 cmc ; Complement for disk i/o semantics
672 popa ; Restore our context except the flags
673
674 ; OOPS, There was no LVM sector there !!
675 jc DriveIO_SaveLVMSectorXBR_no_lvm
676
677 ; Save the LVM sector pointed to by SI
678 mov di, ds ; Segment of that buffer
679 call DriveIO_WriteSectorLBA ; Write the LVM sector
680
681IFDEF AUX_DEBUG
682 IF 1
683 DBG_TEXT_OUT_AUX 'LVMSecSaved'
684 PUSHRF
685 call DEBUG_DumpRegisters
686 call AuxIO_DumpSector
687 ;~ call AuxIO_DumpParagraph
688 ;~ call AuxIO_TeletypeNL
689 POPRF
690 ENDIF
691ENDIF
692
693 jc DriveIO_SaveLVMSectorXBR_no_lvm ; Quit on error
694
695 ; We're done, indicate success and return
696 clc
697 jmp DriveIO_SaveLVMSectorXBR_done
698
699 DriveIO_SaveLVMSectorXBR_no_lvm:
700 ; Indicate no valid LVM sector was saved
701 stc
702
703 DriveIO_SaveLVMSectorXBR_done:
704 ; Restore all registers
705 popa
706
707 ret
708DriveIO_SaveLVMSectorXBR EndP
709
710
711
712; Special error message instead of "LOAD ERROR" during partition scanning,
713; so users will notice that something is bad with their partition table(s)
714DriveIO_GotLoadError Proc Near
715IFDEF AUX_DEBUG
716 IF 1
717 DBG_TEXT_OUT_AUX 'DriveIO_GotLoadError:'
718 PUSHRF
719 call DEBUG_DumpRegisters
720 ;~ call AuxIO_DumpParagraph
721 ;~ call AuxIO_TeletypeNL
722 POPRF
723 ENDIF
724ENDIF
725 test byte ptr cs:[CurIO_Scanning], 1 ; Must be CS:, cause DS!=CS maybe here
726 jnz InScanMode
727 jmp MBR_LoadError
728 InScanMode:
729 mov si, offset TXT_BrokenPartitionTable
730 push cs
731 pop ds
732 call MBR_Teletype
733 mov si, offset BrokenHDD
734 sub dl, 50h ; 80h -> '0'
735 cmp dl, 39h
736 jbe DIOGLE_BelowA
737 add dl, 7 ; 3Ah -> 'A'
738 DIOGLE_BelowA:
739 mov bptr [si+5], dl
740 call MBR_Teletype
741
742 ; JWasm: cannot jump to local label in other procedure.
743 ; Changed to halt here.
744 ;jmp MBRLE_Halt
745 DriveIO_GotLoadError_halt:
746 jmp DriveIO_GotLoadError_halt
747DriveIO_GotLoadError EndP
748
749; #########################################################################
750; Routine: Loads a specified sector to DS:DI
751; #########################################################################
752; Calling : bx:ax - Absolute sector
753; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
754; ds:si - Destination-Adress
755; Returns : none
756; Preserve: all registers
757; #########################################################################
758DriveIO_LoadSector Proc Near Uses ax bx cx dx ds si es di
759
760IFDEF AUX_DEBUG
761 IF 0
762 DBG_TEXT_OUT_AUX 'DriveIO_LoadSector:'
763 PUSHRF
764 call DEBUG_DumpRegisters
765 ;~ call AuxIO_DumpParagraph
766 ;~ call AuxIO_TeletypeNL
767 POPRF
768 ENDIF
769ENDIF
770
771 ; Is the drive not a harddrive?
772 cmp dl, 80h
773 jb DIOLS_UseNormal
774
775 test byte ptr cs:[CurIO_UseExtension], 1
776 jz DIOLS_UseNormal
777 ; Are we forced do use LBA via Setting?
778 jnz DIOLS_UseExtension
779
780 ; Upper 8 bits of LBA-address set?
781 ; Then use LBA (maximum boundary is 16320x16x63 = FB0400h)
782 or bh, bh
783 jnz DIOLS_UseExtension
784 ; Compare Switch-Table value to bit 16-23 of LBA-address
785 mov di, dx
786 and di, 007Fh
787 cmp bptr cs:[LBASwitchTable+di], bl
788 jbe DIOLS_UseExtension
789
790 DIOLS_UseNormal:
791
792IFDEF AUX_DEBUG
793 IF 0
794 DBG_TEXT_OUT_AUX 'DriveIO_ReadSectorCHS:'
795 PUSHRF
796 call DEBUG_DumpRegisters
797 call AuxIO_DumpParagraph
798 call AuxIO_TeletypeNL
799 POPRF
800 ENDIF
801ENDIF
802
803 mov di, 3 ; retry count
804 DIOLS_ErrorLoop:
805 push ds
806 pop es
807 mov bx, si ; ES:BX - Destination
808 mov ax, 0201h ; Function 2 - Load Sector
809 int 13h
810 sti ; enable ints
811 jnc DIOLS_Success
812 dec di ; decrement retry count
813 jnz DIOLS_ErrorLoop
814
815 ; Sector load failed...
816 jmp DriveIO_GotLoadError
817
818 DIOLS_UseExtension:
819
820 mov di, ds ; segment for transfer address
821 call DriveIO_ReadSectorLBA ; extended read
822 jc DriveIO_GotLoadError ; halt on error
823
824 ;~ push cx
825 ;~ mov cs:[INT13X_DAP_NumBlocks], 1 ; Copy ONE sector
826 ;~ mov wptr cs:[INT13X_DAP_Transfer+0], si
827 ;~ mov cx, ds
828 ;~ mov wptr cs:[INT13X_DAP_Transfer+2], cx ; Fill out Transfer Adress
829 ;~ mov wptr cs:[INT13X_DAP_Absolute+0], ax
830 ;~ mov wptr cs:[INT13X_DAP_Absolute+2], bx ; Fill out Absolute Sector
831 ;~ push cs
832 ;~ pop ds
833 ;~ mov si, offset [INT13X_DAP]
834 ;~ mov ah, 42h ; Extended Read
835 ;~ int 13h
836 ;~ pop cx
837 ;~ jnc DIOLS_Success
838
839 ; Sector load failed...
840 ;~ jmp DriveIO_GotLoadError
841
842 DIOLS_Success:
843
844IFDEF AUX_DEBUG
845 IF 0
846 DBG_TEXT_OUT_AUX 'sector loaded'
847 PUSHRF
848 ;~ call DEBUG_DumpRegisters
849 ;~ call AuxIO_DumpSector
850 mov cx, 32
851 @@:
852 call AuxIO_DumpParagraph
853 call AuxIO_TeletypeNL
854 add si, 16
855 loop @B
856 POPRF
857 ENDIF
858ENDIF
859 ret
860DriveIO_LoadSector EndP
861
862
863;##############################################################################
864;# ACTION : Loads the Master Boot Record from the specified drive into buffer
865;# ----------------------------------------------------------------------------
866;# EFFECTS : Modifies DAP structure and fills or clears transfer buffer
867;# ----------------------------------------------------------------------------
868;# IN : DL - BIOS disk number (80h,81h,etc)
869;# : SI - Pointer to transfer buffer
870;# ----------------------------------------------------------------------------
871;# OUT : CF=1 - failure
872;# : AL.0 - MBR signature present
873;# : AL.1 - Primary partitions present
874;# : AL.2 - Extended partitions present
875;# : AL.3 - AiR-BOOT signature present
876;# : AL.4:7 - Reserved, returned as 0
877;# : AH.0:7 - Reserved, returned as 0
878;##############################################################################
879DriveIO_LoadMBR Proc Near uses bx cx dx si di
880
881 ; Always clear the transfer buffer first
882 call ClearSectorBuffer
883
884 ; Assume an invalid MBR
885 xor ax, ax
886
887 ; Accept only valid harddisks
888 call DriveIO_IsValidHarddisk
889 jc DriveIO_LoadMBR_exit
890
891 ; Save the address of the transfer buffer
892 mov di, si
893
894 ; Read the MBR from disk
895 xor ax, ax ; LBA low
896 xor bx, bx ; LBA high
897 xor dh, dh ; Head 0
898 mov cx, 1 ; Sector 1
899 call DriveIO_LoadSector ; Read the sector from disk
900
901 ; Check the loaded MBR for a signature
902 xor ax, ax ; Assume an invalid MBR
903 mov dx, [si+LocBR_Magic] ; Get word from MBR signature location
904 cmp dx, 0aa55h ; Is it the magic value ?
905 jne DriveIO_LoadMBR_exit ; Nope, no need to test anything else
906
907 ; Indicate we have a MBR signature
908 or al, 01h
909
910 ; Advance to the partition table
911 add si, 01beh
912
913 ; Total of 4 entries to check
914 mov cx, 4
915
916 DriveIO_LoadMBR_next_entry:
917 mov dl, [si+LocBRPT_SystemID] ; Get partition-type / system-id
918 add si, 10h ; Point to next entry
919 test dl, dl ; Nothing in this one ?
920 loopz DriveIO_LoadMBR_next_entry ; Then check next entry
921
922 ; All entries checked and last one was also empty, we're done
923 jz DriveIO_LoadMBR_check_ab
924
925 ; Found a non-empty entry, set bits according to its type
926 cmp dl, 05h ; Old style extended container ?
927 jne @F ; Nope...
928 or al, 04h ; Yep, mark ext. container present
929 @@: cmp dl, 0fh ; New style extended container ?
930 jne @F ; Nope...
931 or al, 04h ; Yep, mark ext. container present
932 @@: or al, 02h ; Then is must be a primary
933 jcxz DriveIO_LoadMBR_check_ab ; CX=0? Then all entries processed,
934 jmp DriveIO_LoadMBR_next_entry ; otherwise check next entry
935
936 ; Check if an AiR-BOOT signature is present
937 DriveIO_LoadMBR_check_ab:
938 mov si, offset [MBR_ABSig] ; Offset of AiR-BOOT signature
939 inc di ; Advance buffer pointer
940 inc di ; to AiR-BOOT signature location
941 mov cx, 7 ; Length of AiR-BOOT signature
942 cld ; Direction upwards
943 repe cmpsb ; Compare 7 bytes
944 jne DriveIO_LoadMBR_exit ; Nope, no AiR-BOOT on this disk
945 or al, 08h ; Yep, AiR-BOOT is on this disk
946 ;~ jmp DriveIO_LoadMBR_exit
947
948 DriveIO_LoadMBR_exit:
949 ret
950DriveIO_LoadMBR EndP
951
952
953;##############################################################################
954;# ACTION : Reads a sector from disk using INT13 extensions
955;# ----------------------------------------------------------------------------
956;# EFFECTS : Modifies DAP structure and fills transfer buffer
957;# ----------------------------------------------------------------------------
958;# IN : BX:AX - LBA address of sector
959;# : DI:SI - SEG:OFF of transfer buffer
960;# ----------------------------------------------------------------------------
961;# OUT : CF=1 - failure
962;##############################################################################
963DriveIO_ReadSectorLBA Proc Near
964
965IFDEF AUX_DEBUG
966 IF 0
967 DBG_TEXT_OUT_AUX 'DriveIO_ReadSectorLBA:'
968 PUSHRF
969 call DEBUG_DumpRegisters
970 call AuxIO_DumpParagraph
971 call AuxIO_TeletypeNL
972 POPRF
973 ENDIF
974ENDIF
975
976 ; Push all registers
977 pusha
978 push ds
979 push es
980
981 ; One sector to read
982 mov cs:[INT13X_DAP_NumBlocks], 1
983
984 ; Setup transfer address
985 mov wptr cs:[INT13X_DAP_Transfer+0], si ; offset
986 mov wptr cs:[INT13X_DAP_Transfer+2], di ; segment
987
988 ; Setup LBA64 address of requested sector
989 mov wptr cs:[INT13X_DAP_Absolute+0], ax ; low word lower part
990 mov wptr cs:[INT13X_DAP_Absolute+2], bx ; high word lower part
991 mov wptr cs:[INT13X_DAP_Absolute+4], 0 ; low word upper part
992 mov wptr cs:[INT13X_DAP_Absolute+6], 0 ; high word upper part
993
994 ; Address of packet
995 mov si, offset [INT13X_DAP] ; disk address packet
996
997 ; Do the extended read
998 mov ah, 42h ; read function
999 int 13h ; transfer to bios
1000 sti ; enable ints
1001
1002 ; Error occured
1003 jc DriveIO_ReadSectorLBA_exit
1004
1005 ; AH should also be zero
1006 test ah, ah
1007 stc
1008 jnz DriveIO_ReadSectorLBA_exit
1009
1010 ; Disk read succeeded, clear CF
1011 clc
1012
1013 DriveIO_ReadSectorLBA_exit:
1014
1015 ; Pop all registers
1016 pop es
1017 pop ds
1018 popa
1019
1020 ret
1021DriveIO_ReadSectorLBA EndP
1022
1023
1024
1025;##############################################################################
1026;# ACTION : Writes a sector to disk using INT13 extensions
1027;# ----------------------------------------------------------------------------
1028;# EFFECTS : Modifies DAP structure and mofifies the disk
1029;# ----------------------------------------------------------------------------
1030;# IN : BX:AX - LBA address of sector
1031;# : DI:SI - SEG:OFF of transfer buffer
1032;# ----------------------------------------------------------------------------
1033;# OUT : CF=1 - failure
1034;##############################################################################
1035DriveIO_WriteSectorLBA Proc Near
1036
1037IFDEF AUX_DEBUG
1038 IF 0
1039 DBG_TEXT_OUT_AUX 'DriveIO_WriteSectorLBA:'
1040 PUSHRF
1041 call DEBUG_DumpRegisters
1042 call AuxIO_DumpParagraph
1043 call AuxIO_TeletypeNL
1044 POPRF
1045 ENDIF
1046ENDIF
1047
1048 ; Push all registers
1049 pusha
1050 push ds
1051 push es
1052
1053 ; One sector to read
1054 mov cs:[INT13X_DAP_NumBlocks], 1
1055
1056 ; Setup transfer address
1057 mov wptr cs:[INT13X_DAP_Transfer+0], si ; offset
1058 mov wptr cs:[INT13X_DAP_Transfer+2], di ; segment
1059
1060 ; Setup LBA64 address of requested sector
1061 mov wptr cs:[INT13X_DAP_Absolute+0], ax ; low word lower part
1062 mov wptr cs:[INT13X_DAP_Absolute+2], bx ; high word lower part
1063 mov wptr cs:[INT13X_DAP_Absolute+4], 0 ; low word upper part
1064 mov wptr cs:[INT13X_DAP_Absolute+6], 0 ; high word upper part
1065
1066 ; Address of packet
1067 mov si, offset [INT13X_DAP] ; disk address packet
1068
1069 ; Do the extended write
1070 xor al, al ; no write verify
1071 mov ah, 43h ; write function
1072 int 13h ; transfer to bios
1073 sti ; enable ints
1074
1075 ; Error occured
1076 jc DriveIO_WriteSectorLBA_exit
1077
1078 ; AH should also be zero
1079 test ah, ah
1080 stc
1081 jnz DriveIO_WriteSectorLBA_exit
1082
1083 ; Disk write succeeded, clear CF
1084 clc
1085
1086 DriveIO_WriteSectorLBA_exit:
1087
1088 ; Skip the removable drive check on success
1089 jnc @F
1090
1091 ; Here, CF=1 because of a failure.
1092 ; This could be from a removable drive that is set to read-only,
1093 ; in which case we want to fake success. What this boils down to
1094 ; is that CY must be set to !IsRemovable.
1095 call DriveIO_CalcDiskInfoPointer ; Get DISKINFO pointer
1096 mov dx, [bx+LocDISKINFO_I13X_Flags] ; Get INT13X flags
1097 xor dl, 04h ; Invert 'removable' bit
1098 and dl, 04h ; Mask it out
1099 rcr dl, 3 ; Move it to CY
1100
1101 @@:
1102
1103 ; Pop all registers
1104 pop es
1105 pop ds
1106 popa
1107
1108 ret
1109DriveIO_WriteSectorLBA EndP
1110
1111
1112
1113
1114;##############################################################################
1115;# The Master LVM sector is *not* necessarily located at the end of the BIOS
1116;# view of TRACK0. Its location depends on the *OS/2 geometry* active when the
1117;# disk was partitioned. For disks < 502MiB this will most likely be LBA sector
1118;# 62, but for disks >502MiB, *extended* OS/2 geometry was used and DANIS506
1119;# uses SPT=127 for disks < 1TiB while IBMS506 uses SPT=255.
1120;# When a huge disk < 1TiB was partitioned with IBMS506, thus using SPT=255,
1121;# and the driver was later changed to DANIS506, DANI uses SPT=255, eventhough
1122;# the disk < 1TiB. Whether it is DANI that is LVM aware or something else
1123;# (maybe LVM itself) that makes DANI use the correct geometry has yet to be
1124;# investigated.
1125;#
1126;# Related geometry issues are also present with USB sticks, which can get
1127;# assigned a geometry by OS/2, which can depend if the stick was partitioned
1128;# on foreign systems or not, or even OS/2 manufacturing a geometry that is not
1129;# the same as the BIOS reports to us here. In both cases, fixed disks and
1130;# removable disks, the geometry recorded in the BPB of a partition can also
1131;# influence the geometry that OS/2 assigns. This is the case when 'preparing'
1132;# disks for LVM use, in which case BPB values could be incorporated.
1133;#
1134;# What this all boils down to, is that the geometry reported by the BIOS is
1135;# of no practical use, especially not when taking BIOS USB MSD emulation into
1136;# account. These are among the reasons why AirBoot needs to use LBA addressing
1137;# when handling LVM stuff and why LBA use cannot be disabled in the SETUP
1138;# anymore.
1139;#
1140;# So, a Master LVM sector can be present on any sector from LBA 254 downwards
1141;# and the only way to locate the correct one is to scan all the way down and,
1142;# if one is found, do proper validation on its values, because it may also be
1143;# a 'phantom' LVM sector left over from previous partition layouts.
1144;# Most of such 'phantoms' can be filtered out by verifying the location of
1145;# the found sector against the OS/2 geometry it specifies itself, which means
1146;# it must be located at the LBA of the SPT-1 it specifies.
1147;##############################################################################
1148;# ACTION : Locates the Master LVM sector on the specified disk
1149;# ----------------------------------------------------------------------------
1150;# EFFECTS : Leaves [Scratch] with last sector read or cleared
1151;# ----------------------------------------------------------------------------
1152;# IN : DL - BIOS disk number of drive to search
1153;# ----------------------------------------------------------------------------
1154;# OUT : CF=1 - found
1155;# : BX:AX - LBA address of LVM sector if found, 0 otherwise
1156;##############################################################################
1157DriveIO_LocateMasterLVMSector Proc Near uses cx dx si di ds es
1158
1159IFDEF AUX_DEBUG
1160 IF 0
1161 DBG_TEXT_OUT_AUX 'DriveIO_LocateMasterLVMSector:'
1162 PUSHRF
1163 call DEBUG_DumpRegisters
1164 ;~ call AuxIO_DumpSector
1165 ;~ call AuxIO_DumpParagraph
1166 ;~ call AuxIO_TeletypeNL
1167 POPRF
1168 ENDIF
1169ENDIF
1170
1171 ; LBA address to start scanning down from
1172 mov cx, 255
1173
1174 ; Make sure ES==DS
1175 push ds
1176 pop es
1177
1178 ; Because JCXZ is used, LBA sector 0 is never loaded and checked.
1179 ; This is of course no problem since it is the MBR.
1180 DriveIO_LocateMasterLVMSector_next:
1181 mov si, offset [Scratch] ; Use scratch area to load sectors
1182 call ClearSectorBuffer ; Clear the scratch area
1183 clc ; Indicate Master LVM sector not found
1184 jcxz DriveIO_LocateMasterLVMSector_done
1185
1186 ; Read the LBA sector specified in CX
1187 mov ax, cx ; LBA low
1188 xor bx, bx ; LBA high
1189 mov di, ds ; Segment of scratch buffer
1190 mov si, offset [Scratch] ; Offset of scratch buffer
1191 call DriveIO_ReadSectorLBA ; Read the sector
1192 lahf ; Save CF
1193 dec cx ; Prepare LBA of next sector to read
1194 sahf ; Restore CF
1195 ; No need to do any LVM sector validation when read error, read next
1196 jc DriveIO_LocateMasterLVMSector_next
1197
1198 ; See if the read sector has a valid signature and checksum
1199 call LVM_ValidateSector
1200
1201 ; NC indicates invalid or none-LVM sector, read next
1202 jnc DriveIO_LocateMasterLVMSector_next
1203
1204 ; We have found a valid LVM sector !
1205 ; So it contains the OS/2 geometry for the disk.
1206 ; That means this LVM sector itself must be located on the last sector
1207 ; of the SPT value its OS/2 geometery specifies, which, in LBA terms
1208 ; is LVM SPT-1 -- let's check that...
1209 mov bx, offset [Scratch] ; Offset of the loaded LVM sector
1210 mov al, [bx+LocLVM_Secs] ; Get the LVM SPT value (<=255)
1211 dec al ; Adjust to LVM LBA
1212 mov ah, cl ; Get next LVM LBA to search
1213 inc ah ; This one was found here
1214 cmp al, ah ; If same, LVM LBA location OK
1215 jne DriveIO_LocateMasterLVMSector_next
1216
1217 ; The LVM sector we found is at the location it should be on disk,
1218 ; so it's almost 99% sure this is the correct one.
1219 ; Now we should compare the start and sizes of the partitions in the
1220 ; MBR with the partitions specified in this LVM record.
1221 ; We'll implement that later after some more research.
1222 ; For now we assume this is the correct Master LVM sector for the disk.
1223 inc cx ; CX was prepared to read next, correct that
1224 stc ; Indicate we have found the Master LVM sector
1225
1226 DriveIO_LocateMasterLVMSector_done:
1227 mov bx, 0 ; A Master LVM sector always has high LBA=0
1228 mov ax, cx ; Low LBA of Master LVM sector
1229
1230 ; We leave it up to the caller to store the value in a proper place
1231 ret
1232DriveIO_LocateMasterLVMSector EndP
1233
1234
1235
1236;
1237; ############################################################
1238; # Check for a valid MBR-sector to be written to disk #
1239; ############################################################
1240;
1241; In
1242; --
1243; DL = Physical Disk
1244; BX:CX = LBA sector
1245; DI:SI = Source buffer
1246;
1247; Out
1248; ---
1249; CY = 1 if invalid MBR in source buffer, 0 if valid
1250;
1251; This routine is called when DriveIO_SaveSector attempts to write to the MBR.
1252; It checks if the sector to be written has some sensible values in certain
1253; places. In fact, if the sector is written to the boot-disk, the AiR-BOOT
1254; signature should be present and the partition table should be the same
1255; as the one at the start of the AiR-BOOT code in memory, except maybe for the
1256; active flags.
1257; For other disks, only the active flags are checked to be 00h or 80h and
1258; the AA55h MBR signature.
1259;
1260DriveIO_ProtectMBR Proc Near
1261 pusha ; Push all registers
1262 push es ; Push ES because we need it for string instructions
1263 push cs ; Make ES point...
1264 pop es ; to CS
1265
1266 ; Save the pointer to the sector to write in BX
1267 mov bx,si
1268
1269 ;
1270 ; If the sector to be written is not the boot-disk, then skip
1271 ; checking the AiR-BOOT MBR.
1272 ;
1273 cmp dl, [BIOS_BootDisk]
1274 jne DriveIO_ProtectMBR_is_not_bootdisk
1275
1276 ;
1277 ; The boot-disk is accessed so the sector to be written must be
1278 ; the AiR-BOOT MBR. This is the same as the first 512 bytes
1279 ; relocated to 8000:0000 and this the start of the AB-code.
1280 ;
1281 mov si,bx ; Get pointer to sector to write
1282 xor di,di ; Point DI to start of AB-code (MBR)
1283 mov cx, offset [MBR_PartTable] ; Bytes upto P-table must be same
1284 cld ; Compare upwards
1285 repe cmpsb ; Compare upto P-table
1286
1287 ; If not the same this is not the an AiR-BOOT boot-disk MBR !
1288 jne DriveIO_ProtectMBR_not_valid_MBR ; SEVERE ERROR !
1289
1290 ; Continue with signature check
1291 jmp DriveIO_ProtectMBR_check_signature
1292
1293
1294 ;
1295 ; The disk is not the boot-disk so we don't know what kind of MBR is on it.
1296 ; Some sanity checks should be here.
1297 ;
1298 DriveIO_ProtectMBR_is_not_bootdisk:
1299
1300 ;
1301 ; sanity checks...
1302 ;
1303
1304 ; Continue with signature check
1305 jmp DriveIO_ProtectMBR_check_signature
1306
1307
1308 DriveIO_ProtectMBR_check_signature:
1309 ; See if the sector to write contains a valid signature
1310 mov si,bx ; Get pointer to sector to write
1311 mov di, offset [MBR_Sig] ; Offset to MBR signature
1312 add si,di ; Make SI point to it in sec to write
1313 lodsw ; Load it
1314 cmp ax,0aa55h ; See if it is valid
1315
1316 ; If no signature this cannot be a valid MBR !
1317 jne DriveIO_ProtectMBR_not_valid_MBR ; SEVERE ERROR !
1318
1319
1320 ;
1321 ; The sector to be written seems to be valid.
1322 ; Set CY=0 to indicate a valid MBR.
1323 ;
1324 DriveIO_ProtectMBR_is_valid_MBR:
1325 clc
1326 jmp DriveIO_ProtectMBR_end
1327
1328 ;
1329 ; Something is terribly wrong; a non-MBR sector seems about to be written.
1330 ; Set CY=1 and let the calling code handle this situation.
1331 ;
1332 DriveIO_ProtectMBR_not_valid_MBR:
1333 stc
1334 jmp DriveIO_ProtectMBR_end
1335
1336 ;
1337 ; Return to the caller with no registers modyfied except FLAGS.
1338 ;
1339 DriveIO_ProtectMBR_end:
1340 pop es
1341 popa
1342 ret
1343DriveIO_ProtectMBR Endp
1344
1345
1346
1347; #########################################################################
1348; Routine: Checks if the MBR is addressed by either CHS or LBA
1349; #########################################################################
1350; Calling : bx:ax - Absolute sector
1351; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
1352; Returns : ZF=1 if MBR is addressed, else ZF=0
1353; Preserve: all registers
1354; #########################################################################
1355DriveIO_MBR_Addressed Proc
1356 push ax
1357 push bx
1358
1359 or bx,ax ; Results in 0 in BX if MBR is addressed by LBA
1360 jz DriveIO_MBR_Addressed_done
1361
1362 mov ax,cx ; Results in 1 in AX if CYL 0, SEC 1 is addressed
1363 add al,dh ; Results in 1 in AX if HEAD 0 is addressed
1364 dec ax ; Results in 0 in AX if MBR is addressed by CHS
1365
1366 DriveIO_MBR_Addressed_done:
1367 pop bx
1368 pop ax
1369 ret
1370DriveIO_MBR_Addressed EndP
1371
1372
1373
1374
1375; #########################################################################
1376; Routine: Writes DS:SI to a specified sector
1377; #########################################################################
1378; Calling : bx:ax - Absolute sector
1379; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
1380; ds:si - Source-Adress
1381; Returns : none
1382; Preserve: all registers
1383; #########################################################################
1384DriveIO_SaveSector Proc Near Uses ax bx cx dx ds si es di
1385
1386IFDEF AUX_DEBUG
1387 IF 0
1388 DBG_TEXT_OUT_AUX 'DriveIO_SaveSector:'
1389 PUSHRF
1390 call DEBUG_DumpRegisters
1391 ;~ call AuxIO_DumpParagraph
1392 ;~ call AuxIO_TeletypeNL
1393 POPRF
1394 ENDIF
1395ENDIF
1396
1397
1398;!
1399;! DEBUG_BLOCK
1400;! Force write to LBA0 to test interception routine.
1401;! Do *NOT* enable unless you are debugging, will overwrite MBR !
1402;!
1403IFDEF AUX_DEBUG
1404 IF 0
1405 pushf
1406 pusha
1407 xor ax,ax
1408 xor bx,bx
1409 xor cx,cx
1410 inc cx
1411 xor dh,dh
1412 popa
1413 popf
1414 ENDIF
1415ENDIF
1416
1417 ;
1418 ; Check if the MBR is the destination for the write.
1419 ; ZF=1 if so.
1420 ;
1421 call DriveIO_MBR_Addressed
1422 jnz DriveIO_SaveSector_continue_write
1423
1424
1425 ; MBR is addressed, check the sector that is requested to be written.
1426 ; For the bootdisk it should contain the AiR-BOOT signature, valid
1427 ; partition-table entries and the AA55h signature.
1428 ; If not, something is terribly wrong in some piece of the AB code.
1429 ; For any other disk (80h+) at least a valid partition table should
1430 ; be present together with the AA55h signature.
1431 call DriveIO_ProtectMBR
1432 jnc DriveIO_SaveSector_continue_write
1433
1434
1435 ;
1436 ; WE HAVE A SEVERE ERROR CONDITION !
1437 ; SOME AB CODE TRIES TO WRITE A NON-MBR TO THE DISK !
1438 ; ASK THE USER TO REPORT THIS !
1439 ; HALT THE SYSTEM !
1440 ;
1441
1442 ; Show error-box
1443 mov cx, 0C04h
1444 mov si, offset NonMBRwrite
1445 call SETUP_ShowErrorBox
1446 mov cx, 0C04h
1447 mov si, offset NonMBRwrite_rep
1448 call SETUP_ShowErrorBox
1449
1450
1451IFDEF AUX_DEBUG
1452 IF 0
1453 pushf
1454 pusha
1455 mov si, offset [NonMBRwrite]
1456 call AuxIO_TeletypeNL
1457 call AuxIO_Print
1458 call AuxIO_TeletypeNL
1459 popa
1460 popf
1461 ENDIF
1462ENDIF
1463
1464 ; Show popup and halt the system.
1465 jmp HaltSystem
1466
1467
1468
1469 ;
1470 ; Continue the write if not MBR sector or MBR to write is validated.
1471 ;
1472 DriveIO_SaveSector_continue_write:
1473 test byte ptr cs:[CurIO_UseExtension], 1
1474 jz DIOSS_UseNormal
1475 ; Are we forced do use LBA via Setting?
1476 ; Always use INT13X on v1.0.8+.
1477 ;~ test byte ptr cs:[CFG_ForceLBAUsage], 1
1478 ;~ jnz DIOSS_UseExtension
1479 jmp DIOSS_UseExtension
1480 ; Is the drive not a harddrive?
1481 cmp dl, 80h
1482 jb DIOSS_UseNormal
1483 ; Upper 8 bits of LBA-address set? -> Use LBA (maximum boundary is FB0400h)
1484 or bh, bh
1485 jnz DIOSS_UseExtension
1486 ; Compare Switch-Table value to bit 16-23 of LBA-address
1487 mov di, dx
1488 and di, 007Fh
1489 cmp bptr cs:[LBASwitchTable+di], bl
1490 jbe DIOSS_UseExtension
1491
1492 DIOSS_UseNormal:
1493
1494IFDEF AUX_DEBUG
1495 IF 0
1496 DBG_TEXT_OUT_AUX 'DriveIO_WriteSectorCHS:'
1497 PUSHRF
1498 call DEBUG_DumpRegisters
1499 call AuxIO_DumpParagraph
1500 call AuxIO_TeletypeNL
1501 POPRF
1502 ENDIF
1503ENDIF
1504
1505 mov di, 3 ; retry count
1506 DIOSS_ErrorLoop:
1507 push ds
1508 pop es
1509 mov bx, si ; ES:BX - Destination
1510 mov ax, 0301h ; Function 3 - Write Sector
1511 int 13h
1512 sti ; Enable ints
1513 jnc DIOSS_Success
1514 dec di ; decrement retry count
1515 jnz DIOSS_ErrorLoop
1516 call MBR_SaveError
1517
1518 DIOSS_UseExtension:
1519
1520 mov di, ds ; segment for transfer address
1521 call DriveIO_WriteSectorLBA ; extended write
1522 jc MBR_SaveError ; halt on error
1523
1524 ;~ push cx
1525 ;~ mov cs:[INT13X_DAP_NumBlocks], 1 ; Copy ONE sector
1526 ;~ mov wptr cs:[INT13X_DAP_Transfer+0], si
1527 ;~ mov cx, ds
1528 ;~ mov wptr cs:[INT13X_DAP_Transfer+2], cx ; Fill out Transfer Adress
1529 ;~ mov wptr cs:[INT13X_DAP_Absolute+0], ax
1530 ;~ mov wptr cs:[INT13X_DAP_Absolute+2], bx ; Fill out Absolute Sector
1531 ;~ push cs
1532 ;~ pop ds
1533 ;~ mov si, offset [INT13X_DAP]
1534 ;~ mov ax, 4300h ; Extended Write (No Verify)
1535 ;~ int 13h
1536 ;~ pop cx
1537 ;~ jnc DIOSS_Success
1538 ;~ call MBR_SaveError
1539
1540 DIOSS_Success:
1541 ret
1542DriveIO_SaveSector EndP
1543
1544
1545
1546
1547;##############################################################################
1548;# When a disk has a Master LVM sector, it means it has been prepared for use
1549;# by OS/2 and contains important information about how OS/2 views its geometry
1550;# and other disk related properties. This function assumes the LBA address
1551;# of the Master LVM sector has already been located and simply loads the
1552;# sector into [LVMSector].
1553;#
1554;# Note that because this is an operation similar to the regular loading of
1555;# sectors, the disk I/O semantics are used here. This means CF=0 when an LVM
1556;# sector is successfully loaded and CF=1 otherwise.
1557;##############################################################################
1558;# ACTION : Loads the Master LVM sector if one exists
1559;# ----------------------------------------------------------------------------
1560;# EFFECTS : Modifies DAP structure and [LVMSector]
1561;# ----------------------------------------------------------------------------
1562;# IN : DL - BIOS disk number (80h,81h,etc)
1563;# ----------------------------------------------------------------------------
1564;# OUT : CF=0 - Valid Master LVM sector found and loaded
1565;##############################################################################
1566DriveIO_LoadMasterLVMSector Proc Near
1567
1568IFDEF AUX_DEBUG
1569 IF 0
1570 DBG_TEXT_OUT_AUX 'DriveIO_LoadMasterLVMSector:'
1571 PUSHRF
1572 ;~ call DEBUG_DumpRegisters
1573 ;~ call AuxIO_DumpParagraph
1574 ;~ call AuxIO_TeletypeNL
1575 POPRF
1576 ENDIF
1577ENDIF
1578
1579 ; Save all registers
1580 pusha
1581
1582 ; Check if BIOS disk number is valid
1583 call DriveIO_IsValidHarddisk
1584 jc DriveIO_LoadMasterLVMSector_error
1585
1586 ; Calculate the entry in the DISKINFO array for this disk
1587 call DriveIO_CalcDiskInfoPointer
1588
1589 ; Save the entry for later recalls
1590 mov bp, bx
1591
1592 ; Get the LBA address of the Master LVM sector
1593 mov ax, [bx+LocDISKINFO_LVM_MasterLBA+00h]
1594 mov bx, [bx+LocDISKINFO_LVM_MasterLBA+02h]
1595
1596 ; LBA of Master LVM sector cannot be 0, so none was found during
1597 ; the gathering of disk information.
1598 mov cx, ax
1599 or cx, bx
1600 jz DriveIO_LoadMasterLVMSector_error
1601
1602 ; Load it into [LVMSector]
1603 mov di, ds
1604 mov si, offset [LVMSector]
1605 call DriveIO_ReadSectorLBA
1606 jc DriveIO_LoadMasterLVMSector_error
1607
1608 ; Validate the Master LVM sector
1609 call LVM_ValidateSector
1610
1611 ; Complement success indicator to conform to semantics of this function
1612 cmc
1613
1614 ; Master LVM sector was valid and is now loaded in [LVMSector]
1615 jnc DriveIO_LoadMasterLVMSector_ret
1616
1617 DriveIO_LoadMasterLVMSector_error:
1618
1619 ; Clear the sector buffer for safety reasons
1620 mov si, offset [LVMSector]
1621 call ClearSectorBuffer
1622
1623 ; Indicate no Master LVM sector loaded
1624 stc
1625
1626 DriveIO_LoadMasterLVMSector_ret:
1627
1628 ; Restore all registers
1629 popa
1630
1631 ret
1632DriveIO_LoadMasterLVMSector Endp
1633
1634
1635
1636
1637;##############################################################################
1638;# There is much information to know about the connected disks.
1639;# We also want this information clustered per disk and available before
1640;# further disk and partition scanning takes place.
1641;# This function gathers such information like INT13, INT13X, MBR, LVM, more.
1642;# Especially important is the LVM information, because that contains the
1643;# geometry OS/2 uses to access the disk. Other important information is the
1644;# presence of valid MBRs, logical partitions and whatnot.
1645;# This function gathers such information and stores it in a DISKINFO structure
1646;# for which an instance exists for every disk found.
1647;##############################################################################
1648;# ACTION : Gather disk information and store this in the BSS
1649;# ----------------------------------------------------------------------------
1650;# EFFECTS : Modifies DAP structure and the buffers it uses, fills DISKINFO[n]
1651;# ----------------------------------------------------------------------------
1652;# IN : DL - BIOS disk number (80h,81h,etc)
1653;# ----------------------------------------------------------------------------
1654;# OUT : CF=1 - failure
1655;##############################################################################
1656DriveIO_GatherDiskInfo Proc Near
1657
1658IFDEF AUX_DEBUG
1659 IF 0
1660 DBG_TEXT_OUT_AUX 'DriveIO_GatherDiskInfo:'
1661 PUSHRF
1662 call DEBUG_DumpRegisters
1663 ;~ call AuxIO_DumpParagraph
1664 ;~ call AuxIO_TeletypeNL
1665 POPRF
1666 ENDIF
1667ENDIF
1668
1669 ; Push all registers we use
1670 pusha
1671 push ds
1672 push es
1673
1674 ; Make sure ES=DS
1675 push ds
1676 pop es
1677
1678 ; Check if BIOS disk number is valid
1679 call DriveIO_IsValidHarddisk
1680 jc DriveIO_GatherDiskInfo_error
1681
1682 ; Calculate the entry in the DISKINFO array for this disk
1683 call DriveIO_CalcDiskInfoPointer
1684
1685 ; Save the entry for later recalls
1686 mov bp, bx
1687
1688 ; Store the BIOS disk number in the structure
1689 mov [bx+LocDISKINFO_DiskNum], dl
1690
1691; ------------------------------------------------------------------- [ INT13 ]
1692
1693 ; Get BIOS Disk Parameters (legacy method)
1694 mov ah, 08h ; Get Disk Parameters
1695 int 13h ; Call BIOS
1696 sti ; Enable ints
1697
1698 ; CF=1 or AH!=0 indicates error
1699 jc DriveIO_GatherDiskInfo_error
1700 test ah, ah
1701 jnz DriveIO_GatherDiskInfo_error
1702
1703 ; Recall DISKINFO entry
1704 mov bx, bp
1705
1706 ; Store SPT (WORD)
1707 xor ah, ah ; Zero extend SPT to 16 bits
1708 mov al, cl ; Hi 2 bits max cyl and max sec
1709 and al, 3fh ; Mask max sec (1-based)
1710 mov [bx+LocDISKINFO_I13_Secs], ax ; Store SPT
1711
1712 ; Store HEADS (WORD)
1713 xor dl, dl ; Zero extend HEADS to 16 bits
1714 xchg dl, dh ; Get max head (0-based)
1715 inc dx ; Head count
1716 mov [bx+LocDISKINFO_I13_Heads], dx ; Store HEADS
1717
1718 ; Store CYLS (WORD)
1719 shr cl, 6 ; Hi 2 bits of max cyl to 1:0
1720 xchg cl, ch ; Max cyl (0-based)
1721 inc cx ; Cyl count
1722 mov [bx+LocDISKINFO_I13_Cyls], cx ; Store CYLS
1723
1724 ; Recall BIOS disk number
1725 mov dl, [bx+LocDISKINFO_DiskNum]
1726
1727; ------------------------------------------------------------------ [ INT13X ]
1728
1729 ; Get BIOS Disk Parameters (extended method)
1730 mov si, offset [Scratch] ; Buffer to return disk info
1731 mov ax, 80h ; Size of buffer
1732 mov [si], ax ; Store it in first word
1733 mov ah, 48h ; Get Extended Disk Parameters
1734 int 13h ; Call BIOS
1735 sti ; Enable ints
1736
1737 ; CF=1 or AH!=0 indicates error
1738 jc DriveIO_GatherDiskInfo_error
1739 test ah, ah
1740 jnz DriveIO_GatherDiskInfo_error
1741
1742 ; Store flags (WORD)
1743 cld ; Direction up
1744 lodsw ; Buffersize, discard
1745 lodsw ; Flags (CHS valid etc)
1746 mov [bx+LocDISKINFO_I13X_Flags], ax ; Store them
1747
1748 ; Store CYLS (DWORD)
1749 lodsw ; Cyl count low
1750 mov [bx+LocDISKINFO_I13X_Cyls+00h], ax ; Store CYLS low
1751 lodsw ; Cyl count high
1752 mov [bx+LocDISKINFO_I13X_Cyls+02h], ax ; Store CYLS high
1753
1754 ; Store HEADS (DWORD)
1755 lodsw ; Head count low
1756 mov [bx+LocDISKINFO_I13X_Heads+00h], ax ; Store HEADS low
1757 lodsw ; Head count high
1758 mov [bx+LocDISKINFO_I13X_Heads+02h], ax ; Store HEADS high
1759
1760 ; Store SPT (DWORD)
1761 lodsw ; Secs per track low
1762 mov [bx+LocDISKINFO_I13X_Secs+00h], ax ; Store SPT low
1763 lodsw ; Secs per track high
1764 mov [bx+LocDISKINFO_I13X_Secs+02h], ax ; Store SPT high
1765
1766 ; Store total LBA sectors (QWORD)
1767 lea di, [bx+LocDISKINFO_I13X_SecsLBA]
1768 mov cx, 4
1769 rep movsw
1770
1771 ; Store sector size (WORD)
1772 lodsw
1773 mov [bx+LocDISKINFO_I13X_SecSize], ax
1774
1775 ; Store bus name (4 bytes, space padded, v3.0+)
1776 lea si, [Scratch+24h]
1777 lea di, [bx+LocDISKINFO_I13X_HostBus]
1778 movsw
1779 movsw
1780
1781 ; Store interface name (8 bytes, space padded, v3.0+)
1782 lea di, [bx+LocDISKINFO_I13X_Interface]
1783 mov cx, 4
1784 rep movsw
1785
1786 ; Should gather some more INT13X info here,
1787 ; like maybe Advanced Format stuff or so.
1788 ; We'll investigate that at a later time.
1789
1790; --------------------------------------------------------------------- [ MBR ]
1791
1792 ; Load the MBR
1793 mov si, offset [TmpSector]
1794 call DriveIO_LoadMBR
1795
1796 ; Store MBR flags (valid sig, partitions present, airboot installed)
1797 mov [bx+LocDISKINFO_MbrFlags], al
1798
1799 ; Recall BIOS disk number
1800 mov dl, [bx+LocDISKINFO_DiskNum]
1801
1802; --------------------------------------------------------------------- [ LVM ]
1803
1804 ; Locate the Master LVM sector, if any
1805 call DriveIO_LocateMasterLVMSector
1806
1807 ; Save Master LVM sector LBA high
1808 mov cx, bx
1809
1810 ; Recall DISKINFO entry
1811 mov bx, bp
1812
1813 ; Store Master LVM sector LBA
1814 mov [bx+LocDISKINFO_LVM_MasterLBA+00h], ax
1815 mov [bx+LocDISKINFO_LVM_MasterLBA+02h], cx
1816
1817 ; No Master LVM sector found, so skip storing LVM info for this disk
1818 jnc DriveIO_GatherDiskInfo_no_master_lvm
1819
1820 ; Load the Master LVM sector into [LVMSector]
1821 call DriveIO_LoadMasterLVMSector
1822
1823 ; No valid Master LVM sector, so skip storing LVM info for this disk
1824 jc DriveIO_GatherDiskInfo_no_master_lvm
1825
1826 ; A valid Master LVM sector has been loaded into [LVMSector]
1827 mov si, offset [LVMSector]
1828
1829 ; Get the number of sectors per track (OS/2 geometry)
1830 mov ax, [si+LocLVM_Secs+00h]
1831 mov cx, [si+LocLVM_Secs+02h]
1832
1833 ; Store it
1834 mov [bx+LocDISKINFO_LVM_Secs+00h], ax
1835 mov [bx+LocDISKINFO_LVM_Secs+02h], cx
1836
1837 ; Get the number of heads (OS/2 geometry)
1838 mov ax, [si+LocLVM_Heads+00h]
1839 mov cx, [si+LocLVM_Heads+02h]
1840
1841 ; Store it
1842 mov [bx+LocDISKINFO_LVM_Heads+00h], ax
1843 mov [bx+LocDISKINFO_LVM_Heads+02h], cx
1844
1845 ; Should gather some more LVM info here,
1846 ; like OS/2 extended geometry and other flags.
1847 ; We'll implement that at a later time.
1848
1849 DriveIO_GatherDiskInfo_no_master_lvm:
1850
1851 ; When no Master LVM sector was found,
1852 ; the LVM info in the DISKINFO structure for the disk
1853 ; will be ZERO because the area was cleared in PRECRAP.
1854
1855 ; Indicate success
1856 clc
1857
1858 jmp DriveIO_GatherDiskInfo_ret
1859
1860 DriveIO_GatherDiskInfo_error:
1861 stc
1862 DriveIO_GatherDiskInfo_ret:
1863
1864
1865IFDEF AUX_DEBUG
1866 IF 0
1867 DBG_TEXT_OUT_AUX '[DISKINFO]'
1868 PUSHRF
1869 call DEBUG_DumpRegisters
1870 ;~ call AuxIO_DumpParagraph
1871 ;~ call AuxIO_TeletypeNL
1872 mov si, bp
1873 mov cx, 4
1874 @@:
1875 call AuxIO_DumpParagraph
1876 call AuxIO_TeletypeNL
1877 add si, 16
1878 loop @B
1879 mov si, offset [Scratch]
1880 mov cx, 4
1881 @@:
1882 call AuxIO_DumpParagraph
1883 call AuxIO_TeletypeNL
1884 add si, 16
1885 loop @B
1886 mov si, offset [LVMSector]
1887 mov cx, 7
1888 @@:
1889 call AuxIO_DumpParagraph
1890 call AuxIO_TeletypeNL
1891 add si, 16
1892 loop @B
1893 POPRF
1894 ENDIF
1895ENDIF
1896
1897 ; Restore registers
1898 pop es
1899 pop ds
1900 popa
1901
1902 ret
1903DriveIO_GatherDiskInfo EndP
1904
1905;------------------------------------------------------------------------------
1906; Scan all disks to gather information
1907;------------------------------------------------------------------------------
1908; IN : None
1909; OUT : CF=1 - some failure occured
1910; : ZF=1 - no harddisks
1911; NOTE : This does the preliminary gathering of disk information
1912;------------------------------------------------------------------------------
1913DriveIO_ScanDisks Proc Near
1914
1915IFDEF AUX_DEBUG
1916 IF 0
1917 DBG_TEXT_OUT_AUX 'DriveIO_ScanDisks:'
1918 PUSHRF
1919 call DEBUG_DumpRegisters
1920 ;~ call AuxIO_DumpParagraph
1921 ;~ call AuxIO_TeletypeNL
1922 POPRF
1923 ENDIF
1924ENDIF
1925
1926 ; Save all registers
1927 pusha
1928
1929 ; Get number of disks in DH
1930 call DriveIO_GetHardDriveCount
1931
1932 ; Check if there are any disks to scan
1933 xor cx, cx ; Prepare 16-bit counter
1934 mov cl, dh ; Number of disks now in CX
1935 jcxz DriveIO_ScanDisks_end ; Quit if no disks
1936
1937 ; Scan disks from 80h upward
1938 mov dl, 80h ; BIOS number of first disk
1939 DriveIO_ScanDisks_next:
1940 call DriveIO_GatherDiskInfo ; Gather info for this disk
1941 jc DriveIO_ScanDisks_end ; Quit if some error occured
1942 inc dl ; Advance to next disk
1943 loop DriveIO_ScanDisks_next ; Scan next disk if there is one
1944 test dl, dl ; Set ZF=0
1945 clc ; Indicate success
1946
1947 DriveIO_ScanDisks_end:
1948 ; Restore all registers
1949 popa
1950
1951 ret
1952DriveIO_ScanDisks EndP
1953
1954;------------------------------------------------------------------------------
1955; Calculate pointer to entry in DISKINFO structure
1956;------------------------------------------------------------------------------
1957; IN : DL BIOS disk number (80h etc)
1958; OUT : BX Pointer to entry
1959; NOTE : BIOS disk number must be valid
1960;------------------------------------------------------------------------------
1961DriveIO_CalcDiskInfoPointer Proc Near
1962 xchg bx, ax ; AX is used for calculation
1963 mov al, DISKINFO_Size ; Size of DISKINFO structure
1964 mov ah, dl ; BIOS disk number
1965 sub ah, 80h ; Now 0-based index
1966 mul ah ; Now offset into DISKINFO array
1967 add ax, offset [DiskInformation] ; Base of DISKINFO array
1968 xchg bx, ax ; BX now points to entry for disk
1969 ret
1970DriveIO_CalcDiskInfoPointer EndP
1971
1972;------------------------------------------------------------------------------
1973; Check if the BIOS disk number in DL is a harddisk and in range
1974;------------------------------------------------------------------------------
1975; IN : DL BIOS disk number (80h etc)
1976; OUT : CF=1 if invalid disk number or out of range
1977; NOTE : Only modifies flags
1978;------------------------------------------------------------------------------
1979DriveIO_IsValidHarddisk Proc Near Uses dx
1980 cmp dl, 80h ; BIOS disk number must be at least 80h
1981 jb @F ; Not a harddisk, exit with CY
1982 mov dh, dl ; Save to do compare
1983 sub dh, 80h ; Now 0 based disk number
1984 inc dh ; Now 1 based disk number
1985 cmp [TotalHarddiscs], dh ; Out of range, exit with CY
1986 @@: ret
1987DriveIO_IsValidHarddisk EndP
1988
1989
1990; Values for sectors per track table corresponding to DriveIO_IsHugeDrive return value.
1991;~ secs_per_track_table db 63,127,255,255,255,255
1992
1993;~ db_lmlvm db 'Load Master LVM -- disk: ',0
Note: See TracBrowser for help on using the repository browser.