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

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

ifdef of existing serial code, in preperation for checkin

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