1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : Functions for managing IDEPACK struct.
|
---|
3 |
|
---|
4 | ;
|
---|
5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
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.
|
---|
12 | ;
|
---|
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.
|
---|
17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
18 | ;
|
---|
19 |
|
---|
20 | ; Section containing code
|
---|
21 | SECTION .text
|
---|
22 |
|
---|
23 | ;--------------------------------------------------------------------
|
---|
24 | ; Idepack_FakeToSSBP
|
---|
25 | ; Parameters:
|
---|
26 | ; Nothing
|
---|
27 | ; Returns:
|
---|
28 | ; SS:BP: Ptr to IDEPACK
|
---|
29 | ; Corrupts registers:
|
---|
30 | ; AX
|
---|
31 | ;--------------------------------------------------------------------
|
---|
32 | Idepack_FakeToSSBP:
|
---|
33 | pop ax
|
---|
34 | sub sp, BYTE EXTRA_BYTES_FOR_INTPACK
|
---|
35 | mov bp, sp
|
---|
36 | jmp ax
|
---|
37 |
|
---|
38 |
|
---|
39 | ;--------------------------------------------------------------------
|
---|
40 | ; Idepack_ConvertDapToIdepackAndIssueCommandFromAH
|
---|
41 | ; Parameters:
|
---|
42 | ; AH: IDE command to issue
|
---|
43 | ; BH: Timeout ticks
|
---|
44 | ; BL: IDE Status Register flag to wait after command
|
---|
45 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
46 | ; ES:SI: Ptr to DAP (EBIOS Disk Address Packet)
|
---|
47 | ; SS:BP: Ptr to IDEPACK
|
---|
48 | ; Returns:
|
---|
49 | ; AH: INT 13h Error Code
|
---|
50 | ; CX: Number of successfully transferred sectors (for transfer commands)
|
---|
51 | ; CF: Cleared if success, Set if error
|
---|
52 | ; Corrupts registers:
|
---|
53 | ; AL, BX, (CX), DX, SI, ES
|
---|
54 | ;--------------------------------------------------------------------
|
---|
55 | %ifdef MODULE_EBIOS
|
---|
56 | ALIGN JUMP_ALIGN
|
---|
57 | Idepack_ConvertDapToIdepackAndIssueCommandFromAH:
|
---|
58 | mov al, [es:si+DAP.wSectorCount]
|
---|
59 | mov [bp+IDEPACK.bSectorCount], al
|
---|
60 | mov [bp+IDEPACK.bCommand], ah
|
---|
61 |
|
---|
62 | mov al, [es:si+DAP.qwLBA] ; LBA byte 0
|
---|
63 | mov [bp+IDEPACK.bLbaLow], al
|
---|
64 | mov ax, [es:si+DAP.qwLBA+1] ; LBA bytes 1 and 2
|
---|
65 | mov [bp+IDEPACK.wLbaMiddleAndHigh], ax
|
---|
66 | mov ah, [es:si+DAP.qwLBA+3] ; LBA byte 3, LBA28 bits 24...27
|
---|
67 | mov [bp+IDEPACK.bLbaLowExt], ah
|
---|
68 | mov cx, [es:si+DAP.qwLBA+4] ; LBA bytes 4 and 5
|
---|
69 | mov [bp+IDEPACK.wLbaMiddleAndHighExt], cx
|
---|
70 |
|
---|
71 | and ah, 0Fh ; Limit bits for LBA28
|
---|
72 | call AccessDPT_GetDriveSelectByteToAL
|
---|
73 | or al, ah
|
---|
74 | mov [bp+IDEPACK.bDrvAndHead], al
|
---|
75 |
|
---|
76 | ; Normalize data buffer pointer to ES:SI
|
---|
77 | mov ax, [es:si+DAP.wOffset]
|
---|
78 | mov cx, ax
|
---|
79 | eSHR_IM ax, 4 ; Divide offset by 16
|
---|
80 | add ax, [es:si+DAP.wSegment] ; Add segment
|
---|
81 | mov es, ax ; Segment normalized
|
---|
82 | mov si, cx
|
---|
83 | and si, BYTE 0Fh ; Offset normalized
|
---|
84 | jmp SHORT GetDeviceControlByteToIdepackAndStartTransfer
|
---|
85 | %endif
|
---|
86 |
|
---|
87 |
|
---|
88 | ;--------------------------------------------------------------------
|
---|
89 | ; Idepack_TranslateOldInt13hAddressAndIssueCommandFromAH
|
---|
90 | ; Parameters:
|
---|
91 | ; AH: IDE command to issue
|
---|
92 | ; AL: Number of sectors to transfer (for xfer commands)
|
---|
93 | ; BH: Timeout ticks
|
---|
94 | ; BL: IDE Status Register flag to wait after command
|
---|
95 | ; CH: Cylinder number, bits 7...0
|
---|
96 | ; CL: Bits 7...6: Cylinder number bits 9 and 8
|
---|
97 | ; Bits 5...0: Starting sector number (1...63)
|
---|
98 | ; DH: Starting head number (0...255)
|
---|
99 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
100 | ; ES:SI: Ptr to normalized data buffer (for xfer commands)
|
---|
101 | ; SS:BP: Ptr to IDEPACK (containing INTPACK)
|
---|
102 | ; Returns:
|
---|
103 | ; AH: INT 13h Error Code
|
---|
104 | ; CX: Number of successfully transferred sectors (for transfer commands)
|
---|
105 | ; CF: Cleared if success, Set if error
|
---|
106 | ; Corrupts registers:
|
---|
107 | ; AL, BX, (CX), DX
|
---|
108 | ;--------------------------------------------------------------------
|
---|
109 | ALIGN JUMP_ALIGN
|
---|
110 | Idepack_TranslateOldInt13hAddressAndIssueCommandFromAH:
|
---|
111 | mov [bp+IDEPACK.bSectorCount], al
|
---|
112 | mov [bp+IDEPACK.bCommand], ah
|
---|
113 |
|
---|
114 | push bx
|
---|
115 | call Address_OldInt13hAddressToIdeAddress
|
---|
116 | call AccessDPT_GetDriveSelectByteToAL
|
---|
117 | or al, bh ; AL now has Drive and Head Select Byte
|
---|
118 | mov [bp+IDEPACK.bDrvAndHead], al
|
---|
119 | mov [bp+IDEPACK.bLbaLow], bl
|
---|
120 | mov [bp+IDEPACK.wLbaMiddleAndHigh], cx
|
---|
121 | pop bx
|
---|
122 |
|
---|
123 | GetDeviceControlByteToIdepackAndStartTransfer:
|
---|
124 | call AccessDPT_GetDeviceControlByteToAL
|
---|
125 | mov [bp+IDEPACK.bDeviceControl], al
|
---|
126 | jmp Device_OutputCommandWithParameters
|
---|
127 |
|
---|
128 |
|
---|
129 | ;--------------------------------------------------------------------
|
---|
130 | ; Idepack_StoreNonExtParametersAndIssueCommandFromAL
|
---|
131 | ; Parameters:
|
---|
132 | ; BH: Timeout ticks
|
---|
133 | ; BL: IDE Status Register flag to wait after command
|
---|
134 | ; AL: IDE command to issue
|
---|
135 | ; AH: Parameter to Drive and Head Select Register (Head bits only)
|
---|
136 | ; DL: Parameter to Sector Count Register
|
---|
137 | ; DH: Parameter to LBA Low / Sector Number Register
|
---|
138 | ; CL: Parameter to LBA Middle / Cylinder Low Register
|
---|
139 | ; CH: Parameter to LBA High / Cylinder High Register
|
---|
140 | ; SI: Parameter to Features Register
|
---|
141 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
142 | ; SS:BP: Ptr to IDEPACK
|
---|
143 | ; Returns:
|
---|
144 | ; AH: INT 13h Error Code
|
---|
145 | ; CF: Cleared if success, Set if error
|
---|
146 | ; Corrupts registers:
|
---|
147 | ; AL, BX, CX, DX
|
---|
148 | ;--------------------------------------------------------------------
|
---|
149 | ALIGN JUMP_ALIGN
|
---|
150 | Idepack_StoreNonExtParametersAndIssueCommandFromAL:
|
---|
151 | mov [bp+IDEPACK.bFeatures], si
|
---|
152 | mov [bp+IDEPACK.bCommand], al
|
---|
153 | mov [bp+IDEPACK.wSectorCountAndLbaLow], dx
|
---|
154 | mov [bp+IDEPACK.wLbaMiddleAndHigh], cx
|
---|
155 |
|
---|
156 | ; Drive and Head select byte
|
---|
157 | and ah, MASK_DRVNHEAD_HEAD ; Keep head bits only
|
---|
158 | call AccessDPT_GetDriveSelectByteToAL
|
---|
159 | or al, ah
|
---|
160 | mov [bp+IDEPACK.bDrvAndHead], al
|
---|
161 |
|
---|
162 | ; Device Control byte with interrupts disabled
|
---|
163 | call AccessDPT_GetDeviceControlByteToAL
|
---|
164 | or al, FLG_DEVCONTROL_nIEN ; Disable interrupt
|
---|
165 | mov [bp+IDEPACK.bDeviceControl], al
|
---|
166 |
|
---|
167 | jmp Device_OutputCommandWithParameters
|
---|