[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
|
---|
[526] | 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[376] | 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
|
---|
[547] | 47 | mov al, [es:si+DAP.wSectorCount]
|
---|
| 48 | test al, al
|
---|
| 49 | jz SHORT ZeroSectorsRequestedSoNoErrors
|
---|
| 50 | js SHORT InvalidNumberOfSectorsRequested
|
---|
| 51 |
|
---|
| 52 | %if 0 ; Slow version in the unlikely case that high byte needs to be checked.
|
---|
[221] | 53 | mov ax, [es:si+DAP.wSectorCount]
|
---|
| 54 | test ax, ax
|
---|
| 55 | jz SHORT ZeroSectorsRequestedSoNoErrors
|
---|
| 56 | cmp ax, BYTE 127
|
---|
| 57 | ja SHORT InvalidNumberOfSectorsRequested
|
---|
[547] | 58 | %endif
|
---|
[221] | 59 |
|
---|
[294] | 60 | ; Get EBIOS command index to BX
|
---|
[221] | 61 | ; LBA28 or LBA48 command
|
---|
| 62 | call Prepare_GetOldInt13hCommandIndexToBX
|
---|
[421] | 63 | mov al, [di+DPT.bFlagsLow]
|
---|
[547] | 64 | shl al, 1 ; Set CF if LBA48 supported
|
---|
[421] | 65 | adc bl, bh ; LBA48 EXT commands
|
---|
[221] | 66 | ret
|
---|
[421] | 67 | %endif ; MODULE_EBIOS
|
---|
[221] | 68 |
|
---|
| 69 |
|
---|
| 70 | ;--------------------------------------------------------------------
|
---|
| 71 | ; Prepare_GetOldInt13hCommandIndexToBX
|
---|
| 72 | ; Parameters:
|
---|
| 73 | ; DS:DI: Ptr to DPT
|
---|
| 74 | ; Returns:
|
---|
| 75 | ; BX: Index to command lookup table
|
---|
| 76 | ; Corrupts registers:
|
---|
| 77 | ; Nothing
|
---|
| 78 | ;--------------------------------------------------------------------
|
---|
| 79 | ALIGN JUMP_ALIGN
|
---|
| 80 | Prepare_GetOldInt13hCommandIndexToBX:
|
---|
| 81 | ; Block mode or single sector
|
---|
| 82 | mov bl, [di+DPT.bFlagsHigh]
|
---|
[550] | 83 | and bx, BYTE FLGH_DPT_USE_BLOCK_MODE_COMMANDS ; Bit 1
|
---|
[221] | 84 | ret
|
---|
| 85 |
|
---|
| 86 |
|
---|
[218] | 87 | ;---------------------------------------------------------------------
|
---|
[221] | 88 | ; Prepare_BufferToESSIforOldInt13hTransfer
|
---|
[218] | 89 | ; Parameters:
|
---|
| 90 | ; AL: Number of sectors to transfer
|
---|
[474] | 91 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
[218] | 92 | ; SS:BP: Ptr to IDEPACK
|
---|
| 93 | ; Parameters on INTPACK:
|
---|
| 94 | ; ES:BX: Ptr to data buffer
|
---|
| 95 | ; Returns:
|
---|
| 96 | ; ES:SI: Ptr to normalized data buffer
|
---|
| 97 | ; Exits INT 13h if error
|
---|
| 98 | ; Corrupts registers:
|
---|
| 99 | ; BX
|
---|
| 100 | ;--------------------------------------------------------------------
|
---|
| 101 | ALIGN JUMP_ALIGN
|
---|
[221] | 102 | Prepare_BufferToESSIforOldInt13hTransfer:
|
---|
[477] | 103 | mov si, [bp+IDEPACK.intpack+INTPACK.bx] ; Load offset
|
---|
[480] | 104 | mov es, [bp+IDEPACK.intpack+INTPACK.es] ; Load segment
|
---|
[221] | 105 | ; Fall to Prepare_ByValidatingSectorsInALforOldInt13h
|
---|
[218] | 106 |
|
---|
[221] | 107 | ;---------------------------------------------------------------------
|
---|
| 108 | ; Prepare_ByValidatingSectorsInALforOldInt13h
|
---|
| 109 | ; Parameters:
|
---|
| 110 | ; AL: Number of sectors to transfer
|
---|
| 111 | ; Returns:
|
---|
| 112 | ; Exits INT 13h if invalid number of sectors in AL
|
---|
| 113 | ; Corrupts registers:
|
---|
| 114 | ; Nothing
|
---|
| 115 | ;--------------------------------------------------------------------
|
---|
| 116 | Prepare_ByValidatingSectorsInALforOldInt13h:
|
---|
[218] | 117 | test al, al
|
---|
[221] | 118 | js SHORT .CheckZeroOffsetFor128Sectors ; 128 or more
|
---|
| 119 | jz SHORT InvalidNumberOfSectorsRequested ; Zero not allowed for old INT 13h
|
---|
[218] | 120 | ret ; Continue with transfer
|
---|
| 121 |
|
---|
| 122 | ALIGN JUMP_ALIGN
|
---|
| 123 | .CheckZeroOffsetFor128Sectors:
|
---|
| 124 | cmp al, 128
|
---|
[221] | 125 | ja SHORT InvalidNumberOfSectorsRequested
|
---|
[218] | 126 | test si, si ; Offset must be zero to xfer 128 sectors
|
---|
[221] | 127 | jnz SHORT CannotAlignPointerProperly
|
---|
[218] | 128 | ret ; Continue with transfer
|
---|
| 129 |
|
---|
[221] | 130 | InvalidDAP:
|
---|
| 131 | InvalidNumberOfSectorsRequested:
|
---|
| 132 | Prepare_ReturnFromInt13hWithInvalidFunctionError:
|
---|
[218] | 133 | mov ah, RET_HD_INVALID
|
---|
[322] | 134 | SKIP2B f
|
---|
| 135 | CannotAlignPointerProperly:
|
---|
| 136 | mov ah, RET_HD_BOUNDARY
|
---|
[221] | 137 | ZeroSectorsRequestedSoNoErrors:
|
---|
[218] | 138 | jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
|
---|
| 139 |
|
---|
[221] | 140 |
|
---|
| 141 |
|
---|
| 142 | ; Command lookup tables
|
---|
| 143 | g_rgbReadCommandLookup:
|
---|
| 144 | db COMMAND_READ_SECTORS ; 00b, CHS or LBA28 single sector
|
---|
| 145 | db COMMAND_READ_SECTORS_EXT ; 01b, LBA48 single sector
|
---|
| 146 | db COMMAND_READ_MULTIPLE ; 10b, CHS or LBA28 block mode
|
---|
[413] | 147 | %ifdef MODULE_EBIOS
|
---|
[221] | 148 | db COMMAND_READ_MULTIPLE_EXT ; 11b, LBA48 block mode
|
---|
[413] | 149 | %endif
|
---|
[221] | 150 |
|
---|
| 151 | g_rgbWriteCommandLookup:
|
---|
| 152 | db COMMAND_WRITE_SECTORS
|
---|
| 153 | db COMMAND_WRITE_SECTORS_EXT
|
---|
| 154 | db COMMAND_WRITE_MULTIPLE
|
---|
[413] | 155 | %ifdef MODULE_EBIOS
|
---|
[221] | 156 | db COMMAND_WRITE_MULTIPLE_EXT
|
---|
[413] | 157 | %endif
|
---|
[221] | 158 |
|
---|
| 159 | g_rgbVerifyCommandLookup:
|
---|
| 160 | db COMMAND_VERIFY_SECTORS
|
---|
| 161 | db COMMAND_VERIFY_SECTORS_EXT
|
---|
| 162 | db COMMAND_VERIFY_SECTORS
|
---|
[413] | 163 | %ifdef MODULE_EBIOS
|
---|
[221] | 164 | db COMMAND_VERIFY_SECTORS_EXT
|
---|
[413] | 165 | %endif
|
---|