|
| 1 | +; Patch for Adaptec's 274x BIOS, Version 2.11 to add (rudimentary) EDD support. |
| 2 | +; SHA1 of expected input file: A0EC9AFE433549BB384E76A4167C2CB14BFE3FDA |
| 3 | + |
| 4 | +; Copyright (C) 2021 Michael Karcher (the patch, not the original BIOS!) |
| 5 | +; This patch may be used and distributed according to the MIT License. |
| 6 | + |
| 7 | +.286 |
| 8 | + |
| 9 | +BIOSFrame STRUC |
| 10 | +we_dont_care_1 db 4 dup (?) |
| 11 | +VDSFlags db ? |
| 12 | +we_dont_care_2 db 11 dup (?) |
| 13 | +CDBlen db ? |
| 14 | +we_dont_care_3 db 7 dup (?) |
| 15 | +CDBdata db 12 dup (?) |
| 16 | +we_dont_care_4 db 4 dup (?) |
| 17 | +TransferLenLow dw ? |
| 18 | +TransferLenHigh dw ? |
| 19 | +we_dont_care_5 db 8 dup (?) |
| 20 | +BIOSFlags dw ? |
| 21 | +we_dont_care_6 db 6 dup (?) |
| 22 | +CallerAX dw ? |
| 23 | +CallerBX dw ? |
| 24 | +CallerCX dw ? |
| 25 | +CallerDX dw ? |
| 26 | +CallerSI dw ? |
| 27 | +CallerDI dw ? |
| 28 | +CallerDS dw ? |
| 29 | +CallerES dw ? |
| 30 | +BIOSFrame ENDS |
| 31 | + |
| 32 | +IsNoData = 8 ; Flag for execution unit that this is a "no data" command |
| 33 | +BF_IgnoreSeek = 80h |
| 34 | + |
| 35 | +MAIN SEGMENT |
| 36 | + assume cs:MAIN |
| 37 | + |
| 38 | + org 0BF4h |
| 39 | +ResetLocalState LABEL NEAR |
| 40 | + org 0C28h |
| 41 | +SetTarget LABEL NEAR |
| 42 | + org 0DE1h |
| 43 | +ExecuteCommand LABEL NEAR |
| 44 | + org 0E9Fh |
| 45 | +SetDataAddress LABEL NEAR |
| 46 | + |
| 47 | + org 13ECh |
| 48 | +Func_Unsupported LABEL NEAR |
| 49 | + org 13EEh |
| 50 | +I13FinishWithAH LABEL NEAR |
| 51 | + |
| 52 | + org 16F4h |
| 53 | +Func09_AlwaysOK LABEL NEAR |
| 54 | + |
| 55 | + org 1224h + 12h * 2 |
| 56 | + ; remap functions 12..14 ("always OK") to function 09 ("always OK") |
| 57 | + ; this frees up 13E4..13E8 |
| 58 | + dw OFFSET Func09_AlwaysOK |
| 59 | + dw OFFSET Func09_AlwaysOK |
| 60 | + dw OFFSET Func09_AlwaysOK |
| 61 | + |
| 62 | + org 1224h |
| 63 | +Int13_Dispatch LABEL WORD |
| 64 | + |
| 65 | + org 13BCh |
| 66 | + mov al, BYTE PTR [bp+CallerAX+1] ; originaly whole word to AX |
| 67 | + ;mov bx, [bp+CallerBX] ; superflous, BX is already set |
| 68 | + mov cx, [bp+CallerCX] |
| 69 | + mov dx, [bp+CallerDX] |
| 70 | + push 40h |
| 71 | + pop ds |
| 72 | + cbw |
| 73 | + mov di, ax |
| 74 | + shl di, 1 |
| 75 | + cmp al, 15h |
| 76 | + ja short MaybeI13E |
| 77 | + mov ax, [bp+CallerAX] |
| 78 | + jmp cs:[di + Int13_Dispatch] |
| 79 | +MaybeI13E: |
| 80 | + sub al, 41h |
| 81 | + cmp al, 7 |
| 82 | + ja Func_Unsupported |
| 83 | + mov es, [bp+CallerDS] |
| 84 | + jmp cs:[di - 41h*2 + Int13E_Dispatch] |
| 85 | + |
| 86 | + org 0B4Bh |
| 87 | +Int13E_Dispatch LABEL WORD |
| 88 | + dw OFFSET I13E_checkpresence ; 41h |
| 89 | + dw OFFSET I13E_read ; 42h |
| 90 | + dw OFFSET I13E_write ; 43h |
| 91 | + dw OFFSET I13E_verify ; 44h |
| 92 | + dw OFFSET Func_Unsupported ; 45h (lock/unlock) |
| 93 | + dw OFFSET Func_Unsupported ; 46h (eject) |
| 94 | + dw OFFSET I13E_seek ; 47h |
| 95 | + dw OFFSET I13E_params ; 48h |
| 96 | +I13E_checkpresence: |
| 97 | + mov [bp+CallerBX], 0AA55h ; extensions present |
| 98 | + mov byte ptr [bp+CallerAX + 1], 01h ; version 1.x |
| 99 | + mov [bp+CallerCX], 1 ; support LBA disk calls only |
| 100 | + jmp Func09_AlwaysOK |
| 101 | + |
| 102 | +I13E_params: |
| 103 | + mov di, si |
| 104 | + mov ax, 1Ah |
| 105 | + cmp es:[word ptr di], ax |
| 106 | + jnb go_on |
| 107 | + jmp Func_Unsupported |
| 108 | +go_on: |
| 109 | + stosw |
| 110 | + mov ax, 1 ; No 64K DMA limit, no CHS info |
| 111 | + stosw |
| 112 | + dec ax |
| 113 | + mov cx, 6 |
| 114 | + rep stosw ; clear CHS fields (not reporting them) |
| 115 | + push es |
| 116 | + push di |
| 117 | + call ResetLocalState |
| 118 | + call SetTarget |
| 119 | + mov [bp+CDBdata], 25h ; SCSI read capacity |
| 120 | + mov [bp+CDBlen], 0Ah |
| 121 | + mov [bp+TransferLenLow], 8 |
| 122 | + mov [bp+TransferLenHigh], 0 |
| 123 | + and [bp+VDSFlags], not IsNoData |
| 124 | + pop bx ; address of LBA count. |
| 125 | + ; if the command succeeds, the low 32 bits are set to the |
| 126 | + ; capacity of the drive (-1), the high 32 bits are the sector size. |
| 127 | + ; it's big endian, though :( |
| 128 | + push bx |
| 129 | + call SetDataAddress |
| 130 | + call ExecuteCommand |
| 131 | + pop di |
| 132 | + pop es |
| 133 | + push ax |
| 134 | + mov ax, es:[di] |
| 135 | + xchg ah, al |
| 136 | + xchg ax, es:[di+2] |
| 137 | + xchg ah, al |
| 138 | + add ax, 1 ; from max_lba to sector count |
| 139 | + mov es:[di], ax |
| 140 | + adc es:[word ptr di+2], 0 |
| 141 | + add di, 4 |
| 142 | + |
| 143 | + xor ax, ax |
| 144 | + stosw ; high 32 bit of max LBA |
| 145 | + stosw |
| 146 | + mov ax, 200h ; sector size |
| 147 | + stosw |
| 148 | + pop ax |
| 149 | + jmp I13FinishWithAH |
| 150 | + |
| 151 | + org 184Ah |
| 152 | +I13E_common: |
| 153 | + sbb dx,dx |
| 154 | + call ResetLocalState |
| 155 | + or [bp+VDSFlags], ch |
| 156 | + mov [bp+CDBdata], cl |
| 157 | + mov [bp+CDBlen], 0Ah |
| 158 | + mov ax, es:[si+2] |
| 159 | + and dx, ax |
| 160 | + xchg dh, dl |
| 161 | + mov word ptr [bp+CDBdata + 7], dx ; length to target |
| 162 | + add ax, ax |
| 163 | + mov word ptr [bp+TransferLenLow + 1], ax ; transfer length |
| 164 | + ; set LBA (bswapping it) |
| 165 | + mov ax, es:[si+8] |
| 166 | + xchg ah, al |
| 167 | + mov word ptr [bp+CDBdata + 4], ax |
| 168 | + mov ax, es:[si+10] |
| 169 | + xchg ah, al |
| 170 | + mov word ptr [bp+CDBdata + 2], ax |
| 171 | + test [bp+VDSFlags], IsNoData |
| 172 | + jnz no_data |
| 173 | + les bx, es:[si+4] |
| 174 | + call SetDataAddress |
| 175 | +no_data: |
| 176 | + call ExecuteCommand |
| 177 | + cmp ah, 1 ; unsupported command |
| 178 | + jne usual_case |
| 179 | + test [bp+VDSFlags], IsNoData |
| 180 | + jz usual_case |
| 181 | +return_ok: |
| 182 | + mov ah, 0 ; non-data command: verify or seek; deemed optional |
| 183 | + ; remap "unsupported" to OK |
| 184 | +usual_case: |
| 185 | + jmp I13FinishWithAH |
| 186 | + |
| 187 | + |
| 188 | +I13E_read: |
| 189 | + mov cx, 0028h |
| 190 | + stc |
| 191 | + jmp I13E_common |
| 192 | +I13E_write: |
| 193 | + mov cx, 002Ah |
| 194 | + stc |
| 195 | + jmp I13E_common |
| 196 | +I13E_verify: |
| 197 | + mov cx, 082Fh |
| 198 | + stc |
| 199 | + jmp I13E_common |
| 200 | +I13E_seek: |
| 201 | + test byte ptr [bp+BIOSFlags], BF_IgnoreSeek ; TEST always clears CF |
| 202 | + jnz return_ok |
| 203 | + mov cx, 082Bh |
| 204 | + jmp I13E_common |
| 205 | + |
| 206 | + org 18D8h |
| 207 | + db "EDD 1.0" |
| 208 | + |
| 209 | +MAIN ENDS |
| 210 | +END |
0 commit comments