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

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

Changes to XTIDE Universal BIOS:

  • EBIOS functions now work in lite mode.
File size: 8.0 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 succesfull)
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
66%ifdef MODULE_SERIAL
67 cmp byte [cs:bp+IDEVARS.bDevice], DEVICE_SERIAL_PORT
68 jnz .StoreAddressing
69 or byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
70%endif
71 ; Fall to .StoreAddressing
72
73;--------------------------------------------------------------------
74; .StoreAddressing
75; Parameters:
76; DS:DI: Ptr to Disk Parameter Table
77; ES:SI: Ptr to 512-byte ATA information read from the drive
78; CS:BP: Ptr to IDEVARS for the controller
79; Returns:
80; Nothing
81; Corrupts registers:
82; AX, BX, CX, DX
83;--------------------------------------------------------------------
84.StoreAddressing:
85 ; Check if CHS defined in ROMVARS
86 call AccessDPT_GetPointerToDRVPARAMStoCSBX
87 test byte [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERCHS ; User specified CHS?
88 jnz SHORT .StoreUserDefinedPCHS
89
90 ; Check if LBA supported
91 call AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI
92 test BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
93 jz SHORT .StoreCHSfromAXBHBL ; Small old drive with CHS addressing only
94
95 ; Check if 48-bit LBA supported
96 test BYTE [es:si+ATA6.wSetSup83+1], A6_wSetSup83_LBA48>>8
97 jz SHORT .StoreLBA28addressing
98 or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA48<<ADDRESSING_MODE_FIELD_POSITION
99.StoreLBA28addressing:
100 or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
101 call AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI
102 mov [di+DPT.twLbaSectors], ax
103 mov [di+DPT.twLbaSectors+2], dx
104 mov [di+DPT.twLbaSectors+4], bx
105 call AtaID_GetLbaAssistedCHStoDXAXBLBH
106 mov [di+DPT.bLbaHeads], bl
107 jmp SHORT .StoreBlockMode
108
109;--------------------------------------------------------------------
110; .StoreUserDefinedPCHS
111; Parameters:
112; DS:DI: Ptr to Disk Parameter Table
113; ES:SI: Ptr to 512-byte ATA information read from the drive
114; CS:BP: Ptr to IDEVARS for the controller
115; Returns:
116; AX: Number of P-CHS cylinders
117; BH: Number of P-CHS sectors per track
118; BL: Number of P-CHS heads
119; Corrupts registers:
120; Nothing
121;--------------------------------------------------------------------
122.StoreUserDefinedPCHS:
123 call AccessDPT_GetPointerToDRVPARAMStoCSBX
124 mov ax, [cs:bx+DRVPARAMS.wCylinders]
125 mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
126 ; Fall to .StoreCHSfromAXBHBL
127
128;--------------------------------------------------------------------
129; .StoreCHSfromAXBHBL
130; Parameters:
131; AX: Number of P-CHS cylinders
132; BH: Number of P-CHS sectors per track
133; BL: Number of P-CHS heads
134; DS:DI: Ptr to Disk Parameter Table
135; ES:SI: Ptr to 512-byte ATA information read from the drive
136; CS:BP: Ptr to IDEVARS for the controller
137; Returns:
138; AX: Number of P-CHS cylinders
139; BH: Number of P-CHS sectors per track
140; BL: Number of P-CHS heads
141; Corrupts registers:
142; CX
143;--------------------------------------------------------------------
144.StoreCHSfromAXBHBL:
145 push ax
146 push bx
147 call AccessDPT_ShiftPCHinAXBLtoLCH ; Get number of bits to shift
148 pop bx
149 pop ax
150 jcxz .StorePCHSfromAXDX ; Small drive so use L-CHS addressing
151
152 ; Store P-CHS addressing mode and number of bits to shift in L-CHS to P-CHS translation
153 or cl, ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
154 or [di+DPT.bFlagsLow], cl
155 ; Fall to .StoreChsFromAXBLBH
156
157;--------------------------------------------------------------------
158; .StoreChsFromAXBLBH
159; Parameters:
160; AX: Number of P-CHS cylinders
161; BH: Number of P-CHS sectors per track
162; BL: Number of P-CHS heads
163; DS:DI: Ptr to Disk Parameter Table
164; ES:SI: Ptr to 512-byte ATA information read from the drive
165; CS:BP: Ptr to IDEVARS for the controller
166; Returns:
167; Nothing
168; Corrupts registers:
169; Nothing
170;--------------------------------------------------------------------
171.StorePCHSfromAXDX:
172 mov [di+DPT.wPchsCylinders], ax
173 mov [di+DPT.wPchsHeadsAndSectors], bx
174 ; Fall to .StoreBlockMode
175
176;--------------------------------------------------------------------
177; .StoreBlockMode
178; Parameters:
179; DS:DI: Ptr to Disk Parameter Table
180; ES:SI: Ptr to 512-byte ATA information read from the drive
181; CS:BP: Ptr to IDEVARS for the controller
182; Returns:
183; Nothing
184; Corrupts registers:
185; Nothing
186;--------------------------------------------------------------------
187.StoreBlockMode:
188 cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
189 jbe SHORT .BlockModeTransfersNotSupported
190 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
191.BlockModeTransfersNotSupported:
192 ; Fall to .StoreDeviceSpecificParameters
193
194;--------------------------------------------------------------------
195; .StoreDeviceSpecificParameters
196; Parameters:
197; DS:DI: Ptr to Disk Parameter Table
198; ES:SI: Ptr to 512-byte ATA information read from the drive
199; CS:BP: Ptr to IDEVARS for the controller
200; Returns:
201; Nothing
202; Corrupts registers:
203; AX, BX, CX, DX
204;--------------------------------------------------------------------
205.StoreDeviceSpecificParameters:
206 call Device_FinalizeDPT
207 ; Fall to .StoreDriveNumberAndUpdateDriveCount
208
209;--------------------------------------------------------------------
210; .StoreDriveNumberAndUpdateDriveCount
211; Parameters:
212; DS:DI: Ptr to Disk Parameter Table
213; ES:SI: Ptr to 512-byte ATA information read from the drive
214; CS:BP: Ptr to IDEVARS for the controller
215; ES: BDA Segment
216; Returns:
217; DL: Drive number for new drive
218; CF: Always cleared
219; Corrupts registers:
220; Nothing
221;--------------------------------------------------------------------
222.StoreDriveNumberAndUpdateDriveCount:
223 mov dl, [es:BDA.bHDCount]
224 or dl, 80h ; Set bit 7 since hard disk
225
226 inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
227 inc BYTE [es:BDA.bHDCount] ; Increment drive count to BDA
228
229 cmp BYTE [RAMVARS.bFirstDrv], 0 ; First drive set?
230 ja SHORT .AllDone ; If so, return
231 mov [RAMVARS.bFirstDrv], dl ; Store first drive number
232 clc
233.AllDone:
234 ret
Note: See TracBrowser for help on using the repository browser.