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

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

ifdef of existing serial code, in preperation for checkin

File size: 7.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 .around
69 or byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
70.around:
71%endif
72
73 ; Fall to .StoreAddressing
74
75;--------------------------------------------------------------------
76; .StoreAddressing
77; Parameters:
78; DS:DI: Ptr to Disk Parameter Table
79; ES:SI: Ptr to 512-byte ATA information read from the drive
80; CS:BP: Ptr to IDEVARS for the controller
81; Returns:
82; DX:AX or AX: Number of cylinders
83; BH: Number of sectors per track
84; BL: Number of heads
85; Corrupts registers:
86; CX, (DX)
87;--------------------------------------------------------------------
88.StoreAddressing:
89 ; Check if CHS defined in ROMVARS
90 mov al, FLG_DRVPARAMS_USERCHS ; User specified CHS?
91 call AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
92 jnz SHORT .StoreUserDefinedCHSaddressing
93
94 ; Check if LBA supported
95 call AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI
96 test BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
97 jz SHORT .StoreCHSaddressing
98
99 ; Check if 48-bit LBA supported
100 test BYTE [es:si+ATA6.wSetSup83+1], A6_wSetSup83_LBA48>>8
101 jz SHORT .StoreLBA28addressing
102 or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA48<<ADDRESSING_MODE_FIELD_POSITION
103.StoreLBA28addressing:
104 or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
105 call AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI
106 call AtaID_GetLbaAssistedCHStoDXAXBLBH
107 jmp SHORT .StoreChsFromDXAXBX
108
109 ; Check if P-CHS to L-CHS translation required
110.StoreUserDefinedCHSaddressing:
111 call AccessDPT_GetPointerToDRVPARAMStoCSBX
112 mov ax, [cs:bx+DRVPARAMS.wCylinders]
113 mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
114.StoreCHSaddressing:
115 cmp ax, MAX_LCHS_CYLINDERS
116 jbe SHORT .StoreChsFromAXBX ; No translation required
117
118 ; We need to get number of bits to shift for translation
119 push bx
120 push ax
121 eMOVZX dx, bl ; Heads now in DX
122 xchg bx, ax ; Sectors now in BX
123 call AccessDPT_ShiftPCHinBXDXtoLCH
124 or cl, ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
125 or [di+DPT.bFlagsLow], cl ; Store bits to shift
126 pop ax
127 pop bx
128 ; Fall to .StoreChsFromAXBX
129
130;--------------------------------------------------------------------
131; .StoreChsFromAXBX
132; .StoreChsFromDXAXBX
133; Parameters:
134; DX:AX or AX: Number of cylinders
135; BH: Number of sectors per track
136; BL: Number of heads
137; DS:DI: Ptr to Disk Parameter Table
138; ES:SI: Ptr to 512-byte ATA information read from the drive
139; CS:BP: Ptr to IDEVARS for the controller
140; Returns:
141; Nothing
142; Corrupts registers:
143; DX
144;--------------------------------------------------------------------
145.StoreChsFromAXBX:
146 xor dx, dx
147.StoreChsFromDXAXBX:
148 mov [di+DPT.dwCylinders], ax
149 mov [di+DPT.dwCylinders+2], dx
150 mov [di+DPT.wHeadsAndSectors], bx
151 ; Fall to .StoreBlockMode
152
153;--------------------------------------------------------------------
154; .StoreBlockMode
155; Parameters:
156; DS:DI: Ptr to Disk Parameter Table
157; ES:SI: Ptr to 512-byte ATA information read from the drive
158; CS:BP: Ptr to IDEVARS for the controller
159; Returns:
160; Nothing
161; Corrupts registers:
162; Nothing
163;--------------------------------------------------------------------
164.StoreBlockMode:
165 cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
166 jbe SHORT .BlockModeTransfersNotSupported
167 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
168.BlockModeTransfersNotSupported:
169 ; Fall to .StoreDeviceSpecificParameters
170
171;--------------------------------------------------------------------
172; .StoreDeviceSpecificParameters
173; Parameters:
174; DS:DI: Ptr to Disk Parameter Table
175; ES:SI: Ptr to 512-byte ATA information read from the drive
176; CS:BP: Ptr to IDEVARS for the controller
177; Returns:
178; Nothing
179; Corrupts registers:
180; AX, BX, CX, DX
181;--------------------------------------------------------------------
182.StoreDeviceSpecificParameters:
183 call Device_FinalizeDPT
184 ; Fall to .StoreDriveNumberAndUpdateDriveCount
185
186;--------------------------------------------------------------------
187; .StoreDriveNumberAndUpdateDriveCount
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; ES: BDA Segment
193; Returns:
194; DL: Drive number for new drive
195; CF: Always cleared
196; Corrupts registers:
197; Nothing
198;--------------------------------------------------------------------
199.StoreDriveNumberAndUpdateDriveCount:
200 mov dl, [es:BDA.bHDCount]
201 or dl, 80h ; Set bit 7 since hard disk
202
203 inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
204 inc BYTE [es:BDA.bHDCount] ; Increment drive count to BDA
205
206 cmp BYTE [RAMVARS.bFirstDrv], 0 ; First drive set?
207 ja SHORT .AllDone ; If so, return
208 mov [RAMVARS.bFirstDrv], dl ; Store first drive number
209 clc
210.AllDone:
211 ret
Note: See TracBrowser for help on using the repository browser.