[218] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
| 2 | ; Description : Functions for preparing data buffer for transfer.
|
---|
| 3 |
|
---|
| 4 | ; Section containing code
|
---|
| 5 | SECTION .text
|
---|
| 6 |
|
---|
[221] | 7 | ;--------------------------------------------------------------------
|
---|
| 8 | ; Prepare_ByLoadingDapToESSIandVerifyingForTransfer
|
---|
| 9 | ; Parameters:
|
---|
| 10 | ; SI: Offset to DAP
|
---|
| 11 | ; DS:DI: Ptr to DPT
|
---|
| 12 | ; SS:BP: Ptr to IDEPACK
|
---|
| 13 | ; Parameters on INTPACK:
|
---|
| 14 | ; DS:SI: Ptr to Disk Address Packet
|
---|
| 15 | ; Returns:
|
---|
| 16 | ; BX: Index to command lookup table
|
---|
| 17 | ; ES:SI: Ptr to Disk Address Packet (DAP)
|
---|
| 18 | ; Exits from INT 13h if invalid DAP
|
---|
| 19 | ; Corrupts registers:
|
---|
| 20 | ; AX, DX
|
---|
| 21 | ;--------------------------------------------------------------------
|
---|
| 22 | %ifdef MODULE_EBIOS
|
---|
| 23 | ALIGN JUMP_ALIGN
|
---|
| 24 | Prepare_ByLoadingDapToESSIandVerifyingForTransfer:
|
---|
| 25 | ; Load pointer to DAP to ES:SI and make sure it is valid
|
---|
| 26 | mov es, [bp+IDEPACK.intpack+INTPACK.ds] ; ES:SI to point Disk Address Packet
|
---|
| 27 | cmp BYTE [es:si+DAP.bSize], MINIMUM_DAP_SIZE
|
---|
| 28 | jb SHORT InvalidDAP
|
---|
| 29 |
|
---|
| 30 | ; Make sure that sector count is valid
|
---|
| 31 | mov ax, [es:si+DAP.wSectorCount]
|
---|
| 32 | test ax, ax
|
---|
| 33 | jz SHORT ZeroSectorsRequestedSoNoErrors
|
---|
| 34 | cmp ax, BYTE 127
|
---|
| 35 | ja SHORT InvalidNumberOfSectorsRequested
|
---|
| 36 | ; Fall to GetEbiosCommandIndexToBX
|
---|
| 37 |
|
---|
| 38 | ;--------------------------------------------------------------------
|
---|
| 39 | ; GetEbiosCommandIndexToBX
|
---|
| 40 | ; Parameters:
|
---|
| 41 | ; DS:DI: Ptr to DPT
|
---|
| 42 | ; ES:SI: Ptr to DAP (Disk Address Packet)
|
---|
| 43 | ; Returns:
|
---|
| 44 | ; BX: Index to command lookup table
|
---|
| 45 | ; Corrupts registers:
|
---|
| 46 | ; AX, DX
|
---|
| 47 | ;--------------------------------------------------------------------
|
---|
| 48 | GetEbiosCommandIndexToBX:
|
---|
| 49 | ; LBA28 or LBA48 command
|
---|
| 50 | xor dx, dx
|
---|
| 51 | mov al, [es:si+DAP.qwLBA+3] ; Load LBA48 byte 3 (bits 24...31)
|
---|
| 52 | and ax, 00F0h ; Clear LBA28 bits 24...27
|
---|
| 53 | or ax, [es:si+DAP.qwLBA+4] ; Set bits from LBA bytes 4 and 5
|
---|
| 54 | cmp dx, ax ; Set CF if any of bits 28...47 set
|
---|
| 55 | rcl dx, 1 ; DX = 0 for LBA28, DX = 1 for LBA48
|
---|
| 56 | call Prepare_GetOldInt13hCommandIndexToBX
|
---|
| 57 | or bx, dx ; Set block mode / single sector bit
|
---|
| 58 | ret
|
---|
| 59 | %endif
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | ;--------------------------------------------------------------------
|
---|
| 63 | ; Prepare_GetOldInt13hCommandIndexToBX
|
---|
| 64 | ; Parameters:
|
---|
| 65 | ; DS:DI: Ptr to DPT
|
---|
| 66 | ; Returns:
|
---|
| 67 | ; BX: Index to command lookup table
|
---|
| 68 | ; Corrupts registers:
|
---|
| 69 | ; Nothing
|
---|
| 70 | ;--------------------------------------------------------------------
|
---|
| 71 | ALIGN JUMP_ALIGN
|
---|
| 72 | Prepare_GetOldInt13hCommandIndexToBX:
|
---|
| 73 | ; Block mode or single sector
|
---|
| 74 | mov bl, [di+DPT.bFlagsHigh]
|
---|
| 75 | and bx, BYTE FLGH_DPT_BLOCK_MODE_SUPPORTED ; Bit 1
|
---|
| 76 | ret
|
---|
| 77 |
|
---|
| 78 |
|
---|
[218] | 79 | ;---------------------------------------------------------------------
|
---|
[221] | 80 | ; Prepare_BufferToESSIforOldInt13hTransfer
|
---|
[218] | 81 | ; Parameters:
|
---|
| 82 | ; AL: Number of sectors to transfer
|
---|
| 83 | ; SS:BP: Ptr to IDEPACK
|
---|
| 84 | ; Parameters on INTPACK:
|
---|
| 85 | ; ES:BX: Ptr to data buffer
|
---|
| 86 | ; Returns:
|
---|
| 87 | ; ES:SI: Ptr to normalized data buffer
|
---|
| 88 | ; Exits INT 13h if error
|
---|
| 89 | ; Corrupts registers:
|
---|
| 90 | ; BX
|
---|
| 91 | ;--------------------------------------------------------------------
|
---|
| 92 | ALIGN JUMP_ALIGN
|
---|
[221] | 93 | Prepare_BufferToESSIforOldInt13hTransfer:
|
---|
[218] | 94 | ; Normalize buffer pointer
|
---|
| 95 | mov bx, [bp+IDEPACK.intpack+INTPACK.bx] ; Load offset
|
---|
| 96 | mov si, bx
|
---|
| 97 | eSHR_IM bx, 4 ; Divide offset by 16
|
---|
| 98 | add bx, [bp+IDEPACK.intpack+INTPACK.es]
|
---|
| 99 | mov es, bx ; Segment normalized
|
---|
| 100 | and si, BYTE 0Fh ; Offset normalized
|
---|
[221] | 101 | ; Fall to Prepare_ByValidatingSectorsInALforOldInt13h
|
---|
[218] | 102 |
|
---|
[221] | 103 |
|
---|
| 104 | ;---------------------------------------------------------------------
|
---|
| 105 | ; Prepare_ByValidatingSectorsInALforOldInt13h
|
---|
| 106 | ; Parameters:
|
---|
| 107 | ; AL: Number of sectors to transfer
|
---|
| 108 | ; Returns:
|
---|
| 109 | ; Exits INT 13h if invalid number of sectors in AL
|
---|
| 110 | ; Corrupts registers:
|
---|
| 111 | ; Nothing
|
---|
| 112 | ;--------------------------------------------------------------------
|
---|
| 113 | ALIGN JUMP_ALIGN
|
---|
| 114 | Prepare_ByValidatingSectorsInALforOldInt13h:
|
---|
[218] | 115 | test al, al
|
---|
[221] | 116 | js SHORT .CheckZeroOffsetFor128Sectors ; 128 or more
|
---|
| 117 | jz SHORT InvalidNumberOfSectorsRequested ; Zero not allowed for old INT 13h
|
---|
[218] | 118 | ret ; Continue with transfer
|
---|
| 119 |
|
---|
| 120 | ALIGN JUMP_ALIGN
|
---|
| 121 | .CheckZeroOffsetFor128Sectors:
|
---|
| 122 | cmp al, 128
|
---|
[221] | 123 | ja SHORT InvalidNumberOfSectorsRequested
|
---|
[218] | 124 | mov ah, RET_HD_BOUNDARY
|
---|
| 125 | test si, si ; Offset must be zero to xfer 128 sectors
|
---|
[221] | 126 | jnz SHORT CannotAlignPointerProperly
|
---|
[218] | 127 | ret ; Continue with transfer
|
---|
| 128 |
|
---|
[221] | 129 | InvalidDAP:
|
---|
| 130 | InvalidNumberOfSectorsRequested:
|
---|
| 131 | Prepare_ReturnFromInt13hWithInvalidFunctionError:
|
---|
[218] | 132 | mov ah, RET_HD_INVALID
|
---|
[221] | 133 | ZeroSectorsRequestedSoNoErrors:
|
---|
| 134 | CannotAlignPointerProperly:
|
---|
[218] | 135 | jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
|
---|
| 136 |
|
---|
[221] | 137 |
|
---|
| 138 |
|
---|
| 139 | ; Command lookup tables
|
---|
| 140 | g_rgbReadCommandLookup:
|
---|
| 141 | db COMMAND_READ_SECTORS ; 00b, CHS or LBA28 single sector
|
---|
| 142 | db COMMAND_READ_SECTORS_EXT ; 01b, LBA48 single sector
|
---|
| 143 | db COMMAND_READ_MULTIPLE ; 10b, CHS or LBA28 block mode
|
---|
| 144 | db COMMAND_READ_MULTIPLE_EXT ; 11b, LBA48 block mode
|
---|
| 145 |
|
---|
| 146 | g_rgbWriteCommandLookup:
|
---|
| 147 | db COMMAND_WRITE_SECTORS
|
---|
| 148 | db COMMAND_WRITE_SECTORS_EXT
|
---|
| 149 | db COMMAND_WRITE_MULTIPLE
|
---|
| 150 | db COMMAND_WRITE_MULTIPLE_EXT
|
---|
| 151 |
|
---|
| 152 | g_rgbVerifyCommandLookup:
|
---|
| 153 | db COMMAND_VERIFY_SECTORS
|
---|
| 154 | db COMMAND_VERIFY_SECTORS_EXT
|
---|
| 155 | db COMMAND_VERIFY_SECTORS
|
---|
| 156 | db COMMAND_VERIFY_SECTORS_EXT
|
---|