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

Last change on this file since 49 was 49, checked in by Ben Rietbroek, 11 years ago

Fixed a nasty bug when eCS phase1 is active [2012-05-13]

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 THESE COMMITS!!

Fixes

o Bug Description

When creating a partition in a free space between partitions for
eCS installation, the phase1 boot-through code would calculate the
wrong index for the new partition. As a result the next partition
would be auto-booted instead of the newly installed system.
This bug is also present in v1.07.

o Quick Fix

Run PARTSCAN_ScanForPartitions for a second time when eCS phase1
is active. This resyncs the PartitionXref table.

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