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