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

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

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 10.7 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; DL: Drive number for new drive
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, DH
41;--------------------------------------------------------------------
42CreateDPT_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; 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 mov [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM
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 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 mov [di+DPT.wFlags], ax
81 ; Fall to .StoreAddressing
82
83;--------------------------------------------------------------------
84; .StoreAddressing
85; Parameters:
86; DS:DI: Ptr to Disk Parameter Table
87; ES:SI: Ptr to 512-byte ATA information read from the drive
88; CS:BP: Ptr to IDEVARS for the controller
89; Returns:
90; Nothing
91; Corrupts registers:
92; AX, BX, CX, DX
93;--------------------------------------------------------------------
94.StoreAddressing:
95 ; Check if CHS defined in ROMVARS
96 call AccessDPT_GetPointerToDRVPARAMStoCSBX
97 test byte [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERCHS ; User specified CHS?
98 jnz SHORT .StoreUserDefinedPCHS
99
100 ; Check if LBA supported
101 call AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI
102 test BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
103 jz SHORT .StoreCHSfromAXBHBL ; Small old drive with CHS addressing only
104
105 ; Store LBA 28/48 addressing and total sector count
106 call AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI
107 call StoreLbaAddressingAndTotalSectorCountFromBXDXAX
108
109 ; Replace sector count with user defined if necessary
110 call AccessDPT_GetPointerToDRVPARAMStoCSBX
111 test BYTE [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERLBA
112 jz SHORT .KeepTotalSectorsFromAtaID
113 mov ax, [cs:bx+DRVPARAMS.dwMaximumLBA]
114 mov dx, [cs:bx+DRVPARAMS.dwMaximumLBA+2]
115 xor bx, bx
116
117 ; Compare user defined and ATA-ID sector count and select smaller
118 cmp bx, [di+DPT.twLbaSectors+4]
119 jb SHORT .StoreUserDefinedSectorCountToDPT
120 cmp dx, [di+DPT.twLbaSectors+2]
121 jb SHORT .StoreUserDefinedSectorCountToDPT
122 ja SHORT .KeepTotalSectorsFromAtaID
123 cmp ax, [di+DPT.twLbaSectors]
124 jae SHORT .KeepTotalSectorsFromAtaID
125.StoreUserDefinedSectorCountToDPT:
126 call StoreLbaAddressingAndTotalSectorCountFromBXDXAX
127
128 ; Calculate L-CHS for old INT 13h
129.KeepTotalSectorsFromAtaID:
130 mov bx, [di+DPT.twLbaSectors+4] ; Restore BX
131 call LbaAssist_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH
132 mov [di+DPT.bLbaHeads], bl
133 jmp SHORT .StoreBlockMode
134
135;--------------------------------------------------------------------
136; .StoreUserDefinedPCHS
137; Parameters:
138; DS:DI: Ptr to Disk Parameter Table
139; ES:SI: Ptr to 512-byte ATA information read from the drive
140; CS:BP: Ptr to IDEVARS for the controller
141; Returns:
142; AX: Number of P-CHS cylinders
143; BH: Number of P-CHS sectors per track
144; BL: Number of P-CHS heads
145; Corrupts registers:
146; Nothing
147;--------------------------------------------------------------------
148.StoreUserDefinedPCHS:
149 call AccessDPT_GetPointerToDRVPARAMStoCSBX
150 mov ax, [cs:bx+DRVPARAMS.wCylinders]
151 mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
152 ; Fall to .StoreCHSfromAXBHBL
153
154;--------------------------------------------------------------------
155; .StoreCHSfromAXBHBL
156; Parameters:
157; AX: Number of P-CHS cylinders
158; BH: Number of P-CHS sectors per track
159; BL: Number of P-CHS heads
160; DS:DI: Ptr to Disk Parameter Table
161; ES:SI: Ptr to 512-byte ATA information read from the drive
162; CS:BP: Ptr to IDEVARS for the controller
163; Returns:
164; AX: Number of P-CHS cylinders
165; BH: Number of P-CHS sectors per track
166; BL: Number of P-CHS heads
167; Corrupts registers:
168; CX
169;--------------------------------------------------------------------
170.StoreCHSfromAXBHBL:
171 push ax
172 push bx
173 call AccessDPT_ShiftPCHinAXBLtoLCH ; Get number of bits to shift
174 pop bx
175 pop ax
176 jcxz .StorePCHSfromAXDX ; Small drive so use L-CHS addressing
177
178 ; Store P-CHS addressing mode and number of bits to shift in L-CHS to P-CHS translation
179 or cl, ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
180 or [di+DPT.bFlagsLow], cl
181 ; Fall to .StoreChsFromAXBLBH
182
183;--------------------------------------------------------------------
184; .StoreChsFromAXBLBH
185; Parameters:
186; AX: Number of P-CHS cylinders
187; BH: Number of P-CHS sectors per track
188; BL: Number of P-CHS heads
189; DS:DI: Ptr to Disk Parameter Table
190; ES:SI: Ptr to 512-byte ATA information read from the drive
191; CS:BP: Ptr to IDEVARS for the controller
192; Returns:
193; Nothing
194; Corrupts registers:
195; Nothing
196;--------------------------------------------------------------------
197.StorePCHSfromAXDX:
198 mov [di+DPT.wPchsCylinders], ax
199 mov [di+DPT.wPchsHeadsAndSectors], bx
200 ; Fall to .StoreBlockMode
201
202;--------------------------------------------------------------------
203; .StoreBlockMode
204; Parameters:
205; DS:DI: Ptr to Disk Parameter Table
206; ES:SI: Ptr to 512-byte ATA information read from the drive
207; CS:BP: Ptr to IDEVARS for the controller
208; Returns:
209; Nothing
210; Corrupts registers:
211; Nothing
212;--------------------------------------------------------------------
213.StoreBlockMode:
214 cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
215 jbe SHORT .BlockModeTransfersNotSupported
216 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
217.BlockModeTransfersNotSupported:
218 ; Fall to .StoreDeviceSpecificParameters
219
220;--------------------------------------------------------------------
221; .StoreDeviceSpecificParameters
222; Parameters:
223; DS:DI: Ptr to Disk Parameter Table
224; ES:SI: Ptr to 512-byte ATA information read from the drive
225; CS:BP: Ptr to IDEVARS for the controller
226; Returns:
227; Nothing
228; Corrupts registers:
229; AX, BX, CX, DX
230;--------------------------------------------------------------------
231.StoreDeviceSpecificParameters:
232 call Device_FinalizeDPT
233
234;----------------------------------------------------------------------
235; Update drive counts (hard and floppy)
236;----------------------------------------------------------------------
237
238%ifdef MODULE_SERIAL_FLOPPY
239;
240; These two instructions serve two purposes:
241; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter.
242; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is
243; effectively discarded. This is more of a safety check then code that should ever normally be hit (see below).
244; Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT,
245; this was necessary. Now, this situation shouldn't happen in normal operation, for a couple of reasons:
246; A. xtidecfg always puts configured serial ports at the end of the IDEVARS list
247; B. the auto serial code is always executed last
248; C. the serial server always returns floppy drives last
249;
250 adc byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0
251 jnz .AllDone
252%else
253;
254; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which
255; could lead to unpredictable results since no MBR will be present, etc. The server doesn't know that
256; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan.
257;
258 jc .AllDone
259%endif
260
261 inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
262
263.AllDone:
264 clc
265 ret
266
267
268;--------------------------------------------------------------------
269; StoreLbaAddressingAndTotalSectorCountFromBXDXAX
270; Parameters:
271; BX:DX:AX: Total Sector Count
272; DS:DI: Ptr to Disk Parameter Table
273; Returns:
274; Nothing
275; Corrupts registers:
276; CX
277;--------------------------------------------------------------------
278StoreLbaAddressingAndTotalSectorCountFromBXDXAX:
279 mov [di+DPT.twLbaSectors], ax
280 mov [di+DPT.twLbaSectors+2], dx
281 mov [di+DPT.twLbaSectors+4], bx
282
283 and BYTE [di+DPT.bFlagsLow], ~MASKL_DPT_ADDRESSING_MODE
284 test bx, bx
285 jnz SHORT .SetLba48AddressingToDPT ; Must be LBA48
286
287 ; Drives can report at most 0FFF FFFFh LBA28 sectors according to ATA specification.
288 ; That is (2^28)-1 so we can simply check if DH is zero or not.
289 test dh, dh
290 jz SHORT .SetLba28AddressingToDPT
291.SetLba48AddressingToDPT:
292 or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA48<<ADDRESSING_MODE_FIELD_POSITION
293.SetLba28AddressingToDPT:
294 or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
295 ret
Note: See TracBrowser for help on using the repository browser.