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

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

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