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

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

Changes to XTIDE Universal BIOS:

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