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

Last change on this file since 174 was 173, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

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