[3] | 1 | ; File name : AH25h_HDrvID.asm
|
---|
| 2 | ; Project name : IDE BIOS
|
---|
| 3 | ; Created date : 24.10.2009
|
---|
| 4 | ; Last update : 14.4.2010
|
---|
| 5 | ; Author : Tomi Tilli
|
---|
| 6 | ; Description : Int 13h function AH=25h, Get Drive Information.
|
---|
| 7 |
|
---|
| 8 | ; Section containing code
|
---|
| 9 | SECTION .text
|
---|
| 10 |
|
---|
| 11 | ;--------------------------------------------------------------------
|
---|
| 12 | ; Int 13h function AH=25h, Get Drive Information.
|
---|
| 13 | ;
|
---|
| 14 | ; AH25h_HandlerForGetDriveInformation
|
---|
| 15 | ; Parameters:
|
---|
| 16 | ; AH: Bios function 25h
|
---|
| 17 | ; DL: Drive number
|
---|
| 18 | ; ES:BX: Ptr to buffer to receive 512-byte drive information
|
---|
| 19 | ; Parameters loaded by Int13h_Jump:
|
---|
| 20 | ; DS: RAMVARS segment
|
---|
| 21 | ; Returns:
|
---|
| 22 | ; ES:BX: Ptr to 512-byte buffer to receive drive Information
|
---|
| 23 | ; AH: Int 13h return status
|
---|
| 24 | ; CF: 0 if succesfull, 1 if error
|
---|
| 25 | ; IF: 1
|
---|
| 26 | ; Corrupts registers:
|
---|
| 27 | ; Flags
|
---|
| 28 | ;--------------------------------------------------------------------
|
---|
| 29 | ALIGN JUMP_ALIGN
|
---|
| 30 | AH25h_HandlerForGetDriveInformation:
|
---|
| 31 | push dx
|
---|
| 32 | push cx
|
---|
| 33 | push bx
|
---|
| 34 | push ax
|
---|
| 35 | push es
|
---|
| 36 |
|
---|
| 37 | ; Wait until previously selected drive is ready
|
---|
| 38 | call FindDPT_ForDriveNumber ; DS:DI now points to DPT
|
---|
| 39 | call HDrvSel_SelectDriveAndDisableIRQ
|
---|
| 40 | jc SHORT .Return ; Return if error
|
---|
| 41 |
|
---|
| 42 | ; Get drive information
|
---|
| 43 | call HPIO_NormalizeDataPointer
|
---|
| 44 | push bx
|
---|
| 45 | mov dx, [RAMVARS.wIdeBase] ; Load base port address
|
---|
| 46 | eMOVZX bx, BYTE [di+DPT.bIdeOff] ; Load offset to IDEVARS
|
---|
| 47 | mov bl, [cs:bx+IDEVARS.bBusType]; Load bus type to BL
|
---|
| 48 | mov bh, [di+DPT.bDrvSel] ; Load drive sel byte to BH
|
---|
| 49 | pop di ; Pop buffer offset to DI
|
---|
| 50 | call AH25h_GetDriveInfo ; Get drive information
|
---|
| 51 | .Return:
|
---|
| 52 | pop es
|
---|
| 53 | jmp Int13h_PopXRegsAndReturn
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | ;--------------------------------------------------------------------
|
---|
| 57 | ; Gets drive information using Identify Device command.
|
---|
| 58 | ;
|
---|
| 59 | ; AH25h_GetDriveInfo
|
---|
| 60 | ; Parameters:
|
---|
| 61 | ; BH: Drive Select byte for Drive and Head Select Register
|
---|
| 62 | ; BL: Bus type
|
---|
| 63 | ; DX: IDE Controller base port address
|
---|
| 64 | ; DS: Segment to RAMVARS
|
---|
| 65 | ; ES:DI: Ptr to buffer to receive 512 byte drive information
|
---|
| 66 | ; Returns:
|
---|
| 67 | ; AH: Int 13h return status (will be stored to BDA)
|
---|
| 68 | ; CF: 0 if succesfull, 1 if error
|
---|
| 69 | ; Corrupts registers:
|
---|
| 70 | ; AL, CX
|
---|
| 71 | ;--------------------------------------------------------------------
|
---|
| 72 | ALIGN JUMP_ALIGN
|
---|
| 73 | AH25h_GetDriveInfo:
|
---|
| 74 | push di
|
---|
| 75 | push dx
|
---|
| 76 | push bx
|
---|
| 77 |
|
---|
| 78 | ; Select Master or Slave drive.
|
---|
| 79 | ; DO NOT WAIT UNTIL CURRENTLY SELECTED IS READY!
|
---|
| 80 | ; It makes slave drive detection impossible if master is not present.
|
---|
| 81 | mov [RAMVARS.wIdeBase], dx ; Store IDE Base port to RAMVARS
|
---|
| 82 | add dx, BYTE REG_IDE_DRVHD ; DX to Drive and Head Sel Register
|
---|
| 83 | mov al, bh ; Drive Select byte to AL
|
---|
| 84 | out dx, al ; Select Master or Slave drive
|
---|
| 85 | sub dx, BYTE REG_IDE_DRVHD ; Back to IDE Base port
|
---|
| 86 | call AH25h_GetDriveDetectionTimeoutValue
|
---|
| 87 | call HStatus_WaitRdy ; Wait until ready to accept commands
|
---|
| 88 | jc SHORT .Return ; Return if error
|
---|
| 89 |
|
---|
| 90 | ; Output command
|
---|
| 91 | mov al, HCMD_ID_DEV ; Load Identify Device command to AL
|
---|
| 92 | out dx, al ; Output command
|
---|
| 93 | call SoftDelay_BeforePollingStatusRegister
|
---|
| 94 | call HStatus_WaitDrqDefTime ; Wait until ready to transfer (no IRQ!)
|
---|
| 95 | jc SHORT .Return ; Return if error
|
---|
| 96 |
|
---|
| 97 | ; Transfer data
|
---|
| 98 | sub dx, BYTE REGR_IDE_ST ; DX to IDE Data Reg
|
---|
| 99 | xor bh, bh ; BX now contains bus type
|
---|
| 100 | mov cx, 256 ; Transfer 256 words (single sector)
|
---|
| 101 | cld ; INSW to increment DI
|
---|
| 102 | call [cs:bx+g_rgfnPioRead] ; Read ID sector
|
---|
| 103 | call HStatus_WaitRdyDefTime ; Wait until drive ready
|
---|
| 104 |
|
---|
| 105 | ; Return
|
---|
| 106 | .Return:
|
---|
| 107 | pop bx
|
---|
| 108 | pop dx
|
---|
| 109 | pop di
|
---|
| 110 | ret
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | ;--------------------------------------------------------------------
|
---|
| 114 | ; Returns timeout value for drive detection.
|
---|
| 115 | ; Long timeout is required for detecing first drive to make sure it is
|
---|
| 116 | ; ready after power-on (ATA specification says up to 31 seconds).
|
---|
| 117 | ; Short timeout is used for additional drives to prevent long boot time
|
---|
| 118 | ; when drive has failed or it is not present.
|
---|
| 119 | ;
|
---|
| 120 | ; AH25h_GetDriveDetectionTimeoutValue
|
---|
| 121 | ; Parameters:
|
---|
| 122 | ; DS: Segment to RAMVARS
|
---|
| 123 | ; Returns:
|
---|
| 124 | ; CL: Timeout value
|
---|
| 125 | ; Corrupts registers:
|
---|
| 126 | ; Nothing
|
---|
| 127 | ;--------------------------------------------------------------------
|
---|
| 128 | ALIGN JUMP_ALIGN
|
---|
| 129 | AH25h_GetDriveDetectionTimeoutValue:
|
---|
| 130 | cmp BYTE [RAMVARS.bDrvCnt], 0 ; Detecting first drive?
|
---|
| 131 | je SHORT .GetLongDelayForInitialDetection
|
---|
| 132 | mov cl, B_TIMEOUT_DRVINFO ; Load short timeout
|
---|
| 133 | ret
|
---|
| 134 | ALIGN JUMP_ALIGN
|
---|
| 135 | .GetLongDelayForInitialDetection:
|
---|
| 136 | mov cl, B_TIMEOUT_RESET ; Load long timeout
|
---|
| 137 | ret
|
---|