[218] | 1 | ; Project name : XTIDE Universal BIOS |
---|
| 2 | ; Description : Functions for preparing data buffer for transfer. |
---|
| 3 | |
---|
[376] | 4 | ; |
---|
[445] | 5 | ; XTIDE Universal BIOS and Associated Tools |
---|
[376] | 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team. |
---|
| 7 | ; |
---|
| 8 | ; This program is free software; you can redistribute it and/or modify |
---|
| 9 | ; it under the terms of the GNU General Public License as published by |
---|
| 10 | ; the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | ; (at your option) any later version. |
---|
[445] | 12 | ; |
---|
[376] | 13 | ; This program is distributed in the hope that it will be useful, |
---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | ; GNU General Public License for more details. |
---|
[445] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 18 | ; |
---|
[376] | 19 | |
---|
[218] | 20 | ; Section containing code |
---|
| 21 | SECTION .text |
---|
| 22 | |
---|
[221] | 23 | ;-------------------------------------------------------------------- |
---|
| 24 | ; Prepare_ByLoadingDapToESSIandVerifyingForTransfer |
---|
| 25 | ; Parameters: |
---|
| 26 | ; SI: Offset to DAP |
---|
| 27 | ; DS:DI: Ptr to DPT |
---|
| 28 | ; SS:BP: Ptr to IDEPACK |
---|
| 29 | ; Parameters on INTPACK: |
---|
| 30 | ; DS:SI: Ptr to Disk Address Packet |
---|
| 31 | ; Returns: |
---|
| 32 | ; BX: Index to command lookup table |
---|
| 33 | ; ES:SI: Ptr to Disk Address Packet (DAP) |
---|
| 34 | ; Exits from INT 13h if invalid DAP |
---|
| 35 | ; Corrupts registers: |
---|
| 36 | ; AX, DX |
---|
| 37 | ;-------------------------------------------------------------------- |
---|
| 38 | %ifdef MODULE_EBIOS |
---|
| 39 | ALIGN JUMP_ALIGN |
---|
| 40 | Prepare_ByLoadingDapToESSIandVerifyingForTransfer: |
---|
| 41 | ; Load pointer to DAP to ES:SI and make sure it is valid |
---|
| 42 | mov es, [bp+IDEPACK.intpack+INTPACK.ds] ; ES:SI to point Disk Address Packet |
---|
| 43 | cmp BYTE [es:si+DAP.bSize], MINIMUM_DAP_SIZE |
---|
| 44 | jb SHORT InvalidDAP |
---|
| 45 | |
---|
| 46 | ; Make sure that sector count is valid |
---|
| 47 | mov ax, [es:si+DAP.wSectorCount] |
---|
| 48 | test ax, ax |
---|
| 49 | jz SHORT ZeroSectorsRequestedSoNoErrors |
---|
| 50 | cmp ax, BYTE 127 |
---|
| 51 | ja SHORT InvalidNumberOfSectorsRequested |
---|
| 52 | |
---|
[294] | 53 | ; Get EBIOS command index to BX |
---|
[221] | 54 | ; LBA28 or LBA48 command |
---|
| 55 | call Prepare_GetOldInt13hCommandIndexToBX |
---|
[421] | 56 | mov al, [di+DPT.bFlagsLow] |
---|
[445] | 57 | eSHL_IM al, 1 ; Set CF if LBA48 supported |
---|
[421] | 58 | adc bl, bh ; LBA48 EXT commands |
---|
[221] | 59 | ret |
---|
[421] | 60 | %endif ; MODULE_EBIOS |
---|
[221] | 61 | |
---|
| 62 | |
---|
| 63 | ;-------------------------------------------------------------------- |
---|
| 64 | ; Prepare_GetOldInt13hCommandIndexToBX |
---|
| 65 | ; Parameters: |
---|
| 66 | ; DS:DI: Ptr to DPT |
---|
| 67 | ; Returns: |
---|
| 68 | ; BX: Index to command lookup table |
---|
| 69 | ; Corrupts registers: |
---|
| 70 | ; Nothing |
---|
| 71 | ;-------------------------------------------------------------------- |
---|
| 72 | ALIGN JUMP_ALIGN |
---|
| 73 | Prepare_GetOldInt13hCommandIndexToBX: |
---|
| 74 | ; Block mode or single sector |
---|
| 75 | mov bl, [di+DPT.bFlagsHigh] |
---|
| 76 | and bx, BYTE FLGH_DPT_BLOCK_MODE_SUPPORTED ; Bit 1 |
---|
| 77 | ret |
---|
| 78 | |
---|
| 79 | |
---|
[218] | 80 | ;--------------------------------------------------------------------- |
---|
[221] | 81 | ; Prepare_BufferToESSIforOldInt13hTransfer |
---|
[218] | 82 | ; Parameters: |
---|
| 83 | ; AL: Number of sectors to transfer |
---|
[474] | 84 | ; DS:DI: Ptr to DPT (in RAMVARS segment) |
---|
[218] | 85 | ; SS:BP: Ptr to IDEPACK |
---|
| 86 | ; Parameters on INTPACK: |
---|
| 87 | ; ES:BX: Ptr to data buffer |
---|
| 88 | ; Returns: |
---|
| 89 | ; ES:SI: Ptr to normalized data buffer |
---|
| 90 | ; Exits INT 13h if error |
---|
| 91 | ; Corrupts registers: |
---|
| 92 | ; BX |
---|
| 93 | ;-------------------------------------------------------------------- |
---|
| 94 | ALIGN JUMP_ALIGN |
---|
[221] | 95 | Prepare_BufferToESSIforOldInt13hTransfer: |
---|
[477] | 96 | mov si, [bp+IDEPACK.intpack+INTPACK.bx] ; Load offset |
---|
| 97 | |
---|
| 98 | %ifdef MODULE_8BIT_IDE |
---|
[474] | 99 | cmp BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_DMA |
---|
| 100 | jne SHORT .NormalizeForSmallestPossibleOffset |
---|
| 101 | |
---|
[477] | 102 | ; DMA transfers do not need to normalize pointer |
---|
| 103 | ; (it will be converted to physical address in IdeDmaTransfer.asm) |
---|
| 104 | mov es, [bp+IDEPACK.intpack+INTPACK.es] |
---|
[474] | 105 | jmp SHORT Prepare_ByValidatingSectorsInALforOldInt13h |
---|
[477] | 106 | %endif ; MODULE_8BIT_IDE |
---|
[474] | 107 | |
---|
| 108 | ; Normalize segment for 16b pages |
---|
| 109 | .NormalizeForSmallestPossibleOffset: |
---|
[477] | 110 | mov bx, si |
---|
[218] | 111 | eSHR_IM bx, 4 ; Divide offset by 16 |
---|
| 112 | add bx, [bp+IDEPACK.intpack+INTPACK.es] |
---|
| 113 | mov es, bx ; Segment normalized |
---|
| 114 | and si, BYTE 0Fh ; Offset normalized |
---|
[221] | 115 | ; Fall to Prepare_ByValidatingSectorsInALforOldInt13h |
---|
[218] | 116 | |
---|
[221] | 117 | |
---|
| 118 | ;--------------------------------------------------------------------- |
---|
| 119 | ; Prepare_ByValidatingSectorsInALforOldInt13h |
---|
| 120 | ; Parameters: |
---|
| 121 | ; AL: Number of sectors to transfer |
---|
| 122 | ; Returns: |
---|
| 123 | ; Exits INT 13h if invalid number of sectors in AL |
---|
| 124 | ; Corrupts registers: |
---|
| 125 | ; Nothing |
---|
| 126 | ;-------------------------------------------------------------------- |
---|
| 127 | Prepare_ByValidatingSectorsInALforOldInt13h: |
---|
[218] | 128 | test al, al |
---|
[221] | 129 | js SHORT .CheckZeroOffsetFor128Sectors ; 128 or more |
---|
| 130 | jz SHORT InvalidNumberOfSectorsRequested ; Zero not allowed for old INT 13h |
---|
[218] | 131 | ret ; Continue with transfer |
---|
| 132 | |
---|
| 133 | ALIGN JUMP_ALIGN |
---|
| 134 | .CheckZeroOffsetFor128Sectors: |
---|
| 135 | cmp al, 128 |
---|
[221] | 136 | ja SHORT InvalidNumberOfSectorsRequested |
---|
[218] | 137 | test si, si ; Offset must be zero to xfer 128 sectors |
---|
[221] | 138 | jnz SHORT CannotAlignPointerProperly |
---|
[218] | 139 | ret ; Continue with transfer |
---|
| 140 | |
---|
[221] | 141 | InvalidDAP: |
---|
| 142 | InvalidNumberOfSectorsRequested: |
---|
| 143 | Prepare_ReturnFromInt13hWithInvalidFunctionError: |
---|
[218] | 144 | mov ah, RET_HD_INVALID |
---|
[322] | 145 | SKIP2B f |
---|
| 146 | CannotAlignPointerProperly: |
---|
| 147 | mov ah, RET_HD_BOUNDARY |
---|
[221] | 148 | ZeroSectorsRequestedSoNoErrors: |
---|
[218] | 149 | jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
| 150 | |
---|
[221] | 151 | |
---|
| 152 | |
---|
| 153 | ; Command lookup tables |
---|
| 154 | g_rgbReadCommandLookup: |
---|
| 155 | db COMMAND_READ_SECTORS ; 00b, CHS or LBA28 single sector |
---|
| 156 | db COMMAND_READ_SECTORS_EXT ; 01b, LBA48 single sector |
---|
| 157 | db COMMAND_READ_MULTIPLE ; 10b, CHS or LBA28 block mode |
---|
[413] | 158 | %ifdef MODULE_EBIOS |
---|
[221] | 159 | db COMMAND_READ_MULTIPLE_EXT ; 11b, LBA48 block mode |
---|
[413] | 160 | %endif |
---|
[221] | 161 | |
---|
| 162 | g_rgbWriteCommandLookup: |
---|
| 163 | db COMMAND_WRITE_SECTORS |
---|
| 164 | db COMMAND_WRITE_SECTORS_EXT |
---|
| 165 | db COMMAND_WRITE_MULTIPLE |
---|
[413] | 166 | %ifdef MODULE_EBIOS |
---|
[221] | 167 | db COMMAND_WRITE_MULTIPLE_EXT |
---|
[413] | 168 | %endif |
---|
[221] | 169 | |
---|
| 170 | g_rgbVerifyCommandLookup: |
---|
| 171 | db COMMAND_VERIFY_SECTORS |
---|
| 172 | db COMMAND_VERIFY_SECTORS_EXT |
---|
| 173 | db COMMAND_VERIFY_SECTORS |
---|
[413] | 174 | %ifdef MODULE_EBIOS |
---|
[221] | 175 | db COMMAND_VERIFY_SECTORS_EXT |
---|
[413] | 176 | %endif |
---|