source: trunk/BOOTCODE/REGULAR/DRIVEIO.ASM@ 34

Last change on this file since 34 was 34, checked in by Ben Rietbroek, 13 years ago

Reworked Special Partition Handling [2011-11-24]

Changes

Changed the special partitioning handling code to be more aware
of what kind of partition we're dealing with. This is debug-code.
Most of the added functions are actually redundant and are removed
in later revisions.

Note

This commit and all following commits upto and including the RC3
commit [2012-09-09] are delayed commits from a local repository.
Also, the RC (Release Candidate) naming of the corresponding commits
is a bit misleading. One would label a revision with RC when near to
a final release. Since many things have changed between RC1,RC2 & RC3,
these RC's should be interpreted as mile-stones.

WARNING!!

All commits upto and including the commit of [2012-05-13] contain
a severe bug!! Building from these sources and then disabling
the 'force LBA' feature while also using the drive-letter feature or
editing the label can destroy the MBR on all attached disks!!
DO NOT DISABLE 'FORCE LBA USAGE' WHEN BUILT FROM THE ABOVE COMMITS!!

File size: 41.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 ModuleNames
25DB 'DRIVEIO',0
26ENDIF
27
28; Note: Some routines set DS/ES to CS or even address via CS, even if its not
29; needed. This was done for SECURITY. So DO NOT remove it.
30; Its there to make sure the correct data is loaded/written to/from
31; harddrive.
32;
33; IF YOU MODIFY ANYTHING IN HERE, YOU MAY EASILY BREAK YOUR HARDDRIVE!
34
35; Will only load base-configuration, will NOT load IPT nor Hide-Config
36; Those are originally loaded on startup and will NOT get reloaded.
37DriveIO_LoadConfiguration Proc Near Uses ax bx cx dx es
38 mov ax, cs
39 mov es, ax
40 mov bx, offset Configuration
41 mov dx, 0080h ; First harddrive, Sector 55...
42 mov cx, 0037h
43 mov ax, 0201h ; Function 02, read 1 sector...
44 int 13h
45 jnc DIOLC_NoError
46 call MBR_LoadError ; Will Abort BootUp
47 DIOLC_NoError:
48 ret
49DriveIO_LoadConfiguration EndP
50
51DriveIO_SaveConfiguration Proc Near Uses ax bx cx dx ds es si
52 mov ax, cs
53 mov ds, ax
54 mov es, ax ; Safety first (CS==DS==ES)
55 ; --- Overwrite Floppy-Name with "FloppyDrive"
56 mov si, offset TXT_Floppy_Drive
57 mov di, offset PartitionTable
58 sub di, 30 ; Adjust to Floppy-Name
59 mov cx, 11
60 rep movsb
61 mov si, offset Configuration ; Calculate new checksum
62 xor bx, bx
63
64 ; Changed from 5 to calculated value (not here, see compat. issue below)
65 ; Fixes issue: #2987 -- "air-boot doesn't remember drive letter"
66 ; Size of the ab-configuration in 512 byte sectors
67 ;mov cx, (MBR_BackUpMBR - Configuration) / 200h
68
69 ; AB v1.07 stores a 5 sector configuration with a 5 sector checksum.
70 ; AB v1.0.8 *should* stores a 7 sector configuration with a
71 ; 7 sector checksum.
72 ; Because 5 was hardcoded here, SET(A)BOOT v1.07 will see see an AB v1.0.8
73 ; config as corrupted, while this is not the case.
74 ; So, for compatibility reasons, in v1.0.8, the checksum stored is over
75 ; 5 sectors, to be compatible with v1.07.
76 ; This may change (be corrected) in future versions !
77 mov cx,5
78
79 mov dx, [CFG_CheckConfig]
80 mov [CFG_CheckConfig], bx
81 DIOSC_Loop:
82 call MBR_GetCheckOfSector
83 loop DIOSC_Loop
84 mov [CFG_CheckConfig], bx
85 ; --------------------------------------------------------------------
86 ; ES == CS
87 mov bx, offset Configuration
88 mov dx, 0080h ; First harddrive, Sector 55...
89 mov cx, 0037h
90
91 ; Changed from 5 to calculated value
92 ; Fixes issue: #2987 -- "air-boot doesn't remember drive letter"
93 ; Size of the ab-configuration in 512 byte sectors
94 mov al, (MBR_BackUpMBR - Configuration) / 200h
95 mov ah,03h
96
97 int 13h
98 jnc DIOSC_NoError
99 call MBR_SaveError ; Will Abort BootUp
100 DIOSC_NoError:
101 ret
102DriveIO_SaveConfiguration EndP
103
104DriveIO_UpdateFloppyName Proc Near Uses bx cx dx ds si es di
105 mov ax, cs
106 mov ds, ax
107 mov es, ax
108
109 mov ah, 00h ; Function 2 - Reset Drive
110 xor dl, dl
111 int 13h
112 xor dx, dx ; Cylinder=0, Head=0
113 mov cx, 1 ; Sector=1, Drive=0
114 mov bx, offset TmpSector ; ES:BX - TmpSector
115 mov ax, 0201h ; Function 2 - Load Sector
116 int 13h
117 jnc DIOUFN_AllFine
118
119 ; --- Overwrite Floppy-Name with "No Disc"
120 mov si, offset TXT_Floppy_NoDisc
121 xor ax, ax
122 DIOUFN_WriteFloppyName:
123 mov di, offset PartitionTable
124 sub di, 30 ; Adjust to Floppy-Name
125 mov cl, 11
126 rep movsb
127 ret ; AX=-1 -> GotDisc, =0 -> NoDisc
128
129 ; --- Floppy found and read, data in TempSector
130 DIOUFN_AllFine:
131 mov ax, -1
132 mov si, offset TXT_Floppy_NoName
133 cmp wptr es:[bx+54], 'AF'
134 jne DIOUFN_WriteFloppyName
135 cmp wptr es:[bx+56], '1T'
136 jne DIOUFN_WriteFloppyName
137 cmp bptr es:[bx+58], '2'
138 jne DIOUFN_WriteFloppyName
139 mov si, bx
140 add si, 43 ; FAT12 - Volume Label Location
141 jmp DIOUFN_WriteFloppyName
142DriveIO_UpdateFloppyName EndP
143
144; =============================================================================
145; HARDDRIVE / GENERAL ACCESS
146; =============================================================================
147; The following routines are used for harddisc/floppy access.
148; The access is done via INT 13h/CHS or INT 13h/LBA.
149; Access will be done prefered by INT 13h/CHS, because it's (I wonder!) much
150; faster, than the LBA-method. I don't know, why LBA is so slow. Perhaps BIOS.
151;
152; Internal access (to AiR-BOOT) is always done via INT 13h/CHS.
153
154DriveIO_GetHardDriveCount Proc Near Uses ds si
155 push ds si
156 push 0040h
157 pop ds
158 mov si, 0075h
159 mov dh, ds:[si] ; 40:75 -> POST: Total Harddiscs == DL
160 pop si ds
161 mov TotalHarddiscs, dh
162 ret
163DriveIO_GetHardDriveCount EndP
164
165
166; Fills our LBA-Usage table. It holds the LBA-address, where BIOS/CHS access is
167; stopped and BIOS/LBA access is started.
168; This is calculated by Sector*Heads. Comparing will get done with Bit 25-10
169; on LBA sectors, so we actually divide sector number by 1024.
170DriveIO_InitLBASwitchTable Proc Near Uses es di
171 mov di, offset LBASwitchTable
172 mov dh, TotalHarddiscs
173 mov dl, 80h
174 DIOILUT_DriveLoop:
175 push dx di
176 mov ah, 08h
177 int 13h ; DISK - GET DRIVE PARAMETERS
178 mov ah, 0FBh ; Assume 255 heads/63 sectors, if error
179 jc DIOILUT_Error
180 and cl, 111111b ; Isolate lower 6 bits of CL -> sector count
181
182 ; huge disk 127 sec/track on <1TB using DANI
183; mov cl, 07Fh
184
185 ;movzx ax, cl
186 mov al,cl
187 mov ah,0
188
189 mov bl, dh ; DH -> max head number
190 mul bl ; AX = Sectors*Heads
191 shl ah, 1
192 shl ah, 1 ; Shift 2 bits, so we are able to compare to
193 ; bit 16-23 of the LBA address
194 DIOILUT_Error:
195 pop di dx
196 mov bptr ds:[di], ah ; Save that value
197 inc di ; Go to next BYTE
198 inc dl
199 dec dh
200 jnz DIOILUT_DriveLoop
201 ret
202DriveIO_InitLBASwitchTable EndP
203
204
205
206
207; Adjusts BX:AX / CX:DX to meet LVM sector location
208; Destroys SI
209; Rousseau: Enhanced to handle sector-numbers 127 and 255 besides 63 for LVM-info sectors.
210; Ugly, need to cleanup.
211DriveIO_LVMAdjustToInfoSector Proc Near Uses
212
213
214
215; pusha
216; call AuxIO_TeletypeNL
217
218 ; LBA
219; xchg dx,bx
220; call AuxIO_TeletypeHexDWord
221; call AuxIO_TeletypeNL
222; xchg bx,dx
223
224 ; CYL
225; mov al,ch
226; call AuxIO_TeletypeHexByte
227; call AuxIO_TeletypeNL
228
229 ; HEAD
230; mov al,dh
231; call AuxIO_TeletypeHexByte
232; call AuxIO_TeletypeNL
233
234 ; SEC
235; mov al,cl
236; call AuxIO_TeletypeHexByte
237; call AuxIO_TeletypeNL
238
239 ; DRIVE
240; mov al,dl
241; call AuxIO_TeletypeHexByte
242; call AuxIO_TeletypeNL
243
244; popa
245
246
247 ;local ts:word
248 ;local ts2:word
249
250 pusha
251
252 ; Dump drive
253 mov si,offset drive
254; call AuxIO_Print
255 xchg al,dl
256; call AuxIO_TeletypeHexByte
257; call AuxIO_TeletypeNL
258 xchg dl,al
259
260 ; Dump SPT
261 mov si,offset spt_used
262; call AuxIO_Print
263 push dx
264 push bx
265 xor dh,dh
266 and dl,01111111b
267 shl dx,1
268 shl dx,1
269 mov bx, offset TrueSecs
270 add bx,dx
271 mov ax,word ptr [bx]
272
273 ;mov [ts],ax
274
275; call AuxIO_TeletypeHexWord
276; call AuxIO_TeletypeNL
277 pop bx
278 pop dx
279
280 pusha
281 push dx
282 ; Location of extended position
283 mov dx,word ptr [ExtendedAbsPos+02]
284 mov ax,word ptr [ExtendedAbsPos+00]
285; call AuxIO_TeletypeHexDWord
286; call AuxIO_TeletypeNL
287 pop dx
288
289 xor dh,dh
290 and dl,01111111b
291 shl dx,1
292 shl dx,1
293 mov bx, offset TrueSecs
294 add bx,dx
295
296 mov ax, word ptr[bx]
297; call AuxIO_TeletypeHexWord
298; call AuxIO_TeletypeNL
299 mov al,[ExtendedAbsPosSet] ; if true -> 1st sector of extpart (EBR), not logpart(BPB)
300; call AuxIO_TeletypeHexByte
301; call AuxIO_TeletypeNL
302 ; mov si,offset PartitionSector
303 ; call AuxIO_DumpSector
304 popa
305
306 ; LBA
307 mov si,offset before_lvm_adjust
308; call AuxIO_Print
309
310 xchg dx,bx
311; call AuxIO_TeletypeHexDWord
312; call AuxIO_TeletypeNL
313 xchg bx,dx
314 popa
315
316
317 ;or bx,ax
318 test [ExtendedAbsPosSet],1
319 jz pri
320
321
322
323
324 pusha
325 mov si,offset before_lvm_adjust_log
326; call AuxIO_Print
327 ; LBA
328 xchg dx,bx
329; call AuxIO_TeletypeHexDWord
330; call AuxIO_TeletypeNL
331 xchg bx,dx
332 popa
333
334
335 push dx
336 push bx
337 xor dh,dh
338 and dl,01111111b
339 shl dx,1
340 shl dx,1
341 mov bx,offset TrueSecs
342 add bx,dx
343 mov dx,[bx]
344 dec dx
345 add ax,dx
346 pop bx
347 pop dx
348 adc bx,0
349
350
351 pusha
352 mov si,offset after_lvm_adjust_log
353; call AuxIO_Print
354 ; LBA
355 xchg dx,bx
356; call AuxIO_TeletypeHexDWord
357; call AuxIO_TeletypeNL
358 xchg bx,dx
359 popa
360
361 jmp done
362
363
364
365
366pri:
367
368
369 push ax
370 push cx
371 xor ch, ch ; Zero out upper-byte
372
373 push dx
374 xor dh,dh
375 and dl,01111111b
376 shl dx,1
377 shl dx,1
378 push bx
379 mov bx,offset TrueSecs
380 add bx,dx
381 mov ax,[bx]
382 ;mov [ts2],ax
383 pop bx
384 pop dx
385
386
387
388 ;mov al, 63
389 ;call VideoIO_PrintByteDynamicNumber
390 ;self: jmp self
391
392
393
394 ; DEZE WERKT SOMS NIET GOED
395 ; ROMMELT MET CYLINDERS
396 ; ALLEEN TOEPASSEN ALS INT13X NIET ACTIEF !
397
398 and cl, al ; Isolate lower bits, because upper
399 mov ah, 0
400 mov si, ax ; ones may be used for cylinder
401 sub si, cx
402
403 pop cx
404 pop ax
405
406 or cl, al ; Set sector to last sector
407
408 add ax, si ; Adjust lower LBA
409 adc bx, 0 ; Adjust LBA Sector (BX:AX)
410
411
412
413 ;push ax
414 ;call AuxIO_TeletypeHexWord
415 ;call AuxIO_TeletypeNL
416 ;mov ax,[ts]
417 ;call AuxIO_TeletypeHexWord
418 ;call AuxIO_TeletypeNL
419 ;mov ax,[ts2]
420 ;call AuxIO_TeletypeHexWord
421 ;call AuxIO_TeletypeNL
422 ;pop ax
423
424 ;and ax,[ts]
425
426 jmp done
427
428
429
430done:
431
432
433
434 pusha
435 mov si,offset after_lvm_adjust
436; call AuxIO_Print
437 ; LBA
438 xchg dx,bx
439; call AuxIO_TeletypeHexDWord
440; call AuxIO_TeletypeNL
441 xchg bx,dx
442 popa
443
444
445
446; pusha
447; call AuxIO_TeletypeNL
448
449 ; CYL
450; mov al,ch
451; call AuxIO_TeletypeHexByte
452; call AuxIO_TeletypeNL
453
454 ; HEAD
455; mov al,dh
456; call AuxIO_TeletypeHexByte
457; call AuxIO_TeletypeNL
458
459 ; SEC
460; mov al,cl
461; call AuxIO_TeletypeHexByte
462; call AuxIO_TeletypeNL
463
464 ; DRIVE
465; mov al,dl
466; call AuxIO_TeletypeHexByte
467; call AuxIO_TeletypeNL
468
469; popa
470
471
472
473 ret
474DriveIO_LVMAdjustToInfoSector EndP
475
476drive: db 'drive : ',0
477before_lvm_adjust: db 'before lvm adjust : ',0
478after_lvm_adjust: db 'after lvm adjust : ',0
479before_lvm_adjust_log: db 'before lvm logical adjust: ',0
480after_lvm_adjust_log: db 'after lvm logical adjust : ',0
481spt_used: db 'spt used : ',0
482
483
484
485; #########################################################################
486; Routine: Loads partition to ExecBase and checks for validity
487; #########################################################################
488; Calling : bx:ax - Absolute sector
489; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
490; Returns : Carry Set if invalid partition encountered
491; Preserve: all registers
492; #########################################################################
493DriveIO_LoadPartition Proc Near Uses si
494 mov wptr cs:[CurPartition_Location+0], ax
495 mov wptr cs:[CurPartition_Location+2], bx
496 mov wptr cs:[CurPartition_Location+4], dx
497 mov wptr cs:[CurPartition_Location+6], cx ; Saves the location
498 mov si, offset PartitionSector ; DS:SI - ExecBase
499 call DriveIO_LoadSector
500 clc
501 cmp wptr [si+LocBR_Magic], 0AA55h
502 je DIOLP_Success
503 ; We check, if we are scanning partitions. In that case, if CHS is not 0/0/1
504 ; we will display a "bad partition table" message and halt the system.
505 cmp cx, 0001h
506 jne DIOLP_Failed
507 or dh, dh
508 jnz DIOLP_Failed
509 stc ; Set carry, so no partition table
510 DIOLP_Success:
511
512IFDEF AuxDebug
513 ; show current partition location
514 pushf
515 pusha
516 call AuxIO_TeletypeNL
517 mov si,offset db_curpartloc
518 call AuxIO_Print
519 mov dx,word ptr [CurPartition_Location+02]
520 mov ax,word ptr [CurPartition_Location+00]
521 call AuxIO_TeletypeHexDWord
522 call AuxIO_TeletypeNL
523 mov si,offset PartitionSector
524 call AuxIO_DumpSector
525 call AuxIO_TeletypeNL
526 popa
527 popf
528ENDIF
529
530 ret
531 DIOLP_Failed:
532 jmp DriveIO_GotLoadError
533DriveIO_LoadPartition EndP
534
535; #########################################################################
536; Routine: Writes a partition from ExecBase to its original sector
537; #########################################################################
538; Calling : none
539; Returns : none
540; Preserve: all registers
541; #########################################################################
542DriveIO_SavePartition Proc Near Uses ax bx cx dx si
543 mov ax, wptr cs:[CurPartition_Location+0]
544 mov bx, wptr cs:[CurPartition_Location+2]
545 mov dx, wptr cs:[CurPartition_Location+4]
546 mov cx, wptr cs:[CurPartition_Location+6] ; Gets prev. saved location
547 mov si, offset PartitionSector ; DS:SI - ExecBase
548 cmp wptr [si+LocBR_Magic], 0AA55h ; Checks for signature, if not found
549 jne DIOSP_SevereError ; we assume a really bad error
550 call DriveIO_SaveSector
551 DIOSP_SevereError:
552 ret
553DriveIO_SavePartition EndP
554
555; Keeps DS:SI for caller
556DriveIO_LoadTmpSector Proc Near Uses
557 mov si, offset TmpSector
558 call DriveIO_LoadSector ; Uses INT13X if needed
559 ret
560DriveIO_LoadTmpSector EndP
561
562; Keeps DS:SI for caller
563DriveIO_SaveTmpSector Proc Near Uses
564 mov si, offset TmpSector
565 call DriveIO_SaveSector
566 ret
567DriveIO_SaveTmpSector EndP
568
569; Keeps DS:SI for caller, sets carry if valid LVM sector encountered
570DriveIO_LoadLVMSector Proc Near Uses ax bx cx dx
571 test [CFG_IgnoreLVM], 1 ; We are supposed to ignore LVM, so
572 jnz DIOLLVMS_NoLVMSector ; don't load but declare as bad!
573 mov ax, wptr cs:[CurPartition_Location+0]
574 mov bx, wptr cs:[CurPartition_Location+2]
575 mov dx, wptr cs:[CurPartition_Location+4]
576 mov cx, wptr cs:[CurPartition_Location+6] ; Gets cur. partition location
577
578 call DriveIO_LVMAdjustToInfoSector
579
580 mov si, offset LVMSector
581 call DriveIO_LoadSector
582
583IFDEF AuxDebug
584 ; show current partition location
585 pushf
586 pusha
587; call AuxIO_TeletypeNL
588 mov si,offset db_curlvmsec
589; call AuxIO_Print
590 mov dx,bx
591; call AuxIO_TeletypeHexDWord
592; call AuxIO_TeletypeNL
593 mov si,offset LVMSector
594; call AuxIO_DumpSector
595; call AuxIO_TeletypeNL
596 popa
597 popf
598ENDIF
599
600 call LVM_CheckSectorSignature
601 jnc DIOLLVMS_NoLVMSector
602 call LVM_CheckSectorCRC
603 jnc DIOLLVMS_NoLVMSector
604 ret
605 ; This here is called, if an invalid (or no) LVM information sector is found
606 ; It will truncate the first byte of the sector, so all other routines
607 ; will notice it easily by just comparing the first byte.
608 DIOLLVMS_NoLVMSector:
609 mov bptr [si+LocLVM_SignatureStart], 0
610 ret
611DriveIO_LoadLVMSector EndP
612
613; Keeps DS:SI for caller, saves at anytime w/o checks (!)
614DriveIO_SaveLVMSector Proc Near Uses ax bx cx dx
615 test [CFG_IgnoreLVM], 1 ; We are supposed to ignore LVM, so
616 jnz DIOSLVMS_SevereError ; don't save at anytime (security!)
617 mov ax, wptr cs:[CurPartition_Location+0]
618 mov bx, wptr cs:[CurPartition_Location+2]
619 mov dx, wptr cs:[CurPartition_Location+4]
620 mov cx, wptr cs:[CurPartition_Location+6] ; Gets cur. partition location
621 call LVM_CheckSectorSignature
622 jnc DIOSLVMS_SevereError ; LVM Signature must be there
623 call DriveIO_LVMAdjustToInfoSector
624 mov si, offset LVMSector
625 call DriveIO_SaveSector
626 DIOSLVMS_SevereError:
627 ret
628DriveIO_SaveLVMSector EndP
629
630; Memory-Block that holds information for LBA-access via INT 13h
631DriveIO_DAP: db 10h ; Size of paket
632 db 0 ; Reserved
633DriveIO_DAP_NumBlocks dw 0 ; Number of blocks
634DriveIO_DAP_Transfer dd 0 ; Transfer Adress
635DriveIO_DAP_Absolute dd 0 ; Absolute Sector
636 dd 0 ; Second Part of QWORD
637
638; Special error message instead of "LOAD ERROR" during partition scanning,
639; so users will notice that something is bad with their partition table(s)
640DriveIO_GotLoadError Proc Near
641 test cs:CurIO_Scanning, 1 ; Must be CS:, cause DS!=CS maybe here
642 jnz InScanMode
643 jmp MBR_LoadError
644 InScanMode:
645 mov si, offset TXT_BrokenPartitionTable
646 push cs
647 pop ds
648 call MBR_Teletype
649 mov si, offset BrokenHDD
650 sub dl, 50h ; 80h -> '0'
651 cmp dl, 39h
652 jbe DIOGLE_BelowA
653 add dl, 7 ; 3Ah -> 'A'
654 DIOGLE_BelowA:
655 mov bptr [si+5], dl
656 call MBR_Teletype
657 jmp MBRLE_Halt
658DriveIO_GotLoadError EndP
659
660; #########################################################################
661; Routine: Loads a specified sector to DS:DI
662; #########################################################################
663; Calling : bx:ax - Absolute sector
664; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
665; ds:si - Destination-Adress
666; Returns : none
667; Preserve: all registers
668; #########################################################################
669DriveIO_LoadSector Proc Near Uses ax bx ds si es di
670 test cs:[CurIO_UseExtension], 1
671 jz DIOLS_UseNormal
672 ; Are we forced do use LBA via Setting? ; Rousseau: LBA
673 jnz DIOLS_UseExtension
674 ; Is the drive not a harddrive?
675 cmp dl, 80h
676 jb DIOLS_UseNormal
677 ; Upper 8 bits of LBA-address set? -> Use LBA (maximum boundary is FB0400h)
678 or bh, bh
679 jnz DIOLS_UseExtension
680 ; Compare Switch-Table value to bit 16-23 of LBA-address
681 mov di, dx
682 and di, 007Fh
683 cmp bptr cs:[LBASwitchTable+di], bl
684 jbe DIOLS_UseExtension
685 DIOLS_UseNormal:
686 mov di, 3
687 DIOLS_ErrorLoop:
688 push ds
689 pop es
690 mov bx, si ; ES:BX - Destination
691 mov ax, 0201h ; Function 2 - Load Sector
692 int 13h
693 jnc DIOLS_Success
694 dec di
695 jnz DIOLS_ErrorLoop
696 ; Sector load failed...
697 jmp DriveIO_GotLoadError
698
699 DIOLS_UseExtension:
700 push cx
701 mov cs:[DriveIO_DAP_NumBlocks], 1 ; Copy ONE sector
702 mov wptr cs:[DriveIO_DAP_Transfer+0], si
703 mov cx, ds
704 mov wptr cs:[DriveIO_DAP_Transfer+2], cx ; Fill out Transfer Adress
705 mov wptr cs:[DriveIO_DAP_Absolute+0], ax
706 mov wptr cs:[DriveIO_DAP_Absolute+2], bx ; Fill out Absolute Sector
707 push cs
708 pop ds
709 mov si, offset DriveIO_DAP
710 mov ah, 42h ; Extended Read
711 int 13h
712 pop cx
713 jnc DIOLS_Success
714 ; Sector load failed...
715 jmp DriveIO_GotLoadError
716
717 DIOLS_Success:
718 ret
719DriveIO_LoadSector EndP
720
721
722
723;
724; ############################################################
725; # Load a specified sector from a disk using LBA addressing #
726; ############################################################
727;
728; In
729; --
730; DL = Physical Disk
731; BX:CX = LBA sector
732; DI:SI = Target buffer
733;
734; Out
735; ---
736; AX = Error code
737;
738DriveIO_LoadSectorLBA Proc Near Uses bx cx dx si di ds es
739 ; Get one sector
740 mov cs:[DriveIO_DAP_NumBlocks], 1
741
742 ; Setup buffer address
743 mov wptr cs:[DriveIO_DAP_Transfer+0], si
744 mov wptr cs:[DriveIO_DAP_Transfer+2], di
745
746 ; Setup LBA address of requested sector
747 mov wptr cs:[DriveIO_DAP_Absolute+0], cx
748 mov wptr cs:[DriveIO_DAP_Absolute+2], bx
749 mov wptr cs:[DriveIO_DAP_Absolute+4], 0
750 mov wptr cs:[DriveIO_DAP_Absolute+6], 0
751
752 ; Address of packet
753 mov si, offset DriveIO_DAP
754
755 ; Do the extended read
756 mov ah, 42h
757 int 13h
758
759 ; Looking goot so far
760 jnc DriveIO_LoadSectorLBA_succes1
761
762 ; AH should not be zero, if it is then set to undefined and set carry
763 test ah,ah
764 jnz DriveIO_LoadSectorLBA_error1
765 mov ah, 0bbh ; Undefined error
766 DriveIO_LoadSectorLBA_error1:
767 stc
768 jmp DriveIO_LoadSectorLBA_exit
769
770 ; AL should be zero, if not then set to undefined and set carry
771 DriveIO_LoadSectorLBA_succes1:
772 test ah,ah
773 jz DriveIO_LoadSectorLBA_exit
774 stc
775 jmp DriveIO_LoadSectorLBA_exit
776
777 ; Return to caller
778 DriveIO_LoadSectorLBA_exit:
779 ret
780DriveIO_LoadSectorLBA EndP
781
782
783
784
785; #########################################################################
786; Routine: Writes DS:SI to a specified sector
787; #########################################################################
788; Calling : bx:ax - Absolute sector
789; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
790; ds:si - Source-Adress
791; Returns : none
792; Preserve: all registers
793; #########################################################################
794DriveIO_SaveSector Proc Near Uses ax bx cx ds si es di
795 test cs:[CurIO_UseExtension], 1
796 jz DIOSS_UseNormal
797 ; Are we forced do use LBA via Setting?
798 test cs:[CFG_ForceLBAUsage], 1
799 jnz DIOSS_UseExtension
800 ; Is the drive not a harddrive?
801 cmp dl, 80h
802 jb DIOSS_UseNormal
803 ; Upper 8 bits of LBA-address set? -> Use LBA (maximum boundary is FB0400h)
804 or bh, bh
805 jnz DIOSS_UseExtension
806 ; Compare Switch-Table value to bit 16-23 of LBA-address
807 mov di, dx
808 and di, 007Fh
809 cmp bptr cs:[LBASwitchTable+di], bl
810 jbe DIOSS_UseExtension
811 DIOSS_UseNormal:
812 mov di, 3
813 DIOSS_ErrorLoop:
814 push ds
815 pop es
816 mov bx, si ; ES:BX - Destination
817 mov ax, 0301h ; Function 3 - Write Sector
818 int 13h
819 jnc DIOSS_Success
820 dec di
821 jnz DIOSS_ErrorLoop
822 call MBR_SaveError
823
824 DIOSS_UseExtension:
825 push cx
826 mov cs:[DriveIO_DAP_NumBlocks], 1 ; Copy ONE sector
827 mov wptr cs:[DriveIO_DAP_Transfer+0], si
828 mov cx, ds
829 mov wptr cs:[DriveIO_DAP_Transfer+2], cx ; Fill out Transfer Adress
830 mov wptr cs:[DriveIO_DAP_Absolute+0], ax
831 mov wptr cs:[DriveIO_DAP_Absolute+2], bx ; Fill out Absolute Sector
832 push cs
833 pop ds
834 mov si, offset DriveIO_DAP
835 mov ax, 4300h ; Extended Write (No Verify)
836 int 13h
837 pop cx
838 jnc DIOSS_Success
839 call MBR_SaveError
840
841 DIOSS_Success:
842 ret
843DriveIO_SaveSector EndP
844
845
846; See if a LVM-sector is valid.
847; In : si, pointer to sector
848; Out : CY if valid LVM sector, NC if not
849DriveIO_LVMSectorValid Proc Near
850 pusha
851
852 call LVM_CheckSectorSignature
853 ; NC if no signature found
854 jnc DriveIO_LVMSectorValid_End
855
856 call LVM_CheckSectorCRC
857 ; Force valid !!!
858 stc
859
860 DriveIO_LVMSectorValid_End:
861 popa
862 ret
863DriveIO_LVMSectorValid EndP
864
865; ------------------------------------------------------
866; Rousseau: # Load the master LVM-sector is one exists #
867; ------------------------------------------------------
868; Load the master LVM-sector to get the number of sectors per track as eCS views the drive.
869; If no master LVM-sector is found it is assumed eCS is not installed.
870; The master LVM-sector can be located at three different places according to drive size
871; and partitioning scheme and driver used.
872; When DANIS506.ADD is used, the eCS extended geometry will be 255/127 for drives >502GiB but <1TiB.
873; Then the location will be sector 127 which is LBA 126 (7Eh).
874; IBM1S506.ADD will always use 255/255 for the extended eCS geometry.
875; DANIS506.ADD will use 255/255 for drives >1TiB.
876; Then the location of the master LVM-sector will be 255 which is LBA 254 (FEh).
877; When eCS is installed on a huge drive that alread had a system on it, eCS will be confined to the
878; lower 502GiB of the drive. In this case the normal geometry from Int13X will be used.
879; This is also the case when no valid master LVM-sector can be found.
880;
881; Return CF when valid master LVM sector found, NC if not.
882; Loads sector at [LVMSector] !
883DriveIO_LoadMasterLVMSector Proc Near
884 pusha
885
886 mov si,offset db_lmlvm
887 ;call AuxIO_Print
888
889 ; Physical disk
890; mov al,'<'
891; call VideoIO_PrintSingleChar
892; mov al,dl
893; call VideoIO_PrintHexByte
894; mov al,'>'
895; call VideoIO_PrintSingleChar
896
897 ;call AuxIO_TeletypeHexByte
898 ;call AuxIO_TeletypeNL
899
900
901 ; Loop over the sector-translation table,
902 ; process the first three values from high (255) to low (bios spt, most likely 63)
903 mov cx,3
904 DriveIO_LoadMasterLVMSector_NextTry:
905 ; Number of sectors to read
906 mov [DriveIO_DAP_NumBlocks],1
907
908 ; Setup destination address
909 mov si, offset LVMSector
910 mov wptr [DriveIO_DAP_Transfer+0],si
911 mov ax, ds
912 mov wptr [DriveIO_DAP_Transfer+2],ax
913
914 ; Get the sector-number of the next possible LVM sector (255,127,63)
915 ; using the translation table and the counter as the index
916 mov bx,offset secs_per_track_table
917 mov ax,cx
918 dec ax
919 xlatb
920 dec al
921
922 ;
923 ; AX now contains the LBA address of the sector
924 ; that could be an LVM sector.
925 ; This is all in track0 so the address will not exceed 64kiB sectors.
926 ;
927
928; push ax
929; push ax
930; mov al,'$'
931; call VideoIO_PrintSingleChar
932; pop ax
933; call VideoIO_PrintHexByte
934; mov al,'$'
935; call VideoIO_PrintSingleChar
936; pop ax
937
938IFDEF AuxDebug
939 ; Dump the value
940 ;call AuxIO_TeletypeHexByte
941 ;call AuxIO_TeletypeNL
942ENDIF
943
944 ; Setup the requested LBA sector number
945 mov wptr [DriveIO_DAP_Absolute+0],ax ; LBA low
946 mov wptr [DriveIO_DAP_Absolute+2],00h ; LBA high
947 mov si, offset DriveIO_DAP ; address request packet
948 mov ah, 42h
949 int 13h ; do the i/o
950 cmc ; Complement carry so we can exit imm. on error
951 jnc DriveIO_LoadMasterLVMSector_End ; oops, return with NC
952
953
954 mov si,offset LVMSector
955
956 ; See if this is a valid LVM-sector
957 call DriveIO_LVMSectorValid
958
959; pushf
960; mov ah,0
961; rcl ah,1
962; mov al,'|'
963; call VideoIO_PrintSingleChar
964; mov al,ah
965; call VideoIO_PrintHexByte
966; mov al,'|'
967; call VideoIO_PrintSingleChar
968; popf
969
970
971 ; Yep, we found the master LVM-sector
972 jc DriveIO_LoadMasterLVMSector_Found
973 ; Try next location
974 loop DriveIO_LoadMasterLVMSector_NextTry
975
976 ; No master LVM-sector found, set CF=false
977 clc
978
979 DriveIO_LoadMasterLVMSector_Found:
980 DriveIO_LoadMasterLVMSector_End:
981 popa
982 ret
983DriveIO_LoadMasterLVMSector Endp
984
985
986
987
988; ---------------------------------------------------
989; Rousseau ## Large drives, (eCS) geometry and LBA ##
990; ---------------------------------------------------
991; A sector size of 512 bytes is assumed in the below calculations.
992; Note that this scheme changes when the sector size will be 4096 or larger,
993; like with modern drives that do not translate to 512 bytes per sector anymore.
994; These drives will have a capacity above the 2TiB LBA32 boundary.
995; For now, we assume drives <=2TiB with a sector size of 512 bytes.
996
997; There are a few boundaries that are of importance.
998; Note that these are disk-boundaries and not partition boundaries.
999; Even with a small partition, like <502GiB, OS/2 will use extended geometry on an
1000; empty huge disk.
1001; These boundaries are (from high to low):
1002
1003; (code 5)
1004; 2^32 = 4294967296 = 100000000 sectors = 2048 GiB
1005; This is the LBA32 2TiB boundary.
1006; Everything above it must be addressed using LBA48.
1007; OS/2 can currently not address this space above.
1008
1009; (code4)
1010; 65536*255*255 = 4261478400 = FE010000 sectors ~ 2032 GiB
1011; This is the max OS/2 boundary using 255/255 extended geometry.
1012; OS/2 can currently not address this space above.
1013
1014; (code 3)
1015; 2^31 = 2147483648 = 80000000 sectors = 1024 GiB
1016; This is the LBA32 1TiB boundary.
1017; OS/2 can address this space and will use 255/255 extended geometry.
1018
1019; (code 2)
1020; 65536*255*127 = 2122383360 = 7E810000 sectors ~ 1012 GiB
1021; This is the DANI 1TiB boundary.
1022; OS/2 can address this space and will use 255/255 extended geometry.
1023; Below this DANI will use 255/127 extended geometry.
1024; This matters on where the LVM-sectors are located !
1025
1026; (code 1)
1027; 65536*255*63 = 1052835840 = 3EC10000 sectors ~ 502 GiB
1028; This is the current OS/2 limit using this geometry because OS/2 can currently
1029; not address more than 65536 cylinders.
1030; DANI will address space above with 255/127 extended geometry up until the DANI 1TiB boundary (code 2)
1031
1032; (code 0)
1033; Everything below 65536*255*63 will be addressed using standard geometry.
1034
1035
1036;
1037; This function will return the following values:
1038;
1039
1040; 5 = This drive is above the 2^32 LBA32 (2TB) boundary and has more than 4294967296 sectors.
1041; LBA48 addressing is needed to access the complete capacity of the drive.
1042; OS/2 is currently unable to do so.
1043
1044; 4 = This drive is above the 65536*255*255 (4261478400) boundary but below 2^32.
1045; This is an OS/2 boundary and OS/2 is not able to access the drive above this boundary.
1046
1047; 3 = This drive is above the 2^31 (1TB) boundary and has more than 2147483648 sectors.
1048; OS/2 is able to access the drive using it's extended geometry.
1049; Both DANIS506 and IBM1S506 will use the 255/255 scheme.
1050
1051; 2 = This drive is above the 65536*255*127 (2122383360) boundary but below 2^31.
1052; OS/2 is able to access the drive using it's extended geometry.
1053; Both DANIS506 and IBM1S506 will use the 255/255 scheme.
1054
1055; 1 = This drive is above the 65536*255*63 (1052835840) boundary but below 65536*255*127.
1056; OS/2 is able to access the drive using it's extended geometry.
1057; Note that DANIS506 will use 255/127 and IBM1S506 will use 255/255 geometry !
1058; Using DANI or IBM influences the location of the LVM info-sectors !
1059
1060; 0 = This drive is below the 65536*255*63 (1052835840) boundary.
1061; OS/2 is able to access this drive using the standard 255/63 geometry.
1062
1063; So, any return value >0 means OS/2 extended geometry will be used.
1064; Value 1 will use 255/127 with DANIS506 but 255/255 with IBM1S506.
1065; Values 2 and 3 will use 255/255 on both drivers.
1066; You can or with 0x01 and check for 3 in this case.
1067; Any value above 3 will be a drive who's capacity cannot be fully used by OS/2
1068; The upper limit of 65536*255*255 will be in effect here.
1069
1070; Note this function currently handles the boot-drive only !
1071; It should be extended and use dl for the drive-number as a parameter.
1072; Because we use this function to get this info in a number of places,
1073; all regs and flags except AX are saved and restored.
1074
1075; DL contains BIOS disk-number; 80h for first, 81h for second, etc.
1076DriveIO_GatherDiskInfo Proc Near
1077 pushf
1078 push bx
1079 push cx
1080 push dx
1081 push si
1082 push di
1083 push es
1084
1085 ; Set ES to CS for buffer clearing
1086 push cs
1087 pop es
1088
1089 ; Clear the buffer
1090 ; Don't overwrite the word of the buffersize at index 0 !
1091 ; Old Phoenix BIOSses require word (flags) at 02 to be zero,
1092 ; so we clear the whole buffer to be sure.
1093 mov cx, i13xbuf_size
1094 mov di, offset i13xbuf
1095 mov [di],cx
1096 inc di
1097 inc di
1098 xor ah,ah
1099 cld
1100 rep stosb
1101
1102 ; Get the drive parameters
1103 mov ah, 48h ; Get Drive Parameters (extended version)
1104 ;mov dl, 80h ; Drive number
1105 mov si, offset i13xbuf ; Buffer for result-info
1106 push dx
1107 int 13h ; Call the BIOS-function
1108 pop dx
1109
1110 ; Do some error-checking
1111 or ah,ah ; AH is zero if no error (ZF=1 if no error)
1112 mov ax,0 ; Setup code for non-huge drive (does not influence ZF)
1113 jz DriveIO_GatherDiskInfo_ok ; Return if error (AL<>0 thus ZF=0) but CY not set, assuming non-huge drive
1114 jnc DriveIO_GatherDiskInfo_ok ; Return if error (CY=1), assuming non-huge drive
1115 jmp DriveIO_GatherDiskInfo_ret
1116
1117
1118 DriveIO_GatherDiskInfo_ok:
1119
1120 ;
1121 ; Store the drive geometry
1122 ;
1123
1124 mov si, offset i13xbuf
1125
1126 xor dh,dh
1127 and dl,01111111b
1128 shl dx,1
1129 shl dx,1
1130
1131 ; Store number of cylinders on disk
1132 mov bx, offset BIOS_Cyls
1133 add bx,dx
1134 mov ax,[si+04h]
1135
1136 mov word ptr [bx+00],ax
1137 mov ax,[si+06]
1138 mov word ptr [bx+02],ax
1139
1140 ; Store number of heads per cylinder
1141 mov bx, offset BIOS_Heads
1142 add bx,dx
1143 mov ax,[si+08h]
1144 mov word ptr [bx+00],ax
1145 mov ax,[si+0ah]
1146 mov word ptr [bx+02],ax
1147
1148 ; Store number of sectors per track
1149 mov bx, offset BIOS_Secs
1150 add bx,dx
1151 mov ax,[si+0ch]
1152 mov word ptr [bx+00],ax
1153
1154 ; Update first byte of translation-table to conform to BIOS SPT
1155 mov byte ptr [secs_per_track_table], al
1156
1157 mov ax,[si+0eh]
1158 mov word ptr [bx+02],ax
1159
1160 ; Store total secs
1161 mov bx, offset BIOS_TotalSecs
1162 add bx,dx
1163 add bx,dx
1164 mov ax,[si+10h]
1165
1166 mov word ptr [bx+00],ax
1167 mov ax,[si+12h]
1168 mov word ptr [bx+02],ax
1169 mov ax,[si+14h]
1170 mov word ptr [bx+04],ax
1171 mov ax,[si+18h]
1172 mov word ptr [bx+06],ax
1173
1174 ; Store number of bytes per sector
1175 mov bx, offset BIOS_Bytes
1176 add bx,dx
1177 mov ax,[si+18h]
1178 mov [bx],ax
1179
1180
1181 ;
1182 ; See of it's a huge drive of not
1183 ;
1184
1185 ; Drive is larger than 2TiB
1186 mov ax,5 ; Drive code (5)
1187 mov bx, [si+14h] ; Low word of high dword of sector-count
1188 or bx, [si+16h] ; High word of high dword of sector-count
1189 jnz DriveIO_GatherDiskInfo_ret ; If non-zero we have a drive with >2^32 sectors and thus LBA48 addressing
1190
1191 ; Drive is larger than max OS/2 capacity
1192 dec ax ; Drive code (4)
1193 mov bx, [si+12h] ; High word of low dword of sector-count
1194 cmp bx, 0fe01h ; Boundary
1195 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1196 ; we have a drive larger than to 65536*255*255 = FE010000 sectors
1197
1198 ; Drive can be completely utilized by OS/2
1199 dec ax ; Drive code (3)
1200 cmp bx, 8000h ; Boundary
1201 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1202 ; we have a drive larger than 2^31 sectors but smaller than 65536*255*255
1203
1204 ; This is the small area between DANI 1TiB and LBA 1TiB
1205 dec ax ; Drive code (2)
1206 cmp bx, 7e81h ; Boundary
1207 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1208 ; we have a drive larger than 65536*255*127 but <65536*255*255
1209 ; DANIS506.ADD will use 255/255 extended geometry
1210
1211 ; DANI will use 255/127 in this area, this could impact the location of LVM-sectors ! (last sec on track)
1212 dec ax ; Drive code (1)
1213 cmp bx, 3ec1h ; Boundary
1214 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1215 ; we have a drive larger than 65536*255*63 sectors (OS/2 502GiB Limit!)
1216 ; DANIS506.ADD will use 255/127 extended geometry !
1217 ; IBM1S506.ADD will use 255/255 extended geometry !
1218
1219 ; We have a drive that can be addressed using standard 255/63 geometry
1220 dec ax ; Drive code (0)
1221 ; We have a drive smaller than 65536*255*63 = 3EC10000 sectors
1222
1223 DriveIO_GatherDiskInfo_ret:
1224 pop es
1225 pop di
1226 pop si
1227 pop dx
1228 pop cx
1229 pop bx
1230
1231 mov [CurIO_UseExtension],1
1232
1233 popf
1234 ret
1235DriveIO_GatherDiskInfo EndP
1236
1237
1238
1239; Values for sectors per track table corresponding to DriveIO_IsHugeDrive return value.
1240secs_per_track_table: db 63,127,255,255,255,255
1241
1242db_lmlvm: db 'Load Master LVM -- disk: ',0
Note: See TracBrowser for help on using the repository browser.