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

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

Changes to XTIDE Universal BIOS:

  • Addressing modes are now NORMAL, LARGE and LBA.
  • L-CHS parameters are now generated differently for drives with 8192 or less cylinders.
File size: 9.2 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 AccessDPT_GetPointerToDRVPARAMStoCSBX
98 test byte [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERCHS ; User specified P-CHS?
99 jz SHORT .AutodetectPCHSvalues
100
101 ; Use DRVPARAMS P-CHS values instead of autodetected
102 mov ax, [cs:bx+DRVPARAMS.wCylinders]
103 mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
104 call AtaGeometry_GetLCHStoAXBLBHfromPCHSinAXBLBH
105 jmp SHORT .StoreLCHStoDPT
106
107 ; Get L-CHS parameters and addressing mode
108.AutodetectPCHSvalues:
109 call AtaGeometry_GetLCHStoAXBLBHfromAtaInfoInESSI
110
111.StoreLCHStoDPT:
112 eSHL_IM dl, ADDRESSING_MODE_FIELD_POSITION
113 or cl, dl
114 or [di+DPT.bFlagsLow], cl ; Shift count and addressing mode
115 mov [di+DPT.wLchsCylinders], ax
116 mov [di+DPT.wLchsHeadsAndSectors], bx
117
118 ; Store P-CHS to DPT
119 call AtaGeometry_GetPCHStoAXBLBHfromAtaInfoInESSI
120 mov [di+DPT.bPchsHeads], bl
121%ifdef MODULE_EBIOS
122 mov [di+DPT.wPchsCylinders], ax
123 mov [di+DPT.bPchsSectorsPerTrack], bh
124 ; Fall to .StoreNumberOfLbaSectors
125
126;--------------------------------------------------------------------
127; .StoreNumberOfLbaSectors
128; Parameters:
129; DS:DI: Ptr to Disk Parameter Table
130; ES:SI: Ptr to 512-byte ATA information read from the drive
131; CS:BP: Ptr to IDEVARS for the controller
132; Returns:
133; Nothing
134; Corrupts registers:
135; AX, BX, CX, DX
136;--------------------------------------------------------------------
137 ; Check if LBA supported
138 test BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
139 jz SHORT .NoLbaSupportedSoNoEBIOS
140
141 ; Store LBA 28/48 total sector count
142 call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI
143 call StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
144
145 ; Load user defined LBA
146 call AccessDPT_GetPointerToDRVPARAMStoCSBX
147 test BYTE [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERLBA
148 jz SHORT .KeepTotalSectorsFromAtaID
149 mov ax, [cs:bx+DRVPARAMS.dwMaximumLBA]
150 mov dx, [cs:bx+DRVPARAMS.dwMaximumLBA+2]
151 xor bx, bx
152
153 ; Compare user defined and ATA-ID sector count and select smaller
154 cmp bx, [di+DPT.twLbaSectors+4]
155 jb SHORT .StoreUserDefinedSectorCountToDPT
156 cmp dx, [di+DPT.twLbaSectors+2]
157 jb SHORT .StoreUserDefinedSectorCountToDPT
158 ja SHORT .KeepTotalSectorsFromAtaID
159 cmp ax, [di+DPT.twLbaSectors]
160 jae SHORT .KeepTotalSectorsFromAtaID
161.StoreUserDefinedSectorCountToDPT:
162 xor cx, cx ; Always LBA28 for user defined values
163 call StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
164
165.KeepTotalSectorsFromAtaID:
166.NoLbaSupportedSoNoEBIOS:
167%endif ; MODULE_EBIOS
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 of 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
235
236%ifdef MODULE_EBIOS
237;--------------------------------------------------------------------
238; StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
239; Parameters:
240; BX:DX:AX: Total Sector Count
241; CL: FLGL_DPT_LBA48 if LBA48 supported
242; DS:DI: Ptr to Disk Parameter Table
243; Returns:
244; Nothing
245; Corrupts registers:
246; CL
247;--------------------------------------------------------------------
248StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX:
249 or cl, FLGL_DPT_LBA_AND_EBIOS_SUPPORTED
250 and BYTE [di+DPT.bFlagsLow], ~FLGL_DPT_LBA48
251 or [di+DPT.bFlagsLow], cl
252 mov [di+DPT.twLbaSectors], ax
253 mov [di+DPT.twLbaSectors+2], dx
254 mov [di+DPT.twLbaSectors+4], bx
255 ret
256%endif ; MODULE_EBIOS
Note: See TracBrowser for help on using the repository browser.