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

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

Changes to the XTIDE Universal BIOS:

  • Size optimizations in various files.
File size: 8.3 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_ForNewDrive ; Get new DPT to DS:DI
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; AX: Zero
38; Corrupts registers:
39; Nothing
40;--------------------------------------------------------------------
41.InitializeDPT:
42 xor ax, ax
43 mov BYTE [di+DPT.bSize], DPT_size
44 mov [di+DPT.wDrvNumAndFlags], ax
45 mov BYTE [di+DPT.bReset], MASK_RESET_ALL
46 mov [di+DPT.bIdeOff], bp
47 mov [di+DPT.bDrvSel], bh
48 ; Fall to .StoreDriveControlByte
49
50;--------------------------------------------------------------------
51; .StoreDriveControlByte
52; Parameters:
53; AX: Zero
54; BH: Drive Select byte for Drive and Head Register
55; DS:DI: Ptr to Disk Parameter Table
56; ES:SI: Ptr to 512-byte ATA information read from the drive
57; CS:BP: Ptr to IDEVARS for the controller
58; Returns:
59; Nothing
60; Corrupts registers:
61; AX
62;--------------------------------------------------------------------
63.StoreDriveControlByte:
64 cmp BYTE [cs:bp+IDEVARS.bIRQ], al ; Interrupts enabled?
65 jne SHORT .CheckHeadCount
66 or al, FLG_IDE_CTRL_nIEN ; Disable interrupts
67.CheckHeadCount:
68 cmp BYTE [es:si+ATA1.wHeadCnt], 8 ; 1...8 heads?
69 jbe SHORT .StoreDrvCtrlByteToDPT
70 or al, FLG_IDE_CTRL_O8H ; Over 8 heads (pre-ATA)
71.StoreDrvCtrlByteToDPT:
72 mov [di+DPT.bDrvCtrl], al
73 ; Fall to .StorePCHS
74
75;--------------------------------------------------------------------
76; .StorePCHS
77; Parameters:
78; AH: Zero
79; BH: Drive Select byte for Drive and Head Register
80; DS:DI: Ptr to Disk Parameter Table
81; ES:SI: Ptr to 512-byte ATA information read from the drive
82; CS:BP: Ptr to IDEVARS for the controller
83; Returns:
84; AX: P-CHS cylinders
85; BL: P-CHS heads
86; BH: P-CHS sectors
87; Corrupts registers:
88; Nothing
89;--------------------------------------------------------------------
90.StorePCHS:
91 mov al, FLG_DRVPARAMS_USERCHS ; User specified CHS?
92 call AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
93 jnz SHORT .GetUserSpecifiedPCHS
94 call AtaID_GetPCHS ; Get from ATA information
95 jmp SHORT .StorePCHStoDPT
96
97.GetUserSpecifiedPCHS:
98 call AccessDPT_GetPointerToDRVPARAMStoCSBX
99 mov ax, [cs:bx+DRVPARAMS.wCylinders]
100 mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
101 or BYTE [di+DPT.bFlags], FLG_DPT_USERCHS
102
103.StorePCHStoDPT:
104 mov [di+DPT.wPCyls], ax
105 mov [di+DPT.wHeadsAndSectors], bx
106 ; Fall to .StoreLCHS
107
108;--------------------------------------------------------------------
109; .StoreLCHS
110; Parameters:
111; AX: P-CHS cylinders
112; BL: P-CHS heads
113; DS:DI: Ptr to Disk Parameter Table
114; ES:SI: Ptr to 512-byte ATA information read from the drive
115; Returns:
116; Nothing
117; Corrupts registers:
118; AX, BX, CX
119;--------------------------------------------------------------------
120.StoreLCHS:
121 xor bh, bh ; BX = P-CHS Heads (1...16)
122 xor cx, cx
123.ShiftLoop:
124 cmp ax, 1024 ; Need to shift?
125 jbe SHORT .LimitHeadsTo255 ; If not, return
126 inc cx ; Increment shift count
127 shr ax, 1 ; Halve cylinders
128 shl bx, 1 ; Double heads
129 jmp SHORT .ShiftLoop
130
131.LimitHeadsTo255:
132 test bh, bh ; 256 heads?
133 jz SHORT .StoreLCHStoDPT ; If less, no correction needed
134 dec bx ; Limit to 255 heads since DOS does not support 256 heads
135.StoreLCHStoDPT:
136 mov [di+DPT.bShLtoP], cl
137 mov [di+DPT.wLHeads], bx
138 ; Fall to .StoreAddressing
139
140;--------------------------------------------------------------------
141; .StoreAddressing
142; Parameters:
143; DS:DI: Ptr to Disk Parameter Table
144; ES:SI: Ptr to 512-byte ATA information read from the drive
145; Returns:
146; Nothing
147; Corrupts registers:
148; Nothing
149;--------------------------------------------------------------------
150.StoreAddressing:
151 cmp WORD [di+DPT.wPCyls], 1024 ; L-CHS possible? (no translation needed)
152 jbe SHORT .StoreBlockMode ; If so, nothing needs to be changed
153 test BYTE [di+DPT.bFlags], FLG_DPT_USERCHS
154 jnz SHORT .StorePCHSaddressing ; Use user defined P-CHS
155 test WORD [es:si+ATA1.wCaps], A2_wCaps_LBA
156 jz SHORT .StorePCHSaddressing ; Use P-CHS since LBA not supported
157 test WORD [es:si+ATA6.wSetSup83], A6_wSetSup83_LBA48
158 jz SHORT .StoreLBA28addressing ; Use LBA-28 since LBA-48 not supported
159 or BYTE [di+DPT.bFlags], ADDR_DPT_LBA48<<1
160.StoreLBA28addressing:
161 or BYTE [di+DPT.bFlags], ADDR_DPT_LBA28<<1
162 or BYTE [di+DPT.bDrvSel], FLG_IDE_DRVHD_LBA
163 jmp SHORT .StoreBlockMode
164.StorePCHSaddressing:
165 or BYTE [di+DPT.bFlags], ADDR_DPT_PCHS<<1
166 ; Fall to .StoreBlockMode
167
168;--------------------------------------------------------------------
169; .StoreBlockMode
170; Parameters:
171; DS:DI: Ptr to Disk Parameter Table
172; ES:SI: Ptr to 512-byte ATA information read from the drive
173; Returns:
174; Nothing
175; Corrupts registers:
176; AX
177;--------------------------------------------------------------------
178.StoreBlockMode:
179 mov al, 1 ; Minimum block size is 1 sector
180 mov ah, [es:si+ATA1.bBlckSize] ; Load max block size in sectors
181 mov [di+DPT.wSetAndMaxBlock], ax
182 ; Fall to .StoreEBIOSSupport
183
184;--------------------------------------------------------------------
185; .StoreEBIOSSupport
186; Parameters:
187; DS:DI: Ptr to Disk Parameter Table
188; ES:SI: Ptr to 512-byte ATA information read from the drive
189; Returns:
190; Nothing
191; Corrupts registers:
192; AX, BX, DX
193;--------------------------------------------------------------------
194.StoreEBIOSSupport:
195 test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
196 jz SHORT .StoreDriveNumberAndUpdateDriveCount ; No EBIOS support since small DPTs needed
197
198 mov bl, [di+DPT.bFlags]
199 and bx, BYTE MASK_DPT_ADDR ; Addressing mode
200 jmp [cs:bx+.rgwAddrJmp] ; Jump to handle addressing mode
201.rgwAddrJmp:
202 dw .StoreDriveNumberAndUpdateDriveCount ; ADDR_DPT_LCHS
203 dw .StoreDriveNumberAndUpdateDriveCount ; ADDR_DPT_PCHS
204 dw .SupportForLBA28 ; ADDR_DPT_LBA28
205 dw .SupportForLBA48 ; ADDR_DPT_LBA48
206
207.SupportForLBA28:
208 sub BYTE [di+DPT.bSize], 2 ; Only 4 bytes for sector count
209.SupportForLBA48:
210 add BYTE [di+DPT.bSize], EBDPT_size - DPT_size
211 or BYTE [di+DPT.bFlags], FLG_DPT_EBIOS
212 call AtaID_GetTotalSectorCount
213 mov [di+EBDPT.twCapacity], ax
214 mov [di+EBDPT.twCapacity+2], dx
215 mov [di+EBDPT.twCapacity+4], bx
216 ; Fall to .StoreDriveNumberAndUpdateDriveCount
217
218;--------------------------------------------------------------------
219; .StoreDriveNumberAndUpdateDriveCount
220; Parameters:
221; DS:DI: Ptr to Disk Parameter Table
222; ES:SI: Ptr to 512-byte ATA information read from the drive
223; ES: BDA Segment
224; Returns:
225; DL: Drive number for new drive
226; CF: Cleared if DPT parameters stored successfully
227; Set if any error
228; Corrupts registers:
229; Nothing
230;--------------------------------------------------------------------
231.StoreDriveNumberAndUpdateDriveCount:
232 ; Make sure that more drives can be accepted
233 mov dl, [es:BDA.bHDCount] ; Load number of hard disks
234 test dl, dl ; Hard disks at maximum?
235 stc ; Assume error
236 js SHORT .TooManyDrives ; If so, return
237
238 ; Store drive number to DPT
239 or dl, 80h ; Set bit 7 since hard disk
240 mov [di+DPT.bDrvNum], dl ; Store drive number
241
242 ; Update BDA and RAMVARS
243 inc BYTE [es:BDA.bHDCount] ; Increment drive count to BDA
244 call RamVars_IncrementHardDiskCount
245 clc
246.TooManyDrives:
247 ret
Note: See TracBrowser for help on using the repository browser.