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

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

Use SI instead of BX for actions on sector buffers [v1.1.1-testing]

CAUTION:
This is a testbuild !
AirBoot uses the BIOS to access disks and a small coding error can trash
partition tables or other vital disk structures. You are advised to make
backups of TRACK0 and EBRs before using this testbuild. More info at:
https://rousseaux.github.io/netlabs.air-boot/pdf/AirBoot-v1.1.0-manual.pdf

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