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

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

Skip disks with a GPT (0xee) Identifier [v1.1.3-testing]

This is a quick-n-dirty hack to skip GPT disks.
GPT disks are not truly recognized and this hack has the semantics of
the disk having no partitions.

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.2-manual.pdf

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