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

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

Updated all debug hooks to use the new macros [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.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 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 : None
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 clc ; Indicate Master LVM sector not found
912 jcxz DriveIO_LocateMasterLVMSector_done
913
914 ; Clear the sector buffer
915 mov bx, cx ; Save our precious sector LBA
916 mov cx, 100h ; Clear 256 words is 512 bytes
917 mov di, offset [TmpSector] ; Offset of buffer
918 xor ax, ax ; Value to sture
919 cld ; Increment DI each time
920 rep stosw ; Store the value
921 mov cx, bx ; Restore our precious sector LBA
922
923 ; Now read the LBA sector specified in CX
924 mov ax, cx ; LBA low
925 xor bx, bx ; LBA high
926 mov di, ds ; Segment of temp buffer
927 mov si, offset [TmpSector] ; Offset of temp buffer
928 call DriveIO_ReadSectorLBA ; Read the sector
929 lahf ; Save CF
930 dec cx ; Prepare LBA of next sector to read
931 sahf ; Restore CF
932 ; No need to do any LVM sector validation when read error, read next
933 jc DriveIO_LocateMasterLVMSector_next
934
935 ; See if the read sector has a valid signature and checksum
936 call LVM_ValidateSector
937
938 ; NC indicates invalid or none-LVM sector, read next
939 jnc DriveIO_LocateMasterLVMSector_next
940
941 ; We have found a valid LVM sector !
942 ; So it contains the OS/2 geometry for the disk.
943 ; That means this LVM sector itself must be located on the last sector
944 ; of the SPT value its OS/2 geometery specifies, which, in LBA terms
945 ; is LVM SPT-1 -- let's check that...
946 mov bx, offset [TmpSector] ; Offset of the loaded LVM sector
947 mov al, [bx+LocLVM_Secs] ; Get the LVM SPT value (<=255)
948 dec al ; Adjust to LVM LBA
949 mov ah, cl ; Get next LVM LBA to search
950 inc ah ; This one was found here
951 cmp al, ah ; If same, LVM LBA location OK
952 call DEBUG_DumpRegisters
953 jne DriveIO_LocateMasterLVMSector_next
954
955 ; The LVM sector we found is at the location it should be on disk,
956 ; so it's almost 99% sure this is the correct one.
957 ; Now we should compare the start and sizes of the partitions in the
958 ; MBR with the partitions specified in this LVM record.
959 ; We'll implement that later after some more research.
960 ; For now we assume this is the correct Master LVM sector for the disk.
961 inc cx ; CX was prepared to read next, correct that
962 stc ; Indicate we have found the Master LVM sector
963
964 DriveIO_LocateMasterLVMSector_done:
965 mov bx, 0 ; A Master LVM sector always has high LBA=0
966 mov ax, cx ; Low LBA of Master LVM sector
967
968 ; We leave it up to the caller to store the value in a proper place
969 ret
970DriveIO_LocateMasterLVMSector EndP
971
972
973
974;
975; ############################################################
976; # Check for a valid MBR-sector to be written to disk #
977; ############################################################
978;
979; In
980; --
981; DL = Physical Disk
982; BX:CX = LBA sector
983; DI:SI = Source buffer
984;
985; Out
986; ---
987; CY = 1 if invalid MBR in source buffer, 0 if valid
988;
989; This routine is called when DriveIO_SaveSector attempts to write to the MBR.
990; It checks if the sector to be written has some sensible values in certain
991; places. In fact, if the sector is written to the boot-disk, the AiR-BOOT
992; signature should be present and the partition table should be the same
993; as the one at the start of the AiR-BOOT code in memory, except maybe for the
994; active flags.
995; For other disks, only the active flags are checked to be 00h or 80h and
996; the AA55h MBR signature.
997;
998DriveIO_ProtectMBR Proc Near
999 pusha ; Push all registers
1000 push es ; Push ES because we need it for string instructions
1001 push cs ; Make ES point...
1002 pop es ; to CS
1003
1004 ; Save the pointer to the sector to write in BX
1005 mov bx,si
1006
1007 ;
1008 ; If the sector to be written is not the boot-disk, then skip
1009 ; checking the AiR-BOOT MBR.
1010 ;
1011 cmp dl, [BIOS_BootDisk]
1012 jne DriveIO_ProtectMBR_is_not_bootdisk
1013
1014 ;
1015 ; The boot-disk is accessed so the sector to be written must be
1016 ; the AiR-BOOT MBR. This is the same as the first 512 bytes
1017 ; relocated to 8000:0000 and this the start of the AB-code.
1018 ;
1019 mov si,bx ; Get pointer to sector to write
1020 xor di,di ; Point DI to start of AB-code (MBR)
1021 mov cx, offset [MBR_PartTable] ; Bytes upto P-table must be same
1022 cld ; Compare upwards
1023 repe cmpsb ; Compare upto P-table
1024
1025 ; If not the same this is not the an AiR-BOOT boot-disk MBR !
1026 jne DriveIO_ProtectMBR_not_valid_MBR ; SEVERE ERROR !
1027
1028 ; Continue with signature check
1029 jmp DriveIO_ProtectMBR_check_signature
1030
1031
1032 ;
1033 ; The disk is not the boot-disk so we don't know what kind of MBR is on it.
1034 ; Some sanity checks should be here.
1035 ;
1036 DriveIO_ProtectMBR_is_not_bootdisk:
1037
1038 ;
1039 ; sanity checks...
1040 ;
1041
1042 ; Continue with signature check
1043 jmp DriveIO_ProtectMBR_check_signature
1044
1045
1046 DriveIO_ProtectMBR_check_signature:
1047 ; See if the sector to write contains a valid signature
1048 mov si,bx ; Get pointer to sector to write
1049 mov di, offset [MBR_Sig] ; Offset to MBR signature
1050 add si,di ; Make SI point to it in sec to write
1051 lodsw ; Load it
1052 cmp ax,0aa55h ; See if it is valid
1053
1054 ; If no signature this cannot be a valid MBR !
1055 jne DriveIO_ProtectMBR_not_valid_MBR ; SEVERE ERROR !
1056
1057
1058 ;
1059 ; The sector to be written seems to be valid.
1060 ; Set CY=0 to indicate a valid MBR.
1061 ;
1062 DriveIO_ProtectMBR_is_valid_MBR:
1063 clc
1064 jmp DriveIO_ProtectMBR_end
1065
1066 ;
1067 ; Something is terribly wrong; a non-MBR sector seems about to be written.
1068 ; Set CY=1 and let the calling code handle this situation.
1069 ;
1070 DriveIO_ProtectMBR_not_valid_MBR:
1071 stc
1072 jmp DriveIO_ProtectMBR_end
1073
1074 ;
1075 ; Return to the caller with no registers modyfied except FLAGS.
1076 ;
1077 DriveIO_ProtectMBR_end:
1078 pop es
1079 popa
1080 ret
1081DriveIO_ProtectMBR Endp
1082
1083
1084
1085; #########################################################################
1086; Routine: Checks if the MBR is addressed by either CHS or LBA
1087; #########################################################################
1088; Calling : bx:ax - Absolute sector
1089; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
1090; Returns : ZF=1 if MBR is addressed, else ZF=0
1091; Preserve: all registers
1092; #########################################################################
1093DriveIO_MBR_Addressed Proc
1094 push ax
1095 push bx
1096
1097 or bx,ax ; Results in 0 in BX if MBR is addressed by LBA
1098 jz DriveIO_MBR_Addressed_done
1099
1100 mov ax,cx ; Results in 1 in AX if CYL 0, SEC 1 is addressed
1101 add al,dh ; Results in 1 in AX if HEAD 0 is addressed
1102 dec ax ; Results in 0 in AX if MBR is addressed by CHS
1103
1104 DriveIO_MBR_Addressed_done:
1105 pop bx
1106 pop ax
1107 ret
1108DriveIO_MBR_Addressed EndP
1109
1110
1111
1112
1113; #########################################################################
1114; Routine: Writes DS:SI to a specified sector
1115; #########################################################################
1116; Calling : bx:ax - Absolute sector
1117; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
1118; ds:si - Source-Adress
1119; Returns : none
1120; Preserve: all registers
1121; #########################################################################
1122DriveIO_SaveSector Proc Near Uses ax bx cx dx ds si es di
1123
1124IFDEF AUX_DEBUG
1125 IF 0
1126 DBG_TEXT_OUT_AUX 'DriveIO_SaveSector:'
1127 PUSHRF
1128 ;~ call DEBUG_DumpRegisters
1129 ;~ call AuxIO_DumpParagraph
1130 ;~ call AuxIO_TeletypeNL
1131 POPRF
1132 ENDIF
1133ENDIF
1134
1135
1136;!
1137;! DEBUG_BLOCK
1138;! Force write to LBA0 to test interception routine.
1139;! Do *NOT* enable unless you are debugging, will overwrite MBR !
1140;!
1141IFDEF AUX_DEBUG
1142 IF 0
1143 pushf
1144 pusha
1145 xor ax,ax
1146 xor bx,bx
1147 xor cx,cx
1148 inc cx
1149 xor dh,dh
1150 popa
1151 popf
1152 ENDIF
1153ENDIF
1154
1155 ;
1156 ; Check if the MBR is the destination for the write.
1157 ; ZF=1 if so.
1158 ;
1159 call DriveIO_MBR_Addressed
1160 jnz DriveIO_SaveSector_continue_write
1161
1162
1163 ; MBR is addressed, check the sector that is requested to be written.
1164 ; For the bootdisk it should contain the AiR-BOOT signature, valid
1165 ; partition-table entries and the AA55h signature.
1166 ; If not, something is terribly wrong in some piece of the AB code.
1167 ; For any other disk (80h+) at least a valid partition table should
1168 ; be present together with the AA55h signature.
1169 call DriveIO_ProtectMBR
1170 jnc DriveIO_SaveSector_continue_write
1171
1172
1173 ;
1174 ; WE HAVE A SEVERE ERROR CONDITION !
1175 ; SOME AB CODE TRIES TO WRITE A NON-MBR TO THE DISK !
1176 ; ASK THE USER TO REPORT THIS !
1177 ; HALT THE SYSTEM !
1178 ;
1179
1180 ; Show error-box
1181 mov cx, 0C04h
1182 mov si, offset NonMBRwrite
1183 call SETUP_ShowErrorBox
1184 mov cx, 0C04h
1185 mov si, offset NonMBRwrite_rep
1186 call SETUP_ShowErrorBox
1187
1188
1189IFDEF AUX_DEBUG
1190 IF 0
1191 pushf
1192 pusha
1193 mov si, offset [NonMBRwrite]
1194 call AuxIO_TeletypeNL
1195 call AuxIO_Print
1196 call AuxIO_TeletypeNL
1197 popa
1198 popf
1199 ENDIF
1200ENDIF
1201
1202 ; Show popup and halt the system.
1203 jmp HaltSystem
1204
1205
1206
1207 ;
1208 ; Continue the write if not MBR sector or MBR to write is validated.
1209 ;
1210 DriveIO_SaveSector_continue_write:
1211 test byte ptr cs:[CurIO_UseExtension], 1
1212 jz DIOSS_UseNormal
1213 ; Are we forced do use LBA via Setting?
1214 ; Always use INT13X on v1.0.8+.
1215 ;~ test byte ptr cs:[CFG_ForceLBAUsage], 1
1216 ;~ jnz DIOSS_UseExtension
1217 jmp DIOSS_UseExtension
1218 ; Is the drive not a harddrive?
1219 cmp dl, 80h
1220 jb DIOSS_UseNormal
1221 ; Upper 8 bits of LBA-address set? -> Use LBA (maximum boundary is FB0400h)
1222 or bh, bh
1223 jnz DIOSS_UseExtension
1224 ; Compare Switch-Table value to bit 16-23 of LBA-address
1225 mov di, dx
1226 and di, 007Fh
1227 cmp bptr cs:[LBASwitchTable+di], bl
1228 jbe DIOSS_UseExtension
1229
1230 DIOSS_UseNormal:
1231
1232IFDEF AUX_DEBUG
1233 IF 0
1234 DBG_TEXT_OUT_AUX 'DriveIO_WriteSectorCHS:'
1235 PUSHRF
1236 call DEBUG_DumpRegisters
1237 call AuxIO_DumpParagraph
1238 call AuxIO_TeletypeNL
1239 POPRF
1240 ENDIF
1241ENDIF
1242
1243 mov di, 3 ; retry count
1244 DIOSS_ErrorLoop:
1245 push ds
1246 pop es
1247 mov bx, si ; ES:BX - Destination
1248 mov ax, 0301h ; Function 3 - Write Sector
1249 int 13h
1250 jnc DIOSS_Success
1251 dec di ; decrement retry count
1252 jnz DIOSS_ErrorLoop
1253 call MBR_SaveError
1254
1255 DIOSS_UseExtension:
1256
1257 mov di, ds ; segment for transfer address
1258 call DriveIO_WriteSectorLBA ; extended write
1259 jc MBR_SaveError ; halt on error
1260
1261 ;~ push cx
1262 ;~ mov cs:[INT13X_DAP_NumBlocks], 1 ; Copy ONE sector
1263 ;~ mov wptr cs:[INT13X_DAP_Transfer+0], si
1264 ;~ mov cx, ds
1265 ;~ mov wptr cs:[INT13X_DAP_Transfer+2], cx ; Fill out Transfer Adress
1266 ;~ mov wptr cs:[INT13X_DAP_Absolute+0], ax
1267 ;~ mov wptr cs:[INT13X_DAP_Absolute+2], bx ; Fill out Absolute Sector
1268 ;~ push cs
1269 ;~ pop ds
1270 ;~ mov si, offset [INT13X_DAP]
1271 ;~ mov ax, 4300h ; Extended Write (No Verify)
1272 ;~ int 13h
1273 ;~ pop cx
1274 ;~ jnc DIOSS_Success
1275 ;~ call MBR_SaveError
1276
1277 DIOSS_Success:
1278 ret
1279DriveIO_SaveSector EndP
1280
1281
1282
1283; ------------------------------------------------------
1284; Rousseau: # Load the master LVM-sector if one exists #
1285; ------------------------------------------------------
1286; Load the master LVM-sector to get the number of sectors per track as
1287; OS/2 views the drive. If no master LVM-sector is found it is assumed OS/2
1288; is not installed. The master LVM-sector can be located at three different
1289; places depending on drive size and partitioning scheme and driver used.
1290; When DANIS506.ADD is used, the OS/2 extended geometry will be 255/127 for
1291; drives >502GiB but <1TiB. Then the location will be sector 127 which
1292; is LBA 126 (7Eh).
1293; IBM1S506.ADD will always use 255/255 for the extended OS/2 geometry.
1294; DANIS506.ADD will use 255/255 for drives >1TiB.
1295; Then the location of the master LVM-sector will be 255 which is LBA 254 (FEh).
1296; When OS/2 is installed on a huge drive that alread had a system on it, OS/2
1297; will be confined to the lower 502GiB of the drive.
1298; In this case the normal geometry from Int13X will be used.
1299; This is also the case when no valid master LVM-sector can be found.
1300;
1301; Return CF when valid master LVM sector found, NC if not.
1302; Loads sector at [LVMSector] !
1303DriveIO_LoadMasterLVMSector Proc Near
1304
1305IFDEF AUX_DEBUG
1306 IF 0
1307 DBG_TEXT_OUT_AUX 'DriveIO_LoadMasterLVMSector:'
1308 PUSHRF
1309 ;~ call DEBUG_DumpRegisters
1310 ;~ call AuxIO_DumpParagraph
1311 ;~ call AuxIO_TeletypeNL
1312 POPRF
1313 ENDIF
1314ENDIF
1315
1316 pusha
1317
1318 ; Loop over the sector-translation table,
1319 ; process the first three values from high (255) to low.
1320 ; (bios spt, most likely 63)
1321 mov cx,3
1322 DriveIO_LoadMasterLVMSector_NextTry:
1323 ; Number of sectors to read
1324 mov [INT13X_DAP_NumBlocks],1
1325
1326 ; Setup destination address
1327 mov si, offset [LVMSector]
1328 mov word ptr [INT13X_DAP_Transfer+0],si
1329 mov ax, ds
1330 mov word ptr [INT13X_DAP_Transfer+2],ax
1331
1332 ; Get the sector-number of the next possible LVM sector (255,127,63)
1333 ; using the translation table and the counter as the index
1334 mov bx,offset [secs_per_track_table]
1335 mov ax,cx ; 1-based index to sec_per_track_table
1336 dec ax ; Adjust to 0-based
1337 xlatb ; Get the (well known) SPT
1338 dec al ; Minus 1 for LVM-record
1339
1340 ;
1341 ; AX now contains the LBA address of the sector
1342 ; that could be an LVM sector.
1343 ; This is all in track0 so the address will not exceed 64kiB sectors.
1344 ;
1345
1346
1347IFDEF AUX_DEBUG
1348 IF 0
1349 DBG_TEXT_OUT_AUX 'geo'
1350 PUSHRF
1351 call DEBUG_DumpRegisters
1352 call AuxIO_DumpParagraph
1353 call AuxIO_TeletypeNL
1354 POPRF
1355 ENDIF
1356ENDIF
1357
1358
1359 ; Setup the requested LBA sector number
1360 mov word ptr [INT13X_DAP_Absolute+0],ax ; LBA low NORMAL I/O GEBRUIKEN !
1361 mov word ptr [INT13X_DAP_Absolute+2],00h ; LBA high
1362 mov si, offset [INT13X_DAP] ; address request packet
1363 mov ah, 42h
1364 int 13h ; do the i/o, CF=1->error, CF=0->success
1365;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1366IFDEF AUX_DEBUG
1367 IF 0
1368 pushf
1369 pusha
1370 pushf
1371 xor ax, ax
1372 mov al, dl
1373 call AuxIO_TeletypeHexWord
1374 mov al, '#'
1375 call AuxIO_Teletype
1376 popf
1377 mov ax,0000h
1378 rcl al, 1
1379 call AuxIO_TeletypeHexWord
1380 mov al, '#'
1381 call AuxIO_Teletype
1382 mov ax,word ptr [INT13X_DAP_Absolute+0]
1383 call AuxIO_TeletypeHexWord
1384 mov al, '#'
1385 call AuxIO_Teletype
1386 popa
1387 popf
1388 ENDIF
1389ENDIF
1390
1391 cmc ; Complement carry so we can exit imm. on error
1392 jnc DriveIO_LoadMasterLVMSector_End ; oops, return with NC
1393
1394
1395 mov si,offset [LVMSector]
1396
1397 ; See if this is a valid LVM-sector
1398 ; CY if valid
1399 call LVM_ValidateSector
1400
1401
1402
1403IFDEF AUX_DEBUG
1404 IF 0
1405 DBG_TEXT_OUT_AUX 'lvm record'
1406 PUSHRF
1407 call DEBUG_DumpRegisters
1408 ;~ call AuxIO_DumpSector
1409 mov cx, 7
1410 @@:
1411 call AuxIO_DumpParagraph
1412 call AuxIO_TeletypeNL
1413 add si, 16
1414 loop @B
1415 POPRF
1416 ENDIF
1417ENDIF
1418
1419
1420 ; Yep, we found the master LVM-sector
1421 jc DriveIO_LoadMasterLVMSector_Found
1422
1423 ; Try next location
1424 loop DriveIO_LoadMasterLVMSector_NextTry
1425
1426 ; No master LVM-sector found, set CF=false
1427 clc
1428
1429 DriveIO_LoadMasterLVMSector_Found:
1430 ; Store the address for later use.
1431 mov ax, word ptr [INT13X_DAP_Absolute]
1432 mov word ptr [MasterLVMLBA], ax
1433
1434 DriveIO_LoadMasterLVMSector_End:
1435 popa
1436 ret
1437DriveIO_LoadMasterLVMSector Endp
1438
1439
1440
1441
1442; ---------------------------------------------------
1443; Rousseau ## Large drives, (OS/2) geometry and LBA ##
1444; ---------------------------------------------------
1445; A sector size of 512 bytes is assumed in the below calculations.
1446; Note that this scheme changes when the sector size will be 4096 or larger,
1447; like with modern drives that do not translate to 512 bytes per sector anymore.
1448; These drives will have a capacity above the 2TiB LBA32 boundary.
1449; For now, we assume drives <=2TiB with a sector size of 512 bytes.
1450
1451; There are a few boundaries that are of importance.
1452; Note that these are disk-boundaries and not partition boundaries.
1453; Even with a small partition, like <502GiB, OS/2 will use extended geometry on
1454; an empty huge disk.
1455; These boundaries are (from high to low):
1456
1457; (code 5)
1458; 2^32 = 4294967296 = 100000000 sectors = 2048 GiB
1459; This is the LBA32 2TiB boundary.
1460; Everything above it must be addressed using LBA48.
1461; OS/2 can currently not address this space above.
1462
1463; (code4)
1464; 65536*255*255 = 4261478400 = FE010000 sectors ~ 2032 GiB
1465; This is the max OS/2 boundary using 255/255 extended geometry.
1466; OS/2 can currently not address this space above.
1467
1468; (code 3)
1469; 2^31 = 2147483648 = 80000000 sectors = 1024 GiB
1470; This is the LBA32 1TiB boundary.
1471; OS/2 can address this space and will use 255/255 extended geometry.
1472
1473; (code 2)
1474; 65536*255*127 = 2122383360 = 7E810000 sectors ~ 1012 GiB
1475; This is the DANI 1TiB boundary.
1476; OS/2 can address this space and will use 255/255 extended geometry.
1477; Below this DANI will use 255/127 extended geometry.
1478; This matters on where the LVM-sectors are located !
1479
1480; (code 1)
1481; 65536*255*63 = 1052835840 = 3EC10000 sectors ~ 502 GiB
1482; This is the current OS/2 limit using this geometry because OS/2 can
1483; currently not address more than 65536 cylinders.
1484; DANI will address space above with 255/127 extended geometry up until
1485; the DANI 1TiB boundary (code 2)
1486
1487; (code 0)
1488; Everything below 65536*255*63 will be addressed using standard geometry.
1489
1490
1491;
1492; This function will return the following values:
1493;
1494
1495; 5 = This drive is above the 2^32 LBA32 (2TB) boundary and has more
1496; than 4294967296 sectors.
1497; LBA48 addressing is needed to access the complete capacity of the drive.
1498; OS/2 is currently unable to do so.
1499
1500; 4 = This drive is above the 65536*255*255 (4261478400) boundary but below 2^32.
1501; This is an OS/2 boundary and OS/2 is not able to access the drive above
1502; this boundary.
1503
1504; 3 = This drive is above the 2^31 (1TB) boundary and has more than
1505; 2147483648 sectors.
1506; OS/2 is able to access the drive using it's extended geometry.
1507; Both DANIS506 and IBM1S506 will use the 255/255 scheme.
1508
1509; 2 = This drive is above the 65536*255*127 (2122383360) boundary but below 2^31.
1510; OS/2 is able to access the drive using it's extended geometry.
1511; Both DANIS506 and IBM1S506 will use the 255/255 scheme.
1512
1513; 1 = This drive is above the 65536*255*63 (1052835840) boundary but
1514; below 65536*255*127.
1515; OS/2 is able to access the drive using it's extended geometry.
1516; Note that DANIS506 will use 255/127 and IBM1S506 will use 255/255 geometry !
1517; Using DANI or IBM influences the location of the LVM info-sectors !
1518
1519; 0 = This drive is below the 65536*255*63 (1052835840) boundary.
1520; OS/2 is able to access this drive using the standard 255/63 geometry.
1521
1522; So, any return value >0 means OS/2 extended geometry will be used.
1523; Value 1 will use 255/127 with DANIS506 but 255/255 with IBM1S506.
1524; Values 2 and 3 will use 255/255 on both drivers.
1525; You can or with 0x01 and check for 3 in this case.
1526; Any value above 3 will be a drive who's capacity cannot be fully used by OS/2
1527; The upper limit of 65536*255*255 will be in effect here.
1528
1529; Note this function currently handles the boot-drive only !
1530; It should be extended and use dl for the drive-number as a parameter.
1531; Because we use this function to get this info in a number of places,
1532; all regs and flags except AX are saved and restored.
1533
1534; DL contains BIOS disk-number; 80h for first, 81h for second, etc.
1535DriveIO_GatherDiskInfo Proc Near
1536
1537IFDEF AUX_DEBUG
1538 IF 0
1539 DBG_TEXT_OUT_AUX 'DriveIO_GatherDiskInfo:'
1540 PUSHRF
1541 call DEBUG_DumpRegisters
1542 ;~ call AuxIO_DumpParagraph
1543 ;~ call AuxIO_TeletypeNL
1544 POPRF
1545 ENDIF
1546ENDIF
1547
1548 pushf
1549 push bx
1550 push cx
1551 push dx
1552 push si
1553 push di
1554 push es
1555
1556 ; Set ES to CS for buffer clearing
1557 push cs
1558 pop es
1559
1560 ; Clear the buffer
1561 ; Also setup the buffer size.
1562 ; Old Phoenix BIOSses require word (flags) at 02 to be zero,
1563 ; so we clear the whole buffer to be sure.
1564 mov cx, i13xbuf_size ; Dynamically calculated by assembler.
1565 mov di, offset [i13xbuf] ; Points to size field.
1566 mov [di],cx ; Setup buffer-size.
1567 inc di
1568 inc di ; Now pointing at actual buffer.
1569 xor ah,ah ; Fill value.
1570 cld ; Direction up.
1571 rep stosb ; Clear buffer.
1572
1573 ; Get the drive parameters
1574 mov ah, 48h ; Get Drive Parameters (extended version)
1575 ;mov dl, 80h ; Drive number
1576 mov si, offset [i13xbuf] ; Buffer for result-info
1577 push dx
1578 int 13h ; Call the BIOS-function
1579 pop dx
1580
1581 ; Do some error-checking
1582 or ah,ah ; AH is zero if no error (ZF=1 if no error)
1583 mov ax,0 ; Setup code for non-huge drive (does not influence ZF)
1584 jz DriveIO_GatherDiskInfo_ok ; Return if error (AL<>0 thus ZF=0) but CY not set, assuming non-huge drive
1585 jnc DriveIO_GatherDiskInfo_ok ; Return if error (CY=1), assuming non-huge drive
1586 jmp DriveIO_GatherDiskInfo_ret
1587
1588
1589 DriveIO_GatherDiskInfo_ok:
1590
1591 ;
1592 ; Store the drive geometry
1593 ;
1594
1595 mov si, offset i13xbuf
1596
1597 xor dh,dh
1598 and dl,01111111b
1599 shl dx,1
1600 shl dx,1
1601
1602 ; Store number of cylinders on disk
1603 mov bx, offset BIOS_Cyls
1604 add bx,dx
1605 mov ax,[si+04h]
1606
1607 mov word ptr [bx+00],ax
1608 mov ax,[si+06]
1609 mov word ptr [bx+02],ax
1610
1611 ; Store number of heads per cylinder
1612 mov bx, offset BIOS_Heads
1613 add bx,dx
1614 mov ax,[si+08h]
1615 mov word ptr [bx+00],ax
1616 mov ax,[si+0ah]
1617 mov word ptr [bx+02],ax
1618
1619 ; Store number of sectors per track
1620 mov bx, offset BIOS_Secs
1621 add bx,dx
1622 mov ax,[si+0ch]
1623 mov word ptr [bx+00],ax
1624
1625 ; Update first byte of translation-table to conform to BIOS SPT
1626 ; rousseau.comment.201610122010
1627 ; Very bad !!
1628 ; This table is global and the instruction below would change the
1629 ; first (last checked) 'well known' SPT value to the SPT value of
1630 ; the last disk scanned. This goes wrong when the last disk scanned
1631 ; has a SPT <63, which is often the case when an USB stick is present
1632 ; when AirBoot starts.
1633 ;~ mov byte ptr [secs_per_track_table], al
1634
1635 mov ax,[si+0eh]
1636 mov word ptr [bx+02],ax
1637
1638 ; Store total secs
1639 mov bx, offset [BIOS_TotalSecs]
1640 add bx,dx
1641 add bx,dx
1642 mov ax,[si+10h]
1643
1644 mov word ptr [bx+00],ax
1645 mov ax,[si+12h]
1646 mov word ptr [bx+02],ax
1647 mov ax,[si+14h]
1648 mov word ptr [bx+04],ax
1649 mov ax,[si+18h]
1650 mov word ptr [bx+06],ax
1651
1652 ; Store number of bytes per sector
1653 mov bx, offset [BIOS_Bytes]
1654 add bx,dx
1655 mov ax,[si+18h]
1656 mov [bx],ax
1657
1658
1659 ;
1660 ; See of it's a huge drive of not
1661 ;
1662
1663 ; Drive is larger than 2TiB
1664 mov ax,5 ; Drive code (5)
1665 mov bx, [si+14h] ; Low word of high dword of sector-count
1666 or bx, [si+16h] ; High word of high dword of sector-count
1667 jnz DriveIO_GatherDiskInfo_ret ; If non-zero we have a drive with >2^32 sectors and thus LBA48 addressing
1668
1669 ; Drive is larger than max OS/2 capacity
1670 dec ax ; Drive code (4)
1671 mov bx, [si+12h] ; High word of low dword of sector-count
1672 cmp bx, 0fe01h ; Boundary
1673 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1674 ; we have a drive larger than to 65536*255*255 = FE010000 sectors
1675
1676 ; Drive can be completely utilized by OS/2
1677 dec ax ; Drive code (3)
1678 cmp bx, 8000h ; Boundary
1679 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1680 ; we have a drive larger than 2^31 sectors but smaller than 65536*255*255
1681
1682 ; This is the small area between DANI 1TiB and LBA 1TiB
1683 dec ax ; Drive code (2)
1684 cmp bx, 7e81h ; Boundary
1685 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1686 ; we have a drive larger than 65536*255*127 but <65536*255*255
1687 ; DANIS506.ADD will use 255/255 extended geometry
1688
1689 ; DANI will use 255/127 in this area, this could impact the location of LVM-sectors ! (last sec on track)
1690 dec ax ; Drive code (1)
1691 cmp bx, 3ec1h ; Boundary
1692 jae DriveIO_GatherDiskInfo_ret ; If above or equal to boundary,
1693 ; we have a drive larger than 65536*255*63 sectors (OS/2 502GiB Limit!)
1694 ; DANIS506.ADD will use 255/127 extended geometry !
1695 ; IBM1S506.ADD will use 255/255 extended geometry !
1696
1697 ; We have a drive that can be addressed using standard 255/63 geometry
1698 dec ax ; Drive code (0)
1699 ; We have a drive smaller than 65536*255*63 = 3EC10000 sectors
1700
1701 DriveIO_GatherDiskInfo_ret:
1702 pop es
1703 pop di
1704 pop si
1705 pop dx
1706 pop cx
1707 pop bx
1708
1709 mov byte ptr [CurIO_UseExtension],1
1710
1711 popf
1712 ret
1713DriveIO_GatherDiskInfo EndP
1714
1715
1716;------------------------------------------------------------------------------
1717; Check if the BIOS disk number in DL is a harddisk and in range
1718;------------------------------------------------------------------------------
1719; IN : DL BIOS disk number (80h etc)
1720; OUT : CF=1 if invalid disk number or out of range
1721; NOTE : Only modifies flags
1722;------------------------------------------------------------------------------
1723DriveIO_IsValidHarddisk Proc Near Uses dx
1724 cmp dl, 80h ; BIOS disk number must be at least 80h
1725 jb @F ; Not a harddisk, exit with CY
1726 mov dh, dl ; Save to do compare
1727 sub dh, 80h ; Now 0 based disk number
1728 inc dh ; Now 1 based disk number
1729 cmp [TotalHarddiscs], dh ; Out of range, exit with CY
1730 @@: ret
1731DriveIO_IsValidHarddisk EndP
1732
1733
1734; Values for sectors per track table corresponding to DriveIO_IsHugeDrive return value.
1735secs_per_track_table db 63,127,255,255,255,255
1736
1737;~ db_lmlvm db 'Load Master LVM -- disk: ',0
Note: See TracBrowser for help on using the repository browser.