1 | ; $Id: bs3-mode-DiskQueryGeometry.asm 102150 2023-11-20 11:14:18Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3BiosInt15hE820
|
---|
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 | ;* Defined Constants And Macros *
|
---|
45 | ;*********************************************************************************************************************************
|
---|
46 | ;; Signature: 'SMAP'
|
---|
47 | %define INT15_E820_SIGNATURE 0534d4150h
|
---|
48 |
|
---|
49 |
|
---|
50 | ;*********************************************************************************************************************************
|
---|
51 | ;* External symbols *
|
---|
52 | ;*********************************************************************************************************************************
|
---|
53 | TMPL_BEGIN_TEXT
|
---|
54 | extern TMPL_NM(Bs3SwitchToRM)
|
---|
55 | BS3_BEGIN_TEXT16
|
---|
56 | extern RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_rm)
|
---|
57 | BS3_EXTERN_DATA16 g_aBs3RmIvtOriginal
|
---|
58 |
|
---|
59 |
|
---|
60 | ;;
|
---|
61 | ; Performs a int 13h function 8 call.
|
---|
62 | ;
|
---|
63 | ; @cproto BS3_MODE_PROTO_STUB(uint8_t, Bs3DiskQueryGeometry,(uint8_t bDrive, uint16_t *puMaxCylinder,
|
---|
64 | ; uint8_t *puMaxHead, uint8_t *puMaxSector));
|
---|
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 Bs3DiskQueryGeometry, 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_puMaxCylinder [xBP + xCB + cbCurRetAddr + xCB + sCB*0]
|
---|
93 | %define a_pMaxHead [xBP + xCB + cbCurRetAddr + xCB + sCB*1]
|
---|
94 | %define a_puMaxSector [xBP + xCB + cbCurRetAddr + xCB + sCB*2]
|
---|
95 |
|
---|
96 | %ifdef TMPL_64BIT
|
---|
97 | mov a_bDrive, rcx ; save bDrive
|
---|
98 | mov a_puMaxCylinder, rdx ; save pcCylinders
|
---|
99 | mov a_pMaxHead, r8 ; save pcHeads
|
---|
100 | mov a_puMaxSector, r9 ; save pcSectors
|
---|
101 | movzx edx, cl ; dl = drive
|
---|
102 | %else
|
---|
103 | mov dl, a_bDrive ; dl = drive
|
---|
104 | %endif
|
---|
105 |
|
---|
106 | ;
|
---|
107 | ; Switch to real mode, first we just to the 16-bit text segment.
|
---|
108 | ; This preserve all 32-bit register values.
|
---|
109 | ;
|
---|
110 | %if TMPL_MODE != BS3_MODE_RM
|
---|
111 | %ifndef TMPL_16BIT
|
---|
112 | jmp .to_text16
|
---|
113 | BS3_BEGIN_TEXT16
|
---|
114 | .to_text16:
|
---|
115 | BS3_SET_BITS TMPL_BITS
|
---|
116 | %endif
|
---|
117 | call TMPL_NM(Bs3SwitchToRM)
|
---|
118 | BS3_SET_BITS 16
|
---|
119 | %endif
|
---|
120 | ; Ralf Brown suggest setting es:di to NULL before the call. This is also helpful
|
---|
121 | ; wrt to IVT manipulation (next step).
|
---|
122 | xor di, di
|
---|
123 | mov es, di
|
---|
124 |
|
---|
125 | ;
|
---|
126 | ; Save current and restore the original IVT[13h] entry.
|
---|
127 | ;
|
---|
128 | mov si, seg g_aBs3RmIvtOriginal
|
---|
129 | mov ds, si
|
---|
130 | mov si, g_aBs3RmIvtOriginal
|
---|
131 |
|
---|
132 | push word [es:13h * 4]
|
---|
133 | mov ax, [si + 13h * 4]
|
---|
134 | mov [es:13h * 4], ax
|
---|
135 |
|
---|
136 | push word [es:13h * 4 + 2]
|
---|
137 | mov ax, [si + 13h * 4 + 2]
|
---|
138 | mov [es:13h * 4 + 2], ax
|
---|
139 |
|
---|
140 | ;
|
---|
141 | ; Make the call.
|
---|
142 | ;
|
---|
143 | mov ax, 0800h ; ah=08h
|
---|
144 | xor di, di ; ralf brown suggestion to guard against bios bugs.
|
---|
145 | mov es, di
|
---|
146 | int 13h
|
---|
147 |
|
---|
148 | ;
|
---|
149 | ; Restore the modified IVT[13h] entry.
|
---|
150 | ; Must not touch EFLAGS.CF!
|
---|
151 | ;
|
---|
152 | push word 0
|
---|
153 | pop ds
|
---|
154 | pop word [ds:13h * 4 + 2]
|
---|
155 | pop word [ds:13h * 4]
|
---|
156 |
|
---|
157 | ;
|
---|
158 | ; Switch back.
|
---|
159 | ;
|
---|
160 | %if TMPL_MODE != BS3_MODE_RM
|
---|
161 | call RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_rm)
|
---|
162 | BS3_SET_BITS TMPL_BITS
|
---|
163 | %ifndef TMPL_16BIT
|
---|
164 | jmp .from_text16
|
---|
165 | TMPL_BEGIN_TEXT
|
---|
166 | .from_text16:
|
---|
167 | %endif
|
---|
168 | %endif
|
---|
169 | ;
|
---|
170 | ; Check that we didn't failed.
|
---|
171 | ;
|
---|
172 | jc .failed_return_ah
|
---|
173 |
|
---|
174 | ;
|
---|
175 | ; Save the return values.
|
---|
176 | ; CL[7:6]:CH = max cylinders.
|
---|
177 | ; DH = max heads
|
---|
178 | ; CL[5:0] = max sectors
|
---|
179 | ; Other stuff we don't care about:
|
---|
180 | ; AH = 0
|
---|
181 | ; AL = undefined/zero
|
---|
182 | ; BL = drive type
|
---|
183 | ; DL = max drives.
|
---|
184 | ; ES:DI = driver parameter table for floppies.
|
---|
185 | ;
|
---|
186 | %ifdef TMPL_16BIT
|
---|
187 | les di, a_pMaxHead
|
---|
188 | mov [es:di], dh
|
---|
189 |
|
---|
190 | les di, a_puMaxSector
|
---|
191 | mov al, 3fh
|
---|
192 | and al, cl
|
---|
193 | mov [es:di], al
|
---|
194 |
|
---|
195 | les di, a_puMaxCylinder
|
---|
196 | shr cl, 6
|
---|
197 | xchg cl, ch
|
---|
198 | mov [es:di], cx
|
---|
199 | %else
|
---|
200 | mov xDI, a_pMaxHead
|
---|
201 | mov [xDI], dh
|
---|
202 |
|
---|
203 | mov xDI, a_puMaxSector
|
---|
204 | mov al, 3fh
|
---|
205 | and al, cl
|
---|
206 | mov [xDI], al
|
---|
207 |
|
---|
208 | mov xDI, a_puMaxCylinder
|
---|
209 | shr cl, 6
|
---|
210 | xchg cl, ch
|
---|
211 | mov [xDI], cx
|
---|
212 | %endif
|
---|
213 |
|
---|
214 | ;
|
---|
215 | ; Return success
|
---|
216 | ;
|
---|
217 | mov al, 0
|
---|
218 |
|
---|
219 | .return:
|
---|
220 | %ifndef TMPL_64BIT
|
---|
221 | lea xSP, [xBP - sCB * 6 - xCB*2]
|
---|
222 | pop es
|
---|
223 | pop ds
|
---|
224 | %else
|
---|
225 | lea xSP, [xBP - sCB * 6]
|
---|
226 | %endif
|
---|
227 | pop sDI
|
---|
228 | pop sSI
|
---|
229 | pop sDX
|
---|
230 | pop sCX
|
---|
231 | pop sBX
|
---|
232 | sPOPF
|
---|
233 | leave
|
---|
234 | BS3_HYBRID_RET
|
---|
235 |
|
---|
236 | ;
|
---|
237 | ; Failed.
|
---|
238 | ;
|
---|
239 | .failed_return_ah:
|
---|
240 | mov al, ah
|
---|
241 | cmp al, 0
|
---|
242 | jne .return
|
---|
243 | dec al
|
---|
244 | jmp .return
|
---|
245 | BS3_PROC_END_MODE Bs3DiskQueryGeometry
|
---|
246 |
|
---|