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

Last change on this file since 435 was 422, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

  • Modified ROMVARS for user defined CHS translation mode.
  • Base DPT struct now includes initialization error flags again.
File size: 10.1 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Functions for creating Disk Parameter Table.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12;
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Creates new Disk Parameter Table for detected hard disk.
25; Drive is then fully accessible using any BIOS function.
26;
27; CreateDPT_FromAtaInformation
28; Parameters:
29; BH: Drive Select byte for Drive and Head Register
30; ES:SI: Ptr to 512-byte ATA information read from the drive
31; CS:BP: Ptr to IDEVARS for the controller
32; DS: RAMVARS segment
33; ES: BDA Segment
34; Returns:
35; DS:DI: Ptr to Disk Parameter Table (if successful)
36; CF: Cleared if DPT created successfully
37; Set if any error
38; Corrupts registers:
39; AX, BX, CX, DH
40;--------------------------------------------------------------------
41CreateDPT_FromAtaInformation:
42 call FindDPT_ForNewDriveToDSDI
43 ; Fall to .InitializeDPT
44
45;--------------------------------------------------------------------
46; .InitializeDPT
47; Parameters:
48; BH: Drive Select byte for Drive and Head Register
49; DS:DI: Ptr to Disk Parameter Table
50; CS:BP: Ptr to IDEVARS for the controller
51; Returns:
52; Nothing
53; Corrupts registers:
54; AX
55;--------------------------------------------------------------------
56.InitializeDPT:
57 mov [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM
58 ; Fall to .StoreDriveSelectAndDriveControlByte
59
60;--------------------------------------------------------------------
61; .StoreDriveSelectAndDriveControlByte
62; Parameters:
63; BH: Drive Select byte for Drive and Head Register
64; DS:DI: Ptr to Disk Parameter Table
65; ES:SI: Ptr to 512-byte ATA information read from the drive
66; CS:BP: Ptr to IDEVARS for the controller
67; Returns:
68; Nothing
69; Corrupts registers:
70; AX
71;--------------------------------------------------------------------
72.StoreDriveSelectAndDriveControlByte:
73 mov al, bh
74 and ax, BYTE FLG_DRVNHEAD_DRV ; AL now has Master/Slave bit
75%ifdef MODULE_IRQ
76 cmp [cs:bp+IDEVARS.bIRQ], ah ; Interrupts enabled?
77 jz SHORT .StoreFlags ; If not, do not set interrupt flag
78 or al, FLGL_DPT_ENABLE_IRQ
79.StoreFlags:
80%endif
81 mov [di+DPT.wFlags], ax
82 ; Fall to .StoreCHSparametersAndAddressingMode
83
84;--------------------------------------------------------------------
85; .StoreCHSparametersAndAddressingMode
86; Parameters:
87; DS:DI: Ptr to Disk Parameter Table
88; ES:SI: Ptr to 512-byte ATA information read from the drive
89; CS:BP: Ptr to IDEVARS for the controller
90; Returns:
91; Nothing
92; Corrupts registers:
93; AX, BX, CX, DX
94;--------------------------------------------------------------------
95.StoreCHSparametersAndAddressingMode:
96 ; Check if CHS defined in ROMVARS
97 call GetUserDefinedCapacityToBXAXandFlagsToCXandModeToDXfromROMVARS
98 test cl, FLG_DRVPARAMS_USERCHS
99 jz SHORT .AutodetectPCHSvalues
100
101 ; Translate P-CHS to L-CHS
102 call AtaGeometry_GetLCHStoAXBLBHfromPCHSinAXBLBHandTranslateModeInDX
103 jmp SHORT .StoreLCHStoDPT
104.AutodetectPCHSvalues:
105 call AtaGeometry_GetLCHStoAXBLBHfromAtaInfoInESSIandTranslateModeInDX
106
107.StoreLCHStoDPT:
108 eSHL_IM dl, TRANSLATEMODE_FIELD_POSITION
109 or cl, dl
110 or [di+DPT.bFlagsLow], cl ; Shift count and addressing mode
111 mov [di+DPT.wLchsCylinders], ax
112 mov [di+DPT.wLchsHeadsAndSectors], bx
113
114 ; Store P-CHS to DPT
115 call AtaGeometry_GetPCHStoAXBLBHfromAtaInfoInESSI
116 mov [di+DPT.bPchsHeads], bl
117%ifdef MODULE_EBIOS
118 mov [di+DPT.wPchsCylinders], ax
119 mov [di+DPT.bPchsSectorsPerTrack], bh
120 ; Fall to .StoreNumberOfLbaSectors
121
122;--------------------------------------------------------------------
123; .StoreNumberOfLbaSectors
124; Parameters:
125; DS:DI: Ptr to Disk Parameter Table
126; ES:SI: Ptr to 512-byte ATA information read from the drive
127; CS:BP: Ptr to IDEVARS for the controller
128; Returns:
129; Nothing
130; Corrupts registers:
131; AX, BX, CX, DX
132;--------------------------------------------------------------------
133 ; Check if LBA supported
134 test BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
135 jz SHORT .NoLbaSupportedSoNoEBIOS
136
137 ; Store LBA 28/48 total sector count
138 call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI
139 call StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
140
141 ; Load user defined LBA
142 call GetUserDefinedCapacityToBXAXandFlagsToCXandModeToDXfromROMVARS
143 test cl, FLG_DRVPARAMS_USERLBA
144 jz SHORT .KeepTotalSectorsFromAtaID
145
146 ; Compare user defined and ATA-ID sector count and select smaller
147 xor dx, dx
148 xchg bx, dx ; User defined LBA now in BX:DX:AX
149 cmp bx, [di+DPT.twLbaSectors+4]
150 jb SHORT .StoreUserDefinedSectorCountToDPT
151 cmp dx, [di+DPT.twLbaSectors+2]
152 jb SHORT .StoreUserDefinedSectorCountToDPT
153 ja SHORT .KeepTotalSectorsFromAtaID
154 cmp ax, [di+DPT.twLbaSectors]
155 jae SHORT .KeepTotalSectorsFromAtaID
156.StoreUserDefinedSectorCountToDPT:
157 ; CL bit FLGL_DPT_LBA48 is clear at this point
158 call StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
159
160.KeepTotalSectorsFromAtaID:
161.NoLbaSupportedSoNoEBIOS:
162%endif ; MODULE_EBIOS
163 ; Fall to .StoreBlockMode
164
165;--------------------------------------------------------------------
166; .StoreBlockMode
167; Parameters:
168; DS:DI: Ptr to Disk Parameter Table
169; ES:SI: Ptr to 512-byte ATA information read from the drive
170; CS:BP: Ptr to IDEVARS for the controller
171; Returns:
172; Nothing
173; Corrupts registers:
174; Nothing
175;--------------------------------------------------------------------
176.StoreBlockMode:
177 cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
178 jbe SHORT .BlockModeTransfersNotSupported
179 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
180.BlockModeTransfersNotSupported:
181 ; Fall to .StoreDeviceSpecificParameters
182
183;--------------------------------------------------------------------
184; .StoreDeviceSpecificParameters
185; Parameters:
186; DS:DI: Ptr to Disk Parameter Table
187; ES:SI: Ptr to 512-byte ATA information read from the drive
188; CS:BP: Ptr to IDEVARS for the controller
189; Returns:
190; Nothing
191; Corrupts registers:
192; AX, BX, CX, DX
193;--------------------------------------------------------------------
194.StoreDeviceSpecificParameters:
195 call Device_FinalizeDPT
196
197;----------------------------------------------------------------------
198; Update drive counts (hard and floppy)
199;----------------------------------------------------------------------
200
201%ifdef MODULE_SERIAL_FLOPPY
202;
203; These two instructions serve two purposes:
204; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter.
205; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is
206; effectively discarded. This is more of a safety check then code that should ever normally be hit (see below).
207; Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT,
208; this was necessary. Now, this situation shouldn't happen in normal operation, for a couple of reasons:
209; A. xtidecfg always puts configured serial ports at the end of the IDEVARS list
210; B. the auto serial code is always executed last
211; C. the serial server always returns floppy drives last
212;
213 adc byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0
214 jnz .AllDone
215%else
216;
217; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which
218; could lead to unpredictable results since no MBR will be present, etc. The server doesn't know that
219; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan.
220;
221 jc .AllDone
222%endif
223
224 inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
225
226.AllDone:
227 clc
228 ret
229
230
231;--------------------------------------------------------------------
232; GetUserDefinedCapacityToBXAXandFlagsToCXandModeToDXfromROMVARS
233; Parameters:
234; DS:DI: Ptr to Disk Parameter Table
235; Returns:
236; AX: User defined P-CHS Cylinders or LBA low word
237; BX: User defined P-CHS Heads and Sectors or LBA high word
238; DX: Translate mode or TRANSLATEMODE_AUTO
239; CX: FLG_DRVPARAMS_USERCHS if user defined CHS in BX:AX
240; FLG_DRVPARAMS_USERLBA if user defined LBA in BX:AX
241; Zero if user has not defined capacity
242; Corrupts registers:
243; Nothing
244;--------------------------------------------------------------------
245GetUserDefinedCapacityToBXAXandFlagsToCXandModeToDXfromROMVARS:
246 call AccessDPT_GetPointerToDRVPARAMStoCSBX
247
248 ; Get settings
249 mov cx, [cs:bx+DRVPARAMS.wFlags]
250 mov dx, cx
251 and cx, BYTE FLG_DRVPARAMS_USERCHS | FLG_DRVPARAMS_USERLBA
252 and dx, BYTE MASK_DRVPARAMS_TRANSLATEMODE
253 eSHR_IM dx, TRANSLATEMODE_FIELD_POSITION
254
255 ; Get capacity
256 mov ax, [cs:bx+DRVPARAMS.wCylinders] ; Or .dwMaximumLBA
257 mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors] ; Or .dwMaximumLBA+2
258 ret
259
260
261%ifdef MODULE_EBIOS
262;--------------------------------------------------------------------
263; StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
264; Parameters:
265; BX:DX:AX: Total Sector Count
266; CL: FLGL_DPT_LBA48 if LBA48 supported
267; DS:DI: Ptr to Disk Parameter Table
268; Returns:
269; Nothing
270; Corrupts registers:
271; CL
272;--------------------------------------------------------------------
273StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX:
274 or cl, FLGL_DPT_LBA_AND_EBIOS_SUPPORTED
275 and BYTE [di+DPT.bFlagsLow], ~FLGL_DPT_LBA48
276 or [di+DPT.bFlagsLow], cl
277 mov [di+DPT.twLbaSectors], ax
278 mov [di+DPT.twLbaSectors+2], dx
279 mov [di+DPT.twLbaSectors+4], bx
280 ret
281%endif ; MODULE_EBIOS
Note: See TracBrowser for help on using the repository browser.