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

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

Changed register interface for LBA read/write sector [v1.1.1-testing]

Changed passing the LBA address from BX:CX to BX:AX, so it corresponds
to the load/save sector functions, which do more checking.

This loses the return-status in AH for reading sectors and specifying
write-verify for writing sectors, but that does not really matter.
Status of the last operation should be available using INT13 function
01h and verification of sectors can be done with function 44h if wanted.
CF indicates success or not, which is enough.

This register combination makes it possible to hold both CHS and LBA
sector addresses in registers if needed:
BX:AX ; LBA32
DX:CX ; CHS10

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.5 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 call DriveIO_ReadSectorLBA ; extended read
744 jc DriveIO_GotLoadError ; halt on error
745
746 ;~ push cx
747 ;~ mov cs:[INT13X_DAP_NumBlocks], 1 ; Copy ONE sector
748 ;~ mov wptr cs:[INT13X_DAP_Transfer+0], si
749 ;~ mov cx, ds
750 ;~ mov wptr cs:[INT13X_DAP_Transfer+2], cx ; Fill out Transfer Adress
751 ;~ mov wptr cs:[INT13X_DAP_Absolute+0], ax
752 ;~ mov wptr cs:[INT13X_DAP_Absolute+2], bx ; Fill out Absolute Sector
753 ;~ push cs
754 ;~ pop ds
755 ;~ mov si, offset [INT13X_DAP]
756 ;~ mov ah, 42h ; Extended Read
757 ;~ int 13h
758 ;~ pop cx
759 ;~ jnc DIOLS_Success
760
761 ; Sector load failed...
762 ;~ jmp DriveIO_GotLoadError
763
764 DIOLS_Success:
765
766IFDEF AUX_DEBUG
767 IF 0
768 pusha
769 push si
770 mov si, offset $+5
771 jmp @F
772 db 10,'sector loaded',10,0
773 @@:
774 call AuxIO_Print
775 pop si
776 ;~ call DEBUG_DumpRegisters
777 call AuxIO_DumpSector
778 ;~ call AuxIO_DumpParagraph
779 ;~ call AuxIO_TeletypeNL
780 popa
781 ENDIF
782ENDIF
783 ret
784DriveIO_LoadSector EndP
785
786
787
788;##############################################################################
789;# ACTION : Reads a sector from disk using INT13 extensions
790;# ----------------------------------------------------------------------------
791;# EFFECTS : Modifies DAP structure and fills transfer buffer
792;# ----------------------------------------------------------------------------
793;# IN : BX:AX - LBA address of sector
794;# : DI:SI - SEG:OFF of transfer buffer
795;# ----------------------------------------------------------------------------
796;# OUT : CF=1 - failure
797;##############################################################################
798DriveIO_ReadSectorLBA Proc Near
799
800IFDEF AUX_DEBUG
801 IF 0
802 pushf
803 pusha
804 push si
805 mov si, offset $+5
806 jmp @F
807 db 10,'DriveIO_ReadSectorLBA:',10,0
808 @@:
809 call AuxIO_Print
810 pop si
811 call DEBUG_DumpRegisters
812 call AuxIO_DumpParagraph
813 call AuxIO_TeletypeNL
814 popa
815 popf
816 ENDIF
817ENDIF
818
819 ; Push all registers
820 pusha
821 push ds
822 push es
823
824 ; One sector to read
825 mov cs:[INT13X_DAP_NumBlocks], 1
826
827 ; Setup transfer address
828 mov wptr cs:[INT13X_DAP_Transfer+0], si ; offset
829 mov wptr cs:[INT13X_DAP_Transfer+2], di ; segment
830
831 ; Setup LBA64 address of requested sector
832 mov wptr cs:[INT13X_DAP_Absolute+0], ax ; low word lower part
833 mov wptr cs:[INT13X_DAP_Absolute+2], bx ; high word lower part
834 mov wptr cs:[INT13X_DAP_Absolute+4], 0 ; low word upper part
835 mov wptr cs:[INT13X_DAP_Absolute+6], 0 ; high word upper part
836
837 ; Address of packet
838 mov si, offset [INT13X_DAP] ; disk address packet
839
840 ; Do the extended read
841 mov ah, 42h ; read function
842 int 13h ; transfer to bios
843
844 ; Error occured
845 jc DriveIO_ReadSectorLBA_exit
846
847 ; AH should also be zero
848 test ah, ah
849 stc
850 jnz DriveIO_ReadSectorLBA_exit
851
852 ; Disk read succeeded, clear CF
853 clc
854
855 DriveIO_ReadSectorLBA_exit:
856
857 ; Pop all registers
858 pop es
859 pop ds
860 popa
861
862 ret
863DriveIO_ReadSectorLBA EndP
864
865
866
867;##############################################################################
868;# ACTION : Writes a sector to disk using INT13 extensions
869;# ----------------------------------------------------------------------------
870;# EFFECTS : Modifies DAP structure and mofifies the disk
871;# ----------------------------------------------------------------------------
872;# IN : BX:AX - LBA address of sector
873;# : DI:SI - SEG:OFF of transfer buffer
874;# ----------------------------------------------------------------------------
875;# OUT : CF=1 - failure
876;##############################################################################
877DriveIO_WriteSectorLBA Proc Near
878
879IFDEF AUX_DEBUG
880 IF 0
881 pusha
882 push si
883 mov si, offset $+5
884 jmp @F
885 db 10,'DriveIO_WriteSectorLBA:',10,0
886 @@:
887 call AuxIO_Print
888 pop si
889 call DEBUG_DumpRegisters
890 call AuxIO_DumpParagraph
891 call AuxIO_TeletypeNL
892 popa
893 ENDIF
894ENDIF
895
896 ; Push all registers
897 pusha
898 push ds
899 push es
900
901 ; One sector to read
902 mov cs:[INT13X_DAP_NumBlocks], 1
903
904 ; Setup transfer address
905 mov wptr cs:[INT13X_DAP_Transfer+0], si ; offset
906 mov wptr cs:[INT13X_DAP_Transfer+2], di ; segment
907
908 ; Setup LBA64 address of requested sector
909 mov wptr cs:[INT13X_DAP_Absolute+0], ax ; low word lower part
910 mov wptr cs:[INT13X_DAP_Absolute+2], bx ; high word lower part
911 mov wptr cs:[INT13X_DAP_Absolute+4], 0 ; low word upper part
912 mov wptr cs:[INT13X_DAP_Absolute+6], 0 ; high word upper part
913
914 ; Address of packet
915 mov si, offset [INT13X_DAP] ; disk address packet
916
917 ; Do the extended write
918 xor al, al ; no write verify
919 mov ah, 43h ; write function
920 int 13h ; transfer to bios
921
922 ; Error occured
923 jc DriveIO_WriteSectorLBA_exit
924
925 ; AH should also be zero
926 test ah, ah
927 stc
928 jnz DriveIO_WriteSectorLBA_exit
929
930 ; Disk write succeeded, clear CF
931 clc
932
933 DriveIO_WriteSectorLBA_exit:
934
935 ; Pop all registers
936 pop es
937 pop ds
938 popa
939
940 ret
941DriveIO_WriteSectorLBA EndP
942
943
944
945
946;##############################################################################
947;# The Master LVM sector is *not* necessarily located at the end of the BIOS
948;# view of TRACK0. Its location depends on the *OS/2 geometry* active when the
949;# disk was partitioned. For disks < 502MiB this will most likely be LBA sector
950;# 62, but for disks >502MiB, *extended* OS/2 geometry was used and DANIS506
951;# uses SPT=127 for disks < 1TiB while IBMS506 uses SPT=255.
952;# When a huge disk < 1TiB was partitioned with IBMS506, thus using SPT=255,
953;# and the driver was later changed to DANIS506, DANI uses SPT=255, eventhough
954;# the disk < 1TiB. Whether it is DANI that is LVM aware or something else
955;# (maybe LVM itself) that makes DANI use the correct geometry has yet to be
956;# investigated.
957;#
958;# Related geometry issues are also present with USB sticks, which can get
959;# assigned a geometry by OS/2, which can depend if the stick was partitioned
960;# on foreign systems or not, or even OS/2 manufacturing a geometry that is not
961;# the same as the BIOS reports to us here. In both cases, fixed disks and
962;# removable disks, the geometry recorded in the BPB of a partition can also
963;# influence the geometry that OS/2 assigns. This is the case when 'preparing'
964;# disks for LVM use, in which case BPB values could be incorporated.
965;#
966;# What this all boils down to, is that the geometry reported by the BIOS is
967;# of no practical use, especially not when taking BIOS USB MSD emulation into
968;# account. These are among the reasons why AirBoot needs to use LBA addressing
969;# when handling LVM stuff and why LBA use cannot be disabled in the SETUP
970;# anymore.
971;#
972;# So, a Master LVM sector can be present on any sector from LBA 254 downwards
973;# and the only way to locate the correct one is to scan all the way down and,
974;# if one is found, do proper validation on its values, because it may also be
975;# a 'phantom' LVM sector left over from previous partition layouts.
976;# Most of such 'phantoms' can be filtered out by verifying the location of
977;# the found sector against the OS/2 geometry it specifies itself, which means
978;# it must be located at the LBA of the SPT-1 it specifies.
979;##############################################################################
980;# ACTION : Locates the Master LVM sector on the specified disk
981;# ----------------------------------------------------------------------------
982;# EFFECTS : None
983;# ----------------------------------------------------------------------------
984;# IN : DL - BIOS disk number of drive to search
985;# ----------------------------------------------------------------------------
986;# OUT : CF=1 - found
987;# : BX:AX - LBA address of LVM sector if found, 0 otherwise
988;##############################################################################
989DriveIO_LocateMasterLVMSector Proc Near uses cx dx si di ds es
990
991IFDEF AUX_DEBUG
992 IF 1
993 pushf
994 pusha
995 push si
996 mov si, offset $+5
997 jmp @F
998 db 10,'DriveIO_LocateMasterLVMSector:',10,0
999 @@:
1000 call AuxIO_Print
1001 pop si
1002 ;~ call DEBUG_DumpRegisters
1003 ;~ call AuxIO_DumpSector
1004 ;~ call AuxIO_DumpParagraph
1005 ;~ call AuxIO_TeletypeNL
1006 popa
1007 popf
1008 ENDIF
1009ENDIF
1010
1011 ; LBA address to start scanning down from
1012 mov cx, 255
1013
1014 ; Make sure ES==DS
1015 push ds
1016 pop es
1017
1018 DriveIO_LocateMasterLVMSector_next:
1019 clc ; Indicate Master LVM sector not found
1020 jcxz DriveIO_LocateMasterLVMSector_done
1021
1022 ; Clear the sector buffer
1023 mov bx, cx ; Save our precious sector LBA
1024 mov cx, 100h ; Clear 256 words is 512 bytes
1025 mov di, offset [TmpSector] ; Offset of buffer
1026 xor ax, ax ; Value to sture
1027 cld ; Increment DI each time
1028 rep stosw ; Store the value
1029 mov cx, bx ; Restore our precious sector LBA
1030
1031 ; Now read the LBA sector specified in CX
1032 mov ax, cx ; LBA low
1033 xor bx, bx ; LBA high
1034 mov di, ds ; Segment of temp buffer
1035 mov si, offset [TmpSector] ; Offset of temp buffer
1036 call DriveIO_ReadSectorLBA ; Read the sector
1037 lahf
1038 dec cx ; Prepare LBA of next sector to read
1039 sahf ; Restore CF
1040 ; No need to do any LVM sector validation when read error, read next
1041 jc DriveIO_LocateMasterLVMSector_next
1042
1043 ; See if the read sector has a valid signature and checksum
1044 call LVM_ValidateSector
1045
1046 ; NC indicates invalid or none-LVM sector, read next
1047 jnc DriveIO_LocateMasterLVMSector_next
1048
1049 ; We have found a valid LVM sector !
1050 ; So it contains the OS/2 geometry for the disk.
1051 ; That means this LVM sector itself must be located on the last sector
1052 ; of the SPT value its OS/2 geometery specifies, which, in LBA terms
1053 ; is LVM SPT-1 -- let's check that...
1054 mov bx, offset [TmpSector] ; Offset of the loaded LVM sector
1055 mov al, [bx+LocLVM_Secs] ; Get the LVM SPT value (<=255)
1056 dec al ; Adjust to LVM LBA
1057 mov ah, cl ; Get next LVM LBA to search
1058 inc ah ; This one was found here
1059 cmp al, ah ; If same, LVM LBA location OK
1060 call DEBUG_DumpRegisters
1061 jne DriveIO_LocateMasterLVMSector_next
1062
1063 ; The LVM sector we found is at the location it should be on disk,
1064 ; so it's almost 99% sure this is the correct one.
1065 ; Now we should compare the start and sizes of the partitions in the
1066 ; MBR with the partitions specified in this LVM record.
1067 ; We'll implement that later after some more research.
1068 ; For now we assume this is the correct Master LVM sector for the disk.
1069 inc cx ; CX was prepared to read next, correct that
1070 stc ; Indicate we have found the Master LVM sector
1071
1072 DriveIO_LocateMasterLVMSector_done:
1073 mov bx, 0 ; A Master LVM sector always has high LBA=0
1074 mov ax, cx ; Low LBA of Master LVM sector
1075
1076 ; We leave it up to the caller to store the value in a proper place
1077 ret
1078DriveIO_LocateMasterLVMSector EndP
1079
1080
1081
1082;
1083; ############################################################
1084; # Check for a valid MBR-sector to be written to disk #
1085; ############################################################
1086;
1087; In
1088; --
1089; DL = Physical Disk
1090; BX:CX = LBA sector
1091; DI:SI = Source buffer
1092;
1093; Out
1094; ---
1095; CY = 1 if invalid MBR in source buffer, 0 if valid
1096;
1097; This routine is called when DriveIO_SaveSector attempts to write to the MBR.
1098; It checks if the sector to be written has some sensible values in certain
1099; places. In fact, if the sector is written to the boot-disk, the AiR-BOOT
1100; signature should be present and the partition table should be the same
1101; as the one at the start of the AiR-BOOT code in memory, except maybe for the
1102; active flags.
1103; For other disks, only the active flags are checked to be 00h or 80h and
1104; the AA55h MBR signature.
1105;
1106DriveIO_ProtectMBR Proc Near
1107 pusha ; Push all registers
1108 push es ; Push ES because we need it for string instructions
1109 push cs ; Make ES point...
1110 pop es ; to CS
1111
1112 ; Save the pointer to the sector to write in BX
1113 mov bx,si
1114
1115 ;
1116 ; If the sector to be written is not the boot-disk, then skip
1117 ; checking the AiR-BOOT MBR.
1118 ;
1119 cmp dl, [BIOS_BootDisk]
1120 jne DriveIO_ProtectMBR_is_not_bootdisk
1121
1122 ;
1123 ; The boot-disk is accessed so the sector to be written must be
1124 ; the AiR-BOOT MBR. This is the same as the first 512 bytes
1125 ; relocated to 8000:0000 and this the start of the AB-code.
1126 ;
1127 mov si,bx ; Get pointer to sector to write
1128 xor di,di ; Point DI to start of AB-code (MBR)
1129 mov cx, offset [MBR_PartTable] ; Bytes upto P-table must be same
1130 cld ; Compare upwards
1131 repe cmpsb ; Compare upto P-table
1132
1133 ; If not the same this is not the an AiR-BOOT boot-disk MBR !
1134 jne DriveIO_ProtectMBR_not_valid_MBR ; SEVERE ERROR !
1135
1136 ; Continue with signature check
1137 jmp DriveIO_ProtectMBR_check_signature
1138
1139
1140 ;
1141 ; The disk is not the boot-disk so we don't know what kind of MBR is on it.
1142 ; Some sanity checks should be here.
1143 ;
1144 DriveIO_ProtectMBR_is_not_bootdisk:
1145
1146 ;
1147 ; sanity checks...
1148 ;
1149
1150 ; Continue with signature check
1151 jmp DriveIO_ProtectMBR_check_signature
1152
1153
1154 DriveIO_ProtectMBR_check_signature:
1155 ; See if the sector to write contains a valid signature
1156 mov si,bx ; Get pointer to sector to write
1157 mov di, offset [MBR_Sig] ; Offset to MBR signature
1158 add si,di ; Make SI point to it in sec to write
1159 lodsw ; Load it
1160 cmp ax,0aa55h ; See if it is valid
1161
1162 ; If no signature this cannot be a valid MBR !
1163 jne DriveIO_ProtectMBR_not_valid_MBR ; SEVERE ERROR !
1164
1165
1166 ;
1167 ; The sector to be written seems to be valid.
1168 ; Set CY=0 to indicate a valid MBR.
1169 ;
1170 DriveIO_ProtectMBR_is_valid_MBR:
1171 clc
1172 jmp DriveIO_ProtectMBR_end
1173
1174 ;
1175 ; Something is terribly wrong; a non-MBR sector seems about to be written.
1176 ; Set CY=1 and let the calling code handle this situation.
1177 ;
1178 DriveIO_ProtectMBR_not_valid_MBR:
1179 stc
1180 jmp DriveIO_ProtectMBR_end
1181
1182 ;
1183 ; Return to the caller with no registers modyfied except FLAGS.
1184 ;
1185 DriveIO_ProtectMBR_end:
1186 pop es
1187 popa
1188 ret
1189DriveIO_ProtectMBR Endp
1190
1191
1192
1193; #########################################################################
1194; Routine: Checks if the MBR is addressed by either CHS or LBA
1195; #########################################################################
1196; Calling : bx:ax - Absolute sector
1197; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
1198; Returns : ZF=1 if MBR is addressed, else ZF=0
1199; Preserve: all registers
1200; #########################################################################
1201DriveIO_MBR_Addressed Proc
1202 push ax
1203 push bx
1204
1205 or bx,ax ; Results in 0 in BX if MBR is addressed by LBA
1206 jz DriveIO_MBR_Addressed_done
1207
1208 mov ax,cx ; Results in 1 in AX if CYL 0, SEC 1 is addressed
1209 add al,dh ; Results in 1 in AX if HEAD 0 is addressed
1210 dec ax ; Results in 0 in AX if MBR is addressed by CHS
1211
1212 DriveIO_MBR_Addressed_done:
1213 pop bx
1214 pop ax
1215 ret
1216DriveIO_MBR_Addressed EndP
1217
1218
1219
1220
1221; #########################################################################
1222; Routine: Writes DS:SI to a specified sector
1223; #########################################################################
1224; Calling : bx:ax - Absolute sector
1225; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
1226; ds:si - Source-Adress
1227; Returns : none
1228; Preserve: all registers
1229; #########################################################################
1230DriveIO_SaveSector Proc Near Uses ax bx cx dx ds si es di
1231
1232IFDEF AUX_DEBUG
1233 IF 0
1234 pushf
1235 pusha
1236 push si
1237 mov si, offset $+5
1238 jmp @F
1239 db 10,'DriveIO_SaveSector:',10,0
1240 @@:
1241 call AuxIO_Print
1242 pop si
1243 ;~ call DEBUG_DumpRegisters
1244 ;~ call AuxIO_DumpParagraph
1245 ;~ call AuxIO_TeletypeNL
1246 popa
1247 popf
1248 ENDIF
1249ENDIF
1250
1251
1252;!
1253;! DEBUG_BLOCK
1254;! Force write to LBA0 to test interception routine.
1255;! Do *NOT* enable unless you are debugging, will overwrite MBR !
1256;!
1257IFDEF AUX_DEBUG
1258 IF 0
1259 pushf
1260 pusha
1261 xor ax,ax
1262 xor bx,bx
1263 xor cx,cx
1264 inc cx
1265 xor dh,dh
1266 popa
1267 popf
1268 ENDIF
1269ENDIF
1270
1271 ;
1272 ; Check if the MBR is the destination for the write.
1273 ; ZF=1 if so.
1274 ;
1275 call DriveIO_MBR_Addressed
1276 jnz DriveIO_SaveSector_continue_write
1277
1278
1279 ; MBR is addressed, check the sector that is requested to be written.
1280 ; For the bootdisk it should contain the AiR-BOOT signature, valid
1281 ; partition-table entries and the AA55h signature.
1282 ; If not, something is terribly wrong in some piece of the AB code.
1283 ; For any other disk (80h+) at least a valid partition table should
1284 ; be present together with the AA55h signature.
1285 call DriveIO_ProtectMBR
1286 jnc DriveIO_SaveSector_continue_write
1287
1288
1289 ;
1290 ; WE HAVE A SEVERE ERROR CONDITION !
1291 ; SOME AB CODE TRIES TO WRITE A NON-MBR TO THE DISK !
1292 ; ASK THE USER TO REPORT THIS !
1293 ; HALT THE SYSTEM !
1294 ;
1295
1296 ; Show error-box
1297 mov cx, 0C04h
1298 mov si, offset NonMBRwrite
1299 call SETUP_ShowErrorBox
1300 mov cx, 0C04h
1301 mov si, offset NonMBRwrite_rep
1302 call SETUP_ShowErrorBox
1303
1304
1305IFDEF AUX_DEBUG
1306 IF 0
1307 pushf
1308 pusha
1309 mov si, offset [NonMBRwrite]
1310 call AuxIO_TeletypeNL
1311 call AuxIO_Print
1312 call AuxIO_TeletypeNL
1313 popa
1314 popf
1315 ENDIF
1316ENDIF
1317
1318 ; Show popup and halt the system.
1319 jmp HaltSystem
1320
1321
1322
1323 ;
1324 ; Continue the write if not MBR sector or MBR to write is validated.
1325 ;
1326 DriveIO_SaveSector_continue_write:
1327 test byte ptr cs:[CurIO_UseExtension], 1
1328 jz DIOSS_UseNormal
1329 ; Are we forced do use LBA via Setting?
1330 ; Always use INT13X on v1.0.8+.
1331 ;~ test byte ptr cs:[CFG_ForceLBAUsage], 1
1332 ;~ jnz DIOSS_UseExtension
1333 jmp DIOSS_UseExtension
1334 ; Is the drive not a harddrive?
1335 cmp dl, 80h
1336 jb DIOSS_UseNormal
1337 ; Upper 8 bits of LBA-address set? -> Use LBA (maximum boundary is FB0400h)
1338 or bh, bh
1339 jnz DIOSS_UseExtension
1340 ; Compare Switch-Table value to bit 16-23 of LBA-address
1341 mov di, dx
1342 and di, 007Fh
1343 cmp bptr cs:[LBASwitchTable+di], bl
1344 jbe DIOSS_UseExtension
1345
1346 DIOSS_UseNormal:
1347
1348IFDEF AUX_DEBUG
1349 IF 0
1350 pusha
1351 push si
1352 mov si, offset $+5
1353 jmp @F
1354 db 10,'DriveIO_WriteSectorCHS:',10,0
1355 @@:
1356 call AuxIO_Print
1357 pop si
1358 call DEBUG_DumpRegisters
1359 call AuxIO_DumpParagraph
1360 call AuxIO_TeletypeNL
1361 popa
1362 ENDIF
1363ENDIF
1364
1365 mov di, 3 ; retry count
1366 DIOSS_ErrorLoop:
1367 push ds
1368 pop es
1369 mov bx, si ; ES:BX - Destination
1370 mov ax, 0301h ; Function 3 - Write Sector
1371 int 13h
1372 jnc DIOSS_Success
1373 dec di ; decrement retry count
1374 jnz DIOSS_ErrorLoop
1375 call MBR_SaveError
1376
1377 DIOSS_UseExtension:
1378
1379 mov di, ds ; segment for transfer address
1380 call DriveIO_WriteSectorLBA ; extended write
1381 jc MBR_SaveError ; halt on error
1382
1383 ;~ push cx
1384 ;~ mov cs:[INT13X_DAP_NumBlocks], 1 ; Copy ONE sector
1385 ;~ mov wptr cs:[INT13X_DAP_Transfer+0], si
1386 ;~ mov cx, ds
1387 ;~ mov wptr cs:[INT13X_DAP_Transfer+2], cx ; Fill out Transfer Adress
1388 ;~ mov wptr cs:[INT13X_DAP_Absolute+0], ax
1389 ;~ mov wptr cs:[INT13X_DAP_Absolute+2], bx ; Fill out Absolute Sector
1390 ;~ push cs
1391 ;~ pop ds
1392 ;~ mov si, offset [INT13X_DAP]
1393 ;~ mov ax, 4300h ; Extended Write (No Verify)
1394 ;~ int 13h
1395 ;~ pop cx
1396 ;~ jnc DIOSS_Success
1397 ;~ call MBR_SaveError
1398
1399 DIOSS_Success:
1400 ret
1401DriveIO_SaveSector EndP
1402
1403
1404
1405; ------------------------------------------------------
1406; Rousseau: # Load the master LVM-sector if one exists #
1407; ------------------------------------------------------
1408; Load the master LVM-sector to get the number of sectors per track as
1409; OS/2 views the drive. If no master LVM-sector is found it is assumed OS/2
1410; is not installed. The master LVM-sector can be located at three different
1411; places depending on drive size and partitioning scheme and driver used.
1412; When DANIS506.ADD is used, the OS/2 extended geometry will be 255/127 for
1413; drives >502GiB but <1TiB. Then the location will be sector 127 which
1414; is LBA 126 (7Eh).
1415; IBM1S506.ADD will always use 255/255 for the extended OS/2 geometry.
1416; DANIS506.ADD will use 255/255 for drives >1TiB.
1417; Then the location of the master LVM-sector will be 255 which is LBA 254 (FEh).
1418; When OS/2 is installed on a huge drive that alread had a system on it, OS/2
1419; will be confined to the lower 502GiB of the drive.
1420; In this case the normal geometry from Int13X will be used.
1421; This is also the case when no valid master LVM-sector can be found.
1422;
1423; Return CF when valid master LVM sector found, NC if not.
1424; Loads sector at [LVMSector] !
1425DriveIO_LoadMasterLVMSector Proc Near
1426
1427IFDEF AUX_DEBUG
1428 IF 0
1429 pushf
1430 pusha
1431 push si
1432 mov si, offset $+5
1433 jmp @F
1434 db 10,'DriveIO_LoadMasterLVMSector:',10,0
1435 @@:
1436 call AuxIO_Print
1437 pop si
1438 ;~ call DEBUG_DumpRegisters
1439 ;~ call AuxIO_DumpParagraph
1440 ;~ call AuxIO_TeletypeNL
1441 popa
1442 popf
1443 ENDIF
1444ENDIF
1445
1446 pusha
1447
1448 ; Loop over the sector-translation table,
1449 ; process the first three values from high (255) to low.
1450 ; (bios spt, most likely 63)
1451 mov cx,3
1452 DriveIO_LoadMasterLVMSector_NextTry:
1453 ; Number of sectors to read
1454 mov [INT13X_DAP_NumBlocks],1
1455
1456 ; Setup destination address
1457 mov si, offset [LVMSector]
1458 mov word ptr [INT13X_DAP_Transfer+0],si
1459 mov ax, ds
1460 mov word ptr [INT13X_DAP_Transfer+2],ax
1461
1462 ; Get the sector-number of the next possible LVM sector (255,127,63)
1463 ; using the translation table and the counter as the index
1464 mov bx,offset [secs_per_track_table]
1465 mov ax,cx ; 1-based index to sec_per_track_table
1466 dec ax ; Adjust to 0-based
1467 xlatb ; Get the (well known) SPT
1468 dec al ; Minus 1 for LVM-record
1469
1470 ;
1471 ; AX now contains the LBA address of the sector
1472 ; that could be an LVM sector.
1473 ; This is all in track0 so the address will not exceed 64kiB sectors.
1474 ;
1475
1476
1477IFDEF AUX_DEBUG
1478 IF 0
1479 pushf
1480 pusha
1481 push si
1482 mov si, offset $+5
1483 jmp @F
1484 db 10,'geo',10,0
1485 @@:
1486 call AuxIO_Print
1487 pop si
1488 call DEBUG_DumpRegisters
1489 call AuxIO_DumpParagraph
1490 call AuxIO_TeletypeNL
1491 popa
1492 popf
1493 ENDIF
1494ENDIF
1495
1496
1497 ; Setup the requested LBA sector number
1498 mov word ptr [INT13X_DAP_Absolute+0],ax ; LBA low NORMAL I/O GEBRUIKEN !
1499 mov word ptr [INT13X_DAP_Absolute+2],00h ; LBA high
1500 mov si, offset [INT13X_DAP] ; address request packet
1501 mov ah, 42h
1502 int 13h ; do the i/o, CF=1->error, CF=0->success
1503
1504IFDEF AUX_DEBUG
1505 IF 0
1506 pushf
1507 pusha
1508 pushf
1509 xor ax, ax
1510 mov al, dl
1511 call AuxIO_TeletypeHexWord
1512 mov al, '#'
1513 call AuxIO_Teletype
1514 popf
1515 mov ax,0000h
1516 rcl al, 1
1517 call AuxIO_TeletypeHexWord
1518 mov al, '#'
1519 call AuxIO_Teletype
1520 mov ax,word ptr [INT13X_DAP_Absolute+0]
1521 call AuxIO_TeletypeHexWord
1522 mov al, '#'
1523 call AuxIO_Teletype
1524 popa
1525 popf
1526 ENDIF
1527ENDIF
1528
1529 cmc ; Complement carry so we can exit imm. on error
1530 jnc DriveIO_LoadMasterLVMSector_End ; oops, return with NC
1531
1532
1533 mov si,offset [LVMSector]
1534
1535 ; See if this is a valid LVM-sector
1536 ; CY if valid
1537 call LVM_ValidateSector
1538
1539
1540
1541IFDEF AUX_DEBUG
1542 IF 0
1543 pushf
1544 pusha
1545 push si
1546 mov si, offset $+5
1547 jmp @F
1548 db 10,'lvm record',10,0
1549 @@:
1550 call AuxIO_Print
1551 pop si
1552 call DEBUG_DumpRegisters
1553 ;~ call AuxIO_DumpSector
1554 mov cx, 7
1555 @@:
1556 call AuxIO_DumpParagraph
1557 call AuxIO_TeletypeNL
1558 add si, 16
1559 loop @B
1560 popa
1561 popf
1562 ENDIF
1563ENDIF
1564
1565
1566 ; Yep, we found the master LVM-sector
1567 jc DriveIO_LoadMasterLVMSector_Found
1568
1569 ; Try next location
1570 loop DriveIO_LoadMasterLVMSector_NextTry
1571
1572 ; No master LVM-sector found, set CF=false
1573 clc
1574
1575 DriveIO_LoadMasterLVMSector_Found:
1576 ; Store the address for later use.
1577 mov ax, word ptr [INT13X_DAP_Absolute]
1578 mov word ptr [MasterLVMLBA], ax
1579
1580 DriveIO_LoadMasterLVMSector_End:
1581 popa
1582 ret
1583DriveIO_LoadMasterLVMSector Endp
1584
1585
1586
1587
1588; ---------------------------------------------------
1589; Rousseau ## Large drives, (OS/2) geometry and LBA ##
1590; ---------------------------------------------------
1591; A sector size of 512 bytes is assumed in the below calculations.
1592; Note that this scheme changes when the sector size will be 4096 or larger,
1593; like with modern drives that do not translate to 512 bytes per sector anymore.
1594; These drives will have a capacity above the 2TiB LBA32 boundary.
1595; For now, we assume drives <=2TiB with a sector size of 512 bytes.
1596
1597; There are a few boundaries that are of importance.
1598; Note that these are disk-boundaries and not partition boundaries.
1599; Even with a small partition, like <502GiB, OS/2 will use extended geometry on
1600; an empty huge disk.
1601; These boundaries are (from high to low):
1602
1603; (code 5)
1604; 2^32 = 4294967296 = 100000000 sectors = 2048 GiB
1605; This is the LBA32 2TiB boundary.
1606; Everything above it must be addressed using LBA48.
1607; OS/2 can currently not address this space above.
1608
1609; (code4)
1610; 65536*255*255 = 4261478400 = FE010000 sectors ~ 2032 GiB
1611; This is the max OS/2 boundary using 255/255 extended geometry.
1612; OS/2 can currently not address this space above.
1613
1614; (code 3)
1615; 2^31 = 2147483648 = 80000000 sectors = 1024 GiB
1616; This is the LBA32 1TiB boundary.
1617; OS/2 can address this space and will use 255/255 extended geometry.
1618
1619; (code 2)
1620; 65536*255*127 = 2122383360 = 7E810000 sectors ~ 1012 GiB
1621; This is the DANI 1TiB boundary.
1622; OS/2 can address this space and will use 255/255 extended geometry.
1623; Below this DANI will use 255/127 extended geometry.
1624; This matters on where the LVM-sectors are located !
1625
1626; (code 1)
1627; 65536*255*63 = 1052835840 = 3EC10000 sectors ~ 502 GiB
1628; This is the current OS/2 limit using this geometry because OS/2 can
1629; currently not address more than 65536 cylinders.
1630; DANI will address space above with 255/127 extended geometry up until
1631; the DANI 1TiB boundary (code 2)
1632
1633; (code 0)
1634; Everything below 65536*255*63 will be addressed using standard geometry.
1635
1636
1637;
1638; This function will return the following values:
1639;
1640
1641; 5 = This drive is above the 2^32 LBA32 (2TB) boundary and has more
1642; than 4294967296 sectors.
1643; LBA48 addressing is needed to access the complete capacity of the drive.
1644; OS/2 is currently unable to do so.
1645
1646; 4 = This drive is above the 65536*255*255 (4261478400) boundary but below 2^32.
1647; This is an OS/2 boundary and OS/2 is not able to access the drive above
1648; this boundary.
1649
1650; 3 = This drive is above the 2^31 (1TB) boundary and has more than
1651; 2147483648 sectors.
1652; OS/2 is able to access the drive using it's extended geometry.
1653; Both DANIS506 and IBM1S506 will use the 255/255 scheme.
1654
1655; 2 = This drive is above the 65536*255*127 (2122383360) boundary but below 2^31.
1656; OS/2 is able to access the drive using it's extended geometry.
1657; Both DANIS506 and IBM1S506 will use the 255/255 scheme.
1658
1659; 1 = This drive is above the 65536*255*63 (1052835840) boundary but
1660; below 65536*255*127.
1661; OS/2 is able to access the drive using it's extended geometry.
1662; Note that DANIS506 will use 255/127 and IBM1S506 will use 255/255 geometry !
1663; Using DANI or IBM influences the location of the LVM info-sectors !
1664
1665; 0 = This drive is below the 65536*255*63 (1052835840) boundary.
1666; OS/2 is able to access this drive using the standard 255/63 geometry.
1667
1668; So, any return value >0 means OS/2 extended geometry will be used.
1669; Value 1 will use 255/127 with DANIS506 but 255/255 with IBM1S506.
1670; Values 2 and 3 will use 255/255 on both drivers.
1671; You can or with 0x01 and check for 3 in this case.
1672; Any value above 3 will be a drive who's capacity cannot be fully used by OS/2
1673; The upper limit of 65536*255*255 will be in effect here.
1674
1675; Note this function currently handles the boot-drive only !
1676; It should be extended and use dl for the drive-number as a parameter.
1677; Because we use this function to get this info in a number of places,
1678; all regs and flags except AX are saved and restored.
1679
1680; DL contains BIOS disk-number; 80h for first, 81h for second, etc.
1681DriveIO_GatherDiskInfo Proc Near
1682
1683IFDEF AUX_DEBUG
1684 IF 0
1685 pushf
1686 pusha
1687 push si
1688 mov si, offset $+5
1689 jmp @F
1690 db 10,'DriveIO_GatherDiskInfo:',10,0
1691 @@:
1692 call AuxIO_Print
1693 pop si
1694 call DEBUG_DumpRegisters
1695 ;~ call AuxIO_DumpParagraph
1696 ;~ call AuxIO_TeletypeNL
1697 popa
1698 popf
1699 ENDIF
1700ENDIF
1701
1702 pushf
1703 push bx
1704 push cx
1705 push dx
1706 push si
1707 push di
1708 push es
1709
1710 ; Set ES to CS for buffer clearing
1711 push cs
1712 pop es
1713
1714 ; Clear the buffer
1715 ; Also setup the buffer size.
1716 ; Old Phoenix BIOSses require word (flags) at 02 to be zero,
1717 ; so we clear the whole buffer to be sure.
1718 mov cx, i13xbuf_size ; Dynamically calculated by assembler.
1719 mov di, offset [i13xbuf] ; Points to size field.
1720 mov [di],cx ; Setup buffer-size.
1721 inc di
1722 inc di ; Now pointing at actual buffer.
1723 xor ah,ah ; Fill value.
1724 cld ; Direction up.
1725 rep stosb ; Clear buffer.
1726
1727 ; Get the drive parameters
1728 mov ah, 48h ; Get Drive Parameters (extended version)
1729 ;mov dl, 80h ; Drive number
1730 mov si, offset [i13xbuf] ; Buffer for result-info
1731 push dx
1732 int 13h ; Call the BIOS-function
1733 pop dx
1734
1735 ; Do some error-checking
1736 or ah,ah ; AH is zero if no error (ZF=1 if no error)
1737 mov ax,0 ; Setup code for non-huge drive (does not influence ZF)
1738 jz DriveIO_GatherDiskInfo_ok ; Return if error (AL<>0 thus ZF=0) but CY not set, assuming non-huge drive
1739 jnc DriveIO_GatherDiskInfo_ok ; Return if error (CY=1), assuming non-huge drive
1740 jmp DriveIO_GatherDiskInfo_ret
1741
1742
1743 DriveIO_GatherDiskInfo_ok:
1744
1745 ;
1746 ; Store the drive geometry
1747 ;
1748
1749 mov si, offset i13xbuf
1750
1751 xor dh,dh
1752 and dl,01111111b
1753 shl dx,1
1754 shl dx,1
1755
1756 ; Store number of cylinders on disk
1757 mov bx, offset BIOS_Cyls
1758 add bx,dx
1759 mov ax,[si+04h]
1760
1761 mov word ptr [bx+00],ax
1762 mov ax,[si+06]
1763 mov word ptr [bx+02],ax
1764
1765 ; Store number of heads per cylinder
1766 mov bx, offset BIOS_Heads
1767 add bx,dx
1768 mov ax,[si+08h]
1769 mov word ptr [bx+00],ax
1770 mov ax,[si+0ah]
1771 mov word ptr [bx+02],ax
1772
1773 ; Store number of sectors per track
1774 mov bx, offset BIOS_Secs
1775 add bx,dx
1776 mov ax,[si+0ch]
1777 mov word ptr [bx+00],ax
1778
1779 ; Update first byte of translation-table to conform to BIOS SPT
1780 ; rousseau.comment.201610122010
1781 ; Very bad !!
1782 ; This table is global and the instruction below would change the
1783 ; first (last checked) 'well known' SPT value to the SPT value of
1784 ; the last disk scanned. This goes wrong when the last disk scanned
1785 ; has a SPT <63, which is often the case when an USB stick is present
1786 ; when AirBoot starts.
1787 ;~ mov byte ptr [secs_per_track_table], al
1788
1789 mov ax,[si+0eh]
1790 mov word ptr [bx+02],ax
1791
1792 ; Store total secs
1793 mov bx, offset [BIOS_TotalSecs]
1794 add bx,dx
1795 add bx,dx
1796 mov ax,[si+10h]
1797
1798 mov word ptr [bx+00],ax
1799 mov ax,[si+12h]
1800 mov word ptr [bx+02],ax
1801 mov ax,[si+14h]
1802 mov word ptr [bx+04],ax
1803 mov ax,[si+18h]
1804 mov word ptr [bx+06],ax
1805
1806 ; Store number of bytes per sector
1807 mov bx, offset [BIOS_Bytes]
1808 add bx,dx
1809 mov ax,[si+18h]
1810 mov [bx],ax
1811
1812
1813 ;
1814 ; See of it's a huge drive of not
1815 ;
1816
1817 ; Drive is larger than 2TiB
1818 mov ax,5 ; Drive code (5)
1819 mov bx, [si+14h] ; Low word of high dword of sector-count
1820 or bx, [si+16h] ; High word of high dword of sector-count
1821 jnz DriveIO_GatherDiskInfo_ret ; If non-zero we have a drive with >2^32 sectors and thus LBA48 addressing
1822
1823 ; Drive is larger than max OS/2 capacity
1824 dec ax ; Drive code (4)
1825 mov bx, [si+12h] ; High word of low dword of sector-count
1826 cmp bx, 0fe01h ; Boundary
1827 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1828 ; we have a drive larger than to 65536*255*255 = FE010000 sectors
1829
1830 ; Drive can be completely utilized by OS/2
1831 dec ax ; Drive code (3)
1832 cmp bx, 8000h ; Boundary
1833 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1834 ; we have a drive larger than 2^31 sectors but smaller than 65536*255*255
1835
1836 ; This is the small area between DANI 1TiB and LBA 1TiB
1837 dec ax ; Drive code (2)
1838 cmp bx, 7e81h ; Boundary
1839 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1840 ; we have a drive larger than 65536*255*127 but <65536*255*255
1841 ; DANIS506.ADD will use 255/255 extended geometry
1842
1843 ; DANI will use 255/127 in this area, this could impact the location of LVM-sectors ! (last sec on track)
1844 dec ax ; Drive code (1)
1845 cmp bx, 3ec1h ; Boundary
1846 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1847 ; we have a drive larger than 65536*255*63 sectors (OS/2 502GiB Limit!)
1848 ; DANIS506.ADD will use 255/127 extended geometry !
1849 ; IBM1S506.ADD will use 255/255 extended geometry !
1850
1851 ; We have a drive that can be addressed using standard 255/63 geometry
1852 dec ax ; Drive code (0)
1853 ; We have a drive smaller than 65536*255*63 = 3EC10000 sectors
1854
1855 DriveIO_GatherDiskInfo_ret:
1856 pop es
1857 pop di
1858 pop si
1859 pop dx
1860 pop cx
1861 pop bx
1862
1863 mov byte ptr [CurIO_UseExtension],1
1864
1865 popf
1866 ret
1867DriveIO_GatherDiskInfo EndP
1868
1869
1870
1871; Values for sectors per track table corresponding to DriveIO_IsHugeDrive return value.
1872secs_per_track_table db 63,127,255,255,255,255
1873
1874db_lmlvm db 'Load Master LVM -- disk: ',0
Note: See TracBrowser for help on using the repository browser.