[150] | 1 | ; Project name : XTIDE Universal BIOS |
---|
| 2 | ; Description : Functions for managing IDEPACK struct. |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .text |
---|
| 6 | |
---|
| 7 | ;-------------------------------------------------------------------- |
---|
| 8 | ; Idepack_FakeToSSBP |
---|
| 9 | ; Parameters: |
---|
| 10 | ; Nothing |
---|
| 11 | ; Returns: |
---|
| 12 | ; SS:BP: Ptr to IDEPACK |
---|
| 13 | ; Corrupts registers: |
---|
| 14 | ; AX |
---|
| 15 | ;-------------------------------------------------------------------- |
---|
| 16 | Idepack_FakeToSSBP: |
---|
| 17 | pop ax |
---|
[158] | 18 | sub sp, BYTE EXTRA_BYTES_FOR_INTPACK |
---|
[150] | 19 | mov bp, sp |
---|
| 20 | jmp ax |
---|
| 21 | |
---|
[181] | 22 | |
---|
[150] | 23 | ;-------------------------------------------------------------------- |
---|
[165] | 24 | ; Idepack_ConvertDapToIdepackAndIssueCommandFromAH |
---|
| 25 | ; Parameters: |
---|
| 26 | ; AH: IDE command to issue |
---|
| 27 | ; BH: Timeout ticks |
---|
| 28 | ; BL: IDE Status Register flag to wait after command |
---|
| 29 | ; DS:DI: Ptr to DPT (in RAMVARS segment) |
---|
| 30 | ; ES:SI: Ptr to DAP (EBIOS Disk Address Packet) |
---|
| 31 | ; SS:BP: Ptr to IDEPACK |
---|
| 32 | ; Returns: |
---|
| 33 | ; AH: INT 13h Error Code |
---|
[249] | 34 | ; CX: Number of successfully transferred sectors (for transfer commands) |
---|
[165] | 35 | ; CF: Cleared if success, Set if error |
---|
| 36 | ; Corrupts registers: |
---|
[249] | 37 | ; AL, BX, (CX), DX, SI, ES |
---|
[165] | 38 | ;-------------------------------------------------------------------- |
---|
[181] | 39 | %ifdef MODULE_EBIOS |
---|
[165] | 40 | ALIGN JUMP_ALIGN |
---|
| 41 | Idepack_ConvertDapToIdepackAndIssueCommandFromAH: |
---|
[224] | 42 | mov al, [es:si+DAP.wSectorCount] |
---|
[221] | 43 | mov [bp+IDEPACK.bSectorCount], al |
---|
[165] | 44 | mov [bp+IDEPACK.bCommand], ah |
---|
| 45 | |
---|
| 46 | mov al, [es:si+DAP.qwLBA] ; LBA byte 0 |
---|
| 47 | mov [bp+IDEPACK.bLbaLow], al |
---|
| 48 | mov ax, [es:si+DAP.qwLBA+1] ; LBA bytes 1 and 2 |
---|
| 49 | mov [bp+IDEPACK.wLbaMiddleAndHigh], ax |
---|
| 50 | mov ah, [es:si+DAP.qwLBA+3] ; LBA byte 3, LBA28 bits 24...27 |
---|
| 51 | mov [bp+IDEPACK.bLbaLowExt], ah |
---|
| 52 | mov cx, [es:si+DAP.qwLBA+4] ; LBA bytes 4 and 5 |
---|
| 53 | mov [bp+IDEPACK.wLbaMiddleAndHighExt], cx |
---|
| 54 | |
---|
| 55 | and ah, 0Fh ; Limit bits for LBA28 |
---|
| 56 | call AccessDPT_GetDriveSelectByteToAL |
---|
| 57 | or al, ah |
---|
| 58 | mov [bp+IDEPACK.bDrvAndHead], al |
---|
[221] | 59 | |
---|
| 60 | ; Normalize data buffer pointer to ES:SI |
---|
[224] | 61 | mov ax, [es:si+DAP.wOffset] |
---|
[221] | 62 | mov cx, ax |
---|
| 63 | eSHR_IM ax, 4 ; Divide offset by 16 |
---|
[224] | 64 | add ax, [es:si+DAP.wSegment] ; Add segment |
---|
[221] | 65 | mov es, ax ; Segment normalized |
---|
| 66 | mov si, cx |
---|
| 67 | and si, BYTE 0Fh ; Offset normalized |
---|
[165] | 68 | jmp SHORT GetDeviceControlByteToIdepackAndStartTransfer |
---|
[176] | 69 | %endif |
---|
[165] | 70 | |
---|
[181] | 71 | |
---|
[165] | 72 | ;-------------------------------------------------------------------- |
---|
[150] | 73 | ; Idepack_TranslateOldInt13hAddressAndIssueCommandFromAH |
---|
| 74 | ; Parameters: |
---|
| 75 | ; AH: IDE command to issue |
---|
[221] | 76 | ; AL: Number of sectors to transfer (for xfer commands) |
---|
[150] | 77 | ; BH: Timeout ticks |
---|
| 78 | ; BL: IDE Status Register flag to wait after command |
---|
| 79 | ; CH: Cylinder number, bits 7...0 |
---|
| 80 | ; CL: Bits 7...6: Cylinder number bits 9 and 8 |
---|
| 81 | ; Bits 5...0: Starting sector number (1...63) |
---|
| 82 | ; DH: Starting head number (0...255) |
---|
| 83 | ; DS:DI: Ptr to DPT (in RAMVARS segment) |
---|
[221] | 84 | ; ES:SI: Ptr to normalized data buffer (for xfer commands) |
---|
[218] | 85 | ; SS:BP: Ptr to IDEPACK (containing INTPACK) |
---|
[150] | 86 | ; Returns: |
---|
| 87 | ; AH: INT 13h Error Code |
---|
[249] | 88 | ; CX: Number of successfully transferred sectors (for transfer commands) |
---|
[150] | 89 | ; CF: Cleared if success, Set if error |
---|
| 90 | ; Corrupts registers: |
---|
[249] | 91 | ; AL, BX, (CX), DX |
---|
[150] | 92 | ;-------------------------------------------------------------------- |
---|
| 93 | ALIGN JUMP_ALIGN |
---|
| 94 | Idepack_TranslateOldInt13hAddressAndIssueCommandFromAH: |
---|
[218] | 95 | mov [bp+IDEPACK.bSectorCount], al |
---|
[169] | 96 | mov [bp+IDEPACK.bCommand], ah |
---|
[181] | 97 | |
---|
[150] | 98 | push bx |
---|
[155] | 99 | call Address_OldInt13hAddressToIdeAddress |
---|
[150] | 100 | call AccessDPT_GetDriveSelectByteToAL |
---|
| 101 | or al, bh ; AL now has Drive and Head Select Byte |
---|
| 102 | mov [bp+IDEPACK.bDrvAndHead], al |
---|
| 103 | mov [bp+IDEPACK.bLbaLow], bl |
---|
| 104 | mov [bp+IDEPACK.wLbaMiddleAndHigh], cx |
---|
| 105 | pop bx |
---|
| 106 | |
---|
[165] | 107 | GetDeviceControlByteToIdepackAndStartTransfer: |
---|
[150] | 108 | call AccessDPT_GetDeviceControlByteToAL |
---|
| 109 | mov [bp+IDEPACK.bDeviceControl], al |
---|
[181] | 110 | jmp Device_OutputCommandWithParameters |
---|
[150] | 111 | |
---|
| 112 | |
---|
| 113 | ;-------------------------------------------------------------------- |
---|
| 114 | ; Idepack_StoreNonExtParametersAndIssueCommandFromAL |
---|
| 115 | ; Parameters: |
---|
| 116 | ; BH: Timeout ticks |
---|
| 117 | ; BL: IDE Status Register flag to wait after command |
---|
| 118 | ; AL: IDE command to issue |
---|
| 119 | ; AH: Parameter to Drive and Head Select Register (Head bits only) |
---|
| 120 | ; DL: Parameter to Sector Count Register |
---|
| 121 | ; DH: Parameter to LBA Low / Sector Number Register |
---|
| 122 | ; CL: Parameter to LBA Middle / Cylinder Low Register |
---|
| 123 | ; CH: Parameter to LBA High / Cylinder High Register |
---|
| 124 | ; SI: Parameter to Features Register |
---|
| 125 | ; DS:DI: Ptr to DPT (in RAMVARS segment) |
---|
| 126 | ; SS:BP: Ptr to IDEPACK |
---|
| 127 | ; Returns: |
---|
| 128 | ; AH: INT 13h Error Code |
---|
| 129 | ; CF: Cleared if success, Set if error |
---|
| 130 | ; Corrupts registers: |
---|
| 131 | ; AL, BX, CX, DX |
---|
| 132 | ;-------------------------------------------------------------------- |
---|
| 133 | ALIGN JUMP_ALIGN |
---|
| 134 | Idepack_StoreNonExtParametersAndIssueCommandFromAL: |
---|
| 135 | mov [bp+IDEPACK.bFeatures], si |
---|
| 136 | mov [bp+IDEPACK.bCommand], al |
---|
| 137 | mov [bp+IDEPACK.wSectorCountAndLbaLow], dx |
---|
| 138 | mov [bp+IDEPACK.wLbaMiddleAndHigh], cx |
---|
| 139 | |
---|
| 140 | ; Drive and Head select byte |
---|
| 141 | and ah, MASK_DRVNHEAD_HEAD ; Keep head bits only |
---|
| 142 | call AccessDPT_GetDriveSelectByteToAL |
---|
| 143 | or al, ah |
---|
| 144 | mov [bp+IDEPACK.bDrvAndHead], al |
---|
| 145 | |
---|
| 146 | ; Device Control byte with interrupts disabled |
---|
| 147 | call AccessDPT_GetDeviceControlByteToAL |
---|
| 148 | or al, FLG_DEVCONTROL_nIEN ; Disable interrupt |
---|
| 149 | mov [bp+IDEPACK.bDeviceControl], al |
---|
| 150 | |
---|
| 151 | jmp Device_OutputCommandWithParameters |
---|