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

Last change on this file since 465 was 445, checked in by krille_n_@…, 12 years ago

Changes:

  • A speed optimization to the eSHL_IM macro for 386 and higher. This change breaks emulation in the sense that the macro will fail when given a memory operand as the first parameter.
  • Memory_SumCXbytesFromESSItoAL now returns with the zero flag set/cleared according to the result.
  • Unrolled all the 8 bit READ transfer loops to do 16 bytes per iteration. Added a new macro (UNROLL_SECTORS_IN_CX_TO_OWORDS) as part of it. Size wise this is expensive but I think it should be worth the ROM space. The WRITE transfer loops were left as is since writes are rare anyway (<10% of all disk I/O IIRC).
  • Minor optimizations and fixes here and there.
File size: 10.1 KB
RevLine 
[99]1; Project name : XTIDE Universal BIOS
[3]2; Description : Functions for creating Disk Parameter Table.
3
[376]4;
[445]5; XTIDE Universal BIOS and Associated Tools
[376]6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
[445]12;
[376]13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[445]16; GNU General Public License for more details.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
[445]18;
[376]19
[3]20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Creates new Disk Parameter Table for detected hard disk.
25; Drive is then fully accessible using any BIOS function.
26;
27; CreateDPT_FromAtaInformation
28; Parameters:
29; BH: Drive Select byte for Drive and Head Register
30; ES:SI: Ptr to 512-byte ATA information read from the drive
31; CS:BP: Ptr to IDEVARS for the controller
32; DS: RAMVARS segment
33; ES: BDA Segment
34; Returns:
[294]35; DS:DI: Ptr to Disk Parameter Table (if successful)
[3]36; CF: Cleared if DPT created successfully
37; Set if any error
38; Corrupts registers:
[99]39; AX, BX, CX, DH
[3]40;--------------------------------------------------------------------
41CreateDPT_FromAtaInformation:
[150]42 call FindDPT_ForNewDriveToDSDI
[99]43 ; Fall to .InitializeDPT
[3]44
45;--------------------------------------------------------------------
[99]46; .InitializeDPT
[3]47; Parameters:
48; BH: Drive Select byte for Drive and Head Register
49; DS:DI: Ptr to Disk Parameter Table
50; CS:BP: Ptr to IDEVARS for the controller
51; Returns:
[150]52; Nothing
[3]53; Corrupts registers:
[150]54; AX
[3]55;--------------------------------------------------------------------
[99]56.InitializeDPT:
[422]57 mov [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM
[150]58 ; Fall to .StoreDriveSelectAndDriveControlByte
[3]59
60;--------------------------------------------------------------------
[150]61; .StoreDriveSelectAndDriveControlByte
[3]62; Parameters:
63; BH: Drive Select byte for Drive and Head Register
64; DS:DI: Ptr to Disk Parameter Table
65; ES:SI: Ptr to 512-byte ATA information read from the drive
66; CS:BP: Ptr to IDEVARS for the controller
67; Returns:
[99]68; Nothing
[3]69; Corrupts registers:
70; AX
71;--------------------------------------------------------------------
[150]72.StoreDriveSelectAndDriveControlByte:
73 mov al, bh
74 and ax, BYTE FLG_DRVNHEAD_DRV ; AL now has Master/Slave bit
[411]75%ifdef MODULE_IRQ
[150]76 cmp [cs:bp+IDEVARS.bIRQ], ah ; Interrupts enabled?
77 jz SHORT .StoreFlags ; If not, do not set interrupt flag
[158]78 or al, FLGL_DPT_ENABLE_IRQ
[150]79.StoreFlags:
[411]80%endif
[150]81 mov [di+DPT.wFlags], ax
[421]82 ; Fall to .StoreCHSparametersAndAddressingMode
[3]83
84;--------------------------------------------------------------------
[421]85; .StoreCHSparametersAndAddressingMode
[3]86; Parameters:
87; DS:DI: Ptr to Disk Parameter Table
88; ES:SI: Ptr to 512-byte ATA information read from the drive
89; CS:BP: Ptr to IDEVARS for the controller
90; Returns:
[227]91; Nothing
[3]92; Corrupts registers:
[227]93; AX, BX, CX, DX
[3]94;--------------------------------------------------------------------
[421]95.StoreCHSparametersAndAddressingMode:
[173]96 ; Check if CHS defined in ROMVARS
[422]97 call GetUserDefinedCapacityToBXAXandFlagsToCXandModeToDXfromROMVARS
98 test cl, FLG_DRVPARAMS_USERCHS
[421]99 jz SHORT .AutodetectPCHSvalues
[173]100
[422]101 ; Translate P-CHS to L-CHS
102 call AtaGeometry_GetLCHStoAXBLBHfromPCHSinAXBLBHandTranslateModeInDX
[421]103 jmp SHORT .StoreLCHStoDPT
104.AutodetectPCHSvalues:
[422]105 call AtaGeometry_GetLCHStoAXBLBHfromAtaInfoInESSIandTranslateModeInDX
[421]106
107.StoreLCHStoDPT:
[422]108 eSHL_IM dl, TRANSLATEMODE_FIELD_POSITION
[421]109 or cl, dl
110 or [di+DPT.bFlagsLow], cl ; Shift count and addressing mode
111 mov [di+DPT.wLchsCylinders], ax
112 mov [di+DPT.wLchsHeadsAndSectors], bx
113
114 ; Store P-CHS to DPT
115 call AtaGeometry_GetPCHStoAXBLBHfromAtaInfoInESSI
116 mov [di+DPT.bPchsHeads], bl
117%ifdef MODULE_EBIOS
118 mov [di+DPT.wPchsCylinders], ax
119 mov [di+DPT.bPchsSectorsPerTrack], bh
120 ; Fall to .StoreNumberOfLbaSectors
121
122;--------------------------------------------------------------------
123; .StoreNumberOfLbaSectors
124; Parameters:
125; DS:DI: Ptr to Disk Parameter Table
126; ES:SI: Ptr to 512-byte ATA information read from the drive
127; CS:BP: Ptr to IDEVARS for the controller
128; Returns:
129; Nothing
130; Corrupts registers:
131; AX, BX, CX, DX
132;--------------------------------------------------------------------
[173]133 ; Check if LBA supported
134 test BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
[421]135 jz SHORT .NoLbaSupportedSoNoEBIOS
[3]136
[421]137 ; Store LBA 28/48 total sector count
138 call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI
139 call StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
[324]140
[421]141 ; Load user defined LBA
[422]142 call GetUserDefinedCapacityToBXAXandFlagsToCXandModeToDXfromROMVARS
143 test cl, FLG_DRVPARAMS_USERLBA
[324]144 jz SHORT .KeepTotalSectorsFromAtaID
145
146 ; Compare user defined and ATA-ID sector count and select smaller
[445]147 mov dx, bx
148 xor bx, bx ; User defined LBA now in BX:DX:AX
[324]149 cmp bx, [di+DPT.twLbaSectors+4]
150 jb SHORT .StoreUserDefinedSectorCountToDPT
151 cmp dx, [di+DPT.twLbaSectors+2]
152 jb SHORT .StoreUserDefinedSectorCountToDPT
153 ja SHORT .KeepTotalSectorsFromAtaID
154 cmp ax, [di+DPT.twLbaSectors]
155 jae SHORT .KeepTotalSectorsFromAtaID
156.StoreUserDefinedSectorCountToDPT:
[422]157 ; CL bit FLGL_DPT_LBA48 is clear at this point
[421]158 call StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
[324]159
160.KeepTotalSectorsFromAtaID:
[421]161.NoLbaSupportedSoNoEBIOS:
162%endif ; MODULE_EBIOS
[99]163 ; Fall to .StoreBlockMode
[3]164
165;--------------------------------------------------------------------
[99]166; .StoreBlockMode
[3]167; Parameters:
168; DS:DI: Ptr to Disk Parameter Table
169; ES:SI: Ptr to 512-byte ATA information read from the drive
[160]170; CS:BP: Ptr to IDEVARS for the controller
[3]171; Returns:
[99]172; Nothing
[3]173; Corrupts registers:
[150]174; Nothing
[3]175;--------------------------------------------------------------------
[99]176.StoreBlockMode:
[150]177 cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
178 jbe SHORT .BlockModeTransfersNotSupported
[158]179 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
[150]180.BlockModeTransfersNotSupported:
181 ; Fall to .StoreDeviceSpecificParameters
[3]182
183;--------------------------------------------------------------------
[150]184; .StoreDeviceSpecificParameters
[3]185; Parameters:
186; DS:DI: Ptr to Disk Parameter Table
187; ES:SI: Ptr to 512-byte ATA information read from the drive
[160]188; CS:BP: Ptr to IDEVARS for the controller
[3]189; Returns:
[99]190; Nothing
[3]191; Corrupts registers:
[150]192; AX, BX, CX, DX
[3]193;--------------------------------------------------------------------
[150]194.StoreDeviceSpecificParameters:
195 call Device_FinalizeDPT
[258]196
[262]197;----------------------------------------------------------------------
198; Update drive counts (hard and floppy)
[294]199;----------------------------------------------------------------------
200
[258]201%ifdef MODULE_SERIAL_FLOPPY
202;
203; These two instructions serve two purposes:
204; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter.
[294]205; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is
[258]206; effectively discarded. This is more of a safety check then code that should ever normally be hit (see below).
[294]207; Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT,
[258]208; this was necessary. Now, this situation shouldn't happen in normal operation, for a couple of reasons:
[294]209; A. xtidecfg always puts configured serial ports at the end of the IDEVARS list
[258]210; B. the auto serial code is always executed last
211; C. the serial server always returns floppy drives last
212;
213 adc byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0
[294]214 jnz .AllDone
[258]215%else
216;
217; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which
[294]218; could lead to unpredictable results since no MBR will be present, etc. The server doesn't know that
[258]219; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan.
220;
221 jc .AllDone
222%endif
223
[150]224 inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
[294]225
226.AllDone:
[162]227 clc
[3]228 ret
[258]229
[324]230
[422]231;--------------------------------------------------------------------
232; GetUserDefinedCapacityToBXAXandFlagsToCXandModeToDXfromROMVARS
233; Parameters:
234; DS:DI: Ptr to Disk Parameter Table
235; Returns:
236; AX: User defined P-CHS Cylinders or LBA low word
237; BX: User defined P-CHS Heads and Sectors or LBA high word
238; DX: Translate mode or TRANSLATEMODE_AUTO
239; CX: FLG_DRVPARAMS_USERCHS if user defined CHS in BX:AX
240; FLG_DRVPARAMS_USERLBA if user defined LBA in BX:AX
241; Zero if user has not defined capacity
242; Corrupts registers:
243; Nothing
244;--------------------------------------------------------------------
245GetUserDefinedCapacityToBXAXandFlagsToCXandModeToDXfromROMVARS:
246 call AccessDPT_GetPointerToDRVPARAMStoCSBX
247
248 ; Get settings
249 mov cx, [cs:bx+DRVPARAMS.wFlags]
250 mov dx, cx
251 and cx, BYTE FLG_DRVPARAMS_USERCHS | FLG_DRVPARAMS_USERLBA
252 and dx, BYTE MASK_DRVPARAMS_TRANSLATEMODE
253 eSHR_IM dx, TRANSLATEMODE_FIELD_POSITION
254
255 ; Get capacity
256 mov ax, [cs:bx+DRVPARAMS.wCylinders] ; Or .dwMaximumLBA
257 mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors] ; Or .dwMaximumLBA+2
258 ret
259
260
[421]261%ifdef MODULE_EBIOS
[324]262;--------------------------------------------------------------------
[421]263; StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
[324]264; Parameters:
265; BX:DX:AX: Total Sector Count
[421]266; CL: FLGL_DPT_LBA48 if LBA48 supported
[324]267; DS:DI: Ptr to Disk Parameter Table
268; Returns:
269; Nothing
270; Corrupts registers:
[421]271; CL
[324]272;--------------------------------------------------------------------
[421]273StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX:
274 or cl, FLGL_DPT_LBA_AND_EBIOS_SUPPORTED
275 and BYTE [di+DPT.bFlagsLow], ~FLGL_DPT_LBA48
276 or [di+DPT.bFlagsLow], cl
[324]277 mov [di+DPT.twLbaSectors], ax
278 mov [di+DPT.twLbaSectors+2], dx
279 mov [di+DPT.twLbaSectors+4], bx
280 ret
[421]281%endif ; MODULE_EBIOS
Note: See TracBrowser for help on using the repository browser.