[88] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
[3] | 2 | ; Description : Functions for selecting Master or Slave drive.
|
---|
| 3 |
|
---|
| 4 | ; Section containing code
|
---|
| 5 | SECTION .text
|
---|
| 6 |
|
---|
| 7 | ;--------------------------------------------------------------------
|
---|
| 8 | ; Selects Master or Slave drive for transferring data.
|
---|
| 9 | ; This means that interrupts will be enabled if so configured in
|
---|
| 10 | ; IDEVARS. This function returns after drive is ready to accept commands.
|
---|
| 11 | ;
|
---|
| 12 | ; HDrvSel_SelectDriveForDataTransfer
|
---|
| 13 | ; Parameters:
|
---|
| 14 | ; DS:DI: Ptr to DPT
|
---|
| 15 | ; Returns:
|
---|
| 16 | ; AH: BIOS Error code
|
---|
| 17 | ; CF: 0 if drive selected successfully
|
---|
| 18 | ; 1 if any error
|
---|
| 19 | ; Corrupts registers:
|
---|
| 20 | ; AL, BX
|
---|
| 21 | ;--------------------------------------------------------------------
|
---|
| 22 | ALIGN JUMP_ALIGN
|
---|
| 23 | HDrvSel_SelectDriveForDataTransfer:
|
---|
| 24 | mov al, [di+DPT.bDrvCtrl] ; Load Device Control Byte
|
---|
| 25 | ; Fall to HDrvSel_SelectDriveAndSetControlByte
|
---|
| 26 |
|
---|
| 27 | ;--------------------------------------------------------------------
|
---|
| 28 | ; Selects Master or Slave drive.
|
---|
| 29 | ; Device Control Byte can be used to enable or disable interrupts.
|
---|
| 30 | ; This function returns only after drive is ready to accept commands.
|
---|
| 31 | ;
|
---|
| 32 | ; HDrvSel_SelectDriveAndSetControlByte
|
---|
| 33 | ; Parameters:
|
---|
| 34 | ; AL: Device Control Byte (to enable/disable interrupts)
|
---|
| 35 | ; DS:DI: Ptr to DPT
|
---|
| 36 | ; Returns:
|
---|
| 37 | ; AH: BIOS Error code
|
---|
| 38 | ; CF: 0 if drive selected successfully
|
---|
| 39 | ; 1 if any error
|
---|
| 40 | ; Corrupts registers:
|
---|
| 41 | ; AL, BX
|
---|
| 42 | ;--------------------------------------------------------------------
|
---|
| 43 | ;ALIGN JUMP_ALIGN
|
---|
| 44 | HDrvSel_SelectDriveAndSetControlByte:
|
---|
| 45 | push dx
|
---|
| 46 | push cx
|
---|
| 47 |
|
---|
| 48 | ; Output Device Control Register to enable/disable interrupts
|
---|
| 49 | call HDrvSel_OutputDeviceControlByte
|
---|
| 50 |
|
---|
| 51 | ; Select Master or Slave drive
|
---|
| 52 | mov dx, [RAMVARS.wIdeBase]
|
---|
| 53 | add dx, BYTE REG_IDE_DRVHD
|
---|
| 54 | mov al, [di+DPT.bDrvSel] ; Load Master/Slave selection byte
|
---|
| 55 | out dx, al ; Select drive
|
---|
| 56 |
|
---|
| 57 | ; Wait until drive is ready to accept commands
|
---|
| 58 | call HStatus_WaitRdyDefTime
|
---|
| 59 | pop cx
|
---|
| 60 | pop dx
|
---|
| 61 | ret
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | ;--------------------------------------------------------------------
|
---|
| 65 | ; Outputs Device Control Byte to Device Control Register.
|
---|
| 66 | ;
|
---|
| 67 | ; HDrvSel_OutputDeviceControlByte
|
---|
| 68 | ; Parameters:
|
---|
| 69 | ; AL: Device Control Byte
|
---|
| 70 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 71 | ; Returns:
|
---|
| 72 | ; DX: Device Control Register address
|
---|
| 73 | ; Corrupts registers:
|
---|
| 74 | ; BX
|
---|
| 75 | ;--------------------------------------------------------------------
|
---|
| 76 | ALIGN JUMP_ALIGN
|
---|
| 77 | HDrvSel_OutputDeviceControlByte:
|
---|
| 78 | eMOVZX bx, BYTE [di+DPT.bIdeOff] ; CS:BX now points to IDEVARS
|
---|
| 79 | mov dx, [cs:bx+IDEVARS.wPortCtrl] ; Load Control Block base address
|
---|
| 80 | add dx, BYTE REGW_IDEC_CTRL ; Add offset to Device Control Register
|
---|
| 81 | out dx, al ; Output Device Control byte
|
---|
| 82 | ret
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 | ;--------------------------------------------------------------------
|
---|
| 86 | ; Selects Master or Slave drive and disables interrupts. Interrupts should
|
---|
| 87 | ; be disabled for commands that do not transfer data.
|
---|
| 88 | ; This function returns after drive is ready to accept commands.
|
---|
| 89 | ;
|
---|
| 90 | ; HDrvSel_SelectDriveAndDisableIRQ
|
---|
| 91 | ; Parameters:
|
---|
| 92 | ; DS:DI: Ptr to DPT
|
---|
| 93 | ; Returns:
|
---|
| 94 | ; AH: BIOS Error code
|
---|
| 95 | ; CF: 0 if drive selected successfully
|
---|
| 96 | ; 1 if any error
|
---|
| 97 | ; Corrupts registers:
|
---|
| 98 | ; AL
|
---|
| 99 | ;--------------------------------------------------------------------
|
---|
| 100 | ALIGN JUMP_ALIGN
|
---|
| 101 | HDrvSel_SelectDriveAndDisableIRQ:
|
---|
| 102 | push bx
|
---|
| 103 | mov al, [di+DPT.bDrvCtrl] ; Load Device Control Byte
|
---|
| 104 | or al, FLG_IDE_CTRL_nIEN ; Disable interrupts
|
---|
| 105 | call HDrvSel_SelectDriveAndSetControlByte
|
---|
| 106 | pop bx
|
---|
| 107 | ret
|
---|