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

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

Updated debugging state [v1.1.1-testing]

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

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