source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm@ 287

Last change on this file since 287 was 262, checked in by gregli@…, 13 years ago

More optimizations. Merged RamVars_IsFunction/DriveHandledByThisBIOS in with FindDPT_ForDriveNumber, since they are often used together, making a returned NULL DI pointer indicate a foreign drive in many places. Revamped the iteration done in the handlers for int13/0dh and int13h/0h. Added serial specific print string during drive detection.

File size: 8.4 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Functions for creating Disk Parameter Table.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Creates new Disk Parameter Table for detected hard disk.
9; Drive is then fully accessible using any BIOS function.
10;
11; CreateDPT_FromAtaInformation
12; Parameters:
13; BH: Drive Select byte for Drive and Head Register
14; ES:SI: Ptr to 512-byte ATA information read from the drive
15; CS:BP: Ptr to IDEVARS for the controller
16; DS: RAMVARS segment
17; ES: BDA Segment
18; Returns:
19; DL: Drive number for new drive
20; DS:DI: Ptr to Disk Parameter Table (if succesfull)
21; CF: Cleared if DPT created successfully
22; Set if any error
23; Corrupts registers:
24; AX, BX, CX, DH
25;--------------------------------------------------------------------
26CreateDPT_FromAtaInformation:
27 call FindDPT_ForNewDriveToDSDI
28 ; Fall to .InitializeDPT
29
30;--------------------------------------------------------------------
31; .InitializeDPT
32; Parameters:
33; BH: Drive Select byte for Drive and Head Register
34; DS:DI: Ptr to Disk Parameter Table
35; CS:BP: Ptr to IDEVARS for the controller
36; Returns:
37; Nothing
38; Corrupts registers:
39; AX
40;--------------------------------------------------------------------
41.InitializeDPT:
42 mov [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM
43 ; Fall to .StoreDriveSelectAndDriveControlByte
44
45;--------------------------------------------------------------------
46; .StoreDriveSelectAndDriveControlByte
47; Parameters:
48; BH: Drive Select byte for Drive and Head Register
49; DS:DI: Ptr to Disk Parameter Table
50; ES:SI: Ptr to 512-byte ATA information read from the drive
51; CS:BP: Ptr to IDEVARS for the controller
52; Returns:
53; Nothing
54; Corrupts registers:
55; AX
56;--------------------------------------------------------------------
57.StoreDriveSelectAndDriveControlByte:
58 mov al, bh
59 and ax, BYTE FLG_DRVNHEAD_DRV ; AL now has Master/Slave bit
60 cmp [cs:bp+IDEVARS.bIRQ], ah ; Interrupts enabled?
61 jz SHORT .StoreFlags ; If not, do not set interrupt flag
62 or al, FLGL_DPT_ENABLE_IRQ
63.StoreFlags:
64 mov [di+DPT.wFlags], ax
65 ; Fall to .StoreAddressing
66
67;--------------------------------------------------------------------
68; .StoreAddressing
69; Parameters:
70; DS:DI: Ptr to Disk Parameter Table
71; ES:SI: Ptr to 512-byte ATA information read from the drive
72; CS:BP: Ptr to IDEVARS for the controller
73; Returns:
74; Nothing
75; Corrupts registers:
76; AX, BX, CX, DX
77;--------------------------------------------------------------------
78.StoreAddressing:
79 ; Check if CHS defined in ROMVARS
80 call AccessDPT_GetPointerToDRVPARAMStoCSBX
81 test byte [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERCHS ; User specified CHS?
82 jnz SHORT .StoreUserDefinedPCHS
83
84 ; Check if LBA supported
85 call AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI
86 test BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
87 jz SHORT .StoreCHSfromAXBHBL ; Small old drive with CHS addressing only
88
89 ; Check if 48-bit LBA supported
90 test BYTE [es:si+ATA6.wSetSup83+1], A6_wSetSup83_LBA48>>8
91 jz SHORT .StoreLBA28addressing
92 or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA48<<ADDRESSING_MODE_FIELD_POSITION
93.StoreLBA28addressing:
94 or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
95 call AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI
96 mov [di+DPT.twLbaSectors], ax
97 mov [di+DPT.twLbaSectors+2], dx
98 mov [di+DPT.twLbaSectors+4], bx
99 call AtaID_GetLbaAssistedCHStoDXAXBLBH
100 mov [di+DPT.bLbaHeads], bl
101 jmp SHORT .StoreBlockMode
102
103;--------------------------------------------------------------------
104; .StoreUserDefinedPCHS
105; Parameters:
106; DS:DI: Ptr to Disk Parameter Table
107; ES:SI: Ptr to 512-byte ATA information read from the drive
108; CS:BP: Ptr to IDEVARS for the controller
109; Returns:
110; AX: Number of P-CHS cylinders
111; BH: Number of P-CHS sectors per track
112; BL: Number of P-CHS heads
113; Corrupts registers:
114; Nothing
115;--------------------------------------------------------------------
116.StoreUserDefinedPCHS:
117 call AccessDPT_GetPointerToDRVPARAMStoCSBX
118 mov ax, [cs:bx+DRVPARAMS.wCylinders]
119 mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
120 ; Fall to .StoreCHSfromAXBHBL
121
122;--------------------------------------------------------------------
123; .StoreCHSfromAXBHBL
124; Parameters:
125; AX: Number of P-CHS cylinders
126; BH: Number of P-CHS sectors per track
127; BL: Number of P-CHS heads
128; DS:DI: Ptr to Disk Parameter Table
129; ES:SI: Ptr to 512-byte ATA information read from the drive
130; CS:BP: Ptr to IDEVARS for the controller
131; Returns:
132; AX: Number of P-CHS cylinders
133; BH: Number of P-CHS sectors per track
134; BL: Number of P-CHS heads
135; Corrupts registers:
136; CX
137;--------------------------------------------------------------------
138.StoreCHSfromAXBHBL:
139 push ax
140 push bx
141 call AccessDPT_ShiftPCHinAXBLtoLCH ; Get number of bits to shift
142 pop bx
143 pop ax
144 jcxz .StorePCHSfromAXDX ; Small drive so use L-CHS addressing
145
146 ; Store P-CHS addressing mode and number of bits to shift in L-CHS to P-CHS translation
147 or cl, ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
148 or [di+DPT.bFlagsLow], cl
149 ; Fall to .StoreChsFromAXBLBH
150
151;--------------------------------------------------------------------
152; .StoreChsFromAXBLBH
153; Parameters:
154; AX: Number of P-CHS cylinders
155; BH: Number of P-CHS sectors per track
156; BL: Number of P-CHS heads
157; DS:DI: Ptr to Disk Parameter Table
158; ES:SI: Ptr to 512-byte ATA information read from the drive
159; CS:BP: Ptr to IDEVARS for the controller
160; Returns:
161; Nothing
162; Corrupts registers:
163; Nothing
164;--------------------------------------------------------------------
165.StorePCHSfromAXDX:
166 mov [di+DPT.wPchsCylinders], ax
167 mov [di+DPT.wPchsHeadsAndSectors], bx
168 ; Fall to .StoreBlockMode
169
170;--------------------------------------------------------------------
171; .StoreBlockMode
172; Parameters:
173; DS:DI: Ptr to Disk Parameter Table
174; ES:SI: Ptr to 512-byte ATA information read from the drive
175; CS:BP: Ptr to IDEVARS for the controller
176; Returns:
177; Nothing
178; Corrupts registers:
179; Nothing
180;--------------------------------------------------------------------
181.StoreBlockMode:
182 cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
183 jbe SHORT .BlockModeTransfersNotSupported
184 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
185.BlockModeTransfersNotSupported:
186 ; Fall to .StoreDeviceSpecificParameters
187
188;--------------------------------------------------------------------
189; .StoreDeviceSpecificParameters
190; Parameters:
191; DS:DI: Ptr to Disk Parameter Table
192; ES:SI: Ptr to 512-byte ATA information read from the drive
193; CS:BP: Ptr to IDEVARS for the controller
194; Returns:
195; Nothing
196; Corrupts registers:
197; AX, BX, CX, DX
198;--------------------------------------------------------------------
199.StoreDeviceSpecificParameters:
200 call Device_FinalizeDPT
201
202;----------------------------------------------------------------------
203; Update drive counts (hard and floppy)
204;----------------------------------------------------------------------
205
206%ifdef MODULE_SERIAL_FLOPPY
207;
208; These two instructions serve two purposes:
209; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter.
210; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is
211; effectively discarded. This is more of a safety check then code that should ever normally be hit (see below).
212; Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT,
213; this was necessary. Now, this situation shouldn't happen in normal operation, for a couple of reasons:
214; A. xtidecfg always puts configured serial ports at the end fo the IDEVARS list
215; B. the auto serial code is always executed last
216; C. the serial server always returns floppy drives last
217;
218 adc byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0
219 jnz .AllDone
220%else
221;
222; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which
223; could lead to unpredictable results since no MBR will be present, etc. The server doesn't know that
224; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan.
225;
226 jc .AllDone
227%endif
228
229 inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
230
231.AllDone:
232 clc
233 ret
234
Note: See TracBrowser for help on using the repository browser.