Ignore:
Timestamp:
Jan 31, 2011, 11:27:17 AM (13 years ago)
Author:
aitotat
google:author:
aitotat
Message:

Changes to XTIDE Universal BIOS:

  • Even more initialization code inlining.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm

    r3 r99  
    1 ; File name     :   CreateDPT.asm
    2 ; Project name  :   IDE BIOS
    3 ; Created date  :   12.3.2010
    4 ; Last update   :   26.4.2010
    5 ; Author        :   Tomi Tilli
     1; Project name  :   XTIDE Universal BIOS
    62; Description   :   Functions for creating Disk Parameter Table.
    73
     
    2622;               Set if any error
    2723;   Corrupts registers:
    28 ;       AX, CX, BX, DH
    29 ;--------------------------------------------------------------------
    30 ALIGN JUMP_ALIGN
     24;       AX, BX, CX, DH
     25;--------------------------------------------------------------------
    3126CreateDPT_FromAtaInformation:
    3227    call    FindDPT_ForNewDrive     ; Get new DPT to DS:DI
    33     call    CreateDPT_Initialize
    34     call    CreateDPT_StoreDriveControlByte
    35     call    CreateDPT_StorePCHS
    36     call    CreateDPT_StoreLCHS
    37     call    CreateDPT_StoreAddressing
    38     call    CreateDPT_StoreBlockMode
    39     call    CreateDPT_StoreEBIOSSupport
    40     jmp     CreateDPT_StoreDriveNumberAndUpdateDriveCount
    41 
    42 
    43 ;--------------------------------------------------------------------
    44 ; Initializes empty DPT by storing initial values that are not
    45 ; read from ATA information.
    46 ;
    47 ; CreateDPT_Initialize
    48 ;   Parameters:
    49 ;       BH:     Drive Select byte for Drive and Head Register
    50 ;       DS:DI:  Ptr to Disk Parameter Table
    51 ;       CS:BP:  Ptr to IDEVARS for the controller
    52 ;   Returns:
    53 ;       CF:     Cleared if DPT parameters stored successfully
    54 ;               Set if any error
    55 ;   Corrupts registers:
    56 ;       Nothing
    57 ;--------------------------------------------------------------------
    58 ALIGN JUMP_ALIGN
    59 CreateDPT_Initialize:
    60     xor     ax, ax                      ; Clear AX and CF
     28    ; Fall to .InitializeDPT
     29
     30;--------------------------------------------------------------------
     31; .InitializeDPT
     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:
     37;       AX:     Zero
     38;   Corrupts registers:
     39;       Nothing
     40;--------------------------------------------------------------------
     41.InitializeDPT:
     42    xor     ax, ax
    6143    mov     BYTE [di+DPT.bSize], DPT_size
    62     mov     BYTE [di+DPT.bDrvNum], al
    63     mov     BYTE [di+DPT.bFlags], al
     44    mov     [di+DPT.wDrvNumAndFlags], ax
    6445    mov     BYTE [di+DPT.bReset], MASK_RESET_ALL
    65     mov     WORD [di+DPT.bIdeOff], bp
    66     mov     BYTE [di+DPT.bDrvSel], bh
    67     ret
    68 
    69 
    70 ;--------------------------------------------------------------------
    71 ; Stores Drive Control Byte for Device Control Register.
    72 ;
    73 ; CreateDPT_StoreDriveControlByte
    74 ;   Parameters:
    75 ;       BH:     Drive Select byte for Drive and Head Register
    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:
    80 ;       CF:     Cleared if DPT parameters stored successfully
    81 ;               Set if any error
     46    mov     [di+DPT.bIdeOff], bp
     47    mov     [di+DPT.bDrvSel], bh
     48    ; Fall to .StoreDriveControlByte
     49
     50;--------------------------------------------------------------------
     51; .StoreDriveControlByte
     52;   Parameters:
     53;       AX:     Zero
     54;       BH:     Drive Select byte for Drive and Head Register
     55;       DS:DI:  Ptr to Disk Parameter Table
     56;       ES:SI:  Ptr to 512-byte ATA information read from the drive
     57;       CS:BP:  Ptr to IDEVARS for the controller
     58;   Returns:
     59;       Nothing
    8260;   Corrupts registers:
    8361;       AX
    8462;--------------------------------------------------------------------
    85 ALIGN JUMP_ALIGN
    86 CreateDPT_StoreDriveControlByte:
    87     xor     ax, ax                          ; Zero AX
    88     cmp     BYTE [cs:bp+IDEVARS.bIRQ], 0    ; Interrupts enabled?
     63.StoreDriveControlByte:
     64    cmp     BYTE [cs:bp+IDEVARS.bIRQ], al   ; Interrupts enabled?
    8965    jne     SHORT .CheckHeadCount
    9066    or      al, FLG_IDE_CTRL_nIEN           ; Disable interrupts
    91 ALIGN JUMP_ALIGN
    9267.CheckHeadCount:
    9368    cmp     BYTE [es:si+ATA1.wHeadCnt], 8   ; 1...8 heads?
    94     jbe     SHORT .StoreDriveControlByte
     69    jbe     SHORT .StoreDrvCtrlByteToDPT
    9570    or      al, FLG_IDE_CTRL_O8H            ; Over 8 heads (pre-ATA)
    96 ALIGN JUMP_ALIGN
    97 .StoreDriveControlByte:
     71.StoreDrvCtrlByteToDPT:
    9872    mov     [di+DPT.bDrvCtrl], al
    99     clc
    100     ret
    101 
    102 
    103 ;--------------------------------------------------------------------
    104 ; Stores P-CHS values from ATA information or user specified values to DPT.
    105 ;
    106 ; CreateDPT_StorePCHS
    107 ;   Parameters:
    108 ;       BH:     Drive Select byte for Drive and Head Register
    109 ;       DS:DI:  Ptr to Disk Parameter Table
    110 ;       ES:SI:  Ptr to 512-byte ATA information read from the drive
    111 ;       CS:BP:  Ptr to IDEVARS for the controller
    112 ;   Returns:
    113 ;       CF:     Cleared if DPT parameters stored successfully
    114 ;               Set if any error
    115 ;   Corrupts registers:
    116 ;       AX, BX
    117 ;--------------------------------------------------------------------
    118 ALIGN JUMP_ALIGN
    119 CreateDPT_StorePCHS:
    120     call    CreateDPT_GetUserOrAtaPCHS
    121     mov     [di+DPT.wPCyls], ax
    122     mov     [di+DPT.bPHeads], bh
    123     mov     [di+DPT.bPSect], bl
    124     clc
    125     ret
    126 
    127 ;--------------------------------------------------------------------
    128 ; Returns user specified P-CHS or values read from ATA information.
    129 ;
    130 ; CreateDPT_GetUserOrAtaPCHS
    131 ;   Parameters:
    132 ;       BH:     Drive Select byte for Drive and Head Register
    133 ;       DS:DI:  Ptr to Disk Parameter Table
    134 ;       ES:SI:  Ptr to 512-byte ATA information read from the drive
    135 ;       CS:BP:  Ptr to IDEVARS for the controller
    136 ;   Returns:
    137 ;       AX:     Number of P-CHS cylinders
    138 ;       BL:     Number of P-CHS sectors per track
    139 ;       BH:     Number of P-CHS heads
    140 ;   Corrupts registers:
    141 ;       Nothing
    142 ;--------------------------------------------------------------------
    143 ALIGN JUMP_ALIGN
    144 CreateDPT_GetUserOrAtaPCHS:
    145     mov     ax, FLG_DRVPARAMS_USERCHS   ; User specified CHS?
     73    ; Fall to .StorePCHS
     74
     75;--------------------------------------------------------------------
     76; .StorePCHS
     77;   Parameters:
     78;       AH:     Zero
     79;       BH:     Drive Select byte for Drive and Head Register
     80;       DS:DI:  Ptr to Disk Parameter Table
     81;       ES:SI:  Ptr to 512-byte ATA information read from the drive
     82;       CS:BP:  Ptr to IDEVARS for the controller
     83;   Returns:
     84;       AX:     P-CHS cylinders
     85;       BL:     P-CHS heads
     86;       BH:     P-CHS sectors
     87;   Corrupts registers:
     88;       Nothing
     89;--------------------------------------------------------------------
     90.StorePCHS:
     91    mov     al, FLG_DRVPARAMS_USERCHS   ; User specified CHS?
    14692    call    AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
    147     jnz     SHORT CreateDPT_GetUserSpecifiedPCHS
    148     jmp     AtaID_GetPCHS
    149 
    150 ;--------------------------------------------------------------------
    151 ; Returns user specified P-CHS values from ROMVARS.
    152 ;
    153 ; CreateDPT_GetUserSpecifiedPCHS
    154 ;   Parameters:
    155 ;       DS:DI:  Ptr to Disk Parameter Table
    156 ;       CS:BP:  Ptr to IDEVARS for the controller
    157 ;   Returns:
    158 ;       AX:     Number of user specified P-CHS cylinders
    159 ;       BL:     Number of user specified P-CHS sectors per track
    160 ;       BH:     Number of user specified P-CHS heads
    161 ;   Corrupts registers:
    162 ;       Nothing
    163 ;--------------------------------------------------------------------
    164 ALIGN JUMP_ALIGN
    165 CreateDPT_GetUserSpecifiedPCHS:
     93    jnz     SHORT .GetUserSpecifiedPCHS
     94    call    AtaID_GetPCHS               ; Get from ATA information
     95    jmp     SHORT .StorePCHStoDPT
     96
     97.GetUserSpecifiedPCHS:
    16698    call    AccessDPT_GetPointerToDRVPARAMStoCSBX
    16799    mov     ax, [cs:bx+DRVPARAMS.wCylinders]
    168     mov     bx, [cs:bx+DRVPARAMS.wSectAndHeads]
     100    mov     bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
    169101    or      BYTE [di+DPT.bFlags], FLG_DPT_USERCHS
    170     ret
    171 
    172 
    173 ;--------------------------------------------------------------------
    174 ; Stores L-CHS values by converting from P-CHS values if necessary.
    175 ;
    176 ; CreateDPT_StoreLCHS
    177 ;   Parameters:
    178 ;       DS:DI:  Ptr to Disk Parameter Table
    179 ;       ES:SI:  Ptr to 512-byte ATA information read from the drive
    180 ;   Returns:
    181 ;       CF:     Cleared if DPT parameters stored successfully
    182 ;               Set if any error
    183 ;   Corrupts registers:
    184 ;       AX, CX, DX
    185 ;--------------------------------------------------------------------
    186 ALIGN JUMP_ALIGN
    187 CreateDPT_StoreLCHS:
    188     mov     cx, [di+DPT.wPCyls]         ; P-CHS Cylinders (1...16383)
    189     eMOVZX  dx, BYTE [di+DPT.bPHeads]   ; P-CHS Heads (1...16)
    190     call    CreateDPT_ShiftPCHtoLCH
    191     test    dh, dh                      ; 256 heads?
    192     jz      SHORT .StoreToDPT           ;  If less, no correction needed
    193     dec     dx                          ; Limit to 255 heads since DOS does not support 256 heads
    194 ALIGN JUMP_ALIGN
    195 .StoreToDPT:
    196     mov     [di+DPT.bShLtoP], al
    197     mov     [di+DPT.wLHeads], dx
    198     clc
    199     ret
    200 
    201 ;--------------------------------------------------------------------
    202 ; Returns L-CHS values from P-CHS values.
    203 ; Sectors per track is always the same for both addressing modes.
    204 ;
    205 ; CreateDPT_ShiftPCHtoLCH:
    206 ;   Parameters:
    207 ;       CX:     Number of P-CHS cylinders (1...16383)
    208 ;       DX:     Number of P-CHS heads (1...16)
    209 ;   Returns:
    210 ;       AL:     Number of bits shifted
    211 ;       CX:     Number of L-CHS cylinders (1...1024)
    212 ;       DX:     Number of L-CHS heads (1...256)
    213 ;   Corrupts registers:
    214 ;       Nothing
    215 ;--------------------------------------------------------------------
    216 ALIGN JUMP_ALIGN
    217 CreateDPT_ShiftPCHtoLCH:
    218     xor     al, al              ; Zero AL
    219 ALIGN JUMP_ALIGN
     102
     103.StorePCHStoDPT:
     104    mov     [di+DPT.wPCyls], ax
     105    mov     [di+DPT.wHeadsAndSectors], bx
     106    ; Fall to .StoreLCHS
     107
     108;--------------------------------------------------------------------
     109; .StoreLCHS
     110;   Parameters:
     111;       AX:     P-CHS cylinders
     112;       BL:     P-CHS heads
     113;       DS:DI:  Ptr to Disk Parameter Table
     114;       ES:SI:  Ptr to 512-byte ATA information read from the drive
     115;   Returns:
     116;       Nothing
     117;   Corrupts registers:
     118;       AX, BX, CX
     119;--------------------------------------------------------------------
     120.StoreLCHS:
     121    xor     bh, bh                      ; BX = P-CHS Heads (1...16)
     122    xor     cx, cx
    220123.ShiftLoop:
    221     cmp     cx, 1024            ; Need to shift?
    222     jbe     SHORT .Return       ;  If not, return
    223     inc     ax                  ; Increment shift count
    224     shr     cx, 1               ; Halve cylinders
    225     shl     dx, 1               ; Double heads
     124    cmp     ax, 1024                    ; Need to shift?
     125    jbe     SHORT .LimitHeadsTo255      ;  If not, return
     126    inc     cx                          ; Increment shift count
     127    shr     ax, 1                       ; Halve cylinders
     128    shl     bx, 1                       ; Double heads
    226129    jmp     SHORT .ShiftLoop
    227 ALIGN JUMP_ALIGN
    228 .Return:
    229     ret
    230 
    231 
    232 ;--------------------------------------------------------------------
    233 ; Stores addressing information (L-CHS, P-CHS, LBA28 or LBA48).
    234 ;
    235 ; CreateDPT_StoreAddressing
    236 ;   Parameters:
    237 ;       DS:DI:  Ptr to Disk Parameter Table
    238 ;       ES:SI:  Ptr to 512-byte ATA information read from the drive
    239 ;   Returns:
    240 ;       CF:     Cleared if DPT parameters stored successfully
    241 ;               Set if any error
    242 ;   Corrupts registers:
    243 ;       Nothing
    244 ;--------------------------------------------------------------------
    245 ALIGN JUMP_ALIGN
    246 CreateDPT_StoreAddressing:
     130
     131.LimitHeadsTo255:
     132    test    bh, bh                      ; 256 heads?
     133    jz      SHORT .StoreLCHStoDPT       ;  If less, no correction needed
     134    dec     bx                          ; Limit to 255 heads since DOS does not support 256 heads
     135.StoreLCHStoDPT:
     136    mov     [di+DPT.bShLtoP], cl
     137    mov     [di+DPT.wLHeads], bx
     138    ; Fall to .StoreAddressing
     139
     140;--------------------------------------------------------------------
     141; .StoreAddressing
     142;   Parameters:
     143;       DS:DI:  Ptr to Disk Parameter Table
     144;       ES:SI:  Ptr to 512-byte ATA information read from the drive
     145;   Returns:
     146;       Nothing
     147;   Corrupts registers:
     148;       Nothing
     149;--------------------------------------------------------------------
     150.StoreAddressing:
    247151    cmp     WORD [di+DPT.wPCyls], 1024      ; L-CHS possible? (no translation needed)
    248     jbe     SHORT .Return                   ;  If so, nothing needs to be changed
     152    jbe     SHORT .StoreBlockMode           ;  If so, nothing needs to be changed
    249153    test    BYTE [di+DPT.bFlags], FLG_DPT_USERCHS
    250     jnz     SHORT .StorePCHS                ; Use user defined P-CHS
     154    jnz     SHORT .StorePCHSaddressing      ; Use user defined P-CHS
    251155    test    WORD [es:si+ATA1.wCaps], A2_wCaps_LBA
    252     jz      SHORT .StorePCHS                ; Use P-CHS since LBA not supported
     156    jz      SHORT .StorePCHSaddressing      ; Use P-CHS since LBA not supported
    253157    test    WORD [es:si+ATA6.wSetSup83], A6_wSetSup83_LBA48
    254     jz      SHORT .StoreLBA28               ; Use LBA-28 since LBA-48 not supported
     158    jz      SHORT .StoreLBA28addressing     ; Use LBA-28 since LBA-48 not supported
    255159    or      BYTE [di+DPT.bFlags], ADDR_DPT_LBA48<<1
    256 ALIGN JUMP_ALIGN
    257 .StoreLBA28:
     160.StoreLBA28addressing:
    258161    or      BYTE [di+DPT.bFlags], ADDR_DPT_LBA28<<1
    259162    or      BYTE [di+DPT.bDrvSel], FLG_IDE_DRVHD_LBA
    260     ret
    261 ALIGN JUMP_ALIGN
    262 .StorePCHS:
     163    jmp     SHORT .StoreBlockMode
     164.StorePCHSaddressing:
    263165    or      BYTE [di+DPT.bFlags], ADDR_DPT_PCHS<<1
    264 ALIGN JUMP_ALIGN
    265 .Return:
    266     clc
    267     ret
    268 
    269 
    270 ;--------------------------------------------------------------------
    271 ; Stores Block Mode information.
    272 ;
    273 ; CreateDPT_StoreBlockMode
    274 ;   Parameters:
    275 ;       DS:DI:  Ptr to Disk Parameter Table
    276 ;       ES:SI:  Ptr to 512-byte ATA information read from the drive
    277 ;   Returns:
    278 ;       CF:     Cleared if DPT parameters stored successfully
    279 ;               Set if any error
    280 ;   Corrupts registers:
    281 ;       Nothing
    282 ;--------------------------------------------------------------------
    283 ALIGN JUMP_ALIGN
    284 CreateDPT_StoreBlockMode:
     166    ; Fall to .StoreBlockMode
     167
     168;--------------------------------------------------------------------
     169; .StoreBlockMode
     170;   Parameters:
     171;       DS:DI:  Ptr to Disk Parameter Table
     172;       ES:SI:  Ptr to 512-byte ATA information read from the drive
     173;   Returns:
     174;       Nothing
     175;   Corrupts registers:
     176;       AX
     177;--------------------------------------------------------------------
     178.StoreBlockMode:
    285179    mov     al, 1                       ; Minimum block size is 1 sector
    286180    mov     ah, [es:si+ATA1.bBlckSize]  ; Load max block size in sectors
    287181    mov     [di+DPT.wSetAndMaxBlock], ax
    288     ret
    289 
    290 
    291 ;--------------------------------------------------------------------
    292 ; Stores variables required by EBIOS functions.
    293 ;
    294 ; CreateDPT_StoreEBIOSSupport
    295 ;   Parameters:
    296 ;       DS:DI:  Ptr to Disk Parameter Table
    297 ;       ES:SI:  Ptr to 512-byte ATA information read from the drive
    298 ;   Returns:
    299 ;       CF:     Cleared if DPT parameters stored successfully
    300 ;               Set if any error
     182    ; Fall to .StoreEBIOSSupport
     183
     184;--------------------------------------------------------------------
     185; .StoreEBIOSSupport
     186;   Parameters:
     187;       DS:DI:  Ptr to Disk Parameter Table
     188;       ES:SI:  Ptr to 512-byte ATA information read from the drive
     189;   Returns:
     190;       Nothing
    301191;   Corrupts registers:
    302192;       AX, BX, DX
    303193;--------------------------------------------------------------------
    304 ALIGN JUMP_ALIGN
    305 CreateDPT_StoreEBIOSSupport:
    306     test    BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE  ; (clears CF)
    307     jz      SHORT .DoNotSupportEBIOS    ; No EBIOS support since small DPTs needed
     194.StoreEBIOSSupport:
     195    test    BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
     196    jz      SHORT .StoreDriveNumberAndUpdateDriveCount  ; No EBIOS support since small DPTs needed
     197
    308198    mov     bl, [di+DPT.bFlags]
    309     and     bx, BYTE MASK_DPT_ADDR      ; Addressing mode (clears CF)
    310     jmp     [cs:bx+.rgwAddrJmp]         ; Jump to handle addressing mode
    311 ALIGN WORD_ALIGN
     199    and     bx, BYTE MASK_DPT_ADDR                      ; Addressing mode
     200    jmp     [cs:bx+.rgwAddrJmp]                         ; Jump to handle addressing mode
    312201.rgwAddrJmp:
    313     dw      .DoNotSupportEBIOS          ; ADDR_DPT_LCHS
    314     dw      .DoNotSupportEBIOS          ; ADDR_DPT_PCHS
    315     dw      .SupportForLBA28            ; ADDR_DPT_LBA28
    316     dw      .SupportForLBA48            ; ADDR_DPT_LBA48
    317 ALIGN JUMP_ALIGN
    318 .DoNotSupportEBIOS:
    319     ret
    320 ALIGN JUMP_ALIGN
     202    dw      .StoreDriveNumberAndUpdateDriveCount        ; ADDR_DPT_LCHS
     203    dw      .StoreDriveNumberAndUpdateDriveCount        ; ADDR_DPT_PCHS
     204    dw      .SupportForLBA28                            ; ADDR_DPT_LBA28
     205    dw      .SupportForLBA48                            ; ADDR_DPT_LBA48
     206
    321207.SupportForLBA28:
    322208    sub     BYTE [di+DPT.bSize], 2      ; Only 4 bytes for sector count
    323 ALIGN JUMP_ALIGN
    324209.SupportForLBA48:
    325210    add     BYTE [di+DPT.bSize], EBDPT_size - DPT_size
    326211    or      BYTE [di+DPT.bFlags], FLG_DPT_EBIOS
    327     ; Fall to CreateDPT_StoreEbiosSectorCount
    328 
    329 ;--------------------------------------------------------------------
    330 ; Stores EBIOS total sector count for LBA addressing.
    331 ;
    332 ; CreateDPT_StoreEbiosSectorCount
    333 ;   Parameters:
    334 ;       DS:DI:  Ptr to Disk Parameter Table
    335 ;       ES:SI:  Ptr to 512-byte ATA information read from the drive
    336 ;   Returns:
    337 ;       CF:     Cleared if DPT parameters stored successfully
    338 ;               Set if any error
    339 ;   Corrupts registers:
    340 ;       AX, BX, DX
    341 ;--------------------------------------------------------------------
    342 ;ALIGN JUMP_ALIGN
    343 CreateDPT_StoreEbiosSectorCount:
    344212    call    AtaID_GetTotalSectorCount
    345213    mov     [di+EBDPT.twCapacity], ax
    346214    mov     [di+EBDPT.twCapacity+2], dx
    347215    mov     [di+EBDPT.twCapacity+4], bx
    348     clc
    349     ret
    350 
    351 
    352 ;--------------------------------------------------------------------
    353 ; Stores number for drive and updates drive count.
    354 ;
    355 ; CreateDPT_StoreDriveNumberAndUpdateDriveCount
     216    ; Fall to .StoreDriveNumberAndUpdateDriveCount
     217
     218;--------------------------------------------------------------------
     219; .StoreDriveNumberAndUpdateDriveCount
    356220;   Parameters:
    357221;       DS:DI:  Ptr to Disk Parameter Table
     
    365229;       Nothing
    366230;--------------------------------------------------------------------
    367 ALIGN JUMP_ALIGN
    368 CreateDPT_StoreDriveNumberAndUpdateDriveCount:
     231.StoreDriveNumberAndUpdateDriveCount:
    369232    ; Make sure that more drives can be accepted
    370233    mov     dl, [es:BDA.bHDCount]   ; Load number of hard disks
Note: See TracChangeset for help on using the changeset viewer.