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

Last change on this file since 157 was 150, checked in by Tomi Tilli, 14 years ago

Changes to XTIDE Universal BIOS:

  • Redesigned Disk Parameter Tables.
  • Code generalizations for supporting non-IDE devices in the future.
File size: 7.4 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, FLG_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; Returns:
106; Nothing
107; Corrupts registers:
108; AX, BX, CX
109;--------------------------------------------------------------------
110.StoreLCHS:
111 xor bh, bh ; BX = P-CHS Heads (1...16)
112 xor cx, cx
113.ShiftLoop:
114 cmp ax, 1024 ; Need to shift?
115 jbe SHORT .LimitHeadsTo255 ; If not, return
116 inc cx ; Increment shift count
117 shr ax, 1 ; Halve cylinders
118 shl bx, 1 ; Double heads
119 jmp SHORT .ShiftLoop
120
121.LimitHeadsTo255: ; DOS does not support drives with 256 heads
122 rcr bh, 1 ; Set CF if 256 heads
123 sbb bl, 0 ; Decrement to 255 if 256 heads
124 or [di+DPT.wFlags], cl
125 mov [di+DPT.bLchsHeads], bl
126 ; Fall to .StoreAddressing
127
128;--------------------------------------------------------------------
129; .StoreAddressing
130; Parameters:
131; DS:DI: Ptr to Disk Parameter Table
132; ES:SI: Ptr to 512-byte ATA information read from the drive
133; Returns:
134; Nothing
135; Corrupts registers:
136; AX, BX
137;--------------------------------------------------------------------
138.StoreAddressing:
139 ; Check if L-CHS addressing should be used
140 cmp WORD [di+DPT.wPchsCylinders], 1024 ; L-CHS possible? (no translation needed)
141 jbe SHORT .StoreBlockMode ; If so, nothing needs to be changed
142
143 ; Check if P-CHS addressing should be used
144 mov al, FLG_DRVPARAMS_USERCHS ; User specified CHS?
145 call AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
146 jnz SHORT .StorePCHSaddressing
147 test WORD [es:si+ATA1.wCaps], A2_wCaps_LBA
148 jz SHORT .StorePCHSaddressing ; Use P-CHS since LBA not supported
149
150 ; LBA needs to be used. Check if 48-bit LBA is supported
151 test WORD [es:si+ATA6.wSetSup83], A6_wSetSup83_LBA48
152 jz SHORT .StoreLBA28addressing ; Use LBA-28 since LBA-48 not supported
153 or BYTE [di+DPT.wFlags], ADDRESSING_MODE_LBA48<<ADDRESSING_MODE_FIELD_POSITION
154.StoreLBA28addressing:
155 or BYTE [di+DPT.wFlags], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
156 jmp SHORT .StoreBlockMode
157.StorePCHSaddressing:
158 or BYTE [di+DPT.wFlags], ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
159 ; Fall to .StoreBlockMode
160
161;--------------------------------------------------------------------
162; .StoreBlockMode
163; Parameters:
164; DS:DI: Ptr to Disk Parameter Table
165; ES:SI: Ptr to 512-byte ATA information read from the drive
166; Returns:
167; Nothing
168; Corrupts registers:
169; Nothing
170;--------------------------------------------------------------------
171.StoreBlockMode:
172 cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
173 jbe SHORT .BlockModeTransfersNotSupported
174 or WORD [di+DPT.wFlags], FLG_DPT_BLOCK_MODE_SUPPORTED
175.BlockModeTransfersNotSupported:
176 ; Fall to .StoreDeviceSpecificParameters
177
178;--------------------------------------------------------------------
179; .StoreDeviceSpecificParameters
180; Parameters:
181; DS:DI: Ptr to Disk Parameter Table
182; ES:SI: Ptr to 512-byte ATA information read from the drive
183; Returns:
184; Nothing
185; Corrupts registers:
186; AX, BX, CX, DX
187;--------------------------------------------------------------------
188.StoreDeviceSpecificParameters:
189 call Device_FinalizeDPT
190 ; Fall to .StoreDriveNumberAndUpdateDriveCount
191
192;--------------------------------------------------------------------
193; .StoreDriveNumberAndUpdateDriveCount
194; Parameters:
195; DS:DI: Ptr to Disk Parameter Table
196; ES:SI: Ptr to 512-byte ATA information read from the drive
197; ES: BDA Segment
198; Returns:
199; DL: Drive number for new drive
200; CF: Cleared if DPT parameters stored successfully
201; Set if any error
202; Corrupts registers:
203; Nothing
204;--------------------------------------------------------------------
205.StoreDriveNumberAndUpdateDriveCount:
206 mov dl, [es:BDA.bHDCount]
207 or dl, 80h ; Set bit 7 since hard disk
208
209 inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
210 inc BYTE [es:BDA.bHDCount] ; Increment drive count to BDA
211
212 cmp BYTE [RAMVARS.bFirstDrv], 0 ; First drive set?
213 ja SHORT .AllDone ; If so, return
214 mov [RAMVARS.bFirstDrv], dl ; Store first drive number
215.AllDone:
216 clc
217 ret
Note: See TracBrowser for help on using the repository browser.