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

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

Changes to XTIDE Universal BIOS:

  • Boot Menu now displays correct capacity when using user defined LBA.
File size: 9.8 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Functions for creating Disk Parameter Table.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Creates new Disk Parameter Table for detected hard disk.
9; Drive is then fully accessible using any BIOS function.
10;
11; CreateDPT_FromAtaInformation
12; Parameters:
13; BH: Drive Select byte for Drive and Head Register
14; ES:SI: Ptr to 512-byte ATA information read from the drive
15; CS:BP: Ptr to IDEVARS for the controller
16; DS: RAMVARS segment
17; ES: BDA Segment
18; Returns:
19; DL: Drive number for new drive
20; DS:DI: Ptr to Disk Parameter Table (if successful)
21; CF: Cleared if DPT created successfully
22; Set if any error
23; Corrupts registers:
24; AX, BX, CX, DH
25;--------------------------------------------------------------------
26CreateDPT_FromAtaInformation:
27 call FindDPT_ForNewDriveToDSDI
28 ; Fall to .InitializeDPT
29
30;--------------------------------------------------------------------
31; .InitializeDPT
32; Parameters:
33; BH: Drive Select byte for Drive and Head Register
34; DS:DI: Ptr to Disk Parameter Table
35; CS:BP: Ptr to IDEVARS for the controller
36; Returns:
37; Nothing
38; Corrupts registers:
39; AX
40;--------------------------------------------------------------------
41.InitializeDPT:
42 mov [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM
43 ; Fall to .StoreDriveSelectAndDriveControlByte
44
45;--------------------------------------------------------------------
46; .StoreDriveSelectAndDriveControlByte
47; Parameters:
48; BH: Drive Select byte for Drive and Head Register
49; DS:DI: Ptr to Disk Parameter Table
50; ES:SI: Ptr to 512-byte ATA information read from the drive
51; CS:BP: Ptr to IDEVARS for the controller
52; Returns:
53; Nothing
54; Corrupts registers:
55; AX
56;--------------------------------------------------------------------
57.StoreDriveSelectAndDriveControlByte:
58 mov al, bh
59 and ax, BYTE FLG_DRVNHEAD_DRV ; AL now has Master/Slave bit
60 cmp [cs:bp+IDEVARS.bIRQ], ah ; Interrupts enabled?
61 jz SHORT .StoreFlags ; If not, do not set interrupt flag
62 or al, FLGL_DPT_ENABLE_IRQ
63.StoreFlags:
64 mov [di+DPT.wFlags], ax
65 ; Fall to .StoreAddressing
66
67;--------------------------------------------------------------------
68; .StoreAddressing
69; Parameters:
70; DS:DI: Ptr to Disk Parameter Table
71; ES:SI: Ptr to 512-byte ATA information read from the drive
72; CS:BP: Ptr to IDEVARS for the controller
73; Returns:
74; Nothing
75; Corrupts registers:
76; AX, BX, CX, DX
77;--------------------------------------------------------------------
78.StoreAddressing:
79 ; Check if CHS defined in ROMVARS
80 call AccessDPT_GetPointerToDRVPARAMStoCSBX
81 test byte [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERCHS ; User specified CHS?
82 jnz SHORT .StoreUserDefinedPCHS
83
84 ; Check if LBA supported
85 call AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI
86 test BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
87 jz SHORT .StoreCHSfromAXBHBL ; Small old drive with CHS addressing only
88
89 ; Store LBA 28/48 addressing and total sector count
90 call AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI
91 call StoreLbaAddressingAndTotalSectorCountFromBXDXAX
92
93 ; Replace sector count with user defined if necessary
94 call AccessDPT_GetPointerToDRVPARAMStoCSBX
95 test BYTE [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERLBA
96 jz SHORT .KeepTotalSectorsFromAtaID
97 mov ax, [cs:bx+DRVPARAMS.dwMaximumLBA]
98 mov dx, [cs:bx+DRVPARAMS.dwMaximumLBA+2]
99 xor bx, bx
100
101 ; Compare user defined and ATA-ID sector count and select smaller
102 cmp bx, [di+DPT.twLbaSectors+4]
103 jb SHORT .StoreUserDefinedSectorCountToDPT
104 cmp dx, [di+DPT.twLbaSectors+2]
105 jb SHORT .StoreUserDefinedSectorCountToDPT
106 ja SHORT .KeepTotalSectorsFromAtaID
107 cmp ax, [di+DPT.twLbaSectors]
108 jae SHORT .KeepTotalSectorsFromAtaID
109.StoreUserDefinedSectorCountToDPT:
110 call StoreLbaAddressingAndTotalSectorCountFromBXDXAX
111
112 ; Calculate L-CHS for old INT 13h
113.KeepTotalSectorsFromAtaID:
114 mov bx, [di+DPT.twLbaSectors+4] ; Restore BX
115 call AccessDPT_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH
116 mov [di+DPT.bLbaHeads], bl
117 jmp SHORT .StoreBlockMode
118
119;--------------------------------------------------------------------
120; .StoreUserDefinedPCHS
121; Parameters:
122; DS:DI: Ptr to Disk Parameter Table
123; ES:SI: Ptr to 512-byte ATA information read from the drive
124; CS:BP: Ptr to IDEVARS for the controller
125; Returns:
126; AX: Number of P-CHS cylinders
127; BH: Number of P-CHS sectors per track
128; BL: Number of P-CHS heads
129; Corrupts registers:
130; Nothing
131;--------------------------------------------------------------------
132.StoreUserDefinedPCHS:
133 call AccessDPT_GetPointerToDRVPARAMStoCSBX
134 mov ax, [cs:bx+DRVPARAMS.wCylinders]
135 mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
136 ; Fall to .StoreCHSfromAXBHBL
137
138;--------------------------------------------------------------------
139; .StoreCHSfromAXBHBL
140; Parameters:
141; AX: Number of P-CHS cylinders
142; BH: Number of P-CHS sectors per track
143; BL: Number of P-CHS heads
144; DS:DI: Ptr to Disk Parameter Table
145; ES:SI: Ptr to 512-byte ATA information read from the drive
146; CS:BP: Ptr to IDEVARS for the controller
147; Returns:
148; AX: Number of P-CHS cylinders
149; BH: Number of P-CHS sectors per track
150; BL: Number of P-CHS heads
151; Corrupts registers:
152; CX
153;--------------------------------------------------------------------
154.StoreCHSfromAXBHBL:
155 push ax
156 push bx
157 call AccessDPT_ShiftPCHinAXBLtoLCH ; Get number of bits to shift
158 pop bx
159 pop ax
160 jcxz .StorePCHSfromAXDX ; Small drive so use L-CHS addressing
161
162 ; Store P-CHS addressing mode and number of bits to shift in L-CHS to P-CHS translation
163 or cl, ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
164 or [di+DPT.bFlagsLow], cl
165 ; Fall to .StoreChsFromAXBLBH
166
167;--------------------------------------------------------------------
168; .StoreChsFromAXBLBH
169; Parameters:
170; AX: Number of P-CHS cylinders
171; BH: Number of P-CHS sectors per track
172; BL: Number of P-CHS heads
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.StorePCHSfromAXDX:
182 mov [di+DPT.wPchsCylinders], ax
183 mov [di+DPT.wPchsHeadsAndSectors], bx
184 ; Fall to .StoreBlockMode
185
186;--------------------------------------------------------------------
187; .StoreBlockMode
188; Parameters:
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.StoreBlockMode:
198 cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
199 jbe SHORT .BlockModeTransfersNotSupported
200 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
201.BlockModeTransfersNotSupported:
202 ; Fall to .StoreDeviceSpecificParameters
203
204;--------------------------------------------------------------------
205; .StoreDeviceSpecificParameters
206; Parameters:
207; DS:DI: Ptr to Disk Parameter Table
208; ES:SI: Ptr to 512-byte ATA information read from the drive
209; CS:BP: Ptr to IDEVARS for the controller
210; Returns:
211; Nothing
212; Corrupts registers:
213; AX, BX, CX, DX
214;--------------------------------------------------------------------
215.StoreDeviceSpecificParameters:
216 call Device_FinalizeDPT
217
218;----------------------------------------------------------------------
219; Update drive counts (hard and floppy)
220;----------------------------------------------------------------------
221
222%ifdef MODULE_SERIAL_FLOPPY
223;
224; These two instructions serve two purposes:
225; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter.
226; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is
227; effectively discarded. This is more of a safety check then code that should ever normally be hit (see below).
228; Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT,
229; this was necessary. Now, this situation shouldn't happen in normal operation, for a couple of reasons:
230; A. xtidecfg always puts configured serial ports at the end of the IDEVARS list
231; B. the auto serial code is always executed last
232; C. the serial server always returns floppy drives last
233;
234 adc byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0
235 jnz .AllDone
236%else
237;
238; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which
239; could lead to unpredictable results since no MBR will be present, etc. The server doesn't know that
240; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan.
241;
242 jc .AllDone
243%endif
244
245 inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
246
247.AllDone:
248 clc
249 ret
250
251
252;--------------------------------------------------------------------
253; StoreLbaAddressingAndTotalSectorCountFromBXDXAX
254; Parameters:
255; BX:DX:AX: Total Sector Count
256; DS:DI: Ptr to Disk Parameter Table
257; Returns:
258; Nothing
259; Corrupts registers:
260; CX
261;--------------------------------------------------------------------
262StoreLbaAddressingAndTotalSectorCountFromBXDXAX:
263 mov [di+DPT.twLbaSectors], ax
264 mov [di+DPT.twLbaSectors+2], dx
265 mov [di+DPT.twLbaSectors+4], bx
266
267 and BYTE [di+DPT.bFlagsLow], ~MASKL_DPT_ADDRESSING_MODE
268 test bx, bx
269 jnz SHORT .SetLba48AddressingToDPT
270 test dh, 0F0h
271 jz SHORT .SetLba28AddressingToDPT
272.SetLba48AddressingToDPT:
273 or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA48<<ADDRESSING_MODE_FIELD_POSITION
274.SetLba28AddressingToDPT:
275 or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
276 ret
Note: See TracBrowser for help on using the repository browser.