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

Last change on this file since 185 was 181, checked in by krille_n_@…, 13 years ago

Changes to all parts of the project:

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