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-2013 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
|
---|
21 | SECTION .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 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
31 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
32 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
33 | ; DS: RAMVARS segment
|
---|
34 | ; ES: BDA Segment
|
---|
35 | ; Returns:
|
---|
36 | ; DS:DI: Ptr to Disk Parameter Table (if successful)
|
---|
37 | ; CF: Cleared if DPT created successfully
|
---|
38 | ; Set if any error
|
---|
39 | ; Corrupts registers:
|
---|
40 | ; AX, BX, CX, DX
|
---|
41 | ;--------------------------------------------------------------------
|
---|
42 | CreateDPT_FromAtaInformation:
|
---|
43 | call FindDPT_ForNewDriveToDSDI
|
---|
44 | ; Fall to .InitializeDPT
|
---|
45 |
|
---|
46 | ;--------------------------------------------------------------------
|
---|
47 | ; .InitializeDPT
|
---|
48 | ; Parameters:
|
---|
49 | ; BH: Drive Select byte for Drive and Head Register
|
---|
50 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
51 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
52 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
53 | ; Returns:
|
---|
54 | ; Nothing
|
---|
55 | ; Corrupts registers:
|
---|
56 | ; AX
|
---|
57 | ;--------------------------------------------------------------------
|
---|
58 | .InitializeDPT:
|
---|
59 | call CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI
|
---|
60 | ; Fall to .StoreDriveSelectAndDriveControlByte
|
---|
61 |
|
---|
62 | ;--------------------------------------------------------------------
|
---|
63 | ; .StoreDriveSelectAndDriveControlByte
|
---|
64 | ; Parameters:
|
---|
65 | ; BH: Drive Select byte for Drive and Head Register
|
---|
66 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
67 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
68 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
69 | ; Returns:
|
---|
70 | ; Nothing
|
---|
71 | ; Corrupts registers:
|
---|
72 | ; AX
|
---|
73 | ;--------------------------------------------------------------------
|
---|
74 | .StoreDriveSelectAndDriveControlByte:
|
---|
75 | mov al, bh
|
---|
76 | and ax, BYTE FLG_DRVNHEAD_DRV ; AL now has Master/Slave bit
|
---|
77 | %ifdef MODULE_IRQ
|
---|
78 | cmp [cs:bp+IDEVARS.bIRQ], ah ; Interrupts enabled?
|
---|
79 | jz SHORT .StoreFlags ; If not, do not set interrupt flag
|
---|
80 | or al, FLGL_DPT_ENABLE_IRQ
|
---|
81 | .StoreFlags:
|
---|
82 | %endif
|
---|
83 | mov [di+DPT.wFlags], ax
|
---|
84 | ; Fall to .StoreCHSparametersAndAddressingMode
|
---|
85 |
|
---|
86 | ;--------------------------------------------------------------------
|
---|
87 | ; .StoreCHSparametersAndAddressingMode
|
---|
88 | ; Parameters:
|
---|
89 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
90 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
91 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
92 | ; Returns:
|
---|
93 | ; Nothing
|
---|
94 | ; Corrupts registers:
|
---|
95 | ; AX, BX, CX, DX
|
---|
96 | ;--------------------------------------------------------------------
|
---|
97 | .StoreCHSparametersAndAddressingMode:
|
---|
98 | ; Apply any user limited values to ATA ID
|
---|
99 | call AtaID_ModifyESSIforUserDefinedLimitsAndReturnTranslateModeInDX
|
---|
100 |
|
---|
101 | ; Translate P-CHS to L-CHS
|
---|
102 | call AtaGeometry_GetLCHStoAXBLBHfromAtaInfoInESSIandTranslateModeInDX
|
---|
103 | mov [di+DPT.wLchsCylinders], ax
|
---|
104 | mov [di+DPT.wLchsHeadsAndSectors], bx
|
---|
105 | mov al, dl
|
---|
106 | eSHL_IM al, TRANSLATEMODE_FIELD_POSITION
|
---|
107 | or cl, al
|
---|
108 |
|
---|
109 | ; Store P-CHS and flags
|
---|
110 | call AtaGeometry_GetPCHStoAXBLBHfromAtaInfoInESSI
|
---|
111 | dec dx ; Set ZF if TRANSLATEMODE_LARGE, SF if TRANSLATEMODE_NORMAL
|
---|
112 | js SHORT .NothingToChange
|
---|
113 | jz SHORT .LimitHeadsForLargeAddressingMode
|
---|
114 |
|
---|
115 | or cl, FLGL_DPT_LBA ; Set LBA bit for Assisted LBA
|
---|
116 | jmp SHORT .NothingToChange
|
---|
117 | .LimitHeadsForLargeAddressingMode:
|
---|
118 | MIN_U bl, 15 ; Cannot have 16 P-Heads in LARGE addressing mode
|
---|
119 | .NothingToChange:
|
---|
120 | or [di+DPT.bFlagsLow], cl ; Shift count and addressing mode
|
---|
121 | mov [di+DPT.wPchsHeadsAndSectors], bx
|
---|
122 |
|
---|
123 | %ifdef MODULE_EBIOS
|
---|
124 | test cl, FLGL_DPT_LBA
|
---|
125 | jz SHORT .NoLbaSoNoEBIOS
|
---|
126 |
|
---|
127 | ; Store P-Cylinders but only if we have 15,482,880 or less sectors since
|
---|
128 | ; we only need P-Cylinders so we can return it from AH=48h
|
---|
129 | call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI
|
---|
130 | sub ax, MAX_SECTOR_COUNT_TO_RETURN_PCHS & 0FFFFh
|
---|
131 | sbb dx, MAX_SECTOR_COUNT_TO_RETURN_PCHS >> 16
|
---|
132 | sbb bx, BYTE 0
|
---|
133 | ja SHORT .StoreNumberOfLbaSectors
|
---|
134 |
|
---|
135 | ; Since we might have altered the default P-CHS parameters to be
|
---|
136 | ; presented to the drive (AH=09h), we need to calculate new
|
---|
137 | ; P-Cylinders. It could be read from the ATA ID after
|
---|
138 | ; COMMAND_INITIALIZE_DEVICE_PARAMETERS but that is too much trouble.
|
---|
139 | ; P-Cyls = MIN(16383*16*63, LBA sector count) / (P-Heads * P-Sectors per track)
|
---|
140 | call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI
|
---|
141 | xchg cx, ax ; Sector count to DX:CX
|
---|
142 | mov al, [di+DPT.bPchsHeads]
|
---|
143 | mul BYTE [di+DPT.bPchsSectorsPerTrack]
|
---|
144 | xchg cx, ax
|
---|
145 | div cx ; AX = new P-Cylinders
|
---|
146 | mov [di+DPT.wPchsCylinders], ax
|
---|
147 |
|
---|
148 | ; Store CHS sector count as total sector count
|
---|
149 | mul cx
|
---|
150 | xor bx, bx
|
---|
151 | xor cx, cx ; Clear LBA48 flag
|
---|
152 | jmp SHORT .StoreTotalSectorsFromBXDXAXandLBA48flagFromCL
|
---|
153 | ; Fall to .StoreNumberOfLbaSectors
|
---|
154 |
|
---|
155 | ;--------------------------------------------------------------------
|
---|
156 | ; .StoreNumberOfLbaSectors
|
---|
157 | ; Parameters:
|
---|
158 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
159 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
160 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
161 | ; Returns:
|
---|
162 | ; Nothing
|
---|
163 | ; Corrupts registers:
|
---|
164 | ; AX, BX, CX, DX
|
---|
165 | ;--------------------------------------------------------------------
|
---|
166 | .StoreNumberOfLbaSectors:
|
---|
167 | ; Store LBA 28/48 total sector count
|
---|
168 | call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI
|
---|
169 | .StoreTotalSectorsFromBXDXAXandLBA48flagFromCL:
|
---|
170 | or [di+DPT.bFlagsLow], cl
|
---|
171 | mov [di+DPT.twLbaSectors], ax
|
---|
172 | mov [di+DPT.twLbaSectors+2], dx
|
---|
173 | mov [di+DPT.twLbaSectors+4], bx
|
---|
174 | .NoLbaSoNoEBIOS:
|
---|
175 | %endif ; MODULE_EBIOS
|
---|
176 | ; Fall to .StoreBlockMode
|
---|
177 |
|
---|
178 | ;--------------------------------------------------------------------
|
---|
179 | ; .StoreBlockMode
|
---|
180 | ; Parameters:
|
---|
181 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
182 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
183 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
184 | ; Returns:
|
---|
185 | ; Nothing
|
---|
186 | ; Corrupts registers:
|
---|
187 | ; Nothing
|
---|
188 | ;--------------------------------------------------------------------
|
---|
189 | .StoreBlockMode:
|
---|
190 | cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
|
---|
191 | jbe SHORT .BlockModeTransfersNotSupported
|
---|
192 | or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
|
---|
193 | .BlockModeTransfersNotSupported:
|
---|
194 | ; Fall to .StoreDeviceSpecificParameters
|
---|
195 |
|
---|
196 | ;--------------------------------------------------------------------
|
---|
197 | ; .StoreDeviceSpecificParameters
|
---|
198 | ; Parameters:
|
---|
199 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
200 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
201 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
202 | ; Returns:
|
---|
203 | ; Nothing
|
---|
204 | ; Corrupts registers:
|
---|
205 | ; AX, BX, CX, DX
|
---|
206 | ;--------------------------------------------------------------------
|
---|
207 | .StoreDeviceSpecificParameters:
|
---|
208 | call Device_FinalizeDPT
|
---|
209 |
|
---|
210 | ;----------------------------------------------------------------------
|
---|
211 | ; Update drive counts (hard and floppy)
|
---|
212 | ;----------------------------------------------------------------------
|
---|
213 |
|
---|
214 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
215 | ;
|
---|
216 | ; These two instructions serve two purposes:
|
---|
217 | ; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter.
|
---|
218 | ; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is
|
---|
219 | ; effectively discarded. This is more of a safety check then code that should ever normally be hit (see below).
|
---|
220 | ; Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT,
|
---|
221 | ; this was necessary. Now, this situation shouldn't happen in normal operation, for a couple of reasons:
|
---|
222 | ; A. xtidecfg always puts configured serial ports at the end of the IDEVARS list
|
---|
223 | ; B. the auto serial code is always executed last
|
---|
224 | ; C. the serial server always returns floppy drives last
|
---|
225 | ;
|
---|
226 | adc byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0
|
---|
227 | jnz .AllDone
|
---|
228 | %else
|
---|
229 | ;
|
---|
230 | ; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which
|
---|
231 | ; could lead to unpredictable results since no MBR will be present, etc. The server doesn't know that
|
---|
232 | ; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan.
|
---|
233 | ;
|
---|
234 | jc .AllDone
|
---|
235 | %endif
|
---|
236 |
|
---|
237 | inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
|
---|
238 |
|
---|
239 | .AllDone:
|
---|
240 | clc
|
---|
241 | ret
|
---|
242 |
|
---|
243 |
|
---|
244 | ;--------------------------------------------------------------------
|
---|
245 | ; CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI
|
---|
246 | ; Parameters:
|
---|
247 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
248 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
249 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
250 | ; Returns:
|
---|
251 | ; Nothing
|
---|
252 | ; Corrupts registers:
|
---|
253 | ; AX
|
---|
254 | ;--------------------------------------------------------------------
|
---|
255 | CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI:
|
---|
256 | mov [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM
|
---|
257 |
|
---|
258 | %ifdef MODULE_8BIT_IDE_ADVANCED
|
---|
259 | call DetectDrives_DoesIdevarsInCSBPbelongToXTCF
|
---|
260 | jne SHORT .DeviceUsesPortSpecifiedInIDEVARS
|
---|
261 | mov [di+DPT.wBasePort], dx
|
---|
262 | ret
|
---|
263 | .DeviceUsesPortSpecifiedInIDEVARS:
|
---|
264 | %endif ; MODULE_8BIT_IDE_ADVANCED
|
---|
265 |
|
---|
266 | mov ax, [cs:bp+IDEVARS.wBasePort]
|
---|
267 | mov [di+DPT.wBasePort], ax
|
---|
268 | ret
|
---|