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

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

Changes to XTIDE Universal BIOS:

  • EBIOS functions now work in lite mode.
File size: 8.0 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
[158]62 or al, FLGL_DPT_ENABLE_IRQ
[150]63.StoreFlags:
64 mov [di+DPT.wFlags], ax
[175]65
66%ifdef MODULE_SERIAL
67 cmp byte [cs:bp+IDEVARS.bDevice], DEVICE_SERIAL_PORT
[181]68 jnz .StoreAddressing
[175]69 or byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
[181]70%endif
[173]71 ; Fall to .StoreAddressing
[3]72
73;--------------------------------------------------------------------
[173]74; .StoreAddressing
[3]75; Parameters:
76; DS:DI: Ptr to Disk Parameter Table
77; ES:SI: Ptr to 512-byte ATA information read from the drive
78; CS:BP: Ptr to IDEVARS for the controller
79; Returns:
[227]80; Nothing
[3]81; Corrupts registers:
[227]82; AX, BX, CX, DX
[3]83;--------------------------------------------------------------------
[173]84.StoreAddressing:
85 ; Check if CHS defined in ROMVARS
[193]86 call AccessDPT_GetPointerToDRVPARAMStoCSBX
87 test byte [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERCHS ; User specified CHS?
[227]88 jnz SHORT .StoreUserDefinedPCHS
[173]89
90 ; Check if LBA supported
[169]91 call AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI
[173]92 test BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
[227]93 jz SHORT .StoreCHSfromAXBHBL ; Small old drive with CHS addressing only
[3]94
[173]95 ; Check if 48-bit LBA supported
96 test BYTE [es:si+ATA6.wSetSup83+1], A6_wSetSup83_LBA48>>8
97 jz SHORT .StoreLBA28addressing
98 or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA48<<ADDRESSING_MODE_FIELD_POSITION
99.StoreLBA28addressing:
100 or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
101 call AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI
[227]102 mov [di+DPT.twLbaSectors], ax
103 mov [di+DPT.twLbaSectors+2], dx
104 mov [di+DPT.twLbaSectors+4], bx
[173]105 call AtaID_GetLbaAssistedCHStoDXAXBLBH
[227]106 mov [di+DPT.bLbaHeads], bl
107 jmp SHORT .StoreBlockMode
[173]108
[227]109;--------------------------------------------------------------------
110; .StoreUserDefinedPCHS
111; Parameters:
112; DS:DI: Ptr to Disk Parameter Table
113; ES:SI: Ptr to 512-byte ATA information read from the drive
114; CS:BP: Ptr to IDEVARS for the controller
115; Returns:
116; AX: Number of P-CHS cylinders
117; BH: Number of P-CHS sectors per track
118; BL: Number of P-CHS heads
119; Corrupts registers:
120; Nothing
121;--------------------------------------------------------------------
122.StoreUserDefinedPCHS:
[3]123 call AccessDPT_GetPointerToDRVPARAMStoCSBX
124 mov ax, [cs:bx+DRVPARAMS.wCylinders]
[99]125 mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
[227]126 ; Fall to .StoreCHSfromAXBHBL
[3]127
[227]128;--------------------------------------------------------------------
129; .StoreCHSfromAXBHBL
130; Parameters:
131; AX: Number of P-CHS cylinders
132; BH: Number of P-CHS sectors per track
133; BL: Number of P-CHS heads
134; DS:DI: Ptr to Disk Parameter Table
135; ES:SI: Ptr to 512-byte ATA information read from the drive
136; CS:BP: Ptr to IDEVARS for the controller
137; Returns:
138; AX: Number of P-CHS cylinders
139; BH: Number of P-CHS sectors per track
140; BL: Number of P-CHS heads
141; Corrupts registers:
142; CX
143;--------------------------------------------------------------------
144.StoreCHSfromAXBHBL:
[173]145 push ax
[227]146 push bx
147 call AccessDPT_ShiftPCHinAXBLtoLCH ; Get number of bits to shift
148 pop bx
[173]149 pop ax
[227]150 jcxz .StorePCHSfromAXDX ; Small drive so use L-CHS addressing
[3]151
[227]152 ; Store P-CHS addressing mode and number of bits to shift in L-CHS to P-CHS translation
153 or cl, ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
154 or [di+DPT.bFlagsLow], cl
155 ; Fall to .StoreChsFromAXBLBH
156
[3]157;--------------------------------------------------------------------
[227]158; .StoreChsFromAXBLBH
[3]159; Parameters:
[227]160; AX: Number of P-CHS cylinders
161; BH: Number of P-CHS sectors per track
162; BL: Number of P-CHS heads
[3]163; DS:DI: Ptr to Disk Parameter Table
164; ES:SI: Ptr to 512-byte ATA information read from the drive
[160]165; CS:BP: Ptr to IDEVARS for the controller
[3]166; Returns:
[99]167; Nothing
[3]168; Corrupts registers:
[227]169; Nothing
[3]170;--------------------------------------------------------------------
[227]171.StorePCHSfromAXDX:
172 mov [di+DPT.wPchsCylinders], ax
173 mov [di+DPT.wPchsHeadsAndSectors], bx
[99]174 ; Fall to .StoreBlockMode
[3]175
176;--------------------------------------------------------------------
[99]177; .StoreBlockMode
[3]178; Parameters:
179; DS:DI: Ptr to Disk Parameter Table
180; ES:SI: Ptr to 512-byte ATA information read from the drive
[160]181; CS:BP: Ptr to IDEVARS for the controller
[3]182; Returns:
[99]183; Nothing
[3]184; Corrupts registers:
[150]185; Nothing
[3]186;--------------------------------------------------------------------
[99]187.StoreBlockMode:
[150]188 cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
189 jbe SHORT .BlockModeTransfersNotSupported
[158]190 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
[150]191.BlockModeTransfersNotSupported:
192 ; Fall to .StoreDeviceSpecificParameters
[3]193
194;--------------------------------------------------------------------
[150]195; .StoreDeviceSpecificParameters
[3]196; Parameters:
197; DS:DI: Ptr to Disk Parameter Table
198; ES:SI: Ptr to 512-byte ATA information read from the drive
[160]199; CS:BP: Ptr to IDEVARS for the controller
[3]200; Returns:
[99]201; Nothing
[3]202; Corrupts registers:
[150]203; AX, BX, CX, DX
[3]204;--------------------------------------------------------------------
[150]205.StoreDeviceSpecificParameters:
206 call Device_FinalizeDPT
[99]207 ; Fall to .StoreDriveNumberAndUpdateDriveCount
[3]208
209;--------------------------------------------------------------------
[99]210; .StoreDriveNumberAndUpdateDriveCount
[3]211; Parameters:
212; DS:DI: Ptr to Disk Parameter Table
213; ES:SI: Ptr to 512-byte ATA information read from the drive
[160]214; CS:BP: Ptr to IDEVARS for the controller
[3]215; ES: BDA Segment
216; Returns:
217; DL: Drive number for new drive
[162]218; CF: Always cleared
[3]219; Corrupts registers:
220; Nothing
221;--------------------------------------------------------------------
[99]222.StoreDriveNumberAndUpdateDriveCount:
[150]223 mov dl, [es:BDA.bHDCount]
224 or dl, 80h ; Set bit 7 since hard disk
[3]225
[150]226 inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
227 inc BYTE [es:BDA.bHDCount] ; Increment drive count to BDA
[3]228
[150]229 cmp BYTE [RAMVARS.bFirstDrv], 0 ; First drive set?
230 ja SHORT .AllDone ; If so, return
231 mov [RAMVARS.bFirstDrv], dl ; Store first drive number
[162]232 clc
[150]233.AllDone:
[3]234 ret
Note: See TracBrowser for help on using the repository browser.