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

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

Removed these obsolete functions [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: 65.1 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: [CurIO_UseExtension]
32DriveIO_CheckFor13extensions Proc Near Uses ax bx cx dx
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 [Scratch]
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
420
421; Keeps DS:SI for caller, sets carry if valid LVM sector encountered
422DriveIO_LoadLVMSector Proc Near Uses ax bx cx dx
423
424IFDEF AUX_DEBUG
425 IF 0
426 DBG_TEXT_OUT_AUX 'DriveIO_LoadLVMSector:'
427 PUSHRF
428 call DEBUG_DumpRegisters
429 call AuxIO_DumpSector
430 ;~ call AuxIO_DumpParagraph
431 ;~ call AuxIO_TeletypeNL
432 POPRF
433 ENDIF
434ENDIF
435
436 test byte ptr [CFG_IgnoreLVM], 1 ; We are supposed to ignore LVM, so
437 jnz DIOLLVMS_NoLVMSector ; don't load but declare as bad!
438 mov ax, wptr cs:[CurPartition_Location+0]
439 mov bx, wptr cs:[CurPartition_Location+2]
440 mov dx, wptr cs:[CurPartition_Location+4]
441 mov cx, wptr cs:[CurPartition_Location+6] ; Gets cur. partition location
442
443 call DriveIO_LVMAdjustToInfoSector
444
445 mov si, offset [LVMSector]
446 call DriveIO_LoadSector
447
448IFDEF AUX_DEBUG
449 IF 0
450 DBG_TEXT_OUT_AUX 'lvm record ex'
451 PUSHRF
452 ;~ call AuxIO_TeletypeHexWord
453 ;~ call AuxIO_TeletypeNL
454 call DEBUG_DumpRegisters
455 ;~ call AuxIO_DumpSector
456 mov cx, 7
457 @@:
458 call AuxIO_DumpParagraph
459 call AuxIO_TeletypeNL
460 add si, 16
461 loop @B
462 POPRF
463 ENDIF
464ENDIF
465
466
467 call LVM_CheckSectorSignature
468 jnc DIOLLVMS_NoLVMSector
469 call LVM_CheckSectorCRC
470 jnc DIOLLVMS_NoLVMSector
471 ret
472
473 ; This here is called, if an invalid (or no) LVM information sector is found
474 ; It will truncate the first byte of the sector, so all other routines
475 ; will notice it easily by just comparing the first byte.
476 DIOLLVMS_NoLVMSector:
477 mov bptr [si+LocLVM_SignatureStart], 0
478 ret
479DriveIO_LoadLVMSector EndP
480
481
482
483; Keeps DS:SI for caller, saves at anytime w/o checks (!)
484DriveIO_SaveLVMSector Proc Near Uses ax bx cx dx
485
486IFDEF AUX_DEBUG
487 IF 0
488 DBG_TEXT_OUT_AUX 'DriveIO_SaveLVMSector:'
489 PUSHRF
490 ;~ call DEBUG_DumpRegisters
491 ;~ call AuxIO_DumpParagraph
492 ;~ call AuxIO_TeletypeNL
493 POPRF
494 ENDIF
495ENDIF
496
497 test byte ptr [CFG_IgnoreLVM], 1 ; We are supposed to ignore LVM, so
498 jnz DIOSLVMS_SevereError ; don't save at anytime (security!)
499 mov ax, wptr cs:[CurPartition_Location+0]
500 mov bx, wptr cs:[CurPartition_Location+2]
501 mov dx, wptr cs:[CurPartition_Location+4]
502 mov cx, wptr cs:[CurPartition_Location+6] ; Gets cur. partition location
503 call LVM_CheckSectorSignature
504 jnc DIOSLVMS_SevereError ; LVM Signature must be there
505
506IFDEF AUX_DEBUG
507 IF 0
508 pushf
509 pusha
510 ;~ dioatlvm db 'DriveIO_LVMAdjustToInfoSector',10,0
511 ;~ pushf
512 ;~ pusha
513 ;~ mov si,offset dioatlvm
514 ;~ call AuxIO_Print
515 ;~ popa
516 ;~ popf
517 call DEBUG_DumpRegisters
518 call DEBUG_DumpCHS
519 popa
520 popf
521 ENDIF
522ENDIF
523
524 call DriveIO_LVMAdjustToInfoSector
525
526IFDEF AUX_DEBUG
527 IF 0
528 pushf
529 pusha
530 call DEBUG_DumpRegisters
531 call DEBUG_DumpCHS
532 popa
533 popf
534 ENDIF
535ENDIF
536
537 mov si, offset LVMSector
538 call DriveIO_SaveSector
539 DIOSLVMS_SevereError:
540 ret
541DriveIO_SaveLVMSector EndP
542
543
544
545; Special error message instead of "LOAD ERROR" during partition scanning,
546; so users will notice that something is bad with their partition table(s)
547DriveIO_GotLoadError Proc Near
548 test byte ptr cs:[CurIO_Scanning], 1 ; Must be CS:, cause DS!=CS maybe here
549 jnz InScanMode
550 jmp MBR_LoadError
551 InScanMode:
552 mov si, offset TXT_BrokenPartitionTable
553 push cs
554 pop ds
555 call MBR_Teletype
556 mov si, offset BrokenHDD
557 sub dl, 50h ; 80h -> '0'
558 cmp dl, 39h
559 jbe DIOGLE_BelowA
560 add dl, 7 ; 3Ah -> 'A'
561 DIOGLE_BelowA:
562 mov bptr [si+5], dl
563 call MBR_Teletype
564
565 ; JWasm: cannot jump to local label in other procedure.
566 ; Changed to halt here.
567 ;jmp MBRLE_Halt
568 DriveIO_GotLoadError_halt:
569 jmp DriveIO_GotLoadError_halt
570DriveIO_GotLoadError EndP
571
572; #########################################################################
573; Routine: Loads a specified sector to DS:DI
574; #########################################################################
575; Calling : bx:ax - Absolute sector
576; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
577; ds:si - Destination-Adress
578; Returns : none
579; Preserve: all registers
580; #########################################################################
581DriveIO_LoadSector Proc Near Uses ax bx cx dx ds si es di
582
583IFDEF AUX_DEBUG
584 IF 0
585 DBG_TEXT_OUT_AUX 'DriveIO_LoadSector:'
586 PUSHRF
587 call DEBUG_DumpRegisters
588 ;~ call AuxIO_DumpParagraph
589 ;~ call AuxIO_TeletypeNL
590 POPRF
591 ENDIF
592ENDIF
593
594 ; Is the drive not a harddrive?
595 cmp dl, 80h
596 jb DIOLS_UseNormal
597
598 test byte ptr cs:[CurIO_UseExtension], 1
599 jz DIOLS_UseNormal
600 ; Are we forced do use LBA via Setting?
601 jnz DIOLS_UseExtension
602
603 ; Upper 8 bits of LBA-address set?
604 ; Then use LBA (maximum boundary is 16320x16x63 = FB0400h)
605 or bh, bh
606 jnz DIOLS_UseExtension
607 ; Compare Switch-Table value to bit 16-23 of LBA-address
608 mov di, dx
609 and di, 007Fh
610 cmp bptr cs:[LBASwitchTable+di], bl
611 jbe DIOLS_UseExtension
612
613 DIOLS_UseNormal:
614
615IFDEF AUX_DEBUG
616 IF 0
617 DBG_TEXT_OUT_AUX 'DriveIO_ReadSectorCHS:'
618 PUSHRF
619 call DEBUG_DumpRegisters
620 call AuxIO_DumpParagraph
621 call AuxIO_TeletypeNL
622 POPRF
623 ENDIF
624ENDIF
625
626 mov di, 3 ; retry count
627 DIOLS_ErrorLoop:
628 push ds
629 pop es
630 mov bx, si ; ES:BX - Destination
631 mov ax, 0201h ; Function 2 - Load Sector
632 int 13h
633 jnc DIOLS_Success
634 dec di ; decrement retry count
635 jnz DIOLS_ErrorLoop
636
637 ; Sector load failed...
638 jmp DriveIO_GotLoadError
639
640 DIOLS_UseExtension:
641
642 mov di, ds ; segment for transfer address
643 call DriveIO_ReadSectorLBA ; extended read
644 jc DriveIO_GotLoadError ; halt on error
645
646 ;~ push cx
647 ;~ mov cs:[INT13X_DAP_NumBlocks], 1 ; Copy ONE sector
648 ;~ mov wptr cs:[INT13X_DAP_Transfer+0], si
649 ;~ mov cx, ds
650 ;~ mov wptr cs:[INT13X_DAP_Transfer+2], cx ; Fill out Transfer Adress
651 ;~ mov wptr cs:[INT13X_DAP_Absolute+0], ax
652 ;~ mov wptr cs:[INT13X_DAP_Absolute+2], bx ; Fill out Absolute Sector
653 ;~ push cs
654 ;~ pop ds
655 ;~ mov si, offset [INT13X_DAP]
656 ;~ mov ah, 42h ; Extended Read
657 ;~ int 13h
658 ;~ pop cx
659 ;~ jnc DIOLS_Success
660
661 ; Sector load failed...
662 ;~ jmp DriveIO_GotLoadError
663
664 DIOLS_Success:
665
666IFDEF AUX_DEBUG
667 IF 0
668 DBG_TEXT_OUT_AUX 'sector loaded'
669 PUSHRF
670 ;~ call DEBUG_DumpRegisters
671 ;~ call AuxIO_DumpSector
672 mov cx, 32
673 @@:
674 call AuxIO_DumpParagraph
675 call AuxIO_TeletypeNL
676 add si, 16
677 loop @B
678 POPRF
679 ENDIF
680ENDIF
681 ret
682DriveIO_LoadSector EndP
683
684
685;##############################################################################
686;# ACTION : Loads the Master Boot Record from the specified drive into buffer
687;# ----------------------------------------------------------------------------
688;# EFFECTS : Modifies DAP structure and fills or clears transfer buffer
689;# ----------------------------------------------------------------------------
690;# IN : DL - BIOS disk number (80h,81h,etc)
691;# : SI - Pointer to transfer buffer
692;# ----------------------------------------------------------------------------
693;# OUT : CF=1 - failure
694;# : AL.0 - MBR signature present
695;# : AL.1 - Primary partitions present
696;# : AL.2 - Extended partitions present
697;# : AL.3 - AiR-BOOT signature present
698;# : AL.4:7 - Reserved, returned as 0
699;# : AH.0:7 - Reserved, returned as 0
700;##############################################################################
701DriveIO_LoadMBR Proc Near uses bx cx dx si di
702
703 ; Always clear the transfer buffer first
704 call ClearSectorBuffer
705
706 ; Assume an invalid MBR
707 xor ax, ax
708
709 ; Accept only valid harddisks
710 call DriveIO_IsValidHarddisk
711 jc DriveIO_LoadMBR_exit
712
713 ; Save the address of the transfer buffer
714 mov di, si
715
716 ; Read the MBR from disk
717 xor ax, ax ; LBA low
718 xor bx, bx ; LBA high
719 xor dh, dh ; Head 0
720 mov cx, 1 ; Sector 1
721 call DriveIO_LoadSector ; Read the sector from disk
722
723 ; Check the loaded MBR for a signature
724 xor ax, ax ; Assume an invalid MBR
725 mov dx, [si+LocBR_Magic] ; Get word from MBR signature location
726 cmp dx, 0aa55h ; Is it the magic value ?
727 jne DriveIO_LoadMBR_exit ; Nope, no need to test anything else
728
729 ; Indicate we have a MBR signature
730 or al, 01h
731
732 ; Advance to the partition table
733 add si, 01beh
734
735 ; Total of 4 entries to check
736 mov cx, 4
737
738 DriveIO_LoadMBR_next_entry:
739 mov dl, [si+LocBRPT_SystemID] ; Get partition-type / system-id
740 add si, 10h ; Point to next entry
741 test dl, dl ; Nothing in this one ?
742 loopz DriveIO_LoadMBR_next_entry ; Then check next entry
743
744 ; All entries checked and last one was also empty, we're done
745 jz DriveIO_LoadMBR_check_ab
746
747 ; Found a non-empty entry, set bits according to its type
748 cmp dl, 05h ; Old style extended container ?
749 jne @F ; Nope...
750 or al, 04h ; Yep, mark ext. container present
751 @@: cmp dl, 0fh ; New style extended container ?
752 jne @F ; Nope...
753 or al, 04h ; Yep, mark ext. container present
754 @@: or al, 02h ; Then is must be a primary
755 jcxz DriveIO_LoadMBR_check_ab ; CX=0? Then all entries processed,
756 jmp DriveIO_LoadMBR_next_entry ; otherwise check next entry
757
758 ; Check if an AiR-BOOT signature is present
759 DriveIO_LoadMBR_check_ab:
760 mov si, offset [MBR_ABSig] ; Offset of AiR-BOOT signature
761 inc di ; Advance buffer pointer
762 inc di ; to AiR-BOOT signature location
763 mov cx, 7 ; Length of AiR-BOOT signature
764 cld ; Direction upwards
765 repe cmpsb ; Compare 7 bytes
766 jne DriveIO_LoadMBR_exit ; Nope, no AiR-BOOT on this disk
767 or al, 08h ; Yep, AiR-BOOT is on this disk
768 ;~ jmp DriveIO_LoadMBR_exit
769
770 DriveIO_LoadMBR_exit:
771 ret
772DriveIO_LoadMBR EndP
773
774
775;##############################################################################
776;# ACTION : Reads a sector from disk using INT13 extensions
777;# ----------------------------------------------------------------------------
778;# EFFECTS : Modifies DAP structure and fills transfer buffer
779;# ----------------------------------------------------------------------------
780;# IN : BX:AX - LBA address of sector
781;# : DI:SI - SEG:OFF of transfer buffer
782;# ----------------------------------------------------------------------------
783;# OUT : CF=1 - failure
784;##############################################################################
785DriveIO_ReadSectorLBA Proc Near
786
787IFDEF AUX_DEBUG
788 IF 0
789 DBG_TEXT_OUT_AUX 'DriveIO_ReadSectorLBA:'
790 PUSHRF
791 call DEBUG_DumpRegisters
792 call AuxIO_DumpParagraph
793 call AuxIO_TeletypeNL
794 POPRF
795 ENDIF
796ENDIF
797
798 ; Push all registers
799 pusha
800 push ds
801 push es
802
803 ; One sector to read
804 mov cs:[INT13X_DAP_NumBlocks], 1
805
806 ; Setup transfer address
807 mov wptr cs:[INT13X_DAP_Transfer+0], si ; offset
808 mov wptr cs:[INT13X_DAP_Transfer+2], di ; segment
809
810 ; Setup LBA64 address of requested sector
811 mov wptr cs:[INT13X_DAP_Absolute+0], ax ; low word lower part
812 mov wptr cs:[INT13X_DAP_Absolute+2], bx ; high word lower part
813 mov wptr cs:[INT13X_DAP_Absolute+4], 0 ; low word upper part
814 mov wptr cs:[INT13X_DAP_Absolute+6], 0 ; high word upper part
815
816 ; Address of packet
817 mov si, offset [INT13X_DAP] ; disk address packet
818
819 ; Do the extended read
820 mov ah, 42h ; read function
821 int 13h ; transfer to bios
822
823 ; Error occured
824 jc DriveIO_ReadSectorLBA_exit
825
826 ; AH should also be zero
827 test ah, ah
828 stc
829 jnz DriveIO_ReadSectorLBA_exit
830
831 ; Disk read succeeded, clear CF
832 clc
833
834 DriveIO_ReadSectorLBA_exit:
835
836 ; Pop all registers
837 pop es
838 pop ds
839 popa
840
841 ret
842DriveIO_ReadSectorLBA EndP
843
844
845
846;##############################################################################
847;# ACTION : Writes a sector to disk using INT13 extensions
848;# ----------------------------------------------------------------------------
849;# EFFECTS : Modifies DAP structure and mofifies the disk
850;# ----------------------------------------------------------------------------
851;# IN : BX:AX - LBA address of sector
852;# : DI:SI - SEG:OFF of transfer buffer
853;# ----------------------------------------------------------------------------
854;# OUT : CF=1 - failure
855;##############################################################################
856DriveIO_WriteSectorLBA Proc Near
857
858IFDEF AUX_DEBUG
859 IF 0
860 DBG_TEXT_OUT_AUX 'DriveIO_WriteSectorLBA:'
861 PUSHRF
862 call DEBUG_DumpRegisters
863 call AuxIO_DumpParagraph
864 call AuxIO_TeletypeNL
865 POPRF
866 ENDIF
867ENDIF
868
869 ; Push all registers
870 pusha
871 push ds
872 push es
873
874 ; One sector to read
875 mov cs:[INT13X_DAP_NumBlocks], 1
876
877 ; Setup transfer address
878 mov wptr cs:[INT13X_DAP_Transfer+0], si ; offset
879 mov wptr cs:[INT13X_DAP_Transfer+2], di ; segment
880
881 ; Setup LBA64 address of requested sector
882 mov wptr cs:[INT13X_DAP_Absolute+0], ax ; low word lower part
883 mov wptr cs:[INT13X_DAP_Absolute+2], bx ; high word lower part
884 mov wptr cs:[INT13X_DAP_Absolute+4], 0 ; low word upper part
885 mov wptr cs:[INT13X_DAP_Absolute+6], 0 ; high word upper part
886
887 ; Address of packet
888 mov si, offset [INT13X_DAP] ; disk address packet
889
890 ; Do the extended write
891 xor al, al ; no write verify
892 mov ah, 43h ; write function
893 int 13h ; transfer to bios
894
895 ; Error occured
896 jc DriveIO_WriteSectorLBA_exit
897
898 ; AH should also be zero
899 test ah, ah
900 stc
901 jnz DriveIO_WriteSectorLBA_exit
902
903 ; Disk write succeeded, clear CF
904 clc
905
906 DriveIO_WriteSectorLBA_exit:
907
908 ; Pop all registers
909 pop es
910 pop ds
911 popa
912
913 ret
914DriveIO_WriteSectorLBA EndP
915
916
917
918
919;##############################################################################
920;# The Master LVM sector is *not* necessarily located at the end of the BIOS
921;# view of TRACK0. Its location depends on the *OS/2 geometry* active when the
922;# disk was partitioned. For disks < 502MiB this will most likely be LBA sector
923;# 62, but for disks >502MiB, *extended* OS/2 geometry was used and DANIS506
924;# uses SPT=127 for disks < 1TiB while IBMS506 uses SPT=255.
925;# When a huge disk < 1TiB was partitioned with IBMS506, thus using SPT=255,
926;# and the driver was later changed to DANIS506, DANI uses SPT=255, eventhough
927;# the disk < 1TiB. Whether it is DANI that is LVM aware or something else
928;# (maybe LVM itself) that makes DANI use the correct geometry has yet to be
929;# investigated.
930;#
931;# Related geometry issues are also present with USB sticks, which can get
932;# assigned a geometry by OS/2, which can depend if the stick was partitioned
933;# on foreign systems or not, or even OS/2 manufacturing a geometry that is not
934;# the same as the BIOS reports to us here. In both cases, fixed disks and
935;# removable disks, the geometry recorded in the BPB of a partition can also
936;# influence the geometry that OS/2 assigns. This is the case when 'preparing'
937;# disks for LVM use, in which case BPB values could be incorporated.
938;#
939;# What this all boils down to, is that the geometry reported by the BIOS is
940;# of no practical use, especially not when taking BIOS USB MSD emulation into
941;# account. These are among the reasons why AirBoot needs to use LBA addressing
942;# when handling LVM stuff and why LBA use cannot be disabled in the SETUP
943;# anymore.
944;#
945;# So, a Master LVM sector can be present on any sector from LBA 254 downwards
946;# and the only way to locate the correct one is to scan all the way down and,
947;# if one is found, do proper validation on its values, because it may also be
948;# a 'phantom' LVM sector left over from previous partition layouts.
949;# Most of such 'phantoms' can be filtered out by verifying the location of
950;# the found sector against the OS/2 geometry it specifies itself, which means
951;# it must be located at the LBA of the SPT-1 it specifies.
952;##############################################################################
953;# ACTION : Locates the Master LVM sector on the specified disk
954;# ----------------------------------------------------------------------------
955;# EFFECTS : Leaves [Scratch] with last sector read or cleared
956;# ----------------------------------------------------------------------------
957;# IN : DL - BIOS disk number of drive to search
958;# ----------------------------------------------------------------------------
959;# OUT : CF=1 - found
960;# : BX:AX - LBA address of LVM sector if found, 0 otherwise
961;##############################################################################
962DriveIO_LocateMasterLVMSector Proc Near uses cx dx si di ds es
963
964IFDEF AUX_DEBUG
965 IF 1
966 DBG_TEXT_OUT_AUX 'DriveIO_LocateMasterLVMSector:'
967 PUSHRF
968 call DEBUG_DumpRegisters
969 ;~ call AuxIO_DumpSector
970 ;~ call AuxIO_DumpParagraph
971 ;~ call AuxIO_TeletypeNL
972 POPRF
973 ENDIF
974ENDIF
975
976 ; LBA address to start scanning down from
977 mov cx, 255
978
979 ; Make sure ES==DS
980 push ds
981 pop es
982
983 ; Because JCXZ is used, LBA sector 0 is never loaded and checked.
984 ; This is of course no problem since it is the MBR.
985 DriveIO_LocateMasterLVMSector_next:
986 mov si, offset [Scratch] ; Use scratch area to load sectors
987 call ClearSectorBuffer ; Clear the scratch area
988 clc ; Indicate Master LVM sector not found
989 jcxz DriveIO_LocateMasterLVMSector_done
990
991 ; Read the LBA sector specified in CX
992 mov ax, cx ; LBA low
993 xor bx, bx ; LBA high
994 mov di, ds ; Segment of scratch buffer
995 mov si, offset [Scratch] ; Offset of scratch buffer
996 call DriveIO_ReadSectorLBA ; Read the sector
997 lahf ; Save CF
998 dec cx ; Prepare LBA of next sector to read
999 sahf ; Restore CF
1000 ; No need to do any LVM sector validation when read error, read next
1001 jc DriveIO_LocateMasterLVMSector_next
1002
1003 ; See if the read sector has a valid signature and checksum
1004 call LVM_ValidateSector
1005
1006 ; NC indicates invalid or none-LVM sector, read next
1007 jnc DriveIO_LocateMasterLVMSector_next
1008
1009 ; We have found a valid LVM sector !
1010 ; So it contains the OS/2 geometry for the disk.
1011 ; That means this LVM sector itself must be located on the last sector
1012 ; of the SPT value its OS/2 geometery specifies, which, in LBA terms
1013 ; is LVM SPT-1 -- let's check that...
1014 mov bx, offset [Scratch] ; Offset of the loaded LVM sector
1015 mov al, [bx+LocLVM_Secs] ; Get the LVM SPT value (<=255)
1016 dec al ; Adjust to LVM LBA
1017 mov ah, cl ; Get next LVM LBA to search
1018 inc ah ; This one was found here
1019 cmp al, ah ; If same, LVM LBA location OK
1020 jne DriveIO_LocateMasterLVMSector_next
1021
1022 ; The LVM sector we found is at the location it should be on disk,
1023 ; so it's almost 99% sure this is the correct one.
1024 ; Now we should compare the start and sizes of the partitions in the
1025 ; MBR with the partitions specified in this LVM record.
1026 ; We'll implement that later after some more research.
1027 ; For now we assume this is the correct Master LVM sector for the disk.
1028 inc cx ; CX was prepared to read next, correct that
1029 stc ; Indicate we have found the Master LVM sector
1030
1031 DriveIO_LocateMasterLVMSector_done:
1032 mov bx, 0 ; A Master LVM sector always has high LBA=0
1033 mov ax, cx ; Low LBA of Master LVM sector
1034
1035 ; We leave it up to the caller to store the value in a proper place
1036 ret
1037DriveIO_LocateMasterLVMSector EndP
1038
1039
1040
1041;
1042; ############################################################
1043; # Check for a valid MBR-sector to be written to disk #
1044; ############################################################
1045;
1046; In
1047; --
1048; DL = Physical Disk
1049; BX:CX = LBA sector
1050; DI:SI = Source buffer
1051;
1052; Out
1053; ---
1054; CY = 1 if invalid MBR in source buffer, 0 if valid
1055;
1056; This routine is called when DriveIO_SaveSector attempts to write to the MBR.
1057; It checks if the sector to be written has some sensible values in certain
1058; places. In fact, if the sector is written to the boot-disk, the AiR-BOOT
1059; signature should be present and the partition table should be the same
1060; as the one at the start of the AiR-BOOT code in memory, except maybe for the
1061; active flags.
1062; For other disks, only the active flags are checked to be 00h or 80h and
1063; the AA55h MBR signature.
1064;
1065DriveIO_ProtectMBR Proc Near
1066 pusha ; Push all registers
1067 push es ; Push ES because we need it for string instructions
1068 push cs ; Make ES point...
1069 pop es ; to CS
1070
1071 ; Save the pointer to the sector to write in BX
1072 mov bx,si
1073
1074 ;
1075 ; If the sector to be written is not the boot-disk, then skip
1076 ; checking the AiR-BOOT MBR.
1077 ;
1078 cmp dl, [BIOS_BootDisk]
1079 jne DriveIO_ProtectMBR_is_not_bootdisk
1080
1081 ;
1082 ; The boot-disk is accessed so the sector to be written must be
1083 ; the AiR-BOOT MBR. This is the same as the first 512 bytes
1084 ; relocated to 8000:0000 and this the start of the AB-code.
1085 ;
1086 mov si,bx ; Get pointer to sector to write
1087 xor di,di ; Point DI to start of AB-code (MBR)
1088 mov cx, offset [MBR_PartTable] ; Bytes upto P-table must be same
1089 cld ; Compare upwards
1090 repe cmpsb ; Compare upto P-table
1091
1092 ; If not the same this is not the an AiR-BOOT boot-disk MBR !
1093 jne DriveIO_ProtectMBR_not_valid_MBR ; SEVERE ERROR !
1094
1095 ; Continue with signature check
1096 jmp DriveIO_ProtectMBR_check_signature
1097
1098
1099 ;
1100 ; The disk is not the boot-disk so we don't know what kind of MBR is on it.
1101 ; Some sanity checks should be here.
1102 ;
1103 DriveIO_ProtectMBR_is_not_bootdisk:
1104
1105 ;
1106 ; sanity checks...
1107 ;
1108
1109 ; Continue with signature check
1110 jmp DriveIO_ProtectMBR_check_signature
1111
1112
1113 DriveIO_ProtectMBR_check_signature:
1114 ; See if the sector to write contains a valid signature
1115 mov si,bx ; Get pointer to sector to write
1116 mov di, offset [MBR_Sig] ; Offset to MBR signature
1117 add si,di ; Make SI point to it in sec to write
1118 lodsw ; Load it
1119 cmp ax,0aa55h ; See if it is valid
1120
1121 ; If no signature this cannot be a valid MBR !
1122 jne DriveIO_ProtectMBR_not_valid_MBR ; SEVERE ERROR !
1123
1124
1125 ;
1126 ; The sector to be written seems to be valid.
1127 ; Set CY=0 to indicate a valid MBR.
1128 ;
1129 DriveIO_ProtectMBR_is_valid_MBR:
1130 clc
1131 jmp DriveIO_ProtectMBR_end
1132
1133 ;
1134 ; Something is terribly wrong; a non-MBR sector seems about to be written.
1135 ; Set CY=1 and let the calling code handle this situation.
1136 ;
1137 DriveIO_ProtectMBR_not_valid_MBR:
1138 stc
1139 jmp DriveIO_ProtectMBR_end
1140
1141 ;
1142 ; Return to the caller with no registers modyfied except FLAGS.
1143 ;
1144 DriveIO_ProtectMBR_end:
1145 pop es
1146 popa
1147 ret
1148DriveIO_ProtectMBR Endp
1149
1150
1151
1152; #########################################################################
1153; Routine: Checks if the MBR is addressed by either CHS or LBA
1154; #########################################################################
1155; Calling : bx:ax - Absolute sector
1156; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
1157; Returns : ZF=1 if MBR is addressed, else ZF=0
1158; Preserve: all registers
1159; #########################################################################
1160DriveIO_MBR_Addressed Proc
1161 push ax
1162 push bx
1163
1164 or bx,ax ; Results in 0 in BX if MBR is addressed by LBA
1165 jz DriveIO_MBR_Addressed_done
1166
1167 mov ax,cx ; Results in 1 in AX if CYL 0, SEC 1 is addressed
1168 add al,dh ; Results in 1 in AX if HEAD 0 is addressed
1169 dec ax ; Results in 0 in AX if MBR is addressed by CHS
1170
1171 DriveIO_MBR_Addressed_done:
1172 pop bx
1173 pop ax
1174 ret
1175DriveIO_MBR_Addressed EndP
1176
1177
1178
1179
1180; #########################################################################
1181; Routine: Writes DS:SI to a specified sector
1182; #########################################################################
1183; Calling : bx:ax - Absolute sector
1184; cx:dx - Cylinder/Sector, Side/Drive (hi/lo-byte)
1185; ds:si - Source-Adress
1186; Returns : none
1187; Preserve: all registers
1188; #########################################################################
1189DriveIO_SaveSector Proc Near Uses ax bx cx dx ds si es di
1190
1191IFDEF AUX_DEBUG
1192 IF 0
1193 DBG_TEXT_OUT_AUX 'DriveIO_SaveSector:'
1194 PUSHRF
1195 ;~ call DEBUG_DumpRegisters
1196 ;~ call AuxIO_DumpParagraph
1197 ;~ call AuxIO_TeletypeNL
1198 POPRF
1199 ENDIF
1200ENDIF
1201
1202
1203;!
1204;! DEBUG_BLOCK
1205;! Force write to LBA0 to test interception routine.
1206;! Do *NOT* enable unless you are debugging, will overwrite MBR !
1207;!
1208IFDEF AUX_DEBUG
1209 IF 0
1210 pushf
1211 pusha
1212 xor ax,ax
1213 xor bx,bx
1214 xor cx,cx
1215 inc cx
1216 xor dh,dh
1217 popa
1218 popf
1219 ENDIF
1220ENDIF
1221
1222 ;
1223 ; Check if the MBR is the destination for the write.
1224 ; ZF=1 if so.
1225 ;
1226 call DriveIO_MBR_Addressed
1227 jnz DriveIO_SaveSector_continue_write
1228
1229
1230 ; MBR is addressed, check the sector that is requested to be written.
1231 ; For the bootdisk it should contain the AiR-BOOT signature, valid
1232 ; partition-table entries and the AA55h signature.
1233 ; If not, something is terribly wrong in some piece of the AB code.
1234 ; For any other disk (80h+) at least a valid partition table should
1235 ; be present together with the AA55h signature.
1236 call DriveIO_ProtectMBR
1237 jnc DriveIO_SaveSector_continue_write
1238
1239
1240 ;
1241 ; WE HAVE A SEVERE ERROR CONDITION !
1242 ; SOME AB CODE TRIES TO WRITE A NON-MBR TO THE DISK !
1243 ; ASK THE USER TO REPORT THIS !
1244 ; HALT THE SYSTEM !
1245 ;
1246
1247 ; Show error-box
1248 mov cx, 0C04h
1249 mov si, offset NonMBRwrite
1250 call SETUP_ShowErrorBox
1251 mov cx, 0C04h
1252 mov si, offset NonMBRwrite_rep
1253 call SETUP_ShowErrorBox
1254
1255
1256IFDEF AUX_DEBUG
1257 IF 0
1258 pushf
1259 pusha
1260 mov si, offset [NonMBRwrite]
1261 call AuxIO_TeletypeNL
1262 call AuxIO_Print
1263 call AuxIO_TeletypeNL
1264 popa
1265 popf
1266 ENDIF
1267ENDIF
1268
1269 ; Show popup and halt the system.
1270 jmp HaltSystem
1271
1272
1273
1274 ;
1275 ; Continue the write if not MBR sector or MBR to write is validated.
1276 ;
1277 DriveIO_SaveSector_continue_write:
1278 test byte ptr cs:[CurIO_UseExtension], 1
1279 jz DIOSS_UseNormal
1280 ; Are we forced do use LBA via Setting?
1281 ; Always use INT13X on v1.0.8+.
1282 ;~ test byte ptr cs:[CFG_ForceLBAUsage], 1
1283 ;~ jnz DIOSS_UseExtension
1284 jmp DIOSS_UseExtension
1285 ; Is the drive not a harddrive?
1286 cmp dl, 80h
1287 jb DIOSS_UseNormal
1288 ; Upper 8 bits of LBA-address set? -> Use LBA (maximum boundary is FB0400h)
1289 or bh, bh
1290 jnz DIOSS_UseExtension
1291 ; Compare Switch-Table value to bit 16-23 of LBA-address
1292 mov di, dx
1293 and di, 007Fh
1294 cmp bptr cs:[LBASwitchTable+di], bl
1295 jbe DIOSS_UseExtension
1296
1297 DIOSS_UseNormal:
1298
1299IFDEF AUX_DEBUG
1300 IF 0
1301 DBG_TEXT_OUT_AUX 'DriveIO_WriteSectorCHS:'
1302 PUSHRF
1303 call DEBUG_DumpRegisters
1304 call AuxIO_DumpParagraph
1305 call AuxIO_TeletypeNL
1306 POPRF
1307 ENDIF
1308ENDIF
1309
1310 mov di, 3 ; retry count
1311 DIOSS_ErrorLoop:
1312 push ds
1313 pop es
1314 mov bx, si ; ES:BX - Destination
1315 mov ax, 0301h ; Function 3 - Write Sector
1316 int 13h
1317 jnc DIOSS_Success
1318 dec di ; decrement retry count
1319 jnz DIOSS_ErrorLoop
1320 call MBR_SaveError
1321
1322 DIOSS_UseExtension:
1323
1324 mov di, ds ; segment for transfer address
1325 call DriveIO_WriteSectorLBA ; extended write
1326 jc MBR_SaveError ; halt on error
1327
1328 ;~ push cx
1329 ;~ mov cs:[INT13X_DAP_NumBlocks], 1 ; Copy ONE sector
1330 ;~ mov wptr cs:[INT13X_DAP_Transfer+0], si
1331 ;~ mov cx, ds
1332 ;~ mov wptr cs:[INT13X_DAP_Transfer+2], cx ; Fill out Transfer Adress
1333 ;~ mov wptr cs:[INT13X_DAP_Absolute+0], ax
1334 ;~ mov wptr cs:[INT13X_DAP_Absolute+2], bx ; Fill out Absolute Sector
1335 ;~ push cs
1336 ;~ pop ds
1337 ;~ mov si, offset [INT13X_DAP]
1338 ;~ mov ax, 4300h ; Extended Write (No Verify)
1339 ;~ int 13h
1340 ;~ pop cx
1341 ;~ jnc DIOSS_Success
1342 ;~ call MBR_SaveError
1343
1344 DIOSS_Success:
1345 ret
1346DriveIO_SaveSector EndP
1347
1348
1349
1350
1351;##############################################################################
1352;# When a disk has a Master LVM sector, it means it has been prepared for use
1353;# by OS/2 and contains important information about how OS/2 views its geometry
1354;# and other disk related properties. This function assumes the LBA address
1355;# of the Master LVM sector has already been located and simply loads the
1356;# sector into [LVMSector].
1357;#
1358;# Note that because this is an operation similar to the regular loading of
1359;# sectors, the disk I/O semantics are used here. This means CF=0 when an LVM
1360;# sector is successfully loaded and CF=1 otherwise.
1361;##############################################################################
1362;# ACTION : Loads the Master LVM sector if one exists
1363;# ----------------------------------------------------------------------------
1364;# EFFECTS : Modifies DAP structure and [LVMSector]
1365;# ----------------------------------------------------------------------------
1366;# IN : DL - BIOS disk number (80h,81h,etc)
1367;# ----------------------------------------------------------------------------
1368;# OUT : CF=0 - Valid Master LVM sector found and loaded
1369;##############################################################################
1370DriveIO_LoadMasterLVMSector Proc Near
1371
1372IFDEF AUX_DEBUG
1373 IF 0
1374 DBG_TEXT_OUT_AUX 'DriveIO_LoadMasterLVMSector:'
1375 PUSHRF
1376 ;~ call DEBUG_DumpRegisters
1377 ;~ call AuxIO_DumpParagraph
1378 ;~ call AuxIO_TeletypeNL
1379 POPRF
1380 ENDIF
1381ENDIF
1382
1383 ; Save all registers
1384 pusha
1385
1386 ; Check if BIOS disk number is valid
1387 call DriveIO_IsValidHarddisk
1388 jc DriveIO_LoadMasterLVMSector_error
1389
1390 ; Calculate the entry in the DISKINFO array for this disk
1391 call DriveIO_CalcDiskInfoPointer
1392
1393 ; Save the entry for later recalls
1394 mov bp, bx
1395
1396 ; Get the LBA address of the Master LVM sector
1397 mov ax, [bx+LocDISKINFO_LVM_MasterLBA+00h]
1398 mov bx, [bx+LocDISKINFO_LVM_MasterLBA+02h]
1399
1400 ; LBA of Master LVM sector cannot be 0, so none was found during
1401 ; the gathering of disk information.
1402 mov cx, ax
1403 or cx, bx
1404 jz DriveIO_LoadMasterLVMSector_error
1405
1406 ; Load it into [LVMSector]
1407 mov di, ds
1408 mov si, offset [LVMSector]
1409 call DriveIO_ReadSectorLBA
1410 jc DriveIO_LoadMasterLVMSector_error
1411
1412 ; Validate the Master LVM sector
1413 call LVM_ValidateSector
1414
1415 ; Complement success indicator to conform to semantics of this function
1416 cmc
1417
1418 ; Master LVM sector was valid and is now loaded in [LVMSector]
1419 jnc DriveIO_LoadMasterLVMSector_ret
1420
1421 DriveIO_LoadMasterLVMSector_error:
1422
1423 ; Clear the sector buffer for safety reasons
1424 mov si, offset [LVMSector]
1425 call ClearSectorBuffer
1426
1427 ; Indicate no Master LVM sector loaded
1428 stc
1429
1430 DriveIO_LoadMasterLVMSector_ret:
1431
1432 ; Restore all registers
1433 popa
1434
1435 ret
1436DriveIO_LoadMasterLVMSector Endp
1437
1438
1439
1440
1441;##############################################################################
1442;# There is much information to know about the connected disks.
1443;# We also want this information clustered per disk and available before
1444;# further disk and partition scanning takes place.
1445;# This function gathers such information like INT13, INT13X, MBR, LVM, more.
1446;# Especially important is the LVM information, because that contains the
1447;# geometry OS/2 uses to access the disk. Other important information is the
1448;# presence of valid MBRs, logical partitions and whatnot.
1449;# This function gathers such information and stores it in a DISKINFO structure
1450;# for which an instance exists for every disk found.
1451;##############################################################################
1452;# ACTION : Gather disk information and store this in the BSS
1453;# ----------------------------------------------------------------------------
1454;# EFFECTS : Modifies DAP structure and the buffers it uses, fills DISKINFO[n]
1455;# ----------------------------------------------------------------------------
1456;# IN : DL - BIOS disk number (80h,81h,etc)
1457;# ----------------------------------------------------------------------------
1458;# OUT : CF=1 - failure
1459;##############################################################################
1460DriveIO_GatherDiskInfo Proc Near
1461
1462IFDEF AUX_DEBUG
1463 IF 1
1464 DBG_TEXT_OUT_AUX 'DriveIO_GatherDiskInfo:'
1465 PUSHRF
1466 call DEBUG_DumpRegisters
1467 ;~ call AuxIO_DumpParagraph
1468 ;~ call AuxIO_TeletypeNL
1469 POPRF
1470 ENDIF
1471ENDIF
1472
1473 ; Push all registers we use
1474 pusha
1475 push ds
1476 push es
1477
1478 ; Make sure ES=DS
1479 push ds
1480 pop es
1481
1482 ; Check if BIOS disk number is valid
1483 call DriveIO_IsValidHarddisk
1484 jc DriveIO_GatherDiskInfo_error
1485
1486 ; Calculate the entry in the DISKINFO array for this disk
1487 call DriveIO_CalcDiskInfoPointer
1488
1489 ; Save the entry for later recalls
1490 mov bp, bx
1491
1492 ; Store the BIOS disk number in the structure
1493 mov [bx+LocDISKINFO_DiskNum], dl
1494
1495; ------------------------------------------------------------------- [ INT13 ]
1496
1497 ; Get BIOS Disk Parameters (legacy method)
1498 mov ah, 08h ; Get Disk Parameters
1499 int 13h ; Call BIOS
1500
1501 ; CF=1 or AH!=0 indicates error
1502 jc DriveIO_GatherDiskInfo_error
1503 test ah, ah
1504 jnz DriveIO_GatherDiskInfo_error
1505
1506 ; Recall DISKINFO entry
1507 mov bx, bp
1508
1509 ; Store SPT (WORD)
1510 xor ah, ah ; Zero extend SPT to 16 bits
1511 mov al, cl ; Hi 2 bits max cyl and max sec
1512 and al, 3fh ; Mask max sec (1-based)
1513 mov [bx+LocDISKINFO_I13_Secs], ax ; Store SPT
1514
1515 ; Store HEADS (WORD)
1516 xor dl, dl ; Zero extend HEADS to 16 bits
1517 xchg dl, dh ; Get max head (0-based)
1518 inc dx ; Head count
1519 mov [bx+LocDISKINFO_I13_Heads], dx ; Store HEADS
1520
1521 ; Store CYLS (WORD)
1522 shr cl, 6 ; Hi 2 bits of max cyl to 1:0
1523 xchg cl, ch ; Max cyl (0-based)
1524 inc cx ; Cyl count
1525 mov [bx+LocDISKINFO_I13_Cyls], cx ; Store CYLS
1526
1527 ; Recall BIOS disk number
1528 mov dl, [bx+LocDISKINFO_DiskNum]
1529
1530; ------------------------------------------------------------------ [ INT13X ]
1531
1532 ; Get BIOS Disk Parameters (extended method)
1533 mov si, offset [Scratch] ; Buffer to return disk info
1534 mov ax, 80h ; Size of buffer
1535 mov [si], ax ; Store it in first word
1536 mov ah, 48h ; Get Extended Disk Parameters
1537 int 13h ; Call BIOS
1538
1539 ; CF=1 or AH!=0 indicates error
1540 jc DriveIO_GatherDiskInfo_error
1541 test ah, ah
1542 jnz DriveIO_GatherDiskInfo_error
1543
1544 ; Store flags (WORD)
1545 cld ; Direction up
1546 lodsw ; Buffersize, discard
1547 lodsw ; Flags (CHS valid etc)
1548 mov [bx+LocDISKINFO_I13X_Flags], ax ; Store them
1549
1550 ; Store CYLS (DWORD)
1551 lodsw ; Cyl count low
1552 mov [bx+LocDISKINFO_I13X_Cyls+00h], ax ; Store CYLS low
1553 lodsw ; Cyl count high
1554 mov [bx+LocDISKINFO_I13X_Cyls+02h], ax ; Store CYLS high
1555
1556 ; Store HEADS (DWORD)
1557 lodsw ; Head count low
1558 mov [bx+LocDISKINFO_I13X_Heads+00h], ax ; Store HEADS low
1559 lodsw ; Head count high
1560 mov [bx+LocDISKINFO_I13X_Heads+02h], ax ; Store HEADS high
1561
1562 ; Store SPT (DWORD)
1563 lodsw ; Secs per track low
1564 mov [bx+LocDISKINFO_I13X_Secs+00h], ax ; Store SPT low
1565 lodsw ; Secs per track high
1566 mov [bx+LocDISKINFO_I13X_Secs+02h], ax ; Store SPT high
1567
1568 ; Store total LBA sectors (QWORD)
1569 lea di, [bx+LocDISKINFO_I13X_SecsLBA]
1570 mov cx, 4
1571 rep movsw
1572
1573 ; Store sector size (WORD)
1574 lodsw
1575 mov [bx+LocDISKINFO_I13X_SecSize], ax
1576
1577 ; Store bus name (4 bytes, space padded, v3.0+)
1578 lea si, [Scratch+24h]
1579 lea di, [bx+LocDISKINFO_I13X_HostBus]
1580 movsw
1581 movsw
1582
1583 ; Store interface name (8 bytes, space padded, v3.0+)
1584 lea di, [bx+LocDISKINFO_I13X_Interface]
1585 mov cx, 4
1586 rep movsw
1587
1588 ; Should gather some more INT13X info here,
1589 ; like maybe Advanced Format stuff or so.
1590 ; We'll investigate that at a later time.
1591
1592; --------------------------------------------------------------------- [ MBR ]
1593
1594 ; Load the MBR
1595 mov si, offset [TmpSector]
1596 call DriveIO_LoadMBR
1597
1598 ; Store MBR flags (valid sig, partitions present, airboot installed)
1599 mov [bx+LocDISKINFO_MbrFlags], al
1600
1601 ; Recall BIOS disk number
1602 mov dl, [bx+LocDISKINFO_DiskNum]
1603
1604; --------------------------------------------------------------------- [ LVM ]
1605
1606 ; Locate the Master LVM sector, if any
1607 call DriveIO_LocateMasterLVMSector
1608
1609 ; Save Master LVM sector LBA high
1610 mov cx, bx
1611
1612 ; Recall DISKINFO entry
1613 mov bx, bp
1614
1615 ; Store Master LVM sector LBA
1616 mov [bx+LocDISKINFO_LVM_MasterLBA+00h], ax
1617 mov [bx+LocDISKINFO_LVM_MasterLBA+02h], cx
1618
1619 ; No Master LVM sector found, so skip storing LVM info for this disk
1620 jnc DriveIO_GatherDiskInfo_no_master_lvm
1621
1622 ; Load the Master LVM sector into [LVMSector]
1623 call DriveIO_LoadMasterLVMSector
1624
1625 ; No valid Master LVM sector, so skip storing LVM info for this disk
1626 jc DriveIO_GatherDiskInfo_no_master_lvm
1627
1628 ; A valid Master LVM sector has been loaded into [LVMSector]
1629 mov si, offset [LVMSector]
1630
1631 ; Get the number of sectors per track (OS/2 geometry)
1632 mov ax, [si+LocLVM_Secs+00h]
1633 mov cx, [si+LocLVM_Secs+02h]
1634
1635 ; Store it
1636 mov [bx+LocDISKINFO_LVM_Secs+00h], ax
1637 mov [bx+LocDISKINFO_LVM_Secs+02h], cx
1638
1639 ; Get the number of heads (OS/2 geometry)
1640 mov ax, [si+LocLVM_Heads+00h]
1641 mov cx, [si+LocLVM_Heads+02h]
1642
1643 ; Store it
1644 mov [bx+LocDISKINFO_LVM_Heads+00h], ax
1645 mov [bx+LocDISKINFO_LVM_Heads+02h], cx
1646
1647 ; Should gather some more LVM info here,
1648 ; like OS/2 extended geometry and other flags.
1649 ; We'll implement that at a later time.
1650
1651 DriveIO_GatherDiskInfo_no_master_lvm:
1652
1653 ; When no Master LVM sector was found,
1654 ; the LVM info in the DISKINFO structure for the disk
1655 ; will be ZERO because the area was cleared in PRECRAP.
1656
1657 ; Indicate success
1658 clc
1659
1660 jmp DriveIO_GatherDiskInfo_ret
1661
1662 DriveIO_GatherDiskInfo_error:
1663 stc
1664 DriveIO_GatherDiskInfo_ret:
1665
1666
1667IFDEF AUX_DEBUG
1668 IF 1
1669 DBG_TEXT_OUT_AUX '[DISKINFO]'
1670 PUSHRF
1671 call DEBUG_DumpRegisters
1672 ;~ call AuxIO_DumpParagraph
1673 ;~ call AuxIO_TeletypeNL
1674 mov si, bp
1675 mov cx, 4
1676 @@:
1677 call AuxIO_DumpParagraph
1678 call AuxIO_TeletypeNL
1679 add si, 16
1680 loop @B
1681 mov si, offset [Scratch]
1682 mov cx, 4
1683 @@:
1684 call AuxIO_DumpParagraph
1685 call AuxIO_TeletypeNL
1686 add si, 16
1687 loop @B
1688 mov si, offset [LVMSector]
1689 mov cx, 7
1690 @@:
1691 call AuxIO_DumpParagraph
1692 call AuxIO_TeletypeNL
1693 add si, 16
1694 loop @B
1695 POPRF
1696 ENDIF
1697ENDIF
1698
1699 ; Restore registers
1700 pop es
1701 pop ds
1702 popa
1703
1704 ret
1705DriveIO_GatherDiskInfo EndP
1706
1707;------------------------------------------------------------------------------
1708; Scan all disks to gather information
1709;------------------------------------------------------------------------------
1710; IN : None
1711; OUT : CF=1 - some failure occured
1712; : ZF=1 - no harddisks
1713; NOTE : This does the preliminary gathering of disk information
1714;------------------------------------------------------------------------------
1715DriveIO_ScanDisks Proc Near
1716
1717IFDEF AUX_DEBUG
1718 IF 1
1719 DBG_TEXT_OUT_AUX 'DriveIO_ScanDisks:'
1720 PUSHRF
1721 call DEBUG_DumpRegisters
1722 ;~ call AuxIO_DumpParagraph
1723 ;~ call AuxIO_TeletypeNL
1724 POPRF
1725 ENDIF
1726ENDIF
1727
1728 ; Save all registers
1729 pusha
1730
1731 ; Get number of disks in DH
1732 call DriveIO_GetHardDriveCount
1733
1734 ; Check if there are any disks to scan
1735 xor cx, cx ; Prepare 16-bit counter
1736 mov cl, dh ; Number of disks now in CX
1737 jcxz DriveIO_ScanDisks_end ; Quit if no disks
1738
1739 ; Scan disks from 80h upward
1740 mov dl, 80h ; BIOS number of first disk
1741 DriveIO_ScanDisks_next:
1742 call DriveIO_GatherDiskInfo ; Gather info for this disk
1743 jc DriveIO_ScanDisks_end ; Quit if some error occured
1744 inc dl ; Advance to next disk
1745 loop DriveIO_ScanDisks_next ; Scan next disk if there is one
1746 test dl, dl ; Set ZF=0
1747 clc ; Indicate success
1748
1749 DriveIO_ScanDisks_end:
1750 ; Restore all registers
1751 popa
1752
1753 ret
1754DriveIO_ScanDisks EndP
1755
1756;------------------------------------------------------------------------------
1757; Calculate pointer to entry in DISKINFO structure
1758;------------------------------------------------------------------------------
1759; IN : DL BIOS disk number (80h etc)
1760; OUT : BX Pointer to entry
1761; NOTE : BIOS disk number must be valid
1762;------------------------------------------------------------------------------
1763DriveIO_CalcDiskInfoPointer Proc Near
1764 xchg bx, ax ; AX is used for calculation
1765 mov al, DISKINFO_Size ; Size of DISKINFO structure
1766 mov ah, dl ; BIOS disk number
1767 sub ah, 80h ; Now 0-based index
1768 mul ah ; Now offset into DISKINFO array
1769 add ax, offset [DiskInformation] ; Base of DISKINFO array
1770 xchg bx, ax ; BX now points to entry for disk
1771 ret
1772DriveIO_CalcDiskInfoPointer EndP
1773
1774;------------------------------------------------------------------------------
1775; Check if the BIOS disk number in DL is a harddisk and in range
1776;------------------------------------------------------------------------------
1777; IN : DL BIOS disk number (80h etc)
1778; OUT : CF=1 if invalid disk number or out of range
1779; NOTE : Only modifies flags
1780;------------------------------------------------------------------------------
1781DriveIO_IsValidHarddisk Proc Near Uses dx
1782 cmp dl, 80h ; BIOS disk number must be at least 80h
1783 jb @F ; Not a harddisk, exit with CY
1784 mov dh, dl ; Save to do compare
1785 sub dh, 80h ; Now 0 based disk number
1786 inc dh ; Now 1 based disk number
1787 cmp [TotalHarddiscs], dh ; Out of range, exit with CY
1788 @@: ret
1789DriveIO_IsValidHarddisk EndP
1790
1791
1792; Values for sectors per track table corresponding to DriveIO_IsHugeDrive return value.
1793;~ secs_per_track_table db 63,127,255,255,255,255
1794
1795;~ db_lmlvm db 'Load Master LVM -- disk: ',0
Note: See TracBrowser for help on using the repository browser.