1 | ; $Id: bs3-mode-DiskRead.asm 102181 2023-11-21 09:45:40Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3DiskRead
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2021-2023 Oracle and/or its affiliates.
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox base platform packages, as
|
---|
10 | ; available from https://www.virtualbox.org.
|
---|
11 | ;
|
---|
12 | ; This program is free software; you can redistribute it and/or
|
---|
13 | ; modify it under the terms of the GNU General Public License
|
---|
14 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
15 | ; License.
|
---|
16 | ;
|
---|
17 | ; This program is distributed in the hope that it will be useful, but
|
---|
18 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | ; General Public License for more details.
|
---|
21 | ;
|
---|
22 | ; You should have received a copy of the GNU General Public License
|
---|
23 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | ;
|
---|
25 | ; The contents of this file may alternatively be used under the terms
|
---|
26 | ; of the Common Development and Distribution License Version 1.0
|
---|
27 | ; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | ; in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | ; CDDL are applicable instead of those of the GPL.
|
---|
30 | ;
|
---|
31 | ; You may elect to license modified versions of this file under the
|
---|
32 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | ;
|
---|
34 | ; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | ;
|
---|
36 |
|
---|
37 | ;*********************************************************************************************************************************
|
---|
38 | ;* Header Files *
|
---|
39 | ;*********************************************************************************************************************************
|
---|
40 | %include "bs3kit-template-header.mac"
|
---|
41 |
|
---|
42 |
|
---|
43 | ;*********************************************************************************************************************************
|
---|
44 | ;* External symbols *
|
---|
45 | ;*********************************************************************************************************************************
|
---|
46 | TMPL_BEGIN_TEXT
|
---|
47 | extern TMPL_NM(Bs3SwitchToRM)
|
---|
48 | BS3_BEGIN_TEXT16
|
---|
49 | extern RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_rm)
|
---|
50 |
|
---|
51 | BS3_EXTERN_DATA16 g_aBs3RmIvtOriginal
|
---|
52 | %ifdef TMPL_16BIT
|
---|
53 | BS3_EXTERN_CMN Bs3SelProtFar16DataToRealMode
|
---|
54 | %else
|
---|
55 | BS3_EXTERN_CMN Bs3SelFlatDataToRealMode
|
---|
56 | %endif
|
---|
57 |
|
---|
58 |
|
---|
59 |
|
---|
60 | ;;
|
---|
61 | ; Performs a int 13h function 2 call.
|
---|
62 | ;
|
---|
63 | ; @cproto BS3_MODE_PROTO_STUB(uint8_t, Bs3DiskRead,(uint8_t bDrive, uint16_t uCylinder, uint8_t uHead, uint8_t uSector,
|
---|
64 | ; uint8_t cSectors, void RT_FAR *pvBuf));
|
---|
65 | ;
|
---|
66 | ; @returns Register value (ax/eax). Zero on success, non-zero on failure.
|
---|
67 | ;
|
---|
68 | ; @uses No GPRs (only return full register(s)). In 64-bit mode DS and ES is trashed.
|
---|
69 | ;
|
---|
70 | ; @remarks ASSUMES we're in ring-0 when not in some kind of real mode.
|
---|
71 | ; @remarks ASSUMES we're on a 16-bit suitable stack.
|
---|
72 | ;
|
---|
73 | TMPL_BEGIN_TEXT
|
---|
74 | BS3_PROC_BEGIN_MODE Bs3DiskRead, BS3_PBC_HYBRID
|
---|
75 | push xBP
|
---|
76 | mov xBP, xSP
|
---|
77 | ;; @todo does not work on 286 and earlier!
|
---|
78 | sPUSHF
|
---|
79 | cli
|
---|
80 | push sBX
|
---|
81 | push sCX
|
---|
82 | push sDX
|
---|
83 | push sSI
|
---|
84 | push sDI
|
---|
85 | %ifndef TMPL_64BIT
|
---|
86 | push ds
|
---|
87 | push es
|
---|
88 | %endif
|
---|
89 |
|
---|
90 | ; Load/Save parameters.
|
---|
91 | %define a_bDrive [xBP + xCB + cbCurRetAddr + xCB*0]
|
---|
92 | %define a_uCylinder [xBP + xCB + cbCurRetAddr + xCB*1]
|
---|
93 | %define a_uCylinderHi [xBP + xCB + cbCurRetAddr + xCB*1 + 1]
|
---|
94 | %define a_uHead [xBP + xCB + cbCurRetAddr + xCB*2]
|
---|
95 | %define a_uSector [xBP + xCB + cbCurRetAddr + xCB*3]
|
---|
96 | %define a_cSectors [xBP + xCB + cbCurRetAddr + xCB*4]
|
---|
97 | %define a_pvBuf [xBP + xCB + cbCurRetAddr + xCB*5]
|
---|
98 | %define a_pvBufSel [xBP + xCB + cbCurRetAddr + xCB*5 + 2]
|
---|
99 |
|
---|
100 | %ifdef TMPL_64BIT
|
---|
101 | mov a_bDrive, rcx ; save bDrive
|
---|
102 | mov a_uCylinder, rdx ; save uCylinder
|
---|
103 | mov a_uHead, r8 ; save uHead
|
---|
104 | mov a_uSector, r9 ; save uSector
|
---|
105 | movzx edx, cl ; dl = drive
|
---|
106 | %else
|
---|
107 | mov dl, a_bDrive ; dl = drive
|
---|
108 | %endif
|
---|
109 |
|
---|
110 | ;
|
---|
111 | ; Convert buffer pointer if not in real mode.
|
---|
112 | ; Note! We clean the stack up in the epilogue.
|
---|
113 | ;
|
---|
114 | %ifdef TMPL_64BIT
|
---|
115 | sub rsp, 20h
|
---|
116 | mov rcx, a_pvBuf
|
---|
117 | call Bs3SelFlatDataToRealMode
|
---|
118 | mov a_pvBuf, rax
|
---|
119 | %elifdef TMPL_32BIT
|
---|
120 | mov ecx, a_pvBuf
|
---|
121 | push ecx
|
---|
122 | call Bs3SelFlatDataToRealMode
|
---|
123 | mov a_pvBuf, eax
|
---|
124 | %elif !BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
|
---|
125 | push word a_pvBufSel
|
---|
126 | push word a_pvBuf
|
---|
127 | call Bs3SelProtFar16DataToRealMode
|
---|
128 | mov a_pvBuf, ax
|
---|
129 | mov a_pvBufSel, dx
|
---|
130 | %endif
|
---|
131 |
|
---|
132 | ;
|
---|
133 | ; Set up the BIOS call parameters.
|
---|
134 | ;
|
---|
135 | mov ah, 02h ; read
|
---|
136 | mov al, a_cSectors
|
---|
137 | mov cx, a_uCylinder
|
---|
138 | xchg ch, cl
|
---|
139 | shl cl, 6
|
---|
140 | or cl, a_uSector
|
---|
141 | mov dl, a_bDrive
|
---|
142 | mov dh, a_uHead
|
---|
143 | mov bx, a_pvBuf
|
---|
144 | mov di, a_pvBufSel
|
---|
145 |
|
---|
146 | ;
|
---|
147 | ; Switch to real mode, first we just to the 16-bit text segment.
|
---|
148 | ; This preserve all 32-bit register values.
|
---|
149 | ;
|
---|
150 | %if TMPL_MODE != BS3_MODE_RM
|
---|
151 | %ifndef TMPL_16BIT
|
---|
152 | jmp .to_text16
|
---|
153 | BS3_BEGIN_TEXT16
|
---|
154 | .to_text16:
|
---|
155 | BS3_SET_BITS TMPL_BITS
|
---|
156 | %endif
|
---|
157 | call TMPL_NM(Bs3SwitchToRM)
|
---|
158 | BS3_SET_BITS 16
|
---|
159 | %endif
|
---|
160 |
|
---|
161 | ;
|
---|
162 | ; Make the call.
|
---|
163 | ;
|
---|
164 | mov es, di
|
---|
165 | ; pushf
|
---|
166 | ; sti
|
---|
167 | int 13h
|
---|
168 | ; popf
|
---|
169 |
|
---|
170 | ;
|
---|
171 | ; Switch back.
|
---|
172 | ;
|
---|
173 | %if TMPL_MODE != BS3_MODE_RM
|
---|
174 | call RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_rm)
|
---|
175 | BS3_SET_BITS TMPL_BITS
|
---|
176 | %ifndef TMPL_16BIT
|
---|
177 | jmp .from_text16
|
---|
178 | TMPL_BEGIN_TEXT
|
---|
179 | .from_text16:
|
---|
180 | %endif
|
---|
181 | %endif
|
---|
182 | hlt
|
---|
183 |
|
---|
184 | ;
|
---|
185 | ; Check that we didn't failed.
|
---|
186 | ;
|
---|
187 | jc .failed_return_ah
|
---|
188 | test ah, ah
|
---|
189 | jnz .failed_return_ah
|
---|
190 | %ifdef BS3_STRICT
|
---|
191 | cmp al, a_cSectors
|
---|
192 | je .next
|
---|
193 | int3
|
---|
194 | .next:
|
---|
195 | %endif
|
---|
196 | ;
|
---|
197 | ; Return success
|
---|
198 | ;
|
---|
199 | mov al, 0
|
---|
200 |
|
---|
201 | .return:
|
---|
202 | %ifndef TMPL_64BIT
|
---|
203 | lea xSP, [xBP - sCB * 6 - xCB*2]
|
---|
204 | pop es
|
---|
205 | pop ds
|
---|
206 | %else
|
---|
207 | lea xSP, [xBP - sCB * 6]
|
---|
208 | %endif
|
---|
209 | pop sDI
|
---|
210 | pop sSI
|
---|
211 | pop sDX
|
---|
212 | pop sCX
|
---|
213 | pop sBX
|
---|
214 | sPOPF
|
---|
215 | leave
|
---|
216 | BS3_HYBRID_RET
|
---|
217 |
|
---|
218 | ;
|
---|
219 | ; Failed.
|
---|
220 | ;
|
---|
221 | .failed_return_ah:
|
---|
222 | mov al, ah
|
---|
223 | cmp al, 0
|
---|
224 | jne .return
|
---|
225 | dec al
|
---|
226 | jmp .return
|
---|
227 | BS3_PROC_END_MODE Bs3DiskRead
|
---|
228 |
|
---|