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

Last change on this file since 154 was 150, checked in by Tomi Tilli, 13 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
RevLine 
[99]1; Project name : XTIDE Universal BIOS
[3]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:
[99]24; AX, BX, CX, DH
[3]25;--------------------------------------------------------------------
26CreateDPT_FromAtaInformation:
[150]27 call FindDPT_ForNewDriveToDSDI
[99]28 ; Fall to .InitializeDPT
[3]29
30;--------------------------------------------------------------------
[99]31; .InitializeDPT
[3]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:
[150]37; Nothing
[3]38; Corrupts registers:
[150]39; AX
[3]40;--------------------------------------------------------------------
[99]41.InitializeDPT:
[150]42 mov [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM
43 ; Fall to .StoreDriveSelectAndDriveControlByte
[3]44
45;--------------------------------------------------------------------
[150]46; .StoreDriveSelectAndDriveControlByte
[3]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:
[99]53; Nothing
[3]54; Corrupts registers:
55; AX
56;--------------------------------------------------------------------
[150]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
[99]65 ; Fall to .StorePCHS
[3]66
67;--------------------------------------------------------------------
[99]68; .StorePCHS
[3]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:
[99]75; AX: P-CHS cylinders
76; BL: P-CHS heads
77; BH: P-CHS sectors
[3]78; Corrupts registers:
79; Nothing
80;--------------------------------------------------------------------
[99]81.StorePCHS:
82 mov al, FLG_DRVPARAMS_USERCHS ; User specified CHS?
[3]83 call AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
[99]84 jnz SHORT .GetUserSpecifiedPCHS
85 call AtaID_GetPCHS ; Get from ATA information
86 jmp SHORT .StorePCHStoDPT
[3]87
[99]88.GetUserSpecifiedPCHS:
[3]89 call AccessDPT_GetPointerToDRVPARAMStoCSBX
90 mov ax, [cs:bx+DRVPARAMS.wCylinders]
[99]91 mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
[3]92
[99]93.StorePCHStoDPT:
[150]94 mov [di+DPT.wPchsCylinders], ax
95 mov [di+DPT.wPchsHeadsAndSectors], bx
[99]96 ; Fall to .StoreLCHS
[3]97
98;--------------------------------------------------------------------
[99]99; .StoreLCHS
[3]100; Parameters:
[99]101; AX: P-CHS cylinders
102; BL: P-CHS heads
[3]103; DS:DI: Ptr to Disk Parameter Table
104; ES:SI: Ptr to 512-byte ATA information read from the drive
105; Returns:
[99]106; Nothing
[3]107; Corrupts registers:
[99]108; AX, BX, CX
[3]109;--------------------------------------------------------------------
[99]110.StoreLCHS:
111 xor bh, bh ; BX = P-CHS Heads (1...16)
112 xor cx, cx
[3]113.ShiftLoop:
[99]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
[3]119 jmp SHORT .ShiftLoop
120
[150]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
[99]126 ; Fall to .StoreAddressing
[3]127
128;--------------------------------------------------------------------
[99]129; .StoreAddressing
[3]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:
[99]134; Nothing
[3]135; Corrupts registers:
[150]136; AX, BX
[3]137;--------------------------------------------------------------------
[99]138.StoreAddressing:
[150]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
[3]147 test WORD [es:si+ATA1.wCaps], A2_wCaps_LBA
[150]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
[3]151 test WORD [es:si+ATA6.wSetSup83], A6_wSetSup83_LBA48
[150]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
[99]154.StoreLBA28addressing:
[150]155 or BYTE [di+DPT.wFlags], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
[99]156 jmp SHORT .StoreBlockMode
157.StorePCHSaddressing:
[150]158 or BYTE [di+DPT.wFlags], ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
[99]159 ; Fall to .StoreBlockMode
[3]160
161;--------------------------------------------------------------------
[99]162; .StoreBlockMode
[3]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:
[99]167; Nothing
[3]168; Corrupts registers:
[150]169; Nothing
[3]170;--------------------------------------------------------------------
[99]171.StoreBlockMode:
[150]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
[3]177
178;--------------------------------------------------------------------
[150]179; .StoreDeviceSpecificParameters
[3]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:
[99]184; Nothing
[3]185; Corrupts registers:
[150]186; AX, BX, CX, DX
[3]187;--------------------------------------------------------------------
[150]188.StoreDeviceSpecificParameters:
189 call Device_FinalizeDPT
[99]190 ; Fall to .StoreDriveNumberAndUpdateDriveCount
[3]191
192;--------------------------------------------------------------------
[99]193; .StoreDriveNumberAndUpdateDriveCount
[3]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;--------------------------------------------------------------------
[99]205.StoreDriveNumberAndUpdateDriveCount:
[150]206 mov dl, [es:BDA.bHDCount]
207 or dl, 80h ; Set bit 7 since hard disk
[3]208
[150]209 inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
210 inc BYTE [es:BDA.bHDCount] ; Increment drive count to BDA
[3]211
[150]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:
[3]216 clc
217 ret
Note: See TracBrowser for help on using the repository browser.