[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 | |
---|
[294] | 37 | ; Get EBIOS command index to BX |
---|
[221] | 38 | ; LBA28 or LBA48 command |
---|
[294] | 39 | cwd |
---|
[221] | 40 | mov al, [es:si+DAP.qwLBA+3] ; Load LBA48 byte 3 (bits 24...31) |
---|
[294] | 41 | and al, 0F0h ; Clear LBA28 bits 24...27 |
---|
[221] | 42 | or ax, [es:si+DAP.qwLBA+4] ; Set bits from LBA bytes 4 and 5 |
---|
| 43 | cmp dx, ax ; Set CF if any of bits 28...47 set |
---|
| 44 | rcl dx, 1 ; DX = 0 for LBA28, DX = 1 for LBA48 |
---|
| 45 | call Prepare_GetOldInt13hCommandIndexToBX |
---|
| 46 | or bx, dx ; Set block mode / single sector bit |
---|
| 47 | ret |
---|
| 48 | %endif |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | ;-------------------------------------------------------------------- |
---|
| 52 | ; Prepare_GetOldInt13hCommandIndexToBX |
---|
| 53 | ; Parameters: |
---|
| 54 | ; DS:DI: Ptr to DPT |
---|
| 55 | ; Returns: |
---|
| 56 | ; BX: Index to command lookup table |
---|
| 57 | ; Corrupts registers: |
---|
| 58 | ; Nothing |
---|
| 59 | ;-------------------------------------------------------------------- |
---|
| 60 | ALIGN JUMP_ALIGN |
---|
| 61 | Prepare_GetOldInt13hCommandIndexToBX: |
---|
| 62 | ; Block mode or single sector |
---|
| 63 | mov bl, [di+DPT.bFlagsHigh] |
---|
| 64 | and bx, BYTE FLGH_DPT_BLOCK_MODE_SUPPORTED ; Bit 1 |
---|
| 65 | ret |
---|
| 66 | |
---|
| 67 | |
---|
[218] | 68 | ;--------------------------------------------------------------------- |
---|
[221] | 69 | ; Prepare_BufferToESSIforOldInt13hTransfer |
---|
[218] | 70 | ; Parameters: |
---|
| 71 | ; AL: Number of sectors to transfer |
---|
| 72 | ; SS:BP: Ptr to IDEPACK |
---|
| 73 | ; Parameters on INTPACK: |
---|
| 74 | ; ES:BX: Ptr to data buffer |
---|
| 75 | ; Returns: |
---|
| 76 | ; ES:SI: Ptr to normalized data buffer |
---|
| 77 | ; Exits INT 13h if error |
---|
| 78 | ; Corrupts registers: |
---|
| 79 | ; BX |
---|
| 80 | ;-------------------------------------------------------------------- |
---|
| 81 | ALIGN JUMP_ALIGN |
---|
[221] | 82 | Prepare_BufferToESSIforOldInt13hTransfer: |
---|
[218] | 83 | ; Normalize buffer pointer |
---|
| 84 | mov bx, [bp+IDEPACK.intpack+INTPACK.bx] ; Load offset |
---|
| 85 | mov si, bx |
---|
| 86 | eSHR_IM bx, 4 ; Divide offset by 16 |
---|
| 87 | add bx, [bp+IDEPACK.intpack+INTPACK.es] |
---|
| 88 | mov es, bx ; Segment normalized |
---|
| 89 | and si, BYTE 0Fh ; Offset normalized |
---|
[221] | 90 | ; Fall to Prepare_ByValidatingSectorsInALforOldInt13h |
---|
[218] | 91 | |
---|
[221] | 92 | |
---|
| 93 | ;--------------------------------------------------------------------- |
---|
| 94 | ; Prepare_ByValidatingSectorsInALforOldInt13h |
---|
| 95 | ; Parameters: |
---|
| 96 | ; AL: Number of sectors to transfer |
---|
| 97 | ; Returns: |
---|
| 98 | ; Exits INT 13h if invalid number of sectors in AL |
---|
| 99 | ; Corrupts registers: |
---|
| 100 | ; Nothing |
---|
| 101 | ;-------------------------------------------------------------------- |
---|
| 102 | ALIGN JUMP_ALIGN |
---|
| 103 | Prepare_ByValidatingSectorsInALforOldInt13h: |
---|
[218] | 104 | test al, al |
---|
[221] | 105 | js SHORT .CheckZeroOffsetFor128Sectors ; 128 or more |
---|
| 106 | jz SHORT InvalidNumberOfSectorsRequested ; Zero not allowed for old INT 13h |
---|
[218] | 107 | ret ; Continue with transfer |
---|
| 108 | |
---|
| 109 | ALIGN JUMP_ALIGN |
---|
| 110 | .CheckZeroOffsetFor128Sectors: |
---|
| 111 | cmp al, 128 |
---|
[221] | 112 | ja SHORT InvalidNumberOfSectorsRequested |
---|
[218] | 113 | mov ah, RET_HD_BOUNDARY |
---|
| 114 | test si, si ; Offset must be zero to xfer 128 sectors |
---|
[221] | 115 | jnz SHORT CannotAlignPointerProperly |
---|
[218] | 116 | ret ; Continue with transfer |
---|
| 117 | |
---|
[221] | 118 | InvalidDAP: |
---|
| 119 | InvalidNumberOfSectorsRequested: |
---|
| 120 | Prepare_ReturnFromInt13hWithInvalidFunctionError: |
---|
[218] | 121 | mov ah, RET_HD_INVALID |
---|
[221] | 122 | ZeroSectorsRequestedSoNoErrors: |
---|
| 123 | CannotAlignPointerProperly: |
---|
[218] | 124 | jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
| 125 | |
---|
[221] | 126 | |
---|
| 127 | |
---|
| 128 | ; Command lookup tables |
---|
| 129 | g_rgbReadCommandLookup: |
---|
| 130 | db COMMAND_READ_SECTORS ; 00b, CHS or LBA28 single sector |
---|
| 131 | db COMMAND_READ_SECTORS_EXT ; 01b, LBA48 single sector |
---|
| 132 | db COMMAND_READ_MULTIPLE ; 10b, CHS or LBA28 block mode |
---|
| 133 | db COMMAND_READ_MULTIPLE_EXT ; 11b, LBA48 block mode |
---|
| 134 | |
---|
| 135 | g_rgbWriteCommandLookup: |
---|
| 136 | db COMMAND_WRITE_SECTORS |
---|
| 137 | db COMMAND_WRITE_SECTORS_EXT |
---|
| 138 | db COMMAND_WRITE_MULTIPLE |
---|
| 139 | db COMMAND_WRITE_MULTIPLE_EXT |
---|
| 140 | |
---|
| 141 | g_rgbVerifyCommandLookup: |
---|
| 142 | db COMMAND_VERIFY_SECTORS |
---|
| 143 | db COMMAND_VERIFY_SECTORS_EXT |
---|
| 144 | db COMMAND_VERIFY_SECTORS |
---|
| 145 | db COMMAND_VERIFY_SECTORS_EXT |
---|