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

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

Updated debug hooks (debugging) [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: 56.0 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: AX, BX, CX, DX, CF
32DriveIO_CheckFor13extensions Proc Near
33 mov ah, 41h
34 mov bx, 55AAh
35 mov dl, [BIOS_BootDisk] ; We check using the boot-disk
36 int 13h
37 jc PCCF13E_NotFound ; Error occured
38 cmp bx, 0AA55h
39 je PCCF13E_Found
40 PCCF13E_NotFound:
41 ret
42 PCCF13E_Found:
43 and cx, 1 ; Check 42h-44h,47h,48h supported
44 jz PCCF13E_NotFound ; Sig OK but no support, strange beast
45 mov byte ptr [CurIO_UseExtension], 1
46 ret
47DriveIO_CheckFor13extensions EndP
48
49
50; Note: Some routines set DS/ES to CS or even address via CS, even if its not
51; needed. This was done for SECURITY. So DO NOT remove it.
52; Its there to make sure the correct data is loaded/written to/from
53; harddrive.
54;
55; IF YOU MODIFY ANYTHING IN HERE, YOU MAY EASILY BREAK YOUR HARDDRIVE!
56
57; Will only load base-configuration, will NOT load IPT nor Hide-Config
58; Those are originally loaded on startup and will NOT get reloaded.
59DriveIO_LoadConfiguration Proc Near Uses ax bx cx dx es
60
61IFDEF AUX_DEBUG
62 IF 0
63 pushf
64 pusha
65 push si
66 mov si, offset $+5
67 jmp @F
68 db 10,'DriveIO_LoadConfiguration:',10,0
69 @@:
70 call AuxIO_Print
71 pop si
72 ;~ call DEBUG_DumpRegisters
73 ;~ call AuxIO_DumpParagraph
74 ;~ call AuxIO_TeletypeNL
75 popa
76 popf
77 ENDIF
78ENDIF
79
80 mov ax, cs
81 mov es, ax
82 mov bx, offset Configuration
83 xor dh, dh
84 mov dl, [BIOS_BootDisk] ; Disk we booted from
85 mov cx, 0037h ; Sector 55 (CHS)
86 mov ax, 0201h ; Function 02, read 1 sector...
87 int 13h
88 jnc DIOLC_NoError
89 call MBR_LoadError ; Will Abort BootUp
90 DIOLC_NoError:
91 ret
92DriveIO_LoadConfiguration EndP
93
94DriveIO_SaveConfiguration Proc Near Uses ax bx cx dx ds es si
95
96IFDEF AUX_DEBUG
97 IF 0
98 pushf
99 pusha
100 push si
101 mov si, offset $+5
102 jmp @F
103 db 10,'DriveIO_SaveConfiguration:',10,0
104 @@:
105 call AuxIO_Print
106 pop si
107 ;~ call DEBUG_DumpRegisters
108 ;~ call AuxIO_DumpParagraph
109 ;~ call AuxIO_TeletypeNL
110 popa
111 popf
112 ENDIF
113ENDIF
114
115 mov ax, cs
116 mov ds, ax
117 mov es, ax ; Safety first (CS==DS==ES)
118 ; --- Overwrite Floppy-Name with "FloppyDrive"
119 mov si, offset TXT_Floppy_Drive
120 mov di, offset PartitionTable
121 sub di, 30 ; Adjust to Floppy-Name
122 mov cx, 11
123 rep movsb
124 mov si, offset Configuration ; Calculate new checksum
125 xor bx, bx
126
127 ; Changed from 5 to calculated value (not here, see compat. issue below)
128 ; Fixes issue: #2987 -- "air-boot doesn't remember drive letter"
129 ; Size of the ab-configuration in 512 byte sectors
130 ;mov cx, (MBR_BackUpMBR - Configuration) / 200h
131
132 ; AB v1.07 stores a 5 sector configuration with a 5 sector checksum.
133 ; AB v1.0.8+ *should* stores a 7 sector configuration with a
134 ; 7 sector checksum.
135 ; Because 5 was hardcoded here, SET(A)BOOT v1.07 will see see an AB v1.0.8+
136 ; config as corrupted, while this is not the case.
137 ; So, for compatibility reasons, in v1.0.8+, the checksum stored is over
138 ; 5 sectors, to be compatible with v1.07.
139 ; This may change (be corrected) in future versions !
140 mov cx,5
141
142 mov dx, [CFG_CheckConfig]
143 mov [CFG_CheckConfig], bx
144 DIOSC_Loop:
145 call MBR_GetCheckOfSector
146 loop DIOSC_Loop
147 mov [CFG_CheckConfig], bx
148 ; --------------------------------------------------------------------
149 ; ES == CS
150 mov bx, offset Configuration
151 xor dh, dh
152 mov dl, [BIOS_BootDisk] ; Disk we booted from
153 mov cx, 0037h ; Sector 55 (CHS)
154
155 ; Changed from 5 to calculated value
156 ; Fixes issue: #2987 -- "air-boot doesn't remember drive letter"
157 ; Size of the ab-configuration in 512 byte sectors
158 mov al, (MBR_BackUpMBR - Configuration) / 200h
159 mov ah,03h
160
161 int 13h
162 jnc DIOSC_NoError
163 call MBR_SaveError ; Will Abort BootUp
164 DIOSC_NoError:
165 ret
166DriveIO_SaveConfiguration EndP
167
168DriveIO_UpdateFloppyName Proc Near Uses bx cx dx ds si es di
169 mov ax, cs
170 mov ds, ax
171 mov es, ax
172
173 mov ah, 00h ; Function 0 - Reset Drive
174 xor dl, dl
175 int 13h
176 xor dx, dx ; Cylinder=0, Head=0
177 mov cx, 1 ; Sector=1, Drive=0
178 mov bx, offset TmpSector ; ES:BX - TmpSector
179 mov ax, 0201h ; Function 2 - Load Sector
180 int 13h
181 jnc DIOUFN_AllFine
182
183 ; --- Overwrite Floppy-Name with "No Disc"
184 mov si, offset TXT_Floppy_NoDisc
185 xor ax, ax
186 DIOUFN_WriteFloppyName:
187 mov di, offset PartitionTable
188 sub di, 30 ; Adjust to Floppy-Name
189 mov cl, 11
190 rep movsb
191 ret ; AX=-1 -> GotDisc, =0 -> NoDisc
192
193 ; --- Floppy found and read, data in TempSector
194 DIOUFN_AllFine:
195 mov ax, -1
196 mov si, offset TXT_Floppy_NoName
197 cmp wptr es:[bx+54], 'AF'
198 jne DIOUFN_WriteFloppyName
199 cmp wptr es:[bx+56], '1T'
200 jne DIOUFN_WriteFloppyName
201 cmp bptr es:[bx+58], '2'
202 jne DIOUFN_WriteFloppyName
203 mov si, bx
204 add si, 43 ; FAT12 - Volume Label Location
205 jmp DIOUFN_WriteFloppyName
206DriveIO_UpdateFloppyName EndP
207
208; =============================================================================
209; HARDDRIVE / GENERAL ACCESS
210; =============================================================================
211; The following routines are used for harddisc/floppy access.
212; The access is done via INT 13h/CHS or INT 13h/LBA.
213; Access will be done prefered by INT 13h/CHS, because it's (I wonder!) much
214; faster, than the LBA-method. I don't know, why LBA is so slow. Perhaps BIOS.
215;
216; Internal access (to AiR-BOOT) is always done via INT 13h/CHS.
217
218DriveIO_GetHardDriveCount Proc Near Uses ds si
219 push ds
220 push si
221 push 0040h
222 pop ds
223 mov si, 0075h
224 mov dh, ds:[si] ; 40:75 -> POST: Total Harddiscs == DL
225 pop si
226 pop ds
227 mov [TotalHarddiscs], dh
228 ret
229DriveIO_GetHardDriveCount EndP
230
231
232; Fills our LBA-Usage table. It holds the LBA-address, where BIOS/CHS access is
233; stopped and BIOS/LBA access is started.
234; This is calculated by Sector*Heads. Comparing will get done with Bit 25-10
235; on LBA sectors, so we actually divide sector number by 1024.
236DriveIO_InitLBASwitchTable Proc Near Uses es di
237 mov di, offset LBASwitchTable
238 mov dh, [TotalHarddiscs]
239 mov dl, 80h ; First disk to process
240 DIOILUT_DriveLoop:
241 push dx
242 push di
243 mov ah, 08h
244 int 13h ; DISK - GET DRIVE PARAMETERS
245 mov ah, 0FBh ; Assume 255 heads/63 sectors, if error
246 jc DIOILUT_Error
247 and cl, 111111b ; Isolate lower 6 bits of CL -> sector count
248
249 ;movzx ax, cl
250 mov al,cl
251 mov ah,0
252
253 mov bl, dh ; DH -> max head number
254 mul bl ; AX = Sectors*Heads
255 shl ah, 1
256 shl ah, 1 ; Shift 2 bits, so we are able to compare to
257 ; bit 16-23 of the LBA address
258 DIOILUT_Error:
259 pop di
260 pop dx
261 mov bptr ds:[di], ah ; Save that value
262 inc di ; Go to next BYTE
263 inc dl ; Next disk
264 dec dh ; Decrease disks to process
265 jnz DIOILUT_DriveLoop ; Next disk if DH != 0
266 ret
267DriveIO_InitLBASwitchTable EndP
268
269
270
271
272;FIXME: Only LBA gets updated, need to update CHS too !!!!!!!
273
274; Adjusts BX:AX / CX:DX to meet LVM sector location
275; BX:AX / CX:DX point to MBR or EBR !
276; Destroys SI
277; Rousseau: Enhanced to handle sector-numbers 127 and 255 besides 63 for LVM-info sectors.
278; Ugly, need to cleanup.
279DriveIO_LVMAdjustToInfoSector Proc Near
280
281IFDEF AUX_DEBUG
282 IF 0
283 pusha
284 push si
285 mov si, offset $+5
286 jmp @F
287 db 10,'DriveIO_LVMAdjustToInfoSector:',10,0
288 @@:
289 call AuxIO_Print
290 pop si
291 call DEBUG_DumpRegisters
292 ;~ call AuxIO_DumpParagraph
293 ;~ call AuxIO_TeletypeNL
294 popa
295 ENDIF
296ENDIF
297
298 push cx ; Save Cyl/Sec part
299 xor ch,ch ; Clear low Cyl part
300 and cl,63 ; Clear high Cyl part
301 push bx ; We need BX...
302 push dx ; and DX temoraily
303 mov bx,offset [TrueSecs] ; Offset of sector table
304 xor dh,dh ; Clear DH because we use DL as index
305 and dl,01111111b ; Remove high bit of BIOS disk-nr
306 shl dx,2 ; Index to DWORD table
307 add bx,dx ; Point to TrueSecs for this disk
308 mov si,[bx] ; Get SPT for this disk
309 pop dx ; Restore DX...
310 pop bx ; and BX
311 ;~ sub si,cx ; Adjust offset !! INCORRECT FOR LBA (TP CX != 0 !!)
312 dec si
313 pop cx ; Restore Cyl/Sec part
314 add ax,si ; Add offset to low part...
315 adc bx,0 ; and high part of LBA address
316 or cl,63 ; Adjust CHS part !FIX ME for > 63! !! FIX HUGE DRIVE !!
317
318IFDEF AUX_DEBUG
319 IF 0
320 pusha
321 push si
322 mov si, offset $+5
323 jmp @F
324 db 10,'adjusted',10,0
325 @@:
326 call AuxIO_Print
327 pop si
328 call DEBUG_DumpRegisters
329 ;~ call AuxIO_DumpParagraph
330 ;~ call AuxIO_TeletypeNL
331 popa
332 ENDIF
333ENDIF
334
335 ret
336
337DriveIO_LVMAdjustToInfoSector EndP
338
339
340
341
342
343
344; #########################################################################
345; Routine: Loads partition to ExecBase and checks for validity
346; #########################################################################
347; Calling : bx:ax - Absolute sector
348; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
349; Returns : Carry Set if invalid partition encountered
350; Preserve: all registers
351; #########################################################################
352DriveIO_LoadPartition Proc Near Uses si
353 mov wptr cs:[CurPartition_Location+0], ax
354 mov wptr cs:[CurPartition_Location+2], bx
355 mov wptr cs:[CurPartition_Location+4], dx
356 mov wptr cs:[CurPartition_Location+6], cx ; Saves the location
357 mov si, offset PartitionSector ; DS:SI - ExecBase
358 call DriveIO_LoadSector
359 clc
360 cmp wptr [si+LocBR_Magic], 0AA55h
361 je DIOLP_Success
362 ; We check, if we are scanning partitions. In that case, if CHS is not 0/0/1
363 ; we will display a "bad partition table" message and halt the system.
364 cmp cx, 0001h
365 jne DIOLP_Failed
366 or dh, dh
367 jnz DIOLP_Failed
368 stc ; Set carry, so no partition table
369 DIOLP_Success:
370
371 IFDEF AUX_DEBUG
372 ; show current partition location
373 ;~ pushf
374 ;~ pusha
375 ;~ call AuxIO_TeletypeNL
376 ;~ mov si,offset db_curpartloc
377 ;~ call AuxIO_Print
378 ;~ mov dx,word ptr [CurPartition_Location+02]
379 ;~ mov ax,word ptr [CurPartition_Location+00]
380 ;~ call AuxIO_TeletypeHexDWord
381 ;~ call AuxIO_TeletypeNL
382 ;~ mov si,offset PartitionSector
383 ;~ call AuxIO_DumpSector
384 ;~ call AuxIO_TeletypeNL
385 ;~ popa
386 ;~ popf
387 ENDIF
388
389 ret
390 DIOLP_Failed:
391 jmp DriveIO_GotLoadError
392DriveIO_LoadPartition EndP
393
394; #########################################################################
395; Routine: Writes a partition from ExecBase to its original sector
396; #########################################################################
397; Calling : none
398; Returns : none
399; Preserve: all registers
400; #########################################################################
401DriveIO_SavePartition Proc Near Uses ax bx cx dx si
402
403IFDEF AUX_DEBUG
404 IF 0
405 pushf
406 pusha
407 push si
408 mov si, offset $+5
409 jmp @F
410 db 10,'DriveIO_SavePartition:',10,0
411 @@:
412 call AuxIO_Print
413 pop si
414 ;~ call DEBUG_DumpRegisters
415 ;~ call AuxIO_DumpParagraph
416 ;~ call AuxIO_TeletypeNL
417 popa
418 popf
419 ENDIF
420ENDIF
421
422 mov ax, wptr cs:[CurPartition_Location+0]
423 mov bx, wptr cs:[CurPartition_Location+2]
424 mov dx, wptr cs:[CurPartition_Location+4]
425 mov cx, wptr cs:[CurPartition_Location+6] ; Gets prev. saved location
426 mov si, offset PartitionSector ; DS:SI - ExecBase
427 cmp wptr [si+LocBR_Magic], 0AA55h ; Checks for signature, if not found
428 jne DIOSP_SevereError ; we assume a really bad error
429 call DriveIO_SaveSector
430 DIOSP_SevereError:
431 ret
432DriveIO_SavePartition EndP
433
434; Keeps DS:SI for caller
435DriveIO_LoadTmpSector Proc Near
436 mov si, offset TmpSector
437 call DriveIO_LoadSector
438 ret
439DriveIO_LoadTmpSector EndP
440
441; Keeps DS:SI for caller
442DriveIO_SaveTmpSector Proc Near
443 mov si, offset TmpSector
444 call DriveIO_SaveSector
445 ret
446DriveIO_SaveTmpSector EndP
447
448
449
450; Keeps DS:SI for caller, sets carry if valid LVM sector encountered
451DriveIO_LoadLVMSector Proc Near Uses ax bx cx dx
452
453IFDEF AUX_DEBUG
454 IF 0
455 pushf
456 pusha
457 push si
458 mov si, offset $+5
459 jmp @F
460 db 10,'DriveIO_LoadLVMSector:',10,0
461 @@:
462 call AuxIO_Print
463 pop si
464 ;~ call DEBUG_DumpRegisters
465 ;~ call AuxIO_DumpParagraph
466 ;~ call AuxIO_TeletypeNL
467 popa
468 popf
469 ENDIF
470ENDIF
471
472 test byte ptr [CFG_IgnoreLVM], 1 ; We are supposed to ignore LVM, so
473 jnz DIOLLVMS_NoLVMSector ; don't load but declare as bad!
474 mov ax, wptr cs:[CurPartition_Location+0]
475 mov bx, wptr cs:[CurPartition_Location+2]
476 mov dx, wptr cs:[CurPartition_Location+4]
477 mov cx, wptr cs:[CurPartition_Location+6] ; Gets cur. partition location
478
479 call DriveIO_LVMAdjustToInfoSector
480
481 mov si, offset LVMSector
482 call DriveIO_LoadSector
483
484 IFDEF AUX_DEBUG
485 ; show current partition location
486 ;~ pushf
487 ;~ pusha
488 ;~ call AuxIO_TeletypeNL
489 ;~ mov si,offset db_curlvmsec
490 ;~ call AuxIO_Print
491 ;~ mov dx,bx
492 ;~ call AuxIO_TeletypeHexDWord
493 ;~ call AuxIO_TeletypeNL
494 ;~ mov si,offset LVMSector
495 ;~ call AuxIO_DumpSector
496 ;~ call AuxIO_TeletypeNL
497 ;~ popa
498 ;~ popf
499 ENDIF
500
501 call LVM_CheckSectorSignature
502 jnc DIOLLVMS_NoLVMSector
503 call LVM_CheckSectorCRC
504 jnc DIOLLVMS_NoLVMSector
505 ret
506 ; This here is called, if an invalid (or no) LVM information sector is found
507 ; It will truncate the first byte of the sector, so all other routines
508 ; will notice it easily by just comparing the first byte.
509 DIOLLVMS_NoLVMSector:
510 mov bptr [si+LocLVM_SignatureStart], 0
511 ret
512DriveIO_LoadLVMSector EndP
513
514
515
516; Keeps DS:SI for caller, saves at anytime w/o checks (!)
517DriveIO_SaveLVMSector Proc Near Uses ax bx cx dx
518
519IFDEF AUX_DEBUG
520 IF 0
521 pushf
522 pusha
523 push si
524 mov si, offset $+5
525 jmp @F
526 db 10,'DriveIO_SaveLVMSector:',10,0
527 @@:
528 call AuxIO_Print
529 pop si
530 ;~ call DEBUG_DumpRegisters
531 ;~ call AuxIO_DumpParagraph
532 ;~ call AuxIO_TeletypeNL
533 popa
534 popf
535 ENDIF
536ENDIF
537
538 test byte ptr [CFG_IgnoreLVM], 1 ; We are supposed to ignore LVM, so
539 jnz DIOSLVMS_SevereError ; don't save at anytime (security!)
540 mov ax, wptr cs:[CurPartition_Location+0]
541 mov bx, wptr cs:[CurPartition_Location+2]
542 mov dx, wptr cs:[CurPartition_Location+4]
543 mov cx, wptr cs:[CurPartition_Location+6] ; Gets cur. partition location
544 call LVM_CheckSectorSignature
545 jnc DIOSLVMS_SevereError ; LVM Signature must be there
546
547 IFDEF AUX_DEBUG
548;~ dioatlvm db 'DriveIO_LVMAdjustToInfoSector',10,0
549 ;~ pushf
550 ;~ pusha
551 ;~ mov si,offset dioatlvm
552 ;~ call AuxIO_Print
553 ;~ popa
554 ;~ popf
555 call DEBUG_DumpRegisters
556 call DEBUG_DumpCHS
557 ENDIF
558
559 call DriveIO_LVMAdjustToInfoSector
560
561 IFDEF AUX_DEBUG
562 call DEBUG_DumpRegisters
563 call DEBUG_DumpCHS
564 ENDIF
565
566 mov si, offset LVMSector
567 call DriveIO_SaveSector
568 DIOSLVMS_SevereError:
569 ret
570DriveIO_SaveLVMSector EndP
571
572
573
574; Special error message instead of "LOAD ERROR" during partition scanning,
575; so users will notice that something is bad with their partition table(s)
576DriveIO_GotLoadError Proc Near
577 test byte ptr cs:[CurIO_Scanning], 1 ; Must be CS:, cause DS!=CS maybe here
578 jnz InScanMode
579 jmp MBR_LoadError
580 InScanMode:
581 mov si, offset TXT_BrokenPartitionTable
582 push cs
583 pop ds
584 call MBR_Teletype
585 mov si, offset BrokenHDD
586 sub dl, 50h ; 80h -> '0'
587 cmp dl, 39h
588 jbe DIOGLE_BelowA
589 add dl, 7 ; 3Ah -> 'A'
590 DIOGLE_BelowA:
591 mov bptr [si+5], dl
592 call MBR_Teletype
593
594 ; JWasm: cannot jump to local label in other procedure.
595 ; Changed to halt here.
596 ;jmp MBRLE_Halt
597 DriveIO_GotLoadError_halt:
598 jmp DriveIO_GotLoadError_halt
599DriveIO_GotLoadError EndP
600
601; #########################################################################
602; Routine: Loads a specified sector to DS:DI
603; #########################################################################
604; Calling : bx:ax - Absolute sector
605; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
606; ds:si - Destination-Adress
607; Returns : none
608; Preserve: all registers
609; #########################################################################
610DriveIO_LoadSector Proc Near Uses ax bx cx dx ds si es di
611
612IFDEF AUX_DEBUG
613 IF 0
614 pushf
615 pusha
616 push si
617 mov si, offset $+5
618 jmp @F
619 db 10,'DriveIO_LoadSector:',10,0
620 @@:
621 call AuxIO_Print
622 pop si
623 ;~ call DEBUG_DumpRegisters
624 ;~ call AuxIO_DumpParagraph
625 ;~ call AuxIO_TeletypeNL
626 popa
627 popf
628 ENDIF
629ENDIF
630
631 ; Is the drive not a harddrive?
632 cmp dl, 80h
633 jb DIOLS_UseNormal
634
635 test byte ptr cs:[CurIO_UseExtension], 1
636 jz DIOLS_UseNormal
637 ; Are we forced do use LBA via Setting?
638 jnz DIOLS_UseExtension
639
640 ; Upper 8 bits of LBA-address set?
641 ; Then use LBA (maximum boundary is 16320x16x63 = FB0400h)
642 or bh, bh
643 jnz DIOLS_UseExtension
644 ; Compare Switch-Table value to bit 16-23 of LBA-address
645 mov di, dx
646 and di, 007Fh
647 cmp bptr cs:[LBASwitchTable+di], bl
648 jbe DIOLS_UseExtension
649
650 DIOLS_UseNormal:
651
652IFDEF AUX_DEBUG
653 IF 0
654 pusha
655 push si
656 mov si, offset $+5
657 jmp @F
658 db 10,'DriveIO_ReadSectorCHS:',10,0
659 @@:
660 call AuxIO_Print
661 pop si
662 call DEBUG_DumpRegisters
663 call AuxIO_DumpParagraph
664 call AuxIO_TeletypeNL
665 popa
666 ENDIF
667ENDIF
668
669 mov di, 3 ; retry count
670 DIOLS_ErrorLoop:
671 push ds
672 pop es
673 mov bx, si ; ES:BX - Destination
674 mov ax, 0201h ; Function 2 - Load Sector
675 int 13h
676 jnc DIOLS_Success
677 dec di ; decrement retry count
678 jnz DIOLS_ErrorLoop
679
680 ; Sector load failed...
681 jmp DriveIO_GotLoadError
682
683 DIOLS_UseExtension:
684
685 mov di, ds ; segment for transfer address
686 mov cx, ax ; low word of lba
687 call DriveIO_ReadSectorLBA ; extended read
688 jc DriveIO_GotLoadError ; halt on error
689
690 ;~ push cx
691 ;~ mov cs:[INT13X_DAP_NumBlocks], 1 ; Copy ONE sector
692 ;~ mov wptr cs:[INT13X_DAP_Transfer+0], si
693 ;~ mov cx, ds
694 ;~ mov wptr cs:[INT13X_DAP_Transfer+2], cx ; Fill out Transfer Adress
695 ;~ mov wptr cs:[INT13X_DAP_Absolute+0], ax
696 ;~ mov wptr cs:[INT13X_DAP_Absolute+2], bx ; Fill out Absolute Sector
697 ;~ push cs
698 ;~ pop ds
699 ;~ mov si, offset [INT13X_DAP]
700 ;~ mov ah, 42h ; Extended Read
701 ;~ int 13h
702 ;~ pop cx
703 ;~ jnc DIOLS_Success
704
705 ; Sector load failed...
706 ;~ jmp DriveIO_GotLoadError
707
708 DIOLS_Success:
709 ret
710DriveIO_LoadSector EndP
711
712
713
714;##############################################################################
715;# ACTION : Reads a sector from disk using INT13 extensions
716;# ----------------------------------------------------------------------------
717;# IN : BX:CX - LBA address of sector
718;# : DI:SI - SEG:OFF of transfer buffer
719;# ----------------------------------------------------------------------------
720;# OUT : CF=1 - failure, AH failure code
721;# ----------------------------------------------------------------------------
722;# EFFECTS : Modifies DAP structure and fills transfer buffer
723;##############################################################################
724DriveIO_ReadSectorLBA Proc Near Uses bx cx dx si di ds es
725
726IFDEF AUX_DEBUG
727 IF 0
728 pushf
729 pusha
730 push si
731 mov si, offset $+5
732 jmp @F
733 db 10,'DriveIO_ReadSectorLBA:',10,0
734 @@:
735 call AuxIO_Print
736 pop si
737 call DEBUG_DumpRegisters
738 call AuxIO_DumpParagraph
739 call AuxIO_TeletypeNL
740 popa
741 popf
742 ENDIF
743ENDIF
744
745 ; One sector to read
746 mov cs:[INT13X_DAP_NumBlocks], 1
747
748 ; Setup transfer address
749 mov wptr cs:[INT13X_DAP_Transfer+0], si ; offset
750 mov wptr cs:[INT13X_DAP_Transfer+2], di ; segment
751
752 ; Setup LBA64 address of requested sector
753 mov wptr cs:[INT13X_DAP_Absolute+0], cx ; low word lower part
754 mov wptr cs:[INT13X_DAP_Absolute+2], bx ; high word lower part
755 mov wptr cs:[INT13X_DAP_Absolute+4], 0 ; low word upper part
756 mov wptr cs:[INT13X_DAP_Absolute+6], 0 ; high word upper part
757
758 ; Address of packet
759 mov si, offset [INT13X_DAP] ; disk address packet
760
761 ; Do the extended read
762 mov ah, 42h ; read function
763 int 13h ; transfer to bios
764
765 ; Error occured
766 jc DriveIO_ReadSectorLBA_exit
767
768 ; AH should also be zero
769 test ah, ah
770 stc
771 jnz DriveIO_ReadSectorLBA_exit
772
773 ; Disk read succeeded, clear CF
774 clc
775
776 DriveIO_ReadSectorLBA_exit:
777 ret
778
779DriveIO_ReadSectorLBA EndP
780
781
782
783;##############################################################################
784;# ACTION : Writes a sector to disk using INT13 extensions
785;# ----------------------------------------------------------------------------
786;# IN : AL - write flags, AL.0 verify (1.0,2.0), AL.1 verify (2.1+)
787;# : BX:CX - LBA address of sector
788;# : DI:SI - SEG:OFF of transfer buffer
789;# ----------------------------------------------------------------------------
790;# OUT : CF=1 - failure, AH failure code
791;# ----------------------------------------------------------------------------
792;# EFFECTS : Modifies DAP structure and mofifies the disk
793;##############################################################################
794DriveIO_WriteSectorLBA Proc Near Uses bx cx dx si di ds es
795
796IFDEF AUX_DEBUG
797 IF 0
798 pusha
799 push si
800 mov si, offset $+5
801 jmp @F
802 db 10,'DriveIO_WriteSectorLBA:',10,0
803 @@:
804 call AuxIO_Print
805 pop si
806 call DEBUG_DumpRegisters
807 call AuxIO_DumpParagraph
808 call AuxIO_TeletypeNL
809 popa
810 ENDIF
811ENDIF
812
813 ; Mask reserved bits for wrte flags -- should check version here
814 and al, 03h
815
816 ; One sector to read
817 mov cs:[INT13X_DAP_NumBlocks], 1
818
819 ; Setup transfer address
820 mov wptr cs:[INT13X_DAP_Transfer+0], si ; offset
821 mov wptr cs:[INT13X_DAP_Transfer+2], di ; segment
822
823 ; Setup LBA64 address of requested sector
824 mov wptr cs:[INT13X_DAP_Absolute+0], cx ; low word lower part
825 mov wptr cs:[INT13X_DAP_Absolute+2], bx ; high word lower part
826 mov wptr cs:[INT13X_DAP_Absolute+4], 0 ; low word upper part
827 mov wptr cs:[INT13X_DAP_Absolute+6], 0 ; high word upper part
828
829 ; Address of packet
830 mov si, offset [INT13X_DAP] ; disk address packet
831
832 ; Do the extended write
833 mov ah, 43h ; write function
834 int 13h ; transfer to bios
835
836 ; Error occured
837 jc DriveIO_WriteSectorLBA_exit
838
839 ; AH should also be zero
840 test ah, ah
841 stc
842 jnz DriveIO_WriteSectorLBA_exit
843
844 ; Disk write succeeded, clear CF
845 clc
846
847 DriveIO_WriteSectorLBA_exit:
848 ret
849
850DriveIO_WriteSectorLBA EndP
851
852
853
854;
855; ############################################################
856; # Check for a valid MBR-sector to be written to disk #
857; ############################################################
858;
859; In
860; --
861; DL = Physical Disk
862; BX:CX = LBA sector
863; DI:SI = Source buffer
864;
865; Out
866; ---
867; CY = 1 if invalid MBR in source buffer, 0 if valid
868;
869; This routine is called when DriveIO_SaveSector attempts to write to the MBR.
870; It checks if the sector to be written has some sensible values in certain
871; places. In fact, if the sector is written to the boot-disk, the AiR-BOOT
872; signature should be present and the partition table should be the same
873; as the one at the start of the AiR-BOOT code in memory, except maybe for the
874; active flags.
875; For other disks, only the active flags are checked to be 00h or 80h and
876; the AA55h MBR signature.
877;
878DriveIO_ProtectMBR Proc Near
879 pusha ; Push all registers
880 push es ; Push ES because we need it for string instructions
881 push cs ; Make ES point...
882 pop es ; to CS
883
884 ; Save the pointer to the sector to write in BX
885 mov bx,si
886
887 ;
888 ; If the sector to be written is not the boot-disk, then skip
889 ; checking the AiR-BOOT MBR.
890 ;
891 cmp dl, [BIOS_BootDisk]
892 jne DriveIO_ProtectMBR_is_not_bootdisk
893
894 ;
895 ; The boot-disk is accessed so the sector to be written must be
896 ; the AiR-BOOT MBR. This is the same as the first 512 bytes
897 ; relocated to 8000:0000 and this the start of the AB-code.
898 ;
899 mov si,bx ; Get pointer to sector to write
900 xor di,di ; Point DI to start of AB-code (MBR)
901 mov cx, offset [MBR_PartTable] ; Bytes upto P-table must be same
902 cld ; Compare upwards
903 repe cmpsb ; Compare upto P-table
904
905 ; If not the same this is not the an AiR-BOOT boot-disk MBR !
906 jne DriveIO_ProtectMBR_not_valid_MBR ; SEVERE ERROR !
907
908 ; Continue with signature check
909 jmp DriveIO_ProtectMBR_check_signature
910
911
912 ;
913 ; The disk is not the boot-disk so we don't know what kind of MBR is on it.
914 ; Some sanity checks should be here.
915 ;
916 DriveIO_ProtectMBR_is_not_bootdisk:
917
918 ;
919 ; sanity checks...
920 ;
921
922 ; Continue with signature check
923 jmp DriveIO_ProtectMBR_check_signature
924
925
926 DriveIO_ProtectMBR_check_signature:
927 ; See if the sector to write contains a valid signature
928 mov si,bx ; Get pointer to sector to write
929 mov di, offset [MBR_Sig] ; Offset to MBR signature
930 add si,di ; Make SI point to it in sec to write
931 lodsw ; Load it
932 cmp ax,0aa55h ; See if it is valid
933
934 ; If no signature this cannot be a valid MBR !
935 jne DriveIO_ProtectMBR_not_valid_MBR ; SEVERE ERROR !
936
937
938 ;
939 ; The sector to be written seems to be valid.
940 ; Set CY=0 to indicate a valid MBR.
941 ;
942 DriveIO_ProtectMBR_is_valid_MBR:
943 clc
944 jmp DriveIO_ProtectMBR_end
945
946 ;
947 ; Something is terribly wrong; a non-MBR sector seems about to be written.
948 ; Set CY=1 and let the calling code handle this situation.
949 ;
950 DriveIO_ProtectMBR_not_valid_MBR:
951 stc
952 jmp DriveIO_ProtectMBR_end
953
954 ;
955 ; Return to the caller with no registers modyfied except FLAGS.
956 ;
957 DriveIO_ProtectMBR_end:
958 pop es
959 popa
960 ret
961DriveIO_ProtectMBR Endp
962
963
964
965; #########################################################################
966; Routine: Checks if the MBR is addressed by either CHS or LBA
967; #########################################################################
968; Calling : bx:ax - Absolute sector
969; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
970; Returns : ZF=1 if MBR is addressed, else ZF=0
971; Preserve: all registers
972; #########################################################################
973DriveIO_MBR_Addressed Proc
974 push ax
975 push bx
976
977 or bx,ax ; Results in 0 in BX if MBR is addressed by LBA
978 jz DriveIO_MBR_Addressed_done
979
980 mov ax,cx ; Results in 1 in AX if CYL 0, SEC 1 is addressed
981 add al,dh ; Results in 1 in AX if HEAD 0 is addressed
982 dec ax ; Results in 0 in AX if MBR is addressed by CHS
983
984 DriveIO_MBR_Addressed_done:
985 pop bx
986 pop ax
987 ret
988DriveIO_MBR_Addressed EndP
989
990
991
992
993; #########################################################################
994; Routine: Writes DS:SI to a specified sector
995; #########################################################################
996; Calling : bx:ax - Absolute sector
997; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
998; ds:si - Source-Adress
999; Returns : none
1000; Preserve: all registers
1001; #########################################################################
1002DriveIO_SaveSector Proc Near Uses ax bx cx dx ds si es di
1003
1004IFDEF AUX_DEBUG
1005 IF 0
1006 pushf
1007 pusha
1008 push si
1009 mov si, offset $+5
1010 jmp @F
1011 db 10,'DriveIO_SaveSector:',10,0
1012 @@:
1013 call AuxIO_Print
1014 pop si
1015 ;~ call DEBUG_DumpRegisters
1016 ;~ call AuxIO_DumpParagraph
1017 ;~ call AuxIO_TeletypeNL
1018 popa
1019 popf
1020 ENDIF
1021ENDIF
1022
1023 ;!
1024 ;! DEBUG_BLOCK
1025 ;! Force write to LBA0 to test interception routine.
1026 ;! Do *NOT* enable unless you are debugging, will overwrite MBR !
1027 ;!
1028 ;~ __DIO_FORCE_LBA0_WRITE__ EQU
1029 IFDEF AUX_DEBUG
1030 IFDEF __DIO_FORCE_LBA0_WRITE__
1031 xor ax,ax
1032 xor bx,bx
1033 xor cx,cx
1034 inc cx
1035 xor dh,dh
1036 ENDIF
1037 ENDIF
1038
1039 ;
1040 ; Check if the MBR is the destination for the write.
1041 ; ZF=1 if so.
1042 ;
1043 call DriveIO_MBR_Addressed
1044 jnz DriveIO_SaveSector_continue_write
1045
1046
1047 ; MBR is addressed, check the sector that is requested to be written.
1048 ; For the bootdisk it should contain the AiR-BOOT signature, valid
1049 ; partition-table entries and the AA55h signature.
1050 ; If not, something is terribly wrong in some piece of the AB code.
1051 ; For any other disk (80h+) at least a valid partition table should
1052 ; be present together with the AA55h signature.
1053 call DriveIO_ProtectMBR
1054 jnc DriveIO_SaveSector_continue_write
1055
1056
1057 ;
1058 ; WE HAVE A SEVERE ERROR CONDITION !
1059 ; SOME AB CODE TRIES TO WRITE A NON-MBR TO THE DISK !
1060 ; ASK THE USER TO REPORT THIS !
1061 ; HALT THE SYSTEM !
1062 ;
1063
1064 ; Show error-box
1065 mov cx, 0C04h
1066 mov si, offset NonMBRwrite
1067 call SETUP_ShowErrorBox
1068 mov cx, 0C04h
1069 mov si, offset NonMBRwrite_rep
1070 call SETUP_ShowErrorBox
1071
1072
1073 IFDEF AUX_DEBUG
1074 pusha
1075 mov si, offset NonMBRwrite
1076 call AuxIO_TeletypeNL
1077 call AuxIO_Print
1078 call AuxIO_TeletypeNL
1079 popa
1080 ENDIF
1081
1082 ; Show popup and halt the system.
1083 jmp HaltSystem
1084
1085
1086
1087 ;
1088 ; Continue the write if not MBR sector or MBR to write is validated.
1089 ;
1090 DriveIO_SaveSector_continue_write:
1091 test byte ptr cs:[CurIO_UseExtension], 1
1092 jz DIOSS_UseNormal
1093 ; Are we forced do use LBA via Setting?
1094 ; Always use INT13X on v1.0.8+.
1095 ;~ test byte ptr cs:[CFG_ForceLBAUsage], 1
1096 ;~ jnz DIOSS_UseExtension
1097 jmp DIOSS_UseExtension
1098 ; Is the drive not a harddrive?
1099 cmp dl, 80h
1100 jb DIOSS_UseNormal
1101 ; Upper 8 bits of LBA-address set? -> Use LBA (maximum boundary is FB0400h)
1102 or bh, bh
1103 jnz DIOSS_UseExtension
1104 ; Compare Switch-Table value to bit 16-23 of LBA-address
1105 mov di, dx
1106 and di, 007Fh
1107 cmp bptr cs:[LBASwitchTable+di], bl
1108 jbe DIOSS_UseExtension
1109
1110 DIOSS_UseNormal:
1111
1112IFDEF AUX_DEBUG
1113 IF 0
1114 pusha
1115 push si
1116 mov si, offset $+5
1117 jmp @F
1118 db 10,'DriveIO_WriteSectorCHS:',10,0
1119 @@:
1120 call AuxIO_Print
1121 pop si
1122 call DEBUG_DumpRegisters
1123 call AuxIO_DumpParagraph
1124 call AuxIO_TeletypeNL
1125 popa
1126 ENDIF
1127ENDIF
1128
1129 mov di, 3 ; retry count
1130 DIOSS_ErrorLoop:
1131 push ds
1132 pop es
1133 mov bx, si ; ES:BX - Destination
1134 mov ax, 0301h ; Function 3 - Write Sector
1135 int 13h
1136 jnc DIOSS_Success
1137 dec di ; decrement retry count
1138 jnz DIOSS_ErrorLoop
1139 call MBR_SaveError
1140
1141 DIOSS_UseExtension:
1142
1143 mov di, ds ; segment for transfer address
1144 mov cx, ax ; low word of lba
1145 xor ax, ax ; no verify
1146 call DriveIO_WriteSectorLBA ; extended write
1147 jc MBR_SaveError ; halt on error
1148
1149 ;~ push cx
1150 ;~ mov cs:[INT13X_DAP_NumBlocks], 1 ; Copy ONE sector
1151 ;~ mov wptr cs:[INT13X_DAP_Transfer+0], si
1152 ;~ mov cx, ds
1153 ;~ mov wptr cs:[INT13X_DAP_Transfer+2], cx ; Fill out Transfer Adress
1154 ;~ mov wptr cs:[INT13X_DAP_Absolute+0], ax
1155 ;~ mov wptr cs:[INT13X_DAP_Absolute+2], bx ; Fill out Absolute Sector
1156 ;~ push cs
1157 ;~ pop ds
1158 ;~ mov si, offset [INT13X_DAP]
1159 ;~ mov ax, 4300h ; Extended Write (No Verify)
1160 ;~ int 13h
1161 ;~ pop cx
1162 ;~ jnc DIOSS_Success
1163 ;~ call MBR_SaveError
1164
1165 DIOSS_Success:
1166 ret
1167DriveIO_SaveSector EndP
1168
1169
1170
1171; ------------------------------------------------------
1172; Rousseau: # Load the master LVM-sector if one exists #
1173; ------------------------------------------------------
1174; Load the master LVM-sector to get the number of sectors per track as
1175; OS/2 views the drive. If no master LVM-sector is found it is assumed OS/2
1176; is not installed. The master LVM-sector can be located at three different
1177; places depending on drive size and partitioning scheme and driver used.
1178; When DANIS506.ADD is used, the OS/2 extended geometry will be 255/127 for
1179; drives >502GiB but <1TiB. Then the location will be sector 127 which
1180; is LBA 126 (7Eh).
1181; IBM1S506.ADD will always use 255/255 for the extended OS/2 geometry.
1182; DANIS506.ADD will use 255/255 for drives >1TiB.
1183; Then the location of the master LVM-sector will be 255 which is LBA 254 (FEh).
1184; When OS/2 is installed on a huge drive that alread had a system on it, OS/2
1185; will be confined to the lower 502GiB of the drive.
1186; In this case the normal geometry from Int13X will be used.
1187; This is also the case when no valid master LVM-sector can be found.
1188;
1189; Return CF when valid master LVM sector found, NC if not.
1190; Loads sector at [LVMSector] !
1191DriveIO_LoadMasterLVMSector Proc Near
1192
1193IFDEF AUX_DEBUG
1194 IF 0
1195 pushf
1196 pusha
1197 push si
1198 mov si, offset $+5
1199 jmp @F
1200 db 10,'DriveIO_LoadMasterLVMSector:',10,0
1201 @@:
1202 call AuxIO_Print
1203 pop si
1204 ;~ call DEBUG_DumpRegisters
1205 ;~ call AuxIO_DumpParagraph
1206 ;~ call AuxIO_TeletypeNL
1207 popa
1208 popf
1209 ENDIF
1210ENDIF
1211
1212 pusha
1213
1214 ; Loop over the sector-translation table,
1215 ; process the first three values from high (255) to low.
1216 ; (bios spt, most likely 63)
1217 mov cx,3
1218 DriveIO_LoadMasterLVMSector_NextTry:
1219 ; Number of sectors to read
1220 mov [INT13X_DAP_NumBlocks],1
1221
1222 ; Setup destination address
1223 mov si, offset [LVMSector]
1224 mov word ptr [INT13X_DAP_Transfer+0],si
1225 mov ax, ds
1226 mov word ptr [INT13X_DAP_Transfer+2],ax
1227
1228 ; Get the sector-number of the next possible LVM sector (255,127,63)
1229 ; using the translation table and the counter as the index
1230 mov bx,offset [secs_per_track_table]
1231 mov ax,cx ; 1-based index to sec_per_track_table
1232 dec ax ; Adjust to 0-based
1233 xlatb ; Get the (well known) SPT
1234 dec al ; Minus 1 for LVM-record
1235
1236 ;
1237 ; AX now contains the LBA address of the sector
1238 ; that could be an LVM sector.
1239 ; This is all in track0 so the address will not exceed 64kiB sectors.
1240 ;
1241
1242
1243IFDEF AUX_DEBUG
1244 IF 0
1245 pushf
1246 pusha
1247 push si
1248 mov si, offset $+5
1249 jmp @F
1250 db 10,'geo',10,0
1251 @@:
1252 call AuxIO_Print
1253 pop si
1254 call DEBUG_DumpRegisters
1255 call AuxIO_DumpParagraph
1256 call AuxIO_TeletypeNL
1257 popa
1258 popf
1259 ENDIF
1260ENDIF
1261
1262
1263 ; Setup the requested LBA sector number
1264 mov word ptr [INT13X_DAP_Absolute+0],ax ; LBA low NORMAL I/O GEBRUIKEN !
1265 mov word ptr [INT13X_DAP_Absolute+2],00h ; LBA high
1266 mov si, offset [INT13X_DAP] ; address request packet
1267 mov ah, 42h
1268 int 13h ; do the i/o, CF=1->error, CF=0->success
1269
1270IFDEF AUX_DEBUG
1271 IF 0
1272 pushf
1273 pusha
1274 pushf
1275 xor ax, ax
1276 mov al, dl
1277 call AuxIO_TeletypeHexWord
1278 mov al, '#'
1279 call AuxIO_Teletype
1280 popf
1281 mov ax,0000h
1282 rcl al, 1
1283 call AuxIO_TeletypeHexWord
1284 mov al, '#'
1285 call AuxIO_Teletype
1286 mov ax,word ptr [INT13X_DAP_Absolute+0]
1287 call AuxIO_TeletypeHexWord
1288 mov al, '#'
1289 call AuxIO_Teletype
1290 popa
1291 popf
1292 ENDIF
1293ENDIF
1294
1295 cmc ; Complement carry so we can exit imm. on error
1296 jnc DriveIO_LoadMasterLVMSector_End ; oops, return with NC
1297
1298
1299 mov si,offset [LVMSector]
1300
1301 ; See if this is a valid LVM-sector
1302 ; ZF=0 if valid
1303 call LVM_ValidateSector
1304
1305IFDEF AUX_DEBUG
1306 IF 0
1307 pushf
1308 pusha
1309 push si
1310 mov si, offset $+5
1311 jmp @F
1312 db 10,'lvm record',10,0
1313 @@:
1314 call AuxIO_Print
1315 pop si
1316 call DEBUG_DumpRegisters
1317 call AuxIO_DumpParagraph
1318 call AuxIO_TeletypeNL
1319 popa
1320 popf
1321 ENDIF
1322ENDIF
1323
1324
1325 ; Yep, we found the master LVM-sector
1326 jnz DriveIO_LoadMasterLVMSector_Found
1327 ; Try next location
1328 loop DriveIO_LoadMasterLVMSector_NextTry
1329
1330 ; No master LVM-sector found, set CF=false
1331 clc
1332
1333 DriveIO_LoadMasterLVMSector_Found:
1334 ; Store the address for later use.
1335 mov ax, word ptr [INT13X_DAP_Absolute]
1336 mov word ptr [MasterLVMLBA], ax
1337
1338 DriveIO_LoadMasterLVMSector_End:
1339 popa
1340 ret
1341DriveIO_LoadMasterLVMSector Endp
1342
1343
1344
1345
1346; ---------------------------------------------------
1347; Rousseau ## Large drives, (OS/2) geometry and LBA ##
1348; ---------------------------------------------------
1349; A sector size of 512 bytes is assumed in the below calculations.
1350; Note that this scheme changes when the sector size will be 4096 or larger,
1351; like with modern drives that do not translate to 512 bytes per sector anymore.
1352; These drives will have a capacity above the 2TiB LBA32 boundary.
1353; For now, we assume drives <=2TiB with a sector size of 512 bytes.
1354
1355; There are a few boundaries that are of importance.
1356; Note that these are disk-boundaries and not partition boundaries.
1357; Even with a small partition, like <502GiB, OS/2 will use extended geometry on
1358; an empty huge disk.
1359; These boundaries are (from high to low):
1360
1361; (code 5)
1362; 2^32 = 4294967296 = 100000000 sectors = 2048 GiB
1363; This is the LBA32 2TiB boundary.
1364; Everything above it must be addressed using LBA48.
1365; OS/2 can currently not address this space above.
1366
1367; (code4)
1368; 65536*255*255 = 4261478400 = FE010000 sectors ~ 2032 GiB
1369; This is the max OS/2 boundary using 255/255 extended geometry.
1370; OS/2 can currently not address this space above.
1371
1372; (code 3)
1373; 2^31 = 2147483648 = 80000000 sectors = 1024 GiB
1374; This is the LBA32 1TiB boundary.
1375; OS/2 can address this space and will use 255/255 extended geometry.
1376
1377; (code 2)
1378; 65536*255*127 = 2122383360 = 7E810000 sectors ~ 1012 GiB
1379; This is the DANI 1TiB boundary.
1380; OS/2 can address this space and will use 255/255 extended geometry.
1381; Below this DANI will use 255/127 extended geometry.
1382; This matters on where the LVM-sectors are located !
1383
1384; (code 1)
1385; 65536*255*63 = 1052835840 = 3EC10000 sectors ~ 502 GiB
1386; This is the current OS/2 limit using this geometry because OS/2 can
1387; currently not address more than 65536 cylinders.
1388; DANI will address space above with 255/127 extended geometry up until
1389; the DANI 1TiB boundary (code 2)
1390
1391; (code 0)
1392; Everything below 65536*255*63 will be addressed using standard geometry.
1393
1394
1395;
1396; This function will return the following values:
1397;
1398
1399; 5 = This drive is above the 2^32 LBA32 (2TB) boundary and has more
1400; than 4294967296 sectors.
1401; LBA48 addressing is needed to access the complete capacity of the drive.
1402; OS/2 is currently unable to do so.
1403
1404; 4 = This drive is above the 65536*255*255 (4261478400) boundary but below 2^32.
1405; This is an OS/2 boundary and OS/2 is not able to access the drive above
1406; this boundary.
1407
1408; 3 = This drive is above the 2^31 (1TB) boundary and has more than
1409; 2147483648 sectors.
1410; OS/2 is able to access the drive using it's extended geometry.
1411; Both DANIS506 and IBM1S506 will use the 255/255 scheme.
1412
1413; 2 = This drive is above the 65536*255*127 (2122383360) boundary but below 2^31.
1414; OS/2 is able to access the drive using it's extended geometry.
1415; Both DANIS506 and IBM1S506 will use the 255/255 scheme.
1416
1417; 1 = This drive is above the 65536*255*63 (1052835840) boundary but
1418; below 65536*255*127.
1419; OS/2 is able to access the drive using it's extended geometry.
1420; Note that DANIS506 will use 255/127 and IBM1S506 will use 255/255 geometry !
1421; Using DANI or IBM influences the location of the LVM info-sectors !
1422
1423; 0 = This drive is below the 65536*255*63 (1052835840) boundary.
1424; OS/2 is able to access this drive using the standard 255/63 geometry.
1425
1426; So, any return value >0 means OS/2 extended geometry will be used.
1427; Value 1 will use 255/127 with DANIS506 but 255/255 with IBM1S506.
1428; Values 2 and 3 will use 255/255 on both drivers.
1429; You can or with 0x01 and check for 3 in this case.
1430; Any value above 3 will be a drive who's capacity cannot be fully used by OS/2
1431; The upper limit of 65536*255*255 will be in effect here.
1432
1433; Note this function currently handles the boot-drive only !
1434; It should be extended and use dl for the drive-number as a parameter.
1435; Because we use this function to get this info in a number of places,
1436; all regs and flags except AX are saved and restored.
1437
1438; DL contains BIOS disk-number; 80h for first, 81h for second, etc.
1439DriveIO_GatherDiskInfo Proc Near
1440
1441IFDEF AUX_DEBUG
1442 IF 0
1443 pushf
1444 pusha
1445 push si
1446 mov si, offset $+5
1447 jmp @F
1448 db 10,'DriveIO_GatherDiskInfo:',10,0
1449 @@:
1450 call AuxIO_Print
1451 pop si
1452 ;~ call DEBUG_DumpRegisters
1453 ;~ call AuxIO_DumpParagraph
1454 ;~ call AuxIO_TeletypeNL
1455 popa
1456 popf
1457 ENDIF
1458ENDIF
1459
1460 pushf
1461 push bx
1462 push cx
1463 push dx
1464 push si
1465 push di
1466 push es
1467
1468 ; Set ES to CS for buffer clearing
1469 push cs
1470 pop es
1471
1472 ; Clear the buffer
1473 ; Also setup the buffer size.
1474 ; Old Phoenix BIOSses require word (flags) at 02 to be zero,
1475 ; so we clear the whole buffer to be sure.
1476 mov cx, i13xbuf_size ; Dynamically calculated by assembler.
1477 mov di, offset i13xbuf ; Points to size field.
1478 mov [di],cx ; Setup buffer-size.
1479 inc di
1480 inc di ; Now pointing at actual buffer.
1481 xor ah,ah ; Fill value.
1482 cld ; Direction up.
1483 rep stosb ; Clear buffer.
1484
1485 ; Get the drive parameters
1486 mov ah, 48h ; Get Drive Parameters (extended version)
1487 ;mov dl, 80h ; Drive number
1488 mov si, offset i13xbuf ; Buffer for result-info
1489 push dx
1490 int 13h ; Call the BIOS-function
1491 pop dx
1492
1493 ; Do some error-checking
1494 or ah,ah ; AH is zero if no error (ZF=1 if no error)
1495 mov ax,0 ; Setup code for non-huge drive (does not influence ZF)
1496 jz DriveIO_GatherDiskInfo_ok ; Return if error (AL<>0 thus ZF=0) but CY not set, assuming non-huge drive
1497 jnc DriveIO_GatherDiskInfo_ok ; Return if error (CY=1), assuming non-huge drive
1498 jmp DriveIO_GatherDiskInfo_ret
1499
1500
1501 DriveIO_GatherDiskInfo_ok:
1502
1503 ;
1504 ; Store the drive geometry
1505 ;
1506
1507 mov si, offset i13xbuf
1508
1509 xor dh,dh
1510 and dl,01111111b
1511 shl dx,1
1512 shl dx,1
1513
1514 ; Store number of cylinders on disk
1515 mov bx, offset BIOS_Cyls
1516 add bx,dx
1517 mov ax,[si+04h]
1518
1519 mov word ptr [bx+00],ax
1520 mov ax,[si+06]
1521 mov word ptr [bx+02],ax
1522
1523 ; Store number of heads per cylinder
1524 mov bx, offset BIOS_Heads
1525 add bx,dx
1526 mov ax,[si+08h]
1527 mov word ptr [bx+00],ax
1528 mov ax,[si+0ah]
1529 mov word ptr [bx+02],ax
1530
1531 ; Store number of sectors per track
1532 mov bx, offset BIOS_Secs
1533 add bx,dx
1534 mov ax,[si+0ch]
1535 mov word ptr [bx+00],ax
1536
1537 ; Update first byte of translation-table to conform to BIOS SPT
1538 mov byte ptr [secs_per_track_table], al
1539
1540 mov ax,[si+0eh]
1541 mov word ptr [bx+02],ax
1542
1543 ; Store total secs
1544 mov bx, offset BIOS_TotalSecs
1545 add bx,dx
1546 add bx,dx
1547 mov ax,[si+10h]
1548
1549 mov word ptr [bx+00],ax
1550 mov ax,[si+12h]
1551 mov word ptr [bx+02],ax
1552 mov ax,[si+14h]
1553 mov word ptr [bx+04],ax
1554 mov ax,[si+18h]
1555 mov word ptr [bx+06],ax
1556
1557 ; Store number of bytes per sector
1558 mov bx, offset BIOS_Bytes
1559 add bx,dx
1560 mov ax,[si+18h]
1561 mov [bx],ax
1562
1563
1564 ;
1565 ; See of it's a huge drive of not
1566 ;
1567
1568 ; Drive is larger than 2TiB
1569 mov ax,5 ; Drive code (5)
1570 mov bx, [si+14h] ; Low word of high dword of sector-count
1571 or bx, [si+16h] ; High word of high dword of sector-count
1572 jnz DriveIO_GatherDiskInfo_ret ; If non-zero we have a drive with >2^32 sectors and thus LBA48 addressing
1573
1574 ; Drive is larger than max OS/2 capacity
1575 dec ax ; Drive code (4)
1576 mov bx, [si+12h] ; High word of low dword of sector-count
1577 cmp bx, 0fe01h ; Boundary
1578 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1579 ; we have a drive larger than to 65536*255*255 = FE010000 sectors
1580
1581 ; Drive can be completely utilized by OS/2
1582 dec ax ; Drive code (3)
1583 cmp bx, 8000h ; Boundary
1584 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1585 ; we have a drive larger than 2^31 sectors but smaller than 65536*255*255
1586
1587 ; This is the small area between DANI 1TiB and LBA 1TiB
1588 dec ax ; Drive code (2)
1589 cmp bx, 7e81h ; Boundary
1590 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1591 ; we have a drive larger than 65536*255*127 but <65536*255*255
1592 ; DANIS506.ADD will use 255/255 extended geometry
1593
1594 ; DANI will use 255/127 in this area, this could impact the location of LVM-sectors ! (last sec on track)
1595 dec ax ; Drive code (1)
1596 cmp bx, 3ec1h ; Boundary
1597 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1598 ; we have a drive larger than 65536*255*63 sectors (OS/2 502GiB Limit!)
1599 ; DANIS506.ADD will use 255/127 extended geometry !
1600 ; IBM1S506.ADD will use 255/255 extended geometry !
1601
1602 ; We have a drive that can be addressed using standard 255/63 geometry
1603 dec ax ; Drive code (0)
1604 ; We have a drive smaller than 65536*255*63 = 3EC10000 sectors
1605
1606 DriveIO_GatherDiskInfo_ret:
1607 pop es
1608 pop di
1609 pop si
1610 pop dx
1611 pop cx
1612 pop bx
1613
1614 mov byte ptr [CurIO_UseExtension],1
1615
1616 popf
1617 ret
1618DriveIO_GatherDiskInfo EndP
1619
1620
1621
1622; Values for sectors per track table corresponding to DriveIO_IsHugeDrive return value.
1623secs_per_track_table db 63,127,255,255,255,255
1624
1625db_lmlvm db 'Load Master LVM -- disk: ',0
Note: See TracBrowser for help on using the repository browser.