[3] | 1 | ; File name : AH9h_HInit.asm |
---|
| 2 | ; Project name : IDE BIOS |
---|
| 3 | ; Created date : 9.12.2007 |
---|
[28] | 4 | ; Last update : 1.8.2010 |
---|
[3] | 5 | ; Author : Tomi Tilli |
---|
| 6 | ; Description : Int 13h function AH=9h, Initialize Drive Parameters. |
---|
| 7 | |
---|
| 8 | ; Section containing code |
---|
| 9 | SECTION .text |
---|
| 10 | |
---|
| 11 | ;-------------------------------------------------------------------- |
---|
| 12 | ; Int 13h function AH=9h, Initialize Drive Parameters. |
---|
| 13 | ; |
---|
| 14 | ; AH9h_HandlerForInitializeDriveParameters |
---|
| 15 | ; Parameters: |
---|
| 16 | ; AH: Bios function 9h |
---|
| 17 | ; DL: Drive number |
---|
| 18 | ; Parameters loaded by Int13h_Jump: |
---|
| 19 | ; DS: RAMVARS segment |
---|
| 20 | ; Returns: |
---|
| 21 | ; AH: Int 13h return status |
---|
| 22 | ; CF: 0 if succesfull, 1 if error |
---|
| 23 | ; IF: 1 |
---|
| 24 | ; Corrupts registers: |
---|
| 25 | ; Flags |
---|
| 26 | ;-------------------------------------------------------------------- |
---|
| 27 | ALIGN JUMP_ALIGN |
---|
| 28 | AH9h_HandlerForInitializeDriveParameters: |
---|
| 29 | push dx |
---|
| 30 | push cx |
---|
| 31 | push bx |
---|
| 32 | push ax |
---|
| 33 | call AH9h_InitializeDriveForUse |
---|
| 34 | jmp Int13h_PopXRegsAndReturn |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | ;-------------------------------------------------------------------- |
---|
| 38 | ; Initialized drive to be ready for use. |
---|
| 39 | ; |
---|
| 40 | ; AH9h_InitializeDriveForUse |
---|
| 41 | ; Parameters: |
---|
| 42 | ; DL: Drive number |
---|
| 43 | ; DS: RAMVARS segment |
---|
| 44 | ; Returns: |
---|
| 45 | ; DS:DI: Ptr to DPT |
---|
| 46 | ; AH: Int 13h return status |
---|
| 47 | ; CF: 0 if succesfull, 1 if error |
---|
| 48 | ; Corrupts registers: |
---|
| 49 | ; AL, BX |
---|
| 50 | ;-------------------------------------------------------------------- |
---|
| 51 | ALIGN JUMP_ALIGN |
---|
| 52 | AH9h_InitializeDriveForUse: |
---|
| 53 | push dx |
---|
| 54 | push cx |
---|
| 55 | |
---|
| 56 | ; Try to select drive and wait until ready |
---|
| 57 | call FindDPT_ForDriveNumber |
---|
| 58 | or BYTE [di+DPT.bReset], MASK_RESET_ALL ; Everything uninitialized |
---|
| 59 | call HDrvSel_SelectDriveAndDisableIRQ |
---|
| 60 | jc SHORT .ReturnNotSuccessfull |
---|
| 61 | and BYTE [di+DPT.bReset], ~FLG_RESET_nDRDY ; Clear since success |
---|
| 62 | |
---|
| 63 | ; Initialize CHS parameters if LBA is not used |
---|
| 64 | call AH9h_InitializeDeviceParameters |
---|
| 65 | jc SHORT .RecalibrateDrive |
---|
| 66 | and BYTE [di+DPT.bReset], ~FLG_RESET_nINITPRMS |
---|
| 67 | |
---|
| 68 | ; Recalibrate drive by seeking to cylinder 0 |
---|
| 69 | ALIGN JUMP_ALIGN |
---|
| 70 | .RecalibrateDrive: |
---|
| 71 | call AH11h_RecalibrateDrive |
---|
| 72 | mov dl, [di+DPT.bDrvNum] ; Restore DL |
---|
| 73 | jc SHORT .InitializeBlockMode |
---|
| 74 | and BYTE [di+DPT.bReset], ~FLG_RESET_nRECALIBRATE |
---|
| 75 | |
---|
| 76 | ; Initialize block mode transfers |
---|
| 77 | ALIGN JUMP_ALIGN |
---|
| 78 | .InitializeBlockMode: |
---|
| 79 | call AH9h_InitializeBlockMode |
---|
[28] | 80 | ;mov dl, [di+DPT.bDrvNum] ; Restore DL |
---|
[3] | 81 | jc SHORT .ReturnNotSuccessfull |
---|
| 82 | and BYTE [di+DPT.bReset], ~FLG_RESET_nSETBLOCK |
---|
| 83 | |
---|
[28] | 84 | ; Force PIO mode 0 |
---|
| 85 | ;call AH9h_ForcePioMode0 |
---|
| 86 | |
---|
[3] | 87 | .ReturnNotSuccessfull: |
---|
| 88 | pop cx |
---|
| 89 | pop dx |
---|
| 90 | ret |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | ;-------------------------------------------------------------------- |
---|
| 94 | ; Sends Initialize Device Parameters command to IDE Hard Disk. |
---|
| 95 | ; Initialization is used to initialize logical CHS parameters. Drives |
---|
| 96 | ; may not support all CHS values. |
---|
| 97 | ; This command is only supported by drives that supports CHS addressing. |
---|
| 98 | ; |
---|
| 99 | ; AH9h_InitializeDeviceParameters |
---|
| 100 | ; Parameters: |
---|
| 101 | ; DS:DI: Ptr to DPT |
---|
| 102 | ; Returns: |
---|
| 103 | ; AH: BIOS Error code |
---|
| 104 | ; CF: Cleared if succesfull |
---|
| 105 | ; Set if any error |
---|
| 106 | ; Corrupts registers: |
---|
| 107 | ; AL, BX, CX |
---|
| 108 | ;-------------------------------------------------------------------- |
---|
| 109 | ALIGN JUMP_ALIGN |
---|
| 110 | AH9h_InitializeDeviceParameters: |
---|
| 111 | ; No need to initialize CHS parameters if LBA mode enabled |
---|
| 112 | test BYTE [di+DPT.bDrvSel], FLG_IDE_DRVHD_LBA ; Clears CF |
---|
| 113 | jnz SHORT .Return |
---|
| 114 | |
---|
| 115 | push dx |
---|
| 116 | mov bh, [di+DPT.bPHeads] |
---|
| 117 | dec bh ; Max head number |
---|
| 118 | mov dx, [RAMVARS.wIdeBase] |
---|
| 119 | call HCommand_OutputTranslatedLCHSaddress |
---|
| 120 | mov ah, HCMD_INIT_DEV |
---|
| 121 | mov al, [di+DPT.bPSect] ; Sectors per track |
---|
| 122 | call HCommand_OutputSectorCountAndCommand |
---|
| 123 | call HStatus_WaitBsyDefTime ; Wait until drive ready (DRDY won't be set!) |
---|
| 124 | pop dx |
---|
| 125 | .Return: |
---|
| 126 | ret |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | ;-------------------------------------------------------------------- |
---|
| 130 | ; Initializes block mode transfers. |
---|
| 131 | ; |
---|
| 132 | ; AH9h_InitializeBlockMode |
---|
| 133 | ; Parameters: |
---|
| 134 | ; DL: Drive number |
---|
| 135 | ; DS:DI: Ptr to DPT |
---|
| 136 | ; Returns: |
---|
| 137 | ; AH: BIOS Error code |
---|
| 138 | ; CF: Cleared if succesfull |
---|
| 139 | ; Set if any error |
---|
| 140 | ; Corrupts registers: |
---|
| 141 | ; AL, BX, CX, DX |
---|
| 142 | ;-------------------------------------------------------------------- |
---|
| 143 | ALIGN JUMP_ALIGN |
---|
| 144 | AH9h_InitializeBlockMode: |
---|
| 145 | mov ax, FLG_DRVPARAMS_BLOCKMODE |
---|
| 146 | call AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive |
---|
| 147 | jz SHORT .Return ; Block mode disabled (CF cleared) |
---|
| 148 | eMOVZX ax, BYTE [di+DPT.bMaxBlock] ; Load max block size, zero AH |
---|
| 149 | test al, al ; Block mode supported? (clears CF) |
---|
| 150 | jz SHORT .Return ; If not, return |
---|
| 151 | jmp AH24h_SetBlockSize |
---|
| 152 | .Return: |
---|
| 153 | ret |
---|
[28] | 154 | |
---|
| 155 | |
---|
| 156 | ;-------------------------------------------------------------------- |
---|
| 157 | ; AH9h_ForcePioMode0 |
---|
| 158 | ; Parameters: |
---|
| 159 | ; DL: Drive number |
---|
| 160 | ; DS:DI: Ptr to DPT |
---|
| 161 | ; Returns: |
---|
| 162 | ; AH: BIOS Error code |
---|
| 163 | ; CF: Cleared if succesfull |
---|
| 164 | ; Set if any error |
---|
| 165 | ; Corrupts registers: |
---|
| 166 | ; AX, BX |
---|
| 167 | ;-------------------------------------------------------------------- |
---|
| 168 | ;ALIGN JUMP_ALIGN |
---|
| 169 | ;AH9h_ForcePioMode0: |
---|
| 170 | ; mov bh, 08h ; Parameter to Sector Count Register (PIO Flow Control Transfer Mode 0) |
---|
| 171 | ; mov ax, 2303h ; Feature: Set transfer mode based on value in Sector Count register |
---|
| 172 | ; int 13h |
---|
| 173 | ; jc SHORT .FailedToForcePIO0 |
---|
| 174 | ; ; Debug output here |
---|
| 175 | ; ret |
---|
| 176 | ;.FailedToForcePIO0: |
---|
| 177 | ; ; Debug output here |
---|
| 178 | ; ret |
---|