1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : Functions for preparing data buffer for transfer.
|
---|
3 |
|
---|
4 | ; Section containing code
|
---|
5 | SECTION .text
|
---|
6 |
|
---|
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 |
|
---|
37 | ; Get EBIOS command index to BX
|
---|
38 | ; LBA28 or LBA48 command
|
---|
39 | cwd
|
---|
40 | mov al, [es:si+DAP.qwLBA+3] ; Load LBA48 byte 3 (bits 24...31)
|
---|
41 | and al, 0F0h ; Clear LBA28 bits 24...27
|
---|
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 |
|
---|
68 | ;---------------------------------------------------------------------
|
---|
69 | ; Prepare_BufferToESSIforOldInt13hTransfer
|
---|
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
|
---|
82 | Prepare_BufferToESSIforOldInt13hTransfer:
|
---|
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
|
---|
90 | ; Fall to Prepare_ByValidatingSectorsInALforOldInt13h
|
---|
91 |
|
---|
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:
|
---|
104 | test al, al
|
---|
105 | js SHORT .CheckZeroOffsetFor128Sectors ; 128 or more
|
---|
106 | jz SHORT InvalidNumberOfSectorsRequested ; Zero not allowed for old INT 13h
|
---|
107 | ret ; Continue with transfer
|
---|
108 |
|
---|
109 | ALIGN JUMP_ALIGN
|
---|
110 | .CheckZeroOffsetFor128Sectors:
|
---|
111 | cmp al, 128
|
---|
112 | ja SHORT InvalidNumberOfSectorsRequested
|
---|
113 | test si, si ; Offset must be zero to xfer 128 sectors
|
---|
114 | jnz SHORT CannotAlignPointerProperly
|
---|
115 | ret ; Continue with transfer
|
---|
116 |
|
---|
117 | InvalidDAP:
|
---|
118 | InvalidNumberOfSectorsRequested:
|
---|
119 | Prepare_ReturnFromInt13hWithInvalidFunctionError:
|
---|
120 | mov ah, RET_HD_INVALID
|
---|
121 | SKIP2B f
|
---|
122 | CannotAlignPointerProperly:
|
---|
123 | mov ah, RET_HD_BOUNDARY
|
---|
124 | ZeroSectorsRequestedSoNoErrors:
|
---|
125 | jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
|
---|
126 |
|
---|
127 |
|
---|
128 |
|
---|
129 | ; Command lookup tables
|
---|
130 | g_rgbReadCommandLookup:
|
---|
131 | db COMMAND_READ_SECTORS ; 00b, CHS or LBA28 single sector
|
---|
132 | db COMMAND_READ_SECTORS_EXT ; 01b, LBA48 single sector
|
---|
133 | db COMMAND_READ_MULTIPLE ; 10b, CHS or LBA28 block mode
|
---|
134 | db COMMAND_READ_MULTIPLE_EXT ; 11b, LBA48 block mode
|
---|
135 |
|
---|
136 | g_rgbWriteCommandLookup:
|
---|
137 | db COMMAND_WRITE_SECTORS
|
---|
138 | db COMMAND_WRITE_SECTORS_EXT
|
---|
139 | db COMMAND_WRITE_MULTIPLE
|
---|
140 | db COMMAND_WRITE_MULTIPLE_EXT
|
---|
141 |
|
---|
142 | g_rgbVerifyCommandLookup:
|
---|
143 | db COMMAND_VERIFY_SECTORS
|
---|
144 | db COMMAND_VERIFY_SECTORS_EXT
|
---|
145 | db COMMAND_VERIFY_SECTORS
|
---|
146 | db COMMAND_VERIFY_SECTORS_EXT
|
---|