VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-DiskRead.asm@ 104620

Last change on this file since 104620 was 102270, checked in by vboxsync, 10 months ago

bs3kit: Fixed some issues with loading of a fake 63.5 MB floppy. Added optional checksumming of the images we load (disabled by default, as it's slow in IEM). bugref:10371

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1; $Id: bs3-mode-DiskRead.asm 102270 2023-11-23 00:40:38Z 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;*********************************************************************************************************************************
46TMPL_BEGIN_TEXT
47extern TMPL_NM(Bs3SwitchToRM)
48BS3_BEGIN_TEXT16
49extern RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_rm)
50
51BS3_EXTERN_DATA16 g_aBs3RmIvtOriginal
52%ifdef TMPL_16BIT
53BS3_EXTERN_CMN Bs3SelProtFar16DataToRealMode
54%else
55BS3_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;
73TMPL_BEGIN_TEXT
74BS3_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 dh, a_uHead
138 mov dl, a_bDrive
139 ; For 63.5MB support the entire CL is the sector number, so just treat floppies special.
140 cmp dl, 4 ; ASSUMES the first 4 drive are potentially BIG floppies.
141 jb .floppy
142 mov cx, a_uCylinder
143 xchg ch, cl
144 shl cl, 6
145 or cl, a_uSector
146 jmp .setup_addr
147.floppy:
148 mov ch, a_uCylinder
149 mov cl, a_uSector
150.setup_addr:
151 mov bx, a_pvBuf
152 mov di, a_pvBufSel
153
154 ;
155 ; Switch to real mode, first we just to the 16-bit text segment.
156 ; This preserve all 32-bit register values.
157 ;
158%if TMPL_MODE != BS3_MODE_RM
159 %ifndef TMPL_16BIT
160 jmp .to_text16
161BS3_BEGIN_TEXT16
162.to_text16:
163 BS3_SET_BITS TMPL_BITS
164 %endif
165 call TMPL_NM(Bs3SwitchToRM)
166 BS3_SET_BITS 16
167%endif
168
169 ;
170 ; Make the call.
171 ;
172 mov es, di
173; pushf
174; sti
175 int 13h
176; popf
177
178 ;
179 ; Switch back.
180 ;
181%if TMPL_MODE != BS3_MODE_RM
182 call RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_rm)
183 BS3_SET_BITS TMPL_BITS
184 %ifndef TMPL_16BIT
185 jmp .from_text16
186TMPL_BEGIN_TEXT
187.from_text16:
188 %endif
189%endif
190hlt
191
192 ;
193 ; Check that we didn't failed.
194 ;
195 jc .failed_return_ah
196 test ah, ah
197 jnz .failed_return_ah
198%ifdef BS3_STRICT
199 cmp al, a_cSectors
200 je .next
201 int3
202.next:
203%endif
204 ;
205 ; Return success
206 ;
207 mov al, 0
208
209.return:
210%ifndef TMPL_64BIT
211 lea xSP, [xBP - sCB * 6 - xCB*2]
212 pop es
213 pop ds
214%else
215 lea xSP, [xBP - sCB * 6]
216%endif
217 pop sDI
218 pop sSI
219 pop sDX
220 pop sCX
221 pop sBX
222 sPOPF
223 leave
224 BS3_HYBRID_RET
225
226 ;
227 ; Failed.
228 ;
229.failed_return_ah:
230 mov al, ah
231 cmp al, 0
232 jne .return
233 dec al
234 jmp .return
235BS3_PROC_END_MODE Bs3DiskRead
236
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette