source: trunk/bootcode/regular/driveio.asm

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

Skip disks with a LUKS Signature [v1.1.3-testing]

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