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

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

Changes to all parts of the project:

  • Size optimizations, mostly by excluding code from the BIOS.
  • Cleaned the source a bit, fixed spelling and grammar mistakes.
File size: 7.6 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 ; Fall to .StorePCHS
66
67;--------------------------------------------------------------------
68; .StorePCHS
69; Parameters:
70; BH: Drive Select byte for Drive and Head Register
71; DS:DI: Ptr to Disk Parameter Table
72; ES:SI: Ptr to 512-byte ATA information read from the drive
73; CS:BP: Ptr to IDEVARS for the controller
74; Returns:
75; AX: P-CHS cylinders
76; BL: P-CHS heads
77; BH: P-CHS sectors
78; Corrupts registers:
79; Nothing
80;--------------------------------------------------------------------
81.StorePCHS:
82 mov al, FLG_DRVPARAMS_USERCHS ; User specified CHS?
83 call AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
84 jnz SHORT .GetUserSpecifiedPCHS
85 call AtaID_GetPCHS ; Get from ATA information
86 jmp SHORT .StorePCHStoDPT
87
88.GetUserSpecifiedPCHS:
89 call AccessDPT_GetPointerToDRVPARAMStoCSBX
90 mov ax, [cs:bx+DRVPARAMS.wCylinders]
91 mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
92
93.StorePCHStoDPT:
94 mov [di+DPT.wPchsCylinders], ax
95 mov [di+DPT.wPchsHeadsAndSectors], bx
96 ; Fall to .StoreLCHS
97
98;--------------------------------------------------------------------
99; .StoreLCHS
100; Parameters:
101; AX: P-CHS cylinders
102; BL: P-CHS heads
103; DS:DI: Ptr to Disk Parameter Table
104; ES:SI: Ptr to 512-byte ATA information read from the drive
105; CS:BP: Ptr to IDEVARS for the controller
106; Returns:
107; Nothing
108; Corrupts registers:
109; AX, BX, CX
110;--------------------------------------------------------------------
111.StoreLCHS:
112 xor bh, bh ; BX = P-CHS Heads (1...16)
113 xor cx, cx
114.ShiftLoop:
115 cmp ax, 1024 ; Need to shift?
116 jbe SHORT .LimitHeadsTo255 ; If not, return
117 inc cx ; Increment shift count
118 shr ax, 1 ; Halve cylinders
119 shl bx, 1 ; Double heads
120 jmp SHORT .ShiftLoop
121
122.LimitHeadsTo255: ; DOS does not support drives with 256 heads
123 rcr bh, 1 ; Set CF if 256 heads
124 sbb bl, 0 ; Decrement to 255 if 256 heads
125 or [di+DPT.wFlags], cl
126 mov [di+DPT.bLchsHeads], bl
127 ; Fall to .StoreAddressing
128
129;--------------------------------------------------------------------
130; .StoreAddressing
131; Parameters:
132; DS:DI: Ptr to Disk Parameter Table
133; ES:SI: Ptr to 512-byte ATA information read from the drive
134; CS:BP: Ptr to IDEVARS for the controller
135; Returns:
136; Nothing
137; Corrupts registers:
138; AX, BX
139;--------------------------------------------------------------------
140.StoreAddressing:
141 ; Check if L-CHS addressing should be used
142 cmp WORD [di+DPT.wPchsCylinders], 1024 ; L-CHS possible? (no translation needed)
143 jbe SHORT .StoreBlockMode ; If so, nothing needs to be changed
144
145 ; Check if P-CHS addressing should be used
146 mov al, FLG_DRVPARAMS_USERCHS ; User specified CHS?
147 call AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
148 jnz SHORT .StorePCHSaddressing
149 test WORD [es:si+ATA1.wCaps], A2_wCaps_LBA
150 jz SHORT .StorePCHSaddressing ; Use P-CHS since LBA not supported
151
152 ; LBA needs to be used. Check if 48-bit LBA is supported
153 test WORD [es:si+ATA6.wSetSup83], A6_wSetSup83_LBA48
154 jz SHORT .StoreLBA28addressing ; Use LBA-28 since LBA-48 not supported
155 or BYTE [di+DPT.wFlags], ADDRESSING_MODE_LBA48<<ADDRESSING_MODE_FIELD_POSITION
156.StoreLBA28addressing:
157 or BYTE [di+DPT.wFlags], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
158 jmp SHORT .StoreBlockMode
159.StorePCHSaddressing:
160 or BYTE [di+DPT.wFlags], ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
161 ; Fall to .StoreBlockMode
162
163;--------------------------------------------------------------------
164; .StoreBlockMode
165; Parameters:
166; DS:DI: Ptr to Disk Parameter Table
167; ES:SI: Ptr to 512-byte ATA information read from the drive
168; CS:BP: Ptr to IDEVARS for the controller
169; Returns:
170; Nothing
171; Corrupts registers:
172; Nothing
173;--------------------------------------------------------------------
174.StoreBlockMode:
175 cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
176 jbe SHORT .BlockModeTransfersNotSupported
177 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
178.BlockModeTransfersNotSupported:
179 ; Fall to .StoreDeviceSpecificParameters
180
181;--------------------------------------------------------------------
182; .StoreDeviceSpecificParameters
183; Parameters:
184; DS:DI: Ptr to Disk Parameter Table
185; ES:SI: Ptr to 512-byte ATA information read from the drive
186; CS:BP: Ptr to IDEVARS for the controller
187; Returns:
188; Nothing
189; Corrupts registers:
190; AX, BX, CX, DX
191;--------------------------------------------------------------------
192.StoreDeviceSpecificParameters:
193 call Device_FinalizeDPT
194 ; Fall to .StoreDriveNumberAndUpdateDriveCount
195
196;--------------------------------------------------------------------
197; .StoreDriveNumberAndUpdateDriveCount
198; Parameters:
199; DS:DI: Ptr to Disk Parameter Table
200; ES:SI: Ptr to 512-byte ATA information read from the drive
201; CS:BP: Ptr to IDEVARS for the controller
202; ES: BDA Segment
203; Returns:
204; DL: Drive number for new drive
205; CF: Always cleared
206; Corrupts registers:
207; Nothing
208;--------------------------------------------------------------------
209.StoreDriveNumberAndUpdateDriveCount:
210 mov dl, [es:BDA.bHDCount]
211 or dl, 80h ; Set bit 7 since hard disk
212
213 inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
214 inc BYTE [es:BDA.bHDCount] ; Increment drive count to BDA
215
216 cmp BYTE [RAMVARS.bFirstDrv], 0 ; First drive set?
217 ja SHORT .AllDone ; If so, return
218 mov [RAMVARS.bFirstDrv], dl ; Store first drive number
219 clc
220.AllDone:
221 ret
Note: See TracBrowser for help on using the repository browser.