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

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

Make checking for valid LVM-sector use CF instead of ZF [v1.1.1-testing]

Both the checks for LVM Signature and CRC already use CF on return.
Doing the same for complete LVM-sector validation is more consistent.

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 write flags -- should check version here
814 and al, 03h
815
816 ; Actually, force 'no-write-verify' for now...
817 xor al, al
818
819 ; One sector to read
820 mov cs:[INT13X_DAP_NumBlocks], 1
821
822 ; Setup transfer address
823 mov wptr cs:[INT13X_DAP_Transfer+0], si ; offset
824 mov wptr cs:[INT13X_DAP_Transfer+2], di ; segment
825
826 ; Setup LBA64 address of requested sector
827 mov wptr cs:[INT13X_DAP_Absolute+0], cx ; low word lower part
828 mov wptr cs:[INT13X_DAP_Absolute+2], bx ; high word lower part
829 mov wptr cs:[INT13X_DAP_Absolute+4], 0 ; low word upper part
830 mov wptr cs:[INT13X_DAP_Absolute+6], 0 ; high word upper part
831
832 ; Address of packet
833 mov si, offset [INT13X_DAP] ; disk address packet
834
835 ; Do the extended write
836 mov ah, 43h ; write function
837 int 13h ; transfer to bios
838
839 ; Error occured
840 jc DriveIO_WriteSectorLBA_exit
841
842 ; AH should also be zero
843 test ah, ah
844 stc
845 jnz DriveIO_WriteSectorLBA_exit
846
847 ; Disk write succeeded, clear CF
848 clc
849
850 DriveIO_WriteSectorLBA_exit:
851 ret
852
853DriveIO_WriteSectorLBA EndP
854
855
856
857;
858; ############################################################
859; # Check for a valid MBR-sector to be written to disk #
860; ############################################################
861;
862; In
863; --
864; DL = Physical Disk
865; BX:CX = LBA sector
866; DI:SI = Source buffer
867;
868; Out
869; ---
870; CY = 1 if invalid MBR in source buffer, 0 if valid
871;
872; This routine is called when DriveIO_SaveSector attempts to write to the MBR.
873; It checks if the sector to be written has some sensible values in certain
874; places. In fact, if the sector is written to the boot-disk, the AiR-BOOT
875; signature should be present and the partition table should be the same
876; as the one at the start of the AiR-BOOT code in memory, except maybe for the
877; active flags.
878; For other disks, only the active flags are checked to be 00h or 80h and
879; the AA55h MBR signature.
880;
881DriveIO_ProtectMBR Proc Near
882 pusha ; Push all registers
883 push es ; Push ES because we need it for string instructions
884 push cs ; Make ES point...
885 pop es ; to CS
886
887 ; Save the pointer to the sector to write in BX
888 mov bx,si
889
890 ;
891 ; If the sector to be written is not the boot-disk, then skip
892 ; checking the AiR-BOOT MBR.
893 ;
894 cmp dl, [BIOS_BootDisk]
895 jne DriveIO_ProtectMBR_is_not_bootdisk
896
897 ;
898 ; The boot-disk is accessed so the sector to be written must be
899 ; the AiR-BOOT MBR. This is the same as the first 512 bytes
900 ; relocated to 8000:0000 and this the start of the AB-code.
901 ;
902 mov si,bx ; Get pointer to sector to write
903 xor di,di ; Point DI to start of AB-code (MBR)
904 mov cx, offset [MBR_PartTable] ; Bytes upto P-table must be same
905 cld ; Compare upwards
906 repe cmpsb ; Compare upto P-table
907
908 ; If not the same this is not the an AiR-BOOT boot-disk MBR !
909 jne DriveIO_ProtectMBR_not_valid_MBR ; SEVERE ERROR !
910
911 ; Continue with signature check
912 jmp DriveIO_ProtectMBR_check_signature
913
914
915 ;
916 ; The disk is not the boot-disk so we don't know what kind of MBR is on it.
917 ; Some sanity checks should be here.
918 ;
919 DriveIO_ProtectMBR_is_not_bootdisk:
920
921 ;
922 ; sanity checks...
923 ;
924
925 ; Continue with signature check
926 jmp DriveIO_ProtectMBR_check_signature
927
928
929 DriveIO_ProtectMBR_check_signature:
930 ; See if the sector to write contains a valid signature
931 mov si,bx ; Get pointer to sector to write
932 mov di, offset [MBR_Sig] ; Offset to MBR signature
933 add si,di ; Make SI point to it in sec to write
934 lodsw ; Load it
935 cmp ax,0aa55h ; See if it is valid
936
937 ; If no signature this cannot be a valid MBR !
938 jne DriveIO_ProtectMBR_not_valid_MBR ; SEVERE ERROR !
939
940
941 ;
942 ; The sector to be written seems to be valid.
943 ; Set CY=0 to indicate a valid MBR.
944 ;
945 DriveIO_ProtectMBR_is_valid_MBR:
946 clc
947 jmp DriveIO_ProtectMBR_end
948
949 ;
950 ; Something is terribly wrong; a non-MBR sector seems about to be written.
951 ; Set CY=1 and let the calling code handle this situation.
952 ;
953 DriveIO_ProtectMBR_not_valid_MBR:
954 stc
955 jmp DriveIO_ProtectMBR_end
956
957 ;
958 ; Return to the caller with no registers modyfied except FLAGS.
959 ;
960 DriveIO_ProtectMBR_end:
961 pop es
962 popa
963 ret
964DriveIO_ProtectMBR Endp
965
966
967
968; #########################################################################
969; Routine: Checks if the MBR is addressed by either CHS or LBA
970; #########################################################################
971; Calling : bx:ax - Absolute sector
972; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
973; Returns : ZF=1 if MBR is addressed, else ZF=0
974; Preserve: all registers
975; #########################################################################
976DriveIO_MBR_Addressed Proc
977 push ax
978 push bx
979
980 or bx,ax ; Results in 0 in BX if MBR is addressed by LBA
981 jz DriveIO_MBR_Addressed_done
982
983 mov ax,cx ; Results in 1 in AX if CYL 0, SEC 1 is addressed
984 add al,dh ; Results in 1 in AX if HEAD 0 is addressed
985 dec ax ; Results in 0 in AX if MBR is addressed by CHS
986
987 DriveIO_MBR_Addressed_done:
988 pop bx
989 pop ax
990 ret
991DriveIO_MBR_Addressed EndP
992
993
994
995
996; #########################################################################
997; Routine: Writes DS:SI to a specified sector
998; #########################################################################
999; Calling : bx:ax - Absolute sector
1000; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
1001; ds:si - Source-Adress
1002; Returns : none
1003; Preserve: all registers
1004; #########################################################################
1005DriveIO_SaveSector Proc Near Uses ax bx cx dx ds si es di
1006
1007IFDEF AUX_DEBUG
1008 IF 0
1009 pushf
1010 pusha
1011 push si
1012 mov si, offset $+5
1013 jmp @F
1014 db 10,'DriveIO_SaveSector:',10,0
1015 @@:
1016 call AuxIO_Print
1017 pop si
1018 ;~ call DEBUG_DumpRegisters
1019 ;~ call AuxIO_DumpParagraph
1020 ;~ call AuxIO_TeletypeNL
1021 popa
1022 popf
1023 ENDIF
1024ENDIF
1025
1026 ;!
1027 ;! DEBUG_BLOCK
1028 ;! Force write to LBA0 to test interception routine.
1029 ;! Do *NOT* enable unless you are debugging, will overwrite MBR !
1030 ;!
1031 ;~ __DIO_FORCE_LBA0_WRITE__ EQU
1032 IFDEF AUX_DEBUG
1033 IFDEF __DIO_FORCE_LBA0_WRITE__
1034 xor ax,ax
1035 xor bx,bx
1036 xor cx,cx
1037 inc cx
1038 xor dh,dh
1039 ENDIF
1040 ENDIF
1041
1042 ;
1043 ; Check if the MBR is the destination for the write.
1044 ; ZF=1 if so.
1045 ;
1046 call DriveIO_MBR_Addressed
1047 jnz DriveIO_SaveSector_continue_write
1048
1049
1050 ; MBR is addressed, check the sector that is requested to be written.
1051 ; For the bootdisk it should contain the AiR-BOOT signature, valid
1052 ; partition-table entries and the AA55h signature.
1053 ; If not, something is terribly wrong in some piece of the AB code.
1054 ; For any other disk (80h+) at least a valid partition table should
1055 ; be present together with the AA55h signature.
1056 call DriveIO_ProtectMBR
1057 jnc DriveIO_SaveSector_continue_write
1058
1059
1060 ;
1061 ; WE HAVE A SEVERE ERROR CONDITION !
1062 ; SOME AB CODE TRIES TO WRITE A NON-MBR TO THE DISK !
1063 ; ASK THE USER TO REPORT THIS !
1064 ; HALT THE SYSTEM !
1065 ;
1066
1067 ; Show error-box
1068 mov cx, 0C04h
1069 mov si, offset NonMBRwrite
1070 call SETUP_ShowErrorBox
1071 mov cx, 0C04h
1072 mov si, offset NonMBRwrite_rep
1073 call SETUP_ShowErrorBox
1074
1075
1076 IFDEF AUX_DEBUG
1077 pusha
1078 mov si, offset NonMBRwrite
1079 call AuxIO_TeletypeNL
1080 call AuxIO_Print
1081 call AuxIO_TeletypeNL
1082 popa
1083 ENDIF
1084
1085 ; Show popup and halt the system.
1086 jmp HaltSystem
1087
1088
1089
1090 ;
1091 ; Continue the write if not MBR sector or MBR to write is validated.
1092 ;
1093 DriveIO_SaveSector_continue_write:
1094 test byte ptr cs:[CurIO_UseExtension], 1
1095 jz DIOSS_UseNormal
1096 ; Are we forced do use LBA via Setting?
1097 ; Always use INT13X on v1.0.8+.
1098 ;~ test byte ptr cs:[CFG_ForceLBAUsage], 1
1099 ;~ jnz DIOSS_UseExtension
1100 jmp DIOSS_UseExtension
1101 ; Is the drive not a harddrive?
1102 cmp dl, 80h
1103 jb DIOSS_UseNormal
1104 ; Upper 8 bits of LBA-address set? -> Use LBA (maximum boundary is FB0400h)
1105 or bh, bh
1106 jnz DIOSS_UseExtension
1107 ; Compare Switch-Table value to bit 16-23 of LBA-address
1108 mov di, dx
1109 and di, 007Fh
1110 cmp bptr cs:[LBASwitchTable+di], bl
1111 jbe DIOSS_UseExtension
1112
1113 DIOSS_UseNormal:
1114
1115IFDEF AUX_DEBUG
1116 IF 0
1117 pusha
1118 push si
1119 mov si, offset $+5
1120 jmp @F
1121 db 10,'DriveIO_WriteSectorCHS:',10,0
1122 @@:
1123 call AuxIO_Print
1124 pop si
1125 call DEBUG_DumpRegisters
1126 call AuxIO_DumpParagraph
1127 call AuxIO_TeletypeNL
1128 popa
1129 ENDIF
1130ENDIF
1131
1132 mov di, 3 ; retry count
1133 DIOSS_ErrorLoop:
1134 push ds
1135 pop es
1136 mov bx, si ; ES:BX - Destination
1137 mov ax, 0301h ; Function 3 - Write Sector
1138 int 13h
1139 jnc DIOSS_Success
1140 dec di ; decrement retry count
1141 jnz DIOSS_ErrorLoop
1142 call MBR_SaveError
1143
1144 DIOSS_UseExtension:
1145
1146 mov di, ds ; segment for transfer address
1147 mov cx, ax ; low word of lba
1148 xor ax, ax ; no verify
1149 call DriveIO_WriteSectorLBA ; extended write
1150 jc MBR_SaveError ; halt on error
1151
1152 ;~ push cx
1153 ;~ mov cs:[INT13X_DAP_NumBlocks], 1 ; Copy ONE sector
1154 ;~ mov wptr cs:[INT13X_DAP_Transfer+0], si
1155 ;~ mov cx, ds
1156 ;~ mov wptr cs:[INT13X_DAP_Transfer+2], cx ; Fill out Transfer Adress
1157 ;~ mov wptr cs:[INT13X_DAP_Absolute+0], ax
1158 ;~ mov wptr cs:[INT13X_DAP_Absolute+2], bx ; Fill out Absolute Sector
1159 ;~ push cs
1160 ;~ pop ds
1161 ;~ mov si, offset [INT13X_DAP]
1162 ;~ mov ax, 4300h ; Extended Write (No Verify)
1163 ;~ int 13h
1164 ;~ pop cx
1165 ;~ jnc DIOSS_Success
1166 ;~ call MBR_SaveError
1167
1168 DIOSS_Success:
1169 ret
1170DriveIO_SaveSector EndP
1171
1172
1173
1174; ------------------------------------------------------
1175; Rousseau: # Load the master LVM-sector if one exists #
1176; ------------------------------------------------------
1177; Load the master LVM-sector to get the number of sectors per track as
1178; OS/2 views the drive. If no master LVM-sector is found it is assumed OS/2
1179; is not installed. The master LVM-sector can be located at three different
1180; places depending on drive size and partitioning scheme and driver used.
1181; When DANIS506.ADD is used, the OS/2 extended geometry will be 255/127 for
1182; drives >502GiB but <1TiB. Then the location will be sector 127 which
1183; is LBA 126 (7Eh).
1184; IBM1S506.ADD will always use 255/255 for the extended OS/2 geometry.
1185; DANIS506.ADD will use 255/255 for drives >1TiB.
1186; Then the location of the master LVM-sector will be 255 which is LBA 254 (FEh).
1187; When OS/2 is installed on a huge drive that alread had a system on it, OS/2
1188; will be confined to the lower 502GiB of the drive.
1189; In this case the normal geometry from Int13X will be used.
1190; This is also the case when no valid master LVM-sector can be found.
1191;
1192; Return CF when valid master LVM sector found, NC if not.
1193; Loads sector at [LVMSector] !
1194DriveIO_LoadMasterLVMSector Proc Near
1195
1196IFDEF AUX_DEBUG
1197 IF 0
1198 pushf
1199 pusha
1200 push si
1201 mov si, offset $+5
1202 jmp @F
1203 db 10,'DriveIO_LoadMasterLVMSector:',10,0
1204 @@:
1205 call AuxIO_Print
1206 pop si
1207 ;~ call DEBUG_DumpRegisters
1208 ;~ call AuxIO_DumpParagraph
1209 ;~ call AuxIO_TeletypeNL
1210 popa
1211 popf
1212 ENDIF
1213ENDIF
1214
1215 pusha
1216
1217 ; Loop over the sector-translation table,
1218 ; process the first three values from high (255) to low.
1219 ; (bios spt, most likely 63)
1220 mov cx,3
1221 DriveIO_LoadMasterLVMSector_NextTry:
1222 ; Number of sectors to read
1223 mov [INT13X_DAP_NumBlocks],1
1224
1225 ; Setup destination address
1226 mov si, offset [LVMSector]
1227 mov word ptr [INT13X_DAP_Transfer+0],si
1228 mov ax, ds
1229 mov word ptr [INT13X_DAP_Transfer+2],ax
1230
1231 ; Get the sector-number of the next possible LVM sector (255,127,63)
1232 ; using the translation table and the counter as the index
1233 mov bx,offset [secs_per_track_table]
1234 mov ax,cx ; 1-based index to sec_per_track_table
1235 dec ax ; Adjust to 0-based
1236 xlatb ; Get the (well known) SPT
1237 dec al ; Minus 1 for LVM-record
1238
1239 ;
1240 ; AX now contains the LBA address of the sector
1241 ; that could be an LVM sector.
1242 ; This is all in track0 so the address will not exceed 64kiB sectors.
1243 ;
1244
1245
1246IFDEF AUX_DEBUG
1247 IF 0
1248 pushf
1249 pusha
1250 push si
1251 mov si, offset $+5
1252 jmp @F
1253 db 10,'geo',10,0
1254 @@:
1255 call AuxIO_Print
1256 pop si
1257 call DEBUG_DumpRegisters
1258 call AuxIO_DumpParagraph
1259 call AuxIO_TeletypeNL
1260 popa
1261 popf
1262 ENDIF
1263ENDIF
1264
1265
1266 ; Setup the requested LBA sector number
1267 mov word ptr [INT13X_DAP_Absolute+0],ax ; LBA low NORMAL I/O GEBRUIKEN !
1268 mov word ptr [INT13X_DAP_Absolute+2],00h ; LBA high
1269 mov si, offset [INT13X_DAP] ; address request packet
1270 mov ah, 42h
1271 int 13h ; do the i/o, CF=1->error, CF=0->success
1272
1273IFDEF AUX_DEBUG
1274 IF 0
1275 pushf
1276 pusha
1277 pushf
1278 xor ax, ax
1279 mov al, dl
1280 call AuxIO_TeletypeHexWord
1281 mov al, '#'
1282 call AuxIO_Teletype
1283 popf
1284 mov ax,0000h
1285 rcl al, 1
1286 call AuxIO_TeletypeHexWord
1287 mov al, '#'
1288 call AuxIO_Teletype
1289 mov ax,word ptr [INT13X_DAP_Absolute+0]
1290 call AuxIO_TeletypeHexWord
1291 mov al, '#'
1292 call AuxIO_Teletype
1293 popa
1294 popf
1295 ENDIF
1296ENDIF
1297
1298 cmc ; Complement carry so we can exit imm. on error
1299 jnc DriveIO_LoadMasterLVMSector_End ; oops, return with NC
1300
1301
1302 mov si,offset [LVMSector]
1303
1304 ; See if this is a valid LVM-sector
1305 ; CY if valid
1306 call LVM_ValidateSector
1307
1308IFDEF AUX_DEBUG
1309 IF 0
1310 pushf
1311 pusha
1312 push si
1313 mov si, offset $+5
1314 jmp @F
1315 db 10,'lvm record',10,0
1316 @@:
1317 call AuxIO_Print
1318 pop si
1319 call DEBUG_DumpRegisters
1320 call AuxIO_DumpParagraph
1321 call AuxIO_TeletypeNL
1322 popa
1323 popf
1324 ENDIF
1325ENDIF
1326
1327
1328 ; Yep, we found the master LVM-sector
1329 jc DriveIO_LoadMasterLVMSector_Found
1330
1331 ; Try next location
1332 loop DriveIO_LoadMasterLVMSector_NextTry
1333
1334 ; No master LVM-sector found, set CF=false
1335 clc
1336
1337 DriveIO_LoadMasterLVMSector_Found:
1338 ; Store the address for later use.
1339 mov ax, word ptr [INT13X_DAP_Absolute]
1340 mov word ptr [MasterLVMLBA], ax
1341
1342 DriveIO_LoadMasterLVMSector_End:
1343 popa
1344 ret
1345DriveIO_LoadMasterLVMSector Endp
1346
1347
1348
1349
1350; ---------------------------------------------------
1351; Rousseau ## Large drives, (OS/2) geometry and LBA ##
1352; ---------------------------------------------------
1353; A sector size of 512 bytes is assumed in the below calculations.
1354; Note that this scheme changes when the sector size will be 4096 or larger,
1355; like with modern drives that do not translate to 512 bytes per sector anymore.
1356; These drives will have a capacity above the 2TiB LBA32 boundary.
1357; For now, we assume drives <=2TiB with a sector size of 512 bytes.
1358
1359; There are a few boundaries that are of importance.
1360; Note that these are disk-boundaries and not partition boundaries.
1361; Even with a small partition, like <502GiB, OS/2 will use extended geometry on
1362; an empty huge disk.
1363; These boundaries are (from high to low):
1364
1365; (code 5)
1366; 2^32 = 4294967296 = 100000000 sectors = 2048 GiB
1367; This is the LBA32 2TiB boundary.
1368; Everything above it must be addressed using LBA48.
1369; OS/2 can currently not address this space above.
1370
1371; (code4)
1372; 65536*255*255 = 4261478400 = FE010000 sectors ~ 2032 GiB
1373; This is the max OS/2 boundary using 255/255 extended geometry.
1374; OS/2 can currently not address this space above.
1375
1376; (code 3)
1377; 2^31 = 2147483648 = 80000000 sectors = 1024 GiB
1378; This is the LBA32 1TiB boundary.
1379; OS/2 can address this space and will use 255/255 extended geometry.
1380
1381; (code 2)
1382; 65536*255*127 = 2122383360 = 7E810000 sectors ~ 1012 GiB
1383; This is the DANI 1TiB boundary.
1384; OS/2 can address this space and will use 255/255 extended geometry.
1385; Below this DANI will use 255/127 extended geometry.
1386; This matters on where the LVM-sectors are located !
1387
1388; (code 1)
1389; 65536*255*63 = 1052835840 = 3EC10000 sectors ~ 502 GiB
1390; This is the current OS/2 limit using this geometry because OS/2 can
1391; currently not address more than 65536 cylinders.
1392; DANI will address space above with 255/127 extended geometry up until
1393; the DANI 1TiB boundary (code 2)
1394
1395; (code 0)
1396; Everything below 65536*255*63 will be addressed using standard geometry.
1397
1398
1399;
1400; This function will return the following values:
1401;
1402
1403; 5 = This drive is above the 2^32 LBA32 (2TB) boundary and has more
1404; than 4294967296 sectors.
1405; LBA48 addressing is needed to access the complete capacity of the drive.
1406; OS/2 is currently unable to do so.
1407
1408; 4 = This drive is above the 65536*255*255 (4261478400) boundary but below 2^32.
1409; This is an OS/2 boundary and OS/2 is not able to access the drive above
1410; this boundary.
1411
1412; 3 = This drive is above the 2^31 (1TB) boundary and has more than
1413; 2147483648 sectors.
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; 2 = This drive is above the 65536*255*127 (2122383360) boundary but below 2^31.
1418; OS/2 is able to access the drive using it's extended geometry.
1419; Both DANIS506 and IBM1S506 will use the 255/255 scheme.
1420
1421; 1 = This drive is above the 65536*255*63 (1052835840) boundary but
1422; below 65536*255*127.
1423; OS/2 is able to access the drive using it's extended geometry.
1424; Note that DANIS506 will use 255/127 and IBM1S506 will use 255/255 geometry !
1425; Using DANI or IBM influences the location of the LVM info-sectors !
1426
1427; 0 = This drive is below the 65536*255*63 (1052835840) boundary.
1428; OS/2 is able to access this drive using the standard 255/63 geometry.
1429
1430; So, any return value >0 means OS/2 extended geometry will be used.
1431; Value 1 will use 255/127 with DANIS506 but 255/255 with IBM1S506.
1432; Values 2 and 3 will use 255/255 on both drivers.
1433; You can or with 0x01 and check for 3 in this case.
1434; Any value above 3 will be a drive who's capacity cannot be fully used by OS/2
1435; The upper limit of 65536*255*255 will be in effect here.
1436
1437; Note this function currently handles the boot-drive only !
1438; It should be extended and use dl for the drive-number as a parameter.
1439; Because we use this function to get this info in a number of places,
1440; all regs and flags except AX are saved and restored.
1441
1442; DL contains BIOS disk-number; 80h for first, 81h for second, etc.
1443DriveIO_GatherDiskInfo Proc Near
1444
1445IFDEF AUX_DEBUG
1446 IF 0
1447 pushf
1448 pusha
1449 push si
1450 mov si, offset $+5
1451 jmp @F
1452 db 10,'DriveIO_GatherDiskInfo:',10,0
1453 @@:
1454 call AuxIO_Print
1455 pop si
1456 ;~ call DEBUG_DumpRegisters
1457 ;~ call AuxIO_DumpParagraph
1458 ;~ call AuxIO_TeletypeNL
1459 popa
1460 popf
1461 ENDIF
1462ENDIF
1463
1464 pushf
1465 push bx
1466 push cx
1467 push dx
1468 push si
1469 push di
1470 push es
1471
1472 ; Set ES to CS for buffer clearing
1473 push cs
1474 pop es
1475
1476 ; Clear the buffer
1477 ; Also setup the buffer size.
1478 ; Old Phoenix BIOSses require word (flags) at 02 to be zero,
1479 ; so we clear the whole buffer to be sure.
1480 mov cx, i13xbuf_size ; Dynamically calculated by assembler.
1481 mov di, offset i13xbuf ; Points to size field.
1482 mov [di],cx ; Setup buffer-size.
1483 inc di
1484 inc di ; Now pointing at actual buffer.
1485 xor ah,ah ; Fill value.
1486 cld ; Direction up.
1487 rep stosb ; Clear buffer.
1488
1489 ; Get the drive parameters
1490 mov ah, 48h ; Get Drive Parameters (extended version)
1491 ;mov dl, 80h ; Drive number
1492 mov si, offset i13xbuf ; Buffer for result-info
1493 push dx
1494 int 13h ; Call the BIOS-function
1495 pop dx
1496
1497 ; Do some error-checking
1498 or ah,ah ; AH is zero if no error (ZF=1 if no error)
1499 mov ax,0 ; Setup code for non-huge drive (does not influence ZF)
1500 jz DriveIO_GatherDiskInfo_ok ; Return if error (AL<>0 thus ZF=0) but CY not set, assuming non-huge drive
1501 jnc DriveIO_GatherDiskInfo_ok ; Return if error (CY=1), assuming non-huge drive
1502 jmp DriveIO_GatherDiskInfo_ret
1503
1504
1505 DriveIO_GatherDiskInfo_ok:
1506
1507 ;
1508 ; Store the drive geometry
1509 ;
1510
1511 mov si, offset i13xbuf
1512
1513 xor dh,dh
1514 and dl,01111111b
1515 shl dx,1
1516 shl dx,1
1517
1518 ; Store number of cylinders on disk
1519 mov bx, offset BIOS_Cyls
1520 add bx,dx
1521 mov ax,[si+04h]
1522
1523 mov word ptr [bx+00],ax
1524 mov ax,[si+06]
1525 mov word ptr [bx+02],ax
1526
1527 ; Store number of heads per cylinder
1528 mov bx, offset BIOS_Heads
1529 add bx,dx
1530 mov ax,[si+08h]
1531 mov word ptr [bx+00],ax
1532 mov ax,[si+0ah]
1533 mov word ptr [bx+02],ax
1534
1535 ; Store number of sectors per track
1536 mov bx, offset BIOS_Secs
1537 add bx,dx
1538 mov ax,[si+0ch]
1539 mov word ptr [bx+00],ax
1540
1541 ; Update first byte of translation-table to conform to BIOS SPT
1542 mov byte ptr [secs_per_track_table], al
1543
1544 mov ax,[si+0eh]
1545 mov word ptr [bx+02],ax
1546
1547 ; Store total secs
1548 mov bx, offset BIOS_TotalSecs
1549 add bx,dx
1550 add bx,dx
1551 mov ax,[si+10h]
1552
1553 mov word ptr [bx+00],ax
1554 mov ax,[si+12h]
1555 mov word ptr [bx+02],ax
1556 mov ax,[si+14h]
1557 mov word ptr [bx+04],ax
1558 mov ax,[si+18h]
1559 mov word ptr [bx+06],ax
1560
1561 ; Store number of bytes per sector
1562 mov bx, offset BIOS_Bytes
1563 add bx,dx
1564 mov ax,[si+18h]
1565 mov [bx],ax
1566
1567
1568 ;
1569 ; See of it's a huge drive of not
1570 ;
1571
1572 ; Drive is larger than 2TiB
1573 mov ax,5 ; Drive code (5)
1574 mov bx, [si+14h] ; Low word of high dword of sector-count
1575 or bx, [si+16h] ; High word of high dword of sector-count
1576 jnz DriveIO_GatherDiskInfo_ret ; If non-zero we have a drive with >2^32 sectors and thus LBA48 addressing
1577
1578 ; Drive is larger than max OS/2 capacity
1579 dec ax ; Drive code (4)
1580 mov bx, [si+12h] ; High word of low dword of sector-count
1581 cmp bx, 0fe01h ; Boundary
1582 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1583 ; we have a drive larger than to 65536*255*255 = FE010000 sectors
1584
1585 ; Drive can be completely utilized by OS/2
1586 dec ax ; Drive code (3)
1587 cmp bx, 8000h ; Boundary
1588 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1589 ; we have a drive larger than 2^31 sectors but smaller than 65536*255*255
1590
1591 ; This is the small area between DANI 1TiB and LBA 1TiB
1592 dec ax ; Drive code (2)
1593 cmp bx, 7e81h ; Boundary
1594 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1595 ; we have a drive larger than 65536*255*127 but <65536*255*255
1596 ; DANIS506.ADD will use 255/255 extended geometry
1597
1598 ; DANI will use 255/127 in this area, this could impact the location of LVM-sectors ! (last sec on track)
1599 dec ax ; Drive code (1)
1600 cmp bx, 3ec1h ; Boundary
1601 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1602 ; we have a drive larger than 65536*255*63 sectors (OS/2 502GiB Limit!)
1603 ; DANIS506.ADD will use 255/127 extended geometry !
1604 ; IBM1S506.ADD will use 255/255 extended geometry !
1605
1606 ; We have a drive that can be addressed using standard 255/63 geometry
1607 dec ax ; Drive code (0)
1608 ; We have a drive smaller than 65536*255*63 = 3EC10000 sectors
1609
1610 DriveIO_GatherDiskInfo_ret:
1611 pop es
1612 pop di
1613 pop si
1614 pop dx
1615 pop cx
1616 pop bx
1617
1618 mov byte ptr [CurIO_UseExtension],1
1619
1620 popf
1621 ret
1622DriveIO_GatherDiskInfo EndP
1623
1624
1625
1626; Values for sectors per track table corresponding to DriveIO_IsHugeDrive return value.
1627secs_per_track_table db 63,127,255,255,255,255
1628
1629db_lmlvm db 'Load Master LVM -- disk: ',0
Note: See TracBrowser for help on using the repository browser.