VirtualBox

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

Last change on this file since 106560 was 106061, checked in by vboxsync, 5 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1; $Id: bs3-mode-DiskQueryGeometry.asm 106061 2024-09-16 14:03:52Z vboxsync $
2;; @file
3; BS3Kit - Bs3DiskQueryGeometry
4;
5
6;
7; Copyright (C) 2021-2024 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)
50BS3_EXTERN_DATA16 g_aBs3RmIvtOriginal
51
52
53;;
54; Performs a int 13h function 8 call.
55;
56; @cproto BS3_MODE_PROTO_STUB(uint8_t, Bs3DiskQueryGeometry,(uint8_t bDrive, uint16_t *puMaxCylinder,
57; uint8_t *puMaxHead, uint8_t *puMaxSector));
58;
59; @returns Register value (ax/eax). Zero on success, non-zero on failure.
60;
61; @uses No GPRs (only return full register(s)). In 64-bit mode DS and ES is trashed.
62;
63; @remarks ASSUMES we're in ring-0 when not in some kind of real mode.
64; @remarks ASSUMES we're on a 16-bit suitable stack.
65;
66TMPL_BEGIN_TEXT
67BS3_PROC_BEGIN_MODE Bs3DiskQueryGeometry, BS3_PBC_HYBRID
68 push xBP
69 mov xBP, xSP
70;; @todo does not work on 286 and earlier!
71 sPUSHF
72 cli
73 push sBX
74 push sCX
75 push sDX
76 push sSI
77 push sDI
78%ifndef TMPL_64BIT
79 push ds
80 push es
81%endif
82
83 ; Load/Save parameters.
84%define a_bDrive [xBP + xCB + cbCurRetAddr + xCB*0]
85%define a_puMaxCylinder [xBP + xCB + cbCurRetAddr + xCB + sCB*0]
86%define a_pMaxHead [xBP + xCB + cbCurRetAddr + xCB + sCB*1]
87%define a_puMaxSector [xBP + xCB + cbCurRetAddr + xCB + sCB*2]
88
89%ifdef TMPL_64BIT
90 mov a_bDrive, rcx ; save bDrive
91 mov a_puMaxCylinder, rdx ; save pcCylinders
92 mov a_pMaxHead, r8 ; save pcHeads
93 mov a_puMaxSector, r9 ; save pcSectors
94 movzx edx, cl ; dl = drive
95%else
96 mov dl, a_bDrive ; dl = drive
97%endif
98
99 ;
100 ; Switch to real mode, first we just to the 16-bit text segment.
101 ; This preserve all 32-bit register values.
102 ;
103%if TMPL_MODE != BS3_MODE_RM
104 %ifndef TMPL_16BIT
105 jmp .to_text16
106BS3_BEGIN_TEXT16
107.to_text16:
108 BS3_SET_BITS TMPL_BITS
109 %endif
110 call TMPL_NM(Bs3SwitchToRM)
111 BS3_SET_BITS 16
112%endif
113
114 ;
115 ; Ralf Brown suggest setting es:di to NULL before the call.
116 ; Doubt this is really needed in our case, but whatever.
117 ;
118 xor di, di
119 mov es, di
120
121 ;
122 ; Make the call.
123 ;
124 mov ax, 0800h ; ah=08h
125 xor di, di ; ralf brown suggestion to guard against bios bugs.
126 mov es, di
127 int 13h
128
129 ;
130 ; Switch back.
131 ;
132%if TMPL_MODE != BS3_MODE_RM
133 call RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_rm)
134 BS3_SET_BITS TMPL_BITS
135 %ifndef TMPL_16BIT
136 jmp .from_text16
137TMPL_BEGIN_TEXT
138.from_text16:
139 %endif
140%endif
141 ;
142 ; Check that we didn't failed.
143 ;
144 jc .failed_return_ah
145
146 ;
147 ; Save the return values.
148 ; CL[7:6]:CH = max cylinders.
149 ; DH = max heads
150 ; CL[5:0] = max sectors
151 ; Other stuff we don't care about:
152 ; AH = 0
153 ; AL = undefined/zero
154 ; BL = drive type
155 ; DL = max drives.
156 ; ES:DI = driver parameter table for floppies.
157 ;
158%ifdef TMPL_16BIT
159 les di, a_pMaxHead
160 mov [es:di], dh
161
162 les di, a_puMaxSector
163 cmp byte a_bDrive, 4 ; ASSUMES the first 4 drive are potentially BIG floppies.
164 jge .not_floppy_sectors
165 mov [es:di], cl ; For 63.5 MB the whole of CL is the sector number.
166 mov cl, 0 ; CL does not contribute to the cylinder count, so zero it.
167 jmp .set_max_cylinder
168.not_floppy_sectors:
169 mov al, 3fh
170 and al, cl
171 mov [es:di], al
172
173.set_max_cylinder:
174 les di, a_puMaxCylinder
175 shr cl, 6
176 xchg cl, ch
177 mov [es:di], cx
178%else
179 mov xDI, a_pMaxHead
180 mov [xDI], dh
181
182 mov xDI, a_puMaxSector
183 cmp byte a_bDrive, 4 ; ASSUMES the first 4 drive are potentially BIG floppies.
184 jge .not_floppy_sectors
185 mov [xDI], cl ; For 63.5 MB the whole of CL is the sector number.
186 mov cl, 0 ; CL does not contribute to the cylinder count, so zero it.
187 jmp .set_max_cylinder
188.not_floppy_sectors:
189 mov al, 3fh
190 and al, cl
191 mov [xDI], al
192
193.set_max_cylinder:
194 mov xDI, a_puMaxCylinder
195 shr cl, 6
196 xchg cl, ch
197 mov [xDI], cx
198%endif
199
200 ;
201 ; Return success
202 ;
203 mov al, 0
204
205.return:
206%ifndef TMPL_64BIT
207 lea xSP, [xBP - sCB * 6 - xCB*2]
208 pop es
209 pop ds
210%else
211 lea xSP, [xBP - sCB * 6]
212%endif
213 pop sDI
214 pop sSI
215 pop sDX
216 pop sCX
217 pop sBX
218 sPOPF
219 leave
220 BS3_HYBRID_RET
221
222 ;
223 ; Failed.
224 ;
225.failed_return_ah:
226 mov al, ah
227 cmp al, 0
228 jne .return
229 dec al
230 jmp .return
231BS3_PROC_END_MODE Bs3DiskQueryGeometry
232
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