[3] | 1 | ; File name : AH9h_HInit.asm |
---|
| 2 | ; Project name : IDE BIOS |
---|
| 3 | ; Created date : 9.12.2007 |
---|
| 4 | ; Last update : 26.4.2010 |
---|
| 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 |
---|
| 80 | ;mov dl, [di+DPT.bDrvNum] ; Restore DL |
---|
| 81 | jc SHORT .ReturnNotSuccessfull |
---|
| 82 | and BYTE [di+DPT.bReset], ~FLG_RESET_nSETBLOCK |
---|
| 83 | |
---|
| 84 | .ReturnNotSuccessfull: |
---|
| 85 | pop cx |
---|
| 86 | pop dx |
---|
| 87 | ret |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | ;-------------------------------------------------------------------- |
---|
| 91 | ; Sends Initialize Device Parameters command to IDE Hard Disk. |
---|
| 92 | ; Initialization is used to initialize logical CHS parameters. Drives |
---|
| 93 | ; may not support all CHS values. |
---|
| 94 | ; This command is only supported by drives that supports CHS addressing. |
---|
| 95 | ; |
---|
| 96 | ; AH9h_InitializeDeviceParameters |
---|
| 97 | ; Parameters: |
---|
| 98 | ; DS:DI: Ptr to DPT |
---|
| 99 | ; Returns: |
---|
| 100 | ; AH: BIOS Error code |
---|
| 101 | ; CF: Cleared if succesfull |
---|
| 102 | ; Set if any error |
---|
| 103 | ; Corrupts registers: |
---|
| 104 | ; AL, BX, CX |
---|
| 105 | ;-------------------------------------------------------------------- |
---|
| 106 | ALIGN JUMP_ALIGN |
---|
| 107 | AH9h_InitializeDeviceParameters: |
---|
| 108 | ; No need to initialize CHS parameters if LBA mode enabled |
---|
| 109 | test BYTE [di+DPT.bDrvSel], FLG_IDE_DRVHD_LBA ; Clears CF |
---|
| 110 | jnz SHORT .Return |
---|
| 111 | |
---|
| 112 | push dx |
---|
| 113 | mov bh, [di+DPT.bPHeads] |
---|
| 114 | dec bh ; Max head number |
---|
| 115 | mov dx, [RAMVARS.wIdeBase] |
---|
| 116 | call HCommand_OutputTranslatedLCHSaddress |
---|
| 117 | mov ah, HCMD_INIT_DEV |
---|
| 118 | mov al, [di+DPT.bPSect] ; Sectors per track |
---|
| 119 | call HCommand_OutputSectorCountAndCommand |
---|
| 120 | call HStatus_WaitBsyDefTime ; Wait until drive ready (DRDY won't be set!) |
---|
| 121 | pop dx |
---|
| 122 | .Return: |
---|
| 123 | ret |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | ;-------------------------------------------------------------------- |
---|
| 127 | ; Initializes block mode transfers. |
---|
| 128 | ; |
---|
| 129 | ; AH9h_InitializeBlockMode |
---|
| 130 | ; Parameters: |
---|
| 131 | ; DL: Drive number |
---|
| 132 | ; DS:DI: Ptr to DPT |
---|
| 133 | ; Returns: |
---|
| 134 | ; AH: BIOS Error code |
---|
| 135 | ; CF: Cleared if succesfull |
---|
| 136 | ; Set if any error |
---|
| 137 | ; Corrupts registers: |
---|
| 138 | ; AL, BX, CX, DX |
---|
| 139 | ;-------------------------------------------------------------------- |
---|
| 140 | ALIGN JUMP_ALIGN |
---|
| 141 | AH9h_InitializeBlockMode: |
---|
| 142 | mov ax, FLG_DRVPARAMS_BLOCKMODE |
---|
| 143 | call AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive |
---|
| 144 | jz SHORT .Return ; Block mode disabled (CF cleared) |
---|
| 145 | eMOVZX ax, BYTE [di+DPT.bMaxBlock] ; Load max block size, zero AH |
---|
| 146 | test al, al ; Block mode supported? (clears CF) |
---|
| 147 | jz SHORT .Return ; If not, return |
---|
| 148 | jmp AH24h_SetBlockSize |
---|
| 149 | .Return: |
---|
| 150 | ret |
---|