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

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

Changes to XTIDE Universal BIOS:

  • Addressing modes are now NORMAL, LARGE and LBA.
  • L-CHS parameters are now generated differently for drives with 8192 or less cylinders.
File size: 9.2 KB
RevLine 
[99]1; Project name : XTIDE Universal BIOS
[3]2; Description : Functions for creating Disk Parameter Table.
3
[376]4;
5; XTIDE Universal BIOS and Associated Tools
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.
12;
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
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
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:
[150]57 mov [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM
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
[193]97 call AccessDPT_GetPointerToDRVPARAMStoCSBX
[421]98 test byte [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERCHS ; User specified P-CHS?
99 jz SHORT .AutodetectPCHSvalues
[173]100
[421]101 ; Use DRVPARAMS P-CHS values instead of autodetected
102 mov ax, [cs:bx+DRVPARAMS.wCylinders]
103 mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
104 call AtaGeometry_GetLCHStoAXBLBHfromPCHSinAXBLBH
105 jmp SHORT .StoreLCHStoDPT
106
107 ; Get L-CHS parameters and addressing mode
108.AutodetectPCHSvalues:
109 call AtaGeometry_GetLCHStoAXBLBHfromAtaInfoInESSI
110
111.StoreLCHStoDPT:
112 eSHL_IM dl, ADDRESSING_MODE_FIELD_POSITION
113 or cl, dl
114 or [di+DPT.bFlagsLow], cl ; Shift count and addressing mode
115 mov [di+DPT.wLchsCylinders], ax
116 mov [di+DPT.wLchsHeadsAndSectors], bx
117
118 ; Store P-CHS to DPT
119 call AtaGeometry_GetPCHStoAXBLBHfromAtaInfoInESSI
120 mov [di+DPT.bPchsHeads], bl
121%ifdef MODULE_EBIOS
122 mov [di+DPT.wPchsCylinders], ax
123 mov [di+DPT.bPchsSectorsPerTrack], bh
124 ; Fall to .StoreNumberOfLbaSectors
125
126;--------------------------------------------------------------------
127; .StoreNumberOfLbaSectors
128; Parameters:
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; AX, BX, CX, DX
136;--------------------------------------------------------------------
[173]137 ; Check if LBA supported
138 test BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
[421]139 jz SHORT .NoLbaSupportedSoNoEBIOS
[3]140
[421]141 ; Store LBA 28/48 total sector count
142 call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI
143 call StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
[324]144
[421]145 ; Load user defined LBA
[324]146 call AccessDPT_GetPointerToDRVPARAMStoCSBX
147 test BYTE [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERLBA
148 jz SHORT .KeepTotalSectorsFromAtaID
149 mov ax, [cs:bx+DRVPARAMS.dwMaximumLBA]
150 mov dx, [cs:bx+DRVPARAMS.dwMaximumLBA+2]
151 xor bx, bx
152
153 ; Compare user defined and ATA-ID sector count and select smaller
154 cmp bx, [di+DPT.twLbaSectors+4]
155 jb SHORT .StoreUserDefinedSectorCountToDPT
156 cmp dx, [di+DPT.twLbaSectors+2]
157 jb SHORT .StoreUserDefinedSectorCountToDPT
158 ja SHORT .KeepTotalSectorsFromAtaID
159 cmp ax, [di+DPT.twLbaSectors]
160 jae SHORT .KeepTotalSectorsFromAtaID
161.StoreUserDefinedSectorCountToDPT:
[421]162 xor cx, cx ; Always LBA28 for user defined values
163 call StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
[324]164
165.KeepTotalSectorsFromAtaID:
[421]166.NoLbaSupportedSoNoEBIOS:
167%endif ; MODULE_EBIOS
[99]168 ; Fall to .StoreBlockMode
[3]169
170;--------------------------------------------------------------------
[99]171; .StoreBlockMode
[3]172; Parameters:
173; DS:DI: Ptr to Disk Parameter Table
174; ES:SI: Ptr to 512-byte ATA information read from the drive
[160]175; CS:BP: Ptr to IDEVARS for the controller
[3]176; Returns:
[99]177; Nothing
[3]178; Corrupts registers:
[150]179; Nothing
[3]180;--------------------------------------------------------------------
[99]181.StoreBlockMode:
[150]182 cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
183 jbe SHORT .BlockModeTransfersNotSupported
[158]184 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
[150]185.BlockModeTransfersNotSupported:
186 ; Fall to .StoreDeviceSpecificParameters
[3]187
188;--------------------------------------------------------------------
[150]189; .StoreDeviceSpecificParameters
[3]190; Parameters:
191; DS:DI: Ptr to Disk Parameter Table
192; ES:SI: Ptr to 512-byte ATA information read from the drive
[160]193; CS:BP: Ptr to IDEVARS for the controller
[3]194; Returns:
[99]195; Nothing
[3]196; Corrupts registers:
[150]197; AX, BX, CX, DX
[3]198;--------------------------------------------------------------------
[150]199.StoreDeviceSpecificParameters:
200 call Device_FinalizeDPT
[258]201
[262]202;----------------------------------------------------------------------
203; Update drive counts (hard and floppy)
[294]204;----------------------------------------------------------------------
205
[258]206%ifdef MODULE_SERIAL_FLOPPY
207;
208; These two instructions serve two purposes:
209; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter.
[294]210; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is
[258]211; effectively discarded. This is more of a safety check then code that should ever normally be hit (see below).
[294]212; Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT,
[258]213; this was necessary. Now, this situation shouldn't happen in normal operation, for a couple of reasons:
[294]214; A. xtidecfg always puts configured serial ports at the end of the IDEVARS list
[258]215; B. the auto serial code is always executed last
216; C. the serial server always returns floppy drives last
217;
218 adc byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0
[294]219 jnz .AllDone
[258]220%else
221;
222; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which
[294]223; could lead to unpredictable results since no MBR will be present, etc. The server doesn't know that
[258]224; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan.
225;
226 jc .AllDone
227%endif
228
[150]229 inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
[294]230
231.AllDone:
[162]232 clc
[3]233 ret
[258]234
[324]235
[421]236%ifdef MODULE_EBIOS
[324]237;--------------------------------------------------------------------
[421]238; StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
[324]239; Parameters:
240; BX:DX:AX: Total Sector Count
[421]241; CL: FLGL_DPT_LBA48 if LBA48 supported
[324]242; DS:DI: Ptr to Disk Parameter Table
243; Returns:
244; Nothing
245; Corrupts registers:
[421]246; CL
[324]247;--------------------------------------------------------------------
[421]248StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX:
249 or cl, FLGL_DPT_LBA_AND_EBIOS_SUPPORTED
250 and BYTE [di+DPT.bFlagsLow], ~FLGL_DPT_LBA48
251 or [di+DPT.bFlagsLow], cl
[324]252 mov [di+DPT.twLbaSectors], ax
253 mov [di+DPT.twLbaSectors+2], dx
254 mov [di+DPT.twLbaSectors+4], bx
255 ret
[421]256%endif ; MODULE_EBIOS
Note: See TracBrowser for help on using the repository browser.