1 | ; $Id: VBoxGuestA-os2.asm 4071 2007-08-07 17:07:59Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; VBoxGuest - OS/2 assembly file, the first file in the link.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License as published by the Free Software Foundation,
|
---|
13 | ; in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | ; distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | ; be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ; --------------------------------------------------------------------
|
---|
17 | ;
|
---|
18 | ; This code is based on:
|
---|
19 | ;
|
---|
20 | ; VBoxDrv - OS/2 assembly file, the first file in the link.
|
---|
21 | ;
|
---|
22 | ; Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
|
---|
23 | ;
|
---|
24 | ; Permission is hereby granted, free of charge, to any person
|
---|
25 | ; obtaining a copy of this software and associated documentation
|
---|
26 | ; files (the "Software"), to deal in the Software without
|
---|
27 | ; restriction, including without limitation the rights to use,
|
---|
28 | ; copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
29 | ; copies of the Software, and to permit persons to whom the
|
---|
30 | ; Software is furnished to do so, subject to the following
|
---|
31 | ; conditions:
|
---|
32 | ;
|
---|
33 | ; The above copyright notice and this permission notice shall be
|
---|
34 | ; included in all copies or substantial portions of the Software.
|
---|
35 | ;
|
---|
36 | ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
37 | ; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
38 | ; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
39 | ; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
40 | ; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
41 | ; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
42 | ; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
43 | ; OTHER DEALINGS IN THE SOFTWARE.
|
---|
44 | ;
|
---|
45 |
|
---|
46 |
|
---|
47 | ;*******************************************************************************
|
---|
48 | ;* Header Files *
|
---|
49 | ;*******************************************************************************
|
---|
50 | %define RT_INCL_16BIT_SEGMENTS
|
---|
51 | %include "iprt/asmdefs.mac"
|
---|
52 | %include "iprt/err.mac"
|
---|
53 | %include "VBox/VBoxGuest.mac"
|
---|
54 |
|
---|
55 |
|
---|
56 | ;*******************************************************************************
|
---|
57 | ;* Structures and Typedefs *
|
---|
58 | ;*******************************************************************************
|
---|
59 | ;;
|
---|
60 | ; Request packet header.
|
---|
61 | struc PKTHDR
|
---|
62 | .cb resb 1
|
---|
63 | .unit resb 1
|
---|
64 | .cmd resb 1
|
---|
65 | .status resw 1
|
---|
66 | .res1 resd 1
|
---|
67 | .link resd 1
|
---|
68 | endstruc
|
---|
69 |
|
---|
70 |
|
---|
71 | ;;
|
---|
72 | ; Init request packet - input.
|
---|
73 | struc PKTINITIN
|
---|
74 | .cb resb 1
|
---|
75 | .unit resb 1
|
---|
76 | .cmd resb 1
|
---|
77 | .status resw 1
|
---|
78 | .res1 resd 1
|
---|
79 | .link resd 1
|
---|
80 |
|
---|
81 | .data_1 resb 1
|
---|
82 | .fpfnDevHlp resd 1
|
---|
83 | .fpszArgs resd 1
|
---|
84 | .data_2 resb 1
|
---|
85 | endstruc
|
---|
86 |
|
---|
87 | ;;
|
---|
88 | ; Init request packet - output.
|
---|
89 | struc PKTINITOUT
|
---|
90 | .cb resb 1
|
---|
91 | .unit resb 1
|
---|
92 | .cmd resb 1
|
---|
93 | .status resw 1
|
---|
94 | .res1 resd 1
|
---|
95 | .link resd 1
|
---|
96 |
|
---|
97 | .cUnits resb 1 ; block devs only.
|
---|
98 | .cbCode16 resw 1
|
---|
99 | .cbData16 resw 1
|
---|
100 | .fpaBPBs resd 1 ; block devs only.
|
---|
101 | .data_2 resb 1
|
---|
102 | endstruc
|
---|
103 |
|
---|
104 | ;;
|
---|
105 | ; Open request packet.
|
---|
106 | struc PKTOPEN
|
---|
107 | .cb resb 1
|
---|
108 | .unit resb 1
|
---|
109 | .cmd resb 1
|
---|
110 | .status resw 1
|
---|
111 | .res1 resd 1
|
---|
112 | .link resd 1
|
---|
113 | .sfn resw 1
|
---|
114 | endstruc
|
---|
115 |
|
---|
116 | ;;
|
---|
117 | ; Close request packet.
|
---|
118 | struc PKTCLOSE
|
---|
119 | .cb resb 1
|
---|
120 | .unit resb 1
|
---|
121 | .cmd resb 1
|
---|
122 | .status resw 1
|
---|
123 | .res1 resd 1
|
---|
124 | .link resd 1
|
---|
125 | .sfn resw 1
|
---|
126 | endstruc
|
---|
127 |
|
---|
128 | ;;
|
---|
129 | ; IOCtl request packet.
|
---|
130 | struc PKTIOCTL
|
---|
131 | .cb resb 1
|
---|
132 | .unit resb 1
|
---|
133 | .cmd resb 1
|
---|
134 | .status resw 1
|
---|
135 | .res1 resd 1
|
---|
136 | .link resd 1
|
---|
137 |
|
---|
138 | .cat resb 1
|
---|
139 | .fun resb 1
|
---|
140 | .pParm resd 1
|
---|
141 | .pData resd 1
|
---|
142 | .sfn resw 1
|
---|
143 | .cbParm resw 1
|
---|
144 | .cbData resw 1
|
---|
145 | endstruc
|
---|
146 |
|
---|
147 | ;;
|
---|
148 | ; Read/Write request packet
|
---|
149 | struc PKTRW
|
---|
150 | .cb resb 1
|
---|
151 | .unit resb 1
|
---|
152 | .cmd resb 1
|
---|
153 | .status resw 1
|
---|
154 | .res1 resd 1
|
---|
155 | .link resd 1
|
---|
156 |
|
---|
157 | .media resb 1
|
---|
158 | .PhysTrans resd 1
|
---|
159 | .cbTrans resw 1
|
---|
160 | .start resd 1
|
---|
161 | .sfn resw 1
|
---|
162 | endstruc
|
---|
163 |
|
---|
164 |
|
---|
165 | ;*******************************************************************************
|
---|
166 | ;* Defined Constants And Macros *
|
---|
167 | ;*******************************************************************************
|
---|
168 | ; Some devhdr.inc stuff.
|
---|
169 | %define DEVLEV_3 0180h
|
---|
170 | %define DEV_30 0800h
|
---|
171 | %define DEV_IOCTL 4000h
|
---|
172 | %define DEV_CHAR_DEV 8000h
|
---|
173 |
|
---|
174 | %define DEV_16MB 0002h
|
---|
175 | %define DEV_IOCTL2 0001h
|
---|
176 |
|
---|
177 | ; Some dhcalls.h stuff.
|
---|
178 | %define DevHlp_VirtToLin 05bh
|
---|
179 | %define DevHlp_SAVE_MESSAGE 03dh
|
---|
180 | %define DevHlp_EIO 031h
|
---|
181 | %define DevHlp_SetIRQ 01bh
|
---|
182 | %define DevHlp_PhysToVirt 015h
|
---|
183 |
|
---|
184 | ; Fast IOCtl category, also defined in VBoxGuest.h
|
---|
185 | %define VBOXGUEST_IOCTL_CATEGORY_FAST 0c3h
|
---|
186 |
|
---|
187 | ;;
|
---|
188 | ; Got some nasm/link trouble, so emit the stuff ourselves.
|
---|
189 | ; @param %1 Must be a GLOBALNAME.
|
---|
190 | %macro JMP32TO16 1
|
---|
191 | ;jmp far dword NAME(%1) wrt CODE16
|
---|
192 | db 066h
|
---|
193 | db 0eah
|
---|
194 | dw NAME(%1) wrt CODE16
|
---|
195 | dw CODE16
|
---|
196 | %endmacro
|
---|
197 |
|
---|
198 | ;;
|
---|
199 | ; Got some nasm/link trouble, so emit the stuff ourselves.
|
---|
200 | ; @param %1 Must be a GLOBALNAME.
|
---|
201 | %macro JMP16TO32 1
|
---|
202 | ;jmp far dword NAME(%1) wrt FLAT
|
---|
203 | db 066h
|
---|
204 | db 0eah
|
---|
205 | dd NAME(%1) ;wrt FLAT
|
---|
206 | dw TEXT32 wrt FLAT
|
---|
207 | %endmacro
|
---|
208 |
|
---|
209 |
|
---|
210 | ;*******************************************************************************
|
---|
211 | ;* External Symbols *
|
---|
212 | ;*******************************************************************************
|
---|
213 | segment CODE16
|
---|
214 | extern DOS16OPEN
|
---|
215 | extern DOS16CLOSE
|
---|
216 | extern DOS16WRITE
|
---|
217 | extern DOS16DEVIOCTL2
|
---|
218 | segment TEXT32
|
---|
219 | extern KernThunkStackTo32
|
---|
220 | extern KernThunkStackTo16
|
---|
221 |
|
---|
222 | extern NAME(VBoxGuestOS2Init)
|
---|
223 | extern NAME(VBoxGuestOS2Open)
|
---|
224 | extern NAME(VBoxGuestOS2Close)
|
---|
225 | extern NAME(VBoxGuestOS2IOCtl)
|
---|
226 | extern NAME(VBoxGuestOS2IOCtlFast)
|
---|
227 | extern NAME(VBoxGuestOS2IDCConnect)
|
---|
228 | extern NAME(VBoxGuestOS2IDCService)
|
---|
229 | extern NAME(VBoxGuestOS2ISR)
|
---|
230 |
|
---|
231 |
|
---|
232 | segment DATA16
|
---|
233 |
|
---|
234 | ;;
|
---|
235 | ; Device headers. The first one is the one we'll be opening and the
|
---|
236 | ; latter is only used for 32-bit initialization.
|
---|
237 | GLOBALNAME g_VBoxGuestHdr1
|
---|
238 | dw NAME(g_VBoxGuestHdr2) wrt DATA16 ; NextHeader.off
|
---|
239 | dw DATA16 ; NextHeader.sel
|
---|
240 | dw DEVLEV_3 | DEV_30 | DEV_CHAR_DEV | DEV_IOCTL; SDevAtt
|
---|
241 | dw NAME(VBoxGuestOS2EP) wrt CODE16 ; StrategyEP
|
---|
242 | dw NAME(VBoxGuestOS2IDC) wrt CODE16 ; IDCEP
|
---|
243 | db 'vboxgst$' ; DevName
|
---|
244 | dw 0 ; SDevProtCS
|
---|
245 | dw 0 ; SDevProtDS
|
---|
246 | dw 0 ; SDevRealCS
|
---|
247 | dw 0 ; SDevRealDS
|
---|
248 | dd DEV_16MB | DEV_IOCTL2 ; SDevCaps
|
---|
249 |
|
---|
250 | align 4
|
---|
251 | GLOBALNAME g_VBoxGuestHdr2
|
---|
252 | dd 0ffffffffh ; NextHeader (NIL)
|
---|
253 | dw DEVLEV_3 | DEV_30 | DEV_CHAR_DEV ; SDevAtt
|
---|
254 | dw NAME(VBoxGuestOS2InitEP) wrt CODE16 ; StrategyEP
|
---|
255 | dw 0 ; IDCEP
|
---|
256 | db 'vboxgs1$' ; DevName
|
---|
257 | dw 0 ; SDevProtCS
|
---|
258 | dw 0 ; SDevProtDS
|
---|
259 | dw 0 ; SDevRealCS
|
---|
260 | dw 0 ; SDevRealDS
|
---|
261 | dd DEV_16MB | DEV_IOCTL2 ; SDevCaps
|
---|
262 |
|
---|
263 |
|
---|
264 | ;; Tristate 32-bit initialization indicator [0 = need init, -1 = init failed, 1 init succeeded].
|
---|
265 | ; Check in the open path of the primary driver. The secondary driver will
|
---|
266 | ; open the primary one during it's init and thereby trigger the 32-bit init.
|
---|
267 | GLOBALNAME g_fInitialized
|
---|
268 | db 0
|
---|
269 |
|
---|
270 | align 4
|
---|
271 | ;; Pointer to the device helper service routine
|
---|
272 | ; This is set during the initialization of the 2nd device driver.
|
---|
273 | GLOBALNAME g_fpfnDevHlp
|
---|
274 | dd 0
|
---|
275 |
|
---|
276 |
|
---|
277 | ;; VBoxGuestFindAdapter Output
|
---|
278 | ; @{
|
---|
279 |
|
---|
280 | ;; The MMIO base of the VMMDev.
|
---|
281 | GLOBALNAME g_PhysMMIOBase
|
---|
282 | dd 0
|
---|
283 | ;; The size of the MMIO memory of the VMMDev.
|
---|
284 | GLOBALNAME g_cbMMIO
|
---|
285 | dd 0
|
---|
286 | ;; The I/O port base of the VMMDev.
|
---|
287 | GLOBALNAME g_IOPortBase
|
---|
288 | dw 0
|
---|
289 | ;; The VMMDev Interrupt Line.
|
---|
290 | GLOBALNAME g_bInterruptLine
|
---|
291 | db 0
|
---|
292 | ;; The PCI bus number returned by Find PCI Device.
|
---|
293 | GLOBALNAME g_bPciBusNo
|
---|
294 | db 0
|
---|
295 | ;; The PCI Device No / Function Number returned by Find PCI Device.
|
---|
296 | ; (The upper 5 bits is the number, and the lower 3 the function.)
|
---|
297 | GLOBALNAME g_bPciDevFunNo
|
---|
298 | db 0
|
---|
299 | ;; Flag that is set by the vboxgst$ init routine if VMMDev was found.
|
---|
300 | ; Both init routines must refuse loading the driver if the
|
---|
301 | ; device cannot be located.
|
---|
302 | GLOBALNAME g_fFoundAdapter
|
---|
303 | db 0
|
---|
304 | ;; @}
|
---|
305 |
|
---|
306 |
|
---|
307 | %ifdef DEBUG_READ
|
---|
308 | ;; Where we write to the log.
|
---|
309 | GLOBALNAME g_offLogHead
|
---|
310 | dw 0
|
---|
311 | ;; Where we read from the log.
|
---|
312 | GLOBALNAME g_offLogTail
|
---|
313 | dw 0
|
---|
314 | ;; The size of the log. (power of two!)
|
---|
315 | %define LOG_SIZE 16384
|
---|
316 | GLOBALNAME g_cchLogMax
|
---|
317 | dw LOG_SIZE
|
---|
318 | ;; The log buffer.
|
---|
319 | GLOBALNAME g_szLog
|
---|
320 | times LOG_SIZE db 0
|
---|
321 | %endif ; DEBUG_READ
|
---|
322 |
|
---|
323 |
|
---|
324 | ;
|
---|
325 | ; The init data.
|
---|
326 | ;
|
---|
327 | segment DATA16_INIT
|
---|
328 | GLOBALNAME g_InitDataStart
|
---|
329 |
|
---|
330 | ;; Far pointer to the device argument.
|
---|
331 | g_fpszArgs:
|
---|
332 | dd 0
|
---|
333 |
|
---|
334 | %if 0
|
---|
335 | ;; Message table for the Save_Message device helper.
|
---|
336 | GLOBALNAME g_MsgTab
|
---|
337 | dw 1178 ; MsgId - 'MSG_REPLACEMENT_STRING'.
|
---|
338 | dw 1 ; cMsgStrings
|
---|
339 | dw NAME(g_szInitText) ; MsgStrings[0]
|
---|
340 | dw seg NAME(g_szInitText)
|
---|
341 | %else
|
---|
342 | ;; Far pointer to DOS16WRITE (corrected set before called).
|
---|
343 | ; Just a temporary hack to work around a wlink issue.
|
---|
344 | GLOBALNAME g_fpfnDos16Write
|
---|
345 | dw DOS16WRITE
|
---|
346 | dw seg DOS16WRITE
|
---|
347 | %endif
|
---|
348 |
|
---|
349 | ;; Size of the text currently in the g_szInitText buffer.
|
---|
350 | GLOBALNAME g_cchInitText
|
---|
351 | dw 0
|
---|
352 | ;; The max size of text that can fit into the g_szInitText buffer.
|
---|
353 | GLOBALNAME g_cchInitTextMax
|
---|
354 | dw 512
|
---|
355 | ;; The init text buffer.
|
---|
356 | GLOBALNAME g_szInitText
|
---|
357 | times 512 db 0
|
---|
358 |
|
---|
359 | ;; Message string that's written on failure.
|
---|
360 | g_achLoadFailureMsg1:
|
---|
361 | db 0dh,0ah,'VBoxGuest: load failure no. '
|
---|
362 | g_cchLoadFailureMsg1 EQU $ - g_achLoadFailureMsg1
|
---|
363 | g_achLoadFailureMsg2:
|
---|
364 | db '!',0dh,0ah
|
---|
365 | g_cchLoadFailureMsg2 EQU $ - g_achLoadFailureMsg2
|
---|
366 |
|
---|
367 |
|
---|
368 | ;
|
---|
369 | ; The 16-bit code segment.
|
---|
370 | ;
|
---|
371 | segment CODE16
|
---|
372 |
|
---|
373 |
|
---|
374 | ;;
|
---|
375 | ; The strategy entry point (vboxdrv$).
|
---|
376 | ;
|
---|
377 | ; ss:bx -> request packet
|
---|
378 | ; ds:si -> device header
|
---|
379 | ;
|
---|
380 | ; Can clobber any registers it likes except SP.
|
---|
381 | ;
|
---|
382 | BEGINPROC VBoxGuestOS2EP
|
---|
383 | push ebp
|
---|
384 | mov ebp, esp
|
---|
385 | push es ; bp - 2
|
---|
386 | push bx ; bp - 4
|
---|
387 | and sp, 0fffch
|
---|
388 |
|
---|
389 | ;
|
---|
390 | ; Check for the most frequent first.
|
---|
391 | ;
|
---|
392 | cmp byte [es:bx + PKTHDR.cmd], 10h ; Generic IOCtl
|
---|
393 | jne near VBoxGuestOS2EP_NotGenIOCtl
|
---|
394 |
|
---|
395 |
|
---|
396 | ;
|
---|
397 | ; Generic I/O Control Request.
|
---|
398 | ;
|
---|
399 | VBoxGuestOS2EP_GenIOCtl:
|
---|
400 |
|
---|
401 | ; Fast IOCtl?
|
---|
402 | cmp byte [es:bx + PKTIOCTL.cat], VBOXGUEST_IOCTL_CATEGORY_FAST
|
---|
403 | jne VBoxGuestOS2EP_GenIOCtl_Other
|
---|
404 |
|
---|
405 | ;
|
---|
406 | ; Fast IOCtl.
|
---|
407 | ; DECLASM(int) VBoxGuestOS2IOCtlFast(uint16_t sfn, uint8_t iFunction, uint16_t *pcbParm)
|
---|
408 | ;
|
---|
409 | VBoxGuestOS2EP_GenIOCtl_Fast:
|
---|
410 | mov ax, [es:bx + PKTIOCTL.pData + 2] ; LDT selector to flat address.
|
---|
411 | shr ax, 3
|
---|
412 | shl eax, 16
|
---|
413 | mov ax, [es:bx + PKTIOCTL.pData]
|
---|
414 | push eax ; 08h - pointer to the rc buffer.
|
---|
415 |
|
---|
416 | ; function.
|
---|
417 | movzx edx, byte [es:bx + PKTIOCTL.fun]
|
---|
418 | push edx ; 04h
|
---|
419 |
|
---|
420 | ; system file number.
|
---|
421 | movzx eax, word [es:bx + PKTIOCTL.sfn]
|
---|
422 | push eax ; 00h
|
---|
423 |
|
---|
424 | JMP16TO32 VBoxGuestOS2EP_GenIOCtl_Fast_32
|
---|
425 | segment TEXT32
|
---|
426 | GLOBALNAME VBoxGuestOS2EP_GenIOCtl_Fast_32
|
---|
427 |
|
---|
428 | ; switch stack to 32-bit.
|
---|
429 | mov ax, DATA32 wrt FLAT
|
---|
430 | mov ds, ax
|
---|
431 | mov es, ax
|
---|
432 | call KernThunkStackTo32
|
---|
433 |
|
---|
434 | ; call the C code (don't cleanup the stack).
|
---|
435 | call NAME(VBoxGuestOS2IOCtlFast)
|
---|
436 |
|
---|
437 | ; switch back the stack.
|
---|
438 | push eax
|
---|
439 | call KernThunkStackTo16
|
---|
440 | pop eax
|
---|
441 |
|
---|
442 | JMP32TO16 VBoxGuestOS2EP_GenIOCtl_Fast_32
|
---|
443 | segment CODE16
|
---|
444 | GLOBALNAME VBoxGuestOS2EP_GenIOCtl_Fast_16
|
---|
445 |
|
---|
446 | les bx, [bp - 4] ; Reload the packet pointer.
|
---|
447 | or eax, eax
|
---|
448 | jnz near VBoxGuestOS2EP_GeneralFailure
|
---|
449 |
|
---|
450 | ; setup output stuff.
|
---|
451 | mov edx, esp
|
---|
452 | mov eax, [ss:edx + 0ch] ; output sizes.
|
---|
453 | mov [es:bx + PKTIOCTL.cbParm], eax ; update cbParm and cbData.
|
---|
454 | mov word [es:bx + PKTHDR.status], 00100h ; done, ok.
|
---|
455 |
|
---|
456 | mov sp, bp
|
---|
457 | pop ebp
|
---|
458 | retf
|
---|
459 |
|
---|
460 | ;
|
---|
461 | ; Other IOCtl (slow)
|
---|
462 | ;
|
---|
463 | VBoxGuestOS2EP_GenIOCtl_Other:
|
---|
464 | mov eax, [es:bx + PKTIOCTL.cbParm] ; Load cbParm and cbData
|
---|
465 | push eax ; 1eh - in/out data size.
|
---|
466 | ; 1ch - in/out parameter size.
|
---|
467 | push edx ; 18h - pointer to data size (filled in later).
|
---|
468 | push ecx ; 14h - pointer to param size (filled in later).
|
---|
469 |
|
---|
470 | ; pData (convert to flat 32-bit)
|
---|
471 | mov ax, word [es:bx + PKTIOCTL.pData + 2] ; selector
|
---|
472 | cmp ax, 3 ; <= 3 -> nil selector...
|
---|
473 | jbe .no_data
|
---|
474 | movzx esi, word [es:bx + PKTIOCTL.pData] ; offset
|
---|
475 | mov dl, DevHlp_VirtToLin
|
---|
476 | call far [NAME(g_fpfnDevHlp)]
|
---|
477 | jc near VBoxGuestOS2EP_GeneralFailure
|
---|
478 | jmp .finish_data
|
---|
479 | .no_data:
|
---|
480 | xor eax, eax
|
---|
481 | .finish_data:
|
---|
482 | push eax ; 10h
|
---|
483 |
|
---|
484 | ; pParm (convert to flat 32-bit)
|
---|
485 | mov ax, word [es:bx + PKTIOCTL.pParm + 2] ; selector
|
---|
486 | cmp ax, 3 ; <= 3 -> nil selector...
|
---|
487 | jbe .no_parm
|
---|
488 | movzx esi, word [es:bx + PKTIOCTL.pParm] ; offset
|
---|
489 | mov dl, DevHlp_VirtToLin
|
---|
490 | call far [NAME(g_fpfnDevHlp)]
|
---|
491 | jc near VBoxGuestOS2EP_GeneralFailure
|
---|
492 | jmp .finish_parm
|
---|
493 | .no_parm:
|
---|
494 | xor eax, eax
|
---|
495 | .finish_parm:
|
---|
496 | push eax ; 0ch
|
---|
497 |
|
---|
498 | ; function.
|
---|
499 | movzx edx, byte [es:bx + PKTIOCTL.fun]
|
---|
500 | push edx ; 08h
|
---|
501 |
|
---|
502 | ; category.
|
---|
503 | movzx ecx, byte [es:bx + PKTIOCTL.cat]
|
---|
504 | push ecx ; 04h
|
---|
505 |
|
---|
506 | ; system file number.
|
---|
507 | movzx eax, word [es:bx + PKTIOCTL.sfn]
|
---|
508 | push eax ; 00h
|
---|
509 |
|
---|
510 | JMP16TO32 VBoxGuestOS2EP_GenIOCtl_Other_32
|
---|
511 | segment TEXT32
|
---|
512 | GLOBALNAME VBoxGuestOS2EP_GenIOCtl_Other_32
|
---|
513 |
|
---|
514 | ; switch stack to 32-bit.
|
---|
515 | mov ax, DATA32 wrt FLAT
|
---|
516 | mov ds, ax
|
---|
517 | mov es, ax
|
---|
518 | call KernThunkStackTo32
|
---|
519 |
|
---|
520 | ; update in/out parameter pointers
|
---|
521 | lea eax, [esp + 1ch]
|
---|
522 | mov [esp + 14h], eax
|
---|
523 | lea edx, [esp + 1eh]
|
---|
524 | mov [esp + 18h], edx
|
---|
525 |
|
---|
526 | ; call the C code (don't cleanup the stack).
|
---|
527 | call NAME(VBoxGuestOS2IOCtl)
|
---|
528 |
|
---|
529 | ; switch back the stack.
|
---|
530 | push eax
|
---|
531 | call KernThunkStackTo16
|
---|
532 | pop eax
|
---|
533 |
|
---|
534 | JMP32TO16 VBoxGuestOS2EP_GenIOCtl_Other_16
|
---|
535 | segment CODE16
|
---|
536 | GLOBALNAME VBoxGuestOS2EP_GenIOCtl_Other_16
|
---|
537 |
|
---|
538 | les bx, [bp - 4] ; Reload the packet pointer.
|
---|
539 | or eax, eax
|
---|
540 | jnz near VBoxGuestOS2EP_GeneralFailure
|
---|
541 |
|
---|
542 | ; setup output stuff.
|
---|
543 | mov edx, esp
|
---|
544 | mov eax, [ss:edx + 1ch] ; output sizes.
|
---|
545 | mov [es:bx + PKTIOCTL.cbParm], eax ; update cbParm and cbData.
|
---|
546 | mov word [es:bx + PKTHDR.status], 00100h ; done, ok.
|
---|
547 |
|
---|
548 | mov sp, bp
|
---|
549 | pop ebp
|
---|
550 | retf
|
---|
551 |
|
---|
552 |
|
---|
553 | ;
|
---|
554 | ; Less Performance Critical Requests.
|
---|
555 | ;
|
---|
556 | VBoxGuestOS2EP_NotGenIOCtl:
|
---|
557 | cmp byte [es:bx + PKTHDR.cmd], 0dh ; Open
|
---|
558 | je VBoxGuestOS2EP_Open
|
---|
559 | cmp byte [es:bx + PKTHDR.cmd], 0eh ; Close
|
---|
560 | je VBoxGuestOS2EP_Close
|
---|
561 | cmp byte [es:bx + PKTHDR.cmd], 00h ; Init
|
---|
562 | je VBoxGuestOS2EP_Init
|
---|
563 | %ifdef DEBUG_READ
|
---|
564 | cmp byte [es:bx + PKTHDR.cmd], 04h ; Read
|
---|
565 | je near VBoxGuestOS2EP_Read
|
---|
566 | %endif
|
---|
567 | jmp near VBoxGuestOS2EP_NotSupported
|
---|
568 |
|
---|
569 |
|
---|
570 | ;
|
---|
571 | ; Open Request. w/ ring-0 init.
|
---|
572 | ;
|
---|
573 | VBoxGuestOS2EP_Open:
|
---|
574 | cmp byte [NAME(g_fInitialized)], 1
|
---|
575 | jne VBoxGuestOS2EP_OpenOther
|
---|
576 |
|
---|
577 | ; First argument, the system file number.
|
---|
578 | movzx eax, word [es:bx + PKTOPEN.sfn]
|
---|
579 | push eax
|
---|
580 |
|
---|
581 | JMP16TO32 VBoxGuestOS2EP_Open_32
|
---|
582 | segment TEXT32
|
---|
583 | GLOBALNAME VBoxGuestOS2EP_Open_32
|
---|
584 |
|
---|
585 | ; switch stack to 32-bit.
|
---|
586 | mov ax, DATA32 wrt FLAT
|
---|
587 | mov ds, ax
|
---|
588 | mov es, ax
|
---|
589 | call KernThunkStackTo32
|
---|
590 |
|
---|
591 | ; call the C code.
|
---|
592 | call NAME(VBoxGuestOS2Open)
|
---|
593 |
|
---|
594 | ; switch back the stack.
|
---|
595 | push eax
|
---|
596 | call KernThunkStackTo16
|
---|
597 | pop eax
|
---|
598 |
|
---|
599 | JMP32TO16 VBoxGuestOS2EP_Open_16
|
---|
600 | segment CODE16
|
---|
601 | GLOBALNAME VBoxGuestOS2EP_Open_16
|
---|
602 |
|
---|
603 | les bx, [bp - 4] ; Reload the packet pointer.
|
---|
604 | or eax, eax
|
---|
605 | jnz near VBoxGuestOS2EP_GeneralFailure
|
---|
606 | mov word [es:bx + PKTHDR.status], 00100h ; done, ok.
|
---|
607 | jmp near VBoxGuestOS2EP_Done
|
---|
608 |
|
---|
609 | ; Initializing or failed init?
|
---|
610 | VBoxGuestOS2EP_OpenOther:
|
---|
611 | cmp byte [NAME(g_fInitialized)], 0
|
---|
612 | jne VBoxGuestOS2EP_OpenFailed
|
---|
613 |
|
---|
614 | mov byte [NAME(g_fInitialized)], -1
|
---|
615 | call NAME(VBoxGuestRing0Init)
|
---|
616 | cmp byte [NAME(g_fInitialized)], 1
|
---|
617 | je VBoxGuestOS2EP_Open
|
---|
618 |
|
---|
619 | VBoxGuestOS2EP_OpenFailed:
|
---|
620 | mov word [es:bx + PKTHDR.status], 0810fh ; error, done, init failed.
|
---|
621 | jmp near VBoxGuestOS2EP_Done
|
---|
622 |
|
---|
623 |
|
---|
624 | ;
|
---|
625 | ; Close Request.
|
---|
626 | ;
|
---|
627 | VBoxGuestOS2EP_Close:
|
---|
628 | ; First argument, the system file number.
|
---|
629 | movzx eax, word [es:bx + PKTOPEN.sfn]
|
---|
630 | push eax
|
---|
631 |
|
---|
632 | JMP16TO32 VBoxGuestOS2EP_Close_32
|
---|
633 | segment TEXT32
|
---|
634 | GLOBALNAME VBoxGuestOS2EP_Close_32
|
---|
635 |
|
---|
636 | ; switch stack to 32-bit.
|
---|
637 | mov ax, DATA32 wrt FLAT
|
---|
638 | mov ds, ax
|
---|
639 | mov es, ax
|
---|
640 | call KernThunkStackTo32
|
---|
641 |
|
---|
642 | ; call the C code.
|
---|
643 | call NAME(VBoxGuestOS2Close)
|
---|
644 |
|
---|
645 | ; switch back the stack.
|
---|
646 | push eax
|
---|
647 | call KernThunkStackTo16
|
---|
648 | pop eax
|
---|
649 |
|
---|
650 | JMP32TO16 VBoxGuestOS2EP_Close_16
|
---|
651 | segment CODE16
|
---|
652 | GLOBALNAME VBoxGuestOS2EP_Close_16
|
---|
653 |
|
---|
654 | les bx, [bp - 4] ; Reload the packet pointer.
|
---|
655 | or eax, eax
|
---|
656 | jnz near VBoxGuestOS2EP_GeneralFailure
|
---|
657 | mov word [es:bx + PKTHDR.status], 00100h ; done, ok.
|
---|
658 | jmp near VBoxGuestOS2EP_Done
|
---|
659 |
|
---|
660 |
|
---|
661 | ;
|
---|
662 | ; Init Request.
|
---|
663 | ; Find the VMMDev adapter so we can unload the driver (and avoid trouble) if not found.
|
---|
664 | ;
|
---|
665 | VBoxGuestOS2EP_Init:
|
---|
666 | call NAME(VBoxGuestFindAdapter)
|
---|
667 | test ax, ax
|
---|
668 | jz .ok
|
---|
669 | mov word [es:bx + PKTHDR.status], 0810fh ; error, done, init failed.
|
---|
670 | call NAME(VBoxGuestOS2InitFlushText)
|
---|
671 | jmp .next
|
---|
672 | .ok:
|
---|
673 | mov word [es:bx + PKTHDR.status], 00100h ; done, ok.
|
---|
674 | .next:
|
---|
675 | mov byte [es:bx + PKTINITOUT.cUnits], 0
|
---|
676 | mov word [es:bx + PKTINITOUT.cbCode16], NAME(g_InitCodeStart) wrt CODE16
|
---|
677 | mov word [es:bx + PKTINITOUT.cbData16], NAME(g_InitDataStart) wrt DATA16
|
---|
678 | mov dword [es:bx + PKTINITOUT.fpaBPBs], 0
|
---|
679 | jmp near VBoxGuestOS2EP_Done
|
---|
680 |
|
---|
681 |
|
---|
682 | %ifdef DEBUG_READ
|
---|
683 | ;
|
---|
684 | ; Read Request.
|
---|
685 | ; Return log data.
|
---|
686 | ;
|
---|
687 | VBoxGuestOS2EP_Read:
|
---|
688 | ; Any log data available?
|
---|
689 | xor dx, dx
|
---|
690 | mov ax, [NAME(g_offLogTail)]
|
---|
691 | cmp ax, [NAME(g_offLogHead)]
|
---|
692 | jz near .log_done
|
---|
693 |
|
---|
694 | ; create a temporary mapping of the physical buffer. Docs claims it trashes nearly everything...
|
---|
695 | push ebp
|
---|
696 | mov cx, [es:bx + PKTRW.cbTrans]
|
---|
697 | push cx
|
---|
698 | mov ax, [es:bx + PKTRW.PhysTrans + 2]
|
---|
699 | mov bx, [es:bx + PKTRW.PhysTrans]
|
---|
700 | mov dh, 1
|
---|
701 | mov dl, DevHlp_PhysToVirt
|
---|
702 | call far [NAME(g_fpfnDevHlp)]
|
---|
703 | pop bx ; bx = cbTrans
|
---|
704 | pop ebp
|
---|
705 | jc near .log_phystovirt_failed
|
---|
706 | ; es:di -> the output buffer.
|
---|
707 |
|
---|
708 | ; setup the copy operation.
|
---|
709 | mov ax, [NAME(g_offLogTail)]
|
---|
710 | xor dx, dx ; dx tracks the number of bytes copied.
|
---|
711 | .log_loop:
|
---|
712 | mov cx, [NAME(g_offLogHead)]
|
---|
713 | cmp ax, cx
|
---|
714 | je .log_done
|
---|
715 | jb .log_loop_before
|
---|
716 | mov cx, LOG_SIZE
|
---|
717 | .log_loop_before: ; cx = end offset
|
---|
718 | sub cx, ax ; cx = sequential bytes to copy.
|
---|
719 | cmp cx, bx
|
---|
720 | jbe .log_loop_min
|
---|
721 | mov cx, bx ; output buffer is smaller than available data.
|
---|
722 | .log_loop_min:
|
---|
723 | mov si, NAME(g_szLog)
|
---|
724 | add si, ax ; ds:si -> the log buffer.
|
---|
725 | add dx, cx ; update output counter
|
---|
726 | add ax, cx ; calc new offLogTail
|
---|
727 | and ax, LOG_SIZE - 1
|
---|
728 | rep movsb ; do the copy
|
---|
729 | mov [NAME(g_offLogTail)], ax ; commit the read.
|
---|
730 | jmp .log_loop
|
---|
731 |
|
---|
732 | .log_done:
|
---|
733 | les bx, [bp - 4] ; Reload the packet pointer.
|
---|
734 | mov word [es:bx + PKTRW.cbTrans], dx
|
---|
735 | mov word [es:bx + PKTHDR.status], 00100h ; done, ok.
|
---|
736 | jmp near VBoxGuestOS2EP_Done
|
---|
737 |
|
---|
738 | .log_phystovirt_failed:
|
---|
739 | les bx, [bp - 4] ; Reload the packet pointer.
|
---|
740 | jmp VBoxGuestOS2EP_GeneralFailure
|
---|
741 | %endif ; DEBUG_READ
|
---|
742 |
|
---|
743 |
|
---|
744 | ;
|
---|
745 | ; Return 'unknown command' error.
|
---|
746 | ;
|
---|
747 | VBoxGuestOS2EP_NotSupported:
|
---|
748 | mov word [es:bx + PKTHDR.status], 08103h ; error, done, unknown command.
|
---|
749 | jmp VBoxGuestOS2EP_Done
|
---|
750 |
|
---|
751 | ;
|
---|
752 | ; Return 'general failure' error.
|
---|
753 | ;
|
---|
754 | VBoxGuestOS2EP_GeneralFailure:
|
---|
755 | mov word [es:bx + PKTHDR.status], 0810ch ; error, done, general failure.
|
---|
756 | jmp VBoxGuestOS2EP_Done
|
---|
757 |
|
---|
758 | ;
|
---|
759 | ; Non-optimized return path.
|
---|
760 | ;
|
---|
761 | VBoxGuestOS2EP_Done:
|
---|
762 | mov sp, bp
|
---|
763 | pop ebp
|
---|
764 | retf
|
---|
765 | ENDPROC VBoxGuestOS2EP
|
---|
766 |
|
---|
767 |
|
---|
768 | ;;
|
---|
769 | ; The helper device entry point.
|
---|
770 | ;
|
---|
771 | ; This is only used to do the DosOpen on the main driver so we can
|
---|
772 | ; do ring-3 init and report failures.
|
---|
773 | ;
|
---|
774 | GLOBALNAME VBoxGuestOS2InitEP
|
---|
775 | ; The only request we're servicing is the 'init' one.
|
---|
776 | cmp word [es:bx + PKTHDR.cmd], 0
|
---|
777 | je near NAME(VBoxGuestOS2InitEPServiceInitReq)
|
---|
778 |
|
---|
779 | ; Ok, it's not the init request, just fail it.
|
---|
780 | mov word [es:bx + PKTHDR.status], 08103h ; error, done, unknown command.
|
---|
781 | retf
|
---|
782 |
|
---|
783 |
|
---|
784 | ;;
|
---|
785 | ; The OS/2 IDC entry point.
|
---|
786 | ;
|
---|
787 | ; This is only used to setup connection, the returned structure
|
---|
788 | ; will provide the entry points that we'll be using.
|
---|
789 | ;
|
---|
790 | ; @cproto void far __cdecl VBoxGuestOS2IDC(VBOXGUESTOS2IDCCONNECT far *fpConnectInfo);
|
---|
791 | ;
|
---|
792 | ; @param fpConnectInfo [bp + 8] Pointer to an VBOXGUESTOS2IDCCONNECT structure.
|
---|
793 | ;
|
---|
794 | GLOBALNAME VBoxGuestOS2IDC
|
---|
795 | push ebp ; bp - 0h
|
---|
796 | mov ebp, esp
|
---|
797 | ; save everything we might touch.
|
---|
798 | push es ; bp - 2h
|
---|
799 | push ds ; bp - 4h
|
---|
800 | push eax ; bp - 8h
|
---|
801 | push ebx ; bp - 0ch
|
---|
802 | push ecx ; bp - 10h
|
---|
803 | push edx ; bp - 14h
|
---|
804 | and sp, 0fffch
|
---|
805 |
|
---|
806 | JMP16TO32 VBoxGuestOS2IDC_32
|
---|
807 | segment TEXT32
|
---|
808 | GLOBALNAME VBoxGuestOS2IDC_32
|
---|
809 |
|
---|
810 | ; switch stack to 32-bit.
|
---|
811 | mov ax, DATA32 wrt FLAT
|
---|
812 | mov ds, ax
|
---|
813 | mov es, ax
|
---|
814 | call KernThunkStackTo32
|
---|
815 |
|
---|
816 | ; call the C code.
|
---|
817 | call NAME(VBoxGuestOS2IDCConnect)
|
---|
818 |
|
---|
819 | ;
|
---|
820 | ; Load the return buffer address into ds:ebx and setup the buffer.
|
---|
821 | ; (eax == u32Session)
|
---|
822 | ;
|
---|
823 | mov cx, [ebp + 08h + 2]
|
---|
824 | mov ds, cx
|
---|
825 | movzx ebx, word [ebp + 08h]
|
---|
826 |
|
---|
827 | mov dword [ebx + VBGOS2IDC.u32Version ], VMMDEV_VERSION
|
---|
828 | mov dword [ebx + VBGOS2IDC.u32Session ], eax
|
---|
829 | mov dword [ebx + VBGOS2IDC.pfnServiceEP ], NAME(VBoxGuestOS2IDCService)
|
---|
830 | mov word [ebx + VBGOS2IDC.fpfnServiceEP ], NAME(VBoxGuestOs2IDCService16) wrt CODE16
|
---|
831 | mov word [ebx + VBGOS2IDC.fpfnServiceEP + 2], CODE16
|
---|
832 | mov word [ebx + VBGOS2IDC.fpfnServiceAsmEP ], NAME(VBoxGuestOs2IDCService16Asm) wrt CODE16
|
---|
833 | mov word [ebx + VBGOS2IDC.fpfnServiceAsmEP+2],CODE16
|
---|
834 |
|
---|
835 | mov ax, DATA32 wrt FLAT
|
---|
836 | mov ds, ax
|
---|
837 |
|
---|
838 | ; switch back the stack.
|
---|
839 | call KernThunkStackTo16
|
---|
840 |
|
---|
841 | JMP32TO16 VBoxGuestOS2IDC_16
|
---|
842 | segment CODE16
|
---|
843 | GLOBALNAME VBoxGuestOS2IDC_16
|
---|
844 |
|
---|
845 | ; restore.
|
---|
846 | lea sp, [bp - 14h]
|
---|
847 | pop edx
|
---|
848 | pop ecx
|
---|
849 | pop ebx
|
---|
850 | pop eax
|
---|
851 | pop ds
|
---|
852 | pop es
|
---|
853 | pop ebp
|
---|
854 | retf
|
---|
855 | ENDPROC VBoxGuestOS2IDC
|
---|
856 |
|
---|
857 |
|
---|
858 | ;;
|
---|
859 | ; The 16-bit IDC entry point, cdecl.
|
---|
860 | ;
|
---|
861 | ; All this does is thunking the request into something that fits
|
---|
862 | ; the 32-bit IDC service routine.
|
---|
863 | ;
|
---|
864 | ;
|
---|
865 | ; @returns VBox status code.
|
---|
866 | ; @param u32Session bp + 8h - The above session handle.
|
---|
867 | ; @param iFunction bp + 0ch - The requested function.
|
---|
868 | ; @param pvData bp + 0eh - The input/output data buffer. The caller ensures that this
|
---|
869 | ; cannot be swapped out, or that it's acceptable to take a
|
---|
870 | ; page in fault in the current context. If the request doesn't
|
---|
871 | ; take input or produces output, passing NULL is okay.
|
---|
872 | ; @param cbData bp + 12h - The size of the data buffer.
|
---|
873 | ; @param pcbDataReturned bp + 14h - Where to store the amount of data that's returned.
|
---|
874 | ; This can be NULL if pvData is NULL.
|
---|
875 | ;
|
---|
876 | ; @cproto long far __cdecl VBoxGuestOs2IDCService16(uint32_t u32Session, uint16_t iFunction, void far *fpvData, uint16_t cbData, uint16_t far *pcbDataReturned);
|
---|
877 | ;
|
---|
878 | GLOBALNAME VBoxGuestOs2IDCService16
|
---|
879 | push ebp ; bp - 0h
|
---|
880 | mov ebp, esp
|
---|
881 | push es ; bp - 2h
|
---|
882 | push ds ; bp - 4h
|
---|
883 | push ecx ; bp - 8h
|
---|
884 | push edx ; bp - 0ch
|
---|
885 | push esi ; bp - 10h
|
---|
886 | and sp, 0fffch ; align the stack.
|
---|
887 |
|
---|
888 | ; locals
|
---|
889 | push dword 0 ; esp + 18h (dd): cbDataReturned
|
---|
890 |
|
---|
891 | ; load our ds (for g_fpfnDevHlp).
|
---|
892 | mov ax, DATA16
|
---|
893 | mov ds, ax
|
---|
894 |
|
---|
895 | ;
|
---|
896 | ; Create the call frame before switching.
|
---|
897 | ;
|
---|
898 | push dword 0 ; esp + 14h: &cbDataReturned (filled in after stack switch)
|
---|
899 | movzx ecx, word [bp + 12h]
|
---|
900 | push ecx ; esp + 10h: cbData
|
---|
901 |
|
---|
902 | ; thunk data argument if present.
|
---|
903 | mov ax, [bp + 0eh + 2] ; selector
|
---|
904 | cmp ax, 3 ; <= 3 -> nil selector...
|
---|
905 | jbe .no_data
|
---|
906 | movzx esi, word [bp + 0eh] ; offset
|
---|
907 | mov dl, DevHlp_VirtToLin
|
---|
908 | call far [NAME(g_fpfnDevHlp)]
|
---|
909 | jc near VBoxGuestOs2IDCService16_InvalidPointer
|
---|
910 | jmp .finish_data
|
---|
911 | .no_data:
|
---|
912 | xor eax, eax
|
---|
913 | .finish_data:
|
---|
914 | push eax ; esp + 08h: pvData
|
---|
915 | movzx edx, word [bp + 0ch]
|
---|
916 | push edx ; esp + 04h: iFunction
|
---|
917 | mov ecx, [bp + 08h]
|
---|
918 | push ecx ; esp + 00h: u32Session
|
---|
919 |
|
---|
920 | JMP16TO32 VBoxGuestOs2IDCService16_32
|
---|
921 | segment TEXT32
|
---|
922 | GLOBALNAME VBoxGuestOs2IDCService16_32
|
---|
923 |
|
---|
924 | ; switch stack to 32-bit.
|
---|
925 | mov ax, DATA32 wrt FLAT
|
---|
926 | mov ds, ax
|
---|
927 | mov es, ax
|
---|
928 | call KernThunkStackTo32
|
---|
929 |
|
---|
930 | ; update the cbDataReturned pointer
|
---|
931 | lea eax, [esp + 18h]
|
---|
932 | mov [esp + 14h], eax
|
---|
933 |
|
---|
934 | ; call the C code (don't cleanup the stack).
|
---|
935 | call NAME(VBoxGuestOS2IDCService)
|
---|
936 |
|
---|
937 | ; switch back the stack.
|
---|
938 | push eax
|
---|
939 | call KernThunkStackTo16
|
---|
940 | pop eax
|
---|
941 |
|
---|
942 | JMP32TO16 VBoxGuestOs2IDCService16_16
|
---|
943 | segment CODE16
|
---|
944 | GLOBALNAME VBoxGuestOs2IDCService16_16
|
---|
945 |
|
---|
946 | ; Set *pcbDataReturned.
|
---|
947 | cmp word [bp + 14h + 2], 3
|
---|
948 | jbe .no_pcbDataReturned
|
---|
949 | xchg dx, bx
|
---|
950 | mov cx, [esp + 18h]
|
---|
951 | les bx, [bp + 14h]
|
---|
952 | mov word [es:bx], cx
|
---|
953 | xchg dx, bx
|
---|
954 | .no_pcbDataReturned:
|
---|
955 |
|
---|
956 | VBoxGuestOs2IDCService16_Done:
|
---|
957 | lea sp, [bp - 10h]
|
---|
958 | pop esi
|
---|
959 | pop edx
|
---|
960 | pop ecx
|
---|
961 | pop ds
|
---|
962 | pop es
|
---|
963 | pop ebp
|
---|
964 | retf
|
---|
965 |
|
---|
966 | VBoxGuestOs2IDCService16_InvalidPointer:
|
---|
967 | mov ax, VERR_INVALID_POINTER
|
---|
968 | jmp VBoxGuestOs2IDCService16_Done
|
---|
969 | ENDPROC VBoxGuestOs2IDCService16
|
---|
970 |
|
---|
971 |
|
---|
972 | ;;
|
---|
973 | ; The 16-bit IDC entry point, register based.
|
---|
974 | ;
|
---|
975 | ; This is just a wrapper around VBoxGuestOs2IDCService16 to simplify
|
---|
976 | ; calls from 16-bit assembly code.
|
---|
977 | ;
|
---|
978 | ; @returns ax: VBox status code; cx: The amount of data returned.
|
---|
979 | ;
|
---|
980 | ; @param u32Session eax - The above session handle.
|
---|
981 | ; @param iFunction dl - The requested function.
|
---|
982 | ; @param pvData es:bx - The input/output data buffer.
|
---|
983 | ; @param cbData cx - The size of the data buffer.
|
---|
984 | ;
|
---|
985 | GLOBALNAME VBoxGuestOs2IDCService16Asm
|
---|
986 | push ebp ; bp - 0h
|
---|
987 | mov ebp, esp
|
---|
988 | push edx ; bp - 4h
|
---|
989 | lea sp, [bp - 18h] ; allocate the call frame.
|
---|
990 |
|
---|
991 | ; bp - 06h (dw): oops...
|
---|
992 | mov [bp - 08h], word 0 ; bp - 08h (dw): cbDataReturned
|
---|
993 |
|
---|
994 | mov [bp - 0eh], cx ; bp - 0eh (dw): cbData (NOTE: out of order to free up CX)
|
---|
995 | lea cx, [bp - 08h] ; bp - 0ch (dd): &cbDataReturned
|
---|
996 | mov [bp - 0ah], cx
|
---|
997 | mov cx, ss
|
---|
998 | mov [bp - 0ch], cx
|
---|
999 | mov [bp - 10h], bx ; bp - 10h (dd): pvData
|
---|
1000 | mov cx, es
|
---|
1001 | mov [bp - 12h], cx
|
---|
1002 | mov [bp - 14h], dl ; bp - 14h (dw): iFunction
|
---|
1003 | mov [bp - 13h], byte 0
|
---|
1004 | mov [bp - 18h], eax ; bp - 18h (dd): u32Session
|
---|
1005 |
|
---|
1006 | call NAME(VBoxGuestOs2IDCService16)
|
---|
1007 |
|
---|
1008 | mov cx, [bp - 08h] ; cbDataReturned.
|
---|
1009 |
|
---|
1010 | mov edx, [bp - 4]
|
---|
1011 | mov esp, ebp
|
---|
1012 | pop ebp
|
---|
1013 | retf
|
---|
1014 | ENDPROC VBoxGuestOs2IDCService16Asm
|
---|
1015 |
|
---|
1016 |
|
---|
1017 |
|
---|
1018 | ;;
|
---|
1019 | ; The 16-bit interrupt service routine.
|
---|
1020 | ;
|
---|
1021 | ; OS/2 saves all registers according to the docs, although it doesn't say whether
|
---|
1022 | ; this includes the 32-bit parts. Since it doesn't cost much to be careful, save
|
---|
1023 | ; everything.
|
---|
1024 | ;
|
---|
1025 | ; @returns CF=0 if it's our interrupt, CF=1 it it isn't.
|
---|
1026 | ;
|
---|
1027 | ;
|
---|
1028 | GLOBALNAME VBoxGuestOS2ISR16
|
---|
1029 | push ebp
|
---|
1030 | mov ebp, esp
|
---|
1031 | pushf ; bp - 02h
|
---|
1032 | cli
|
---|
1033 | push eax ; bp - 06h
|
---|
1034 | push edx ; bp - 0ah
|
---|
1035 | push ebx ; bp - 0eh
|
---|
1036 | push ds ; bp - 10h
|
---|
1037 | push es ; bp - 12h
|
---|
1038 | push ecx ; bp - 16h
|
---|
1039 | push esi ; bp - 1ah
|
---|
1040 | push edi ; bp - 1eh
|
---|
1041 |
|
---|
1042 | and sp, 0fff0h ; align the stack (16-bytes make GCC extremely happy).
|
---|
1043 |
|
---|
1044 | JMP16TO32 VBoxGuestOS2ISR16_32
|
---|
1045 | segment TEXT32
|
---|
1046 | GLOBALNAME VBoxGuestOS2ISR16_32
|
---|
1047 |
|
---|
1048 | mov ax, DATA32 wrt FLAT
|
---|
1049 | mov ds, ax
|
---|
1050 | mov es, ax
|
---|
1051 |
|
---|
1052 | call KernThunkStackTo32
|
---|
1053 |
|
---|
1054 | call NAME(VBoxGuestOS2ISR)
|
---|
1055 | mov ebx, eax
|
---|
1056 |
|
---|
1057 | call KernThunkStackTo16
|
---|
1058 |
|
---|
1059 | JMP32TO16 VBoxGuestOS2ISR16_16
|
---|
1060 | segment CODE16
|
---|
1061 | GLOBALNAME VBoxGuestOS2ISR16_16
|
---|
1062 |
|
---|
1063 | lea sp, [bp - 1eh]
|
---|
1064 | pop edi
|
---|
1065 | pop esi
|
---|
1066 | pop ecx
|
---|
1067 | pop es
|
---|
1068 | pop ds
|
---|
1069 | test bl, 0ffh
|
---|
1070 | jnz .our
|
---|
1071 | pop ebx
|
---|
1072 | pop edx
|
---|
1073 | pop eax
|
---|
1074 | popf
|
---|
1075 | pop ebp
|
---|
1076 | stc
|
---|
1077 | retf
|
---|
1078 |
|
---|
1079 | ;
|
---|
1080 | ; Do EIO.
|
---|
1081 | ;
|
---|
1082 | .our:
|
---|
1083 | mov al, [NAME(g_bInterruptLine)]
|
---|
1084 | mov dl, DevHlp_EIO
|
---|
1085 | call far [NAME(g_fpfnDevHlp)]
|
---|
1086 |
|
---|
1087 | pop ebx
|
---|
1088 | pop edx
|
---|
1089 | pop eax
|
---|
1090 | popf
|
---|
1091 | pop ebp
|
---|
1092 | clc
|
---|
1093 | retf
|
---|
1094 | ENDPROC VBoxGuestOS2ISR16
|
---|
1095 |
|
---|
1096 |
|
---|
1097 |
|
---|
1098 |
|
---|
1099 |
|
---|
1100 |
|
---|
1101 | ;
|
---|
1102 | ; The 32-bit text segment.
|
---|
1103 | ;
|
---|
1104 | segment TEXT32
|
---|
1105 | ;;
|
---|
1106 | ; 32-bit worker for registering the ISR.
|
---|
1107 | ;
|
---|
1108 | ; @returns 0 on success, some non-zero OS/2 error code on failure.
|
---|
1109 | ; @param bIrq [ebp + 8] The IRQ number. (uint8_t)
|
---|
1110 | ;
|
---|
1111 | GLOBALNAME VBoxGuestOS2SetIRQ
|
---|
1112 | push ebp
|
---|
1113 | mov ebp, esp
|
---|
1114 | push ebx
|
---|
1115 | push ds
|
---|
1116 |
|
---|
1117 | call KernThunkStackTo16
|
---|
1118 |
|
---|
1119 | movzx ebx, byte [ebp + 8] ; load bIrq into BX.
|
---|
1120 |
|
---|
1121 | JMP32TO16 VBoxGuestOS2SetIRQ_16
|
---|
1122 | segment CODE16
|
---|
1123 | GLOBALNAME VBoxGuestOS2SetIRQ_16
|
---|
1124 |
|
---|
1125 | mov ax, DATA16 ; for g_fpfnDevHlp.
|
---|
1126 | mov ds, ax
|
---|
1127 | mov ax, NAME(VBoxGuestOS2ISR16) ; The devhlp assume it's relative to DS.
|
---|
1128 | mov dh, 1 ; 1 = shared
|
---|
1129 | mov dl, DevHlp_SetIRQ
|
---|
1130 | call far [NAME(g_fpfnDevHlp)]
|
---|
1131 | jnc .ok
|
---|
1132 | movzx eax, ax
|
---|
1133 | or eax, eax
|
---|
1134 | jnz .go_back
|
---|
1135 | or eax, 6
|
---|
1136 | jmp .go_back
|
---|
1137 | .ok:
|
---|
1138 | xor eax, eax
|
---|
1139 |
|
---|
1140 | .go_back:
|
---|
1141 | JMP16TO32 VBoxGuestOS2SetIRQ_32
|
---|
1142 | segment TEXT32
|
---|
1143 | GLOBALNAME VBoxGuestOS2SetIRQ_32
|
---|
1144 |
|
---|
1145 | pop ds ; KernThunkStackTo32 ASSUMES flat DS and ES.
|
---|
1146 |
|
---|
1147 | mov ebx, eax
|
---|
1148 | call KernThunkStackTo32
|
---|
1149 | mov eax, ebx
|
---|
1150 |
|
---|
1151 | pop ebx
|
---|
1152 | pop ebp
|
---|
1153 | ret
|
---|
1154 | ENDPROC VBoxGuestOS2SetIRQ
|
---|
1155 |
|
---|
1156 |
|
---|
1157 |
|
---|
1158 |
|
---|
1159 | ;
|
---|
1160 | ; The 16-bit init code.
|
---|
1161 | ;
|
---|
1162 | segment CODE16_INIT
|
---|
1163 | GLOBALNAME g_InitCodeStart
|
---|
1164 |
|
---|
1165 | ;; The device name for DosOpen.
|
---|
1166 | g_szDeviceName:
|
---|
1167 | db '\DEV\vboxgst$', 0
|
---|
1168 |
|
---|
1169 | ; icsdebug can't see where stuff starts otherwise. (kDevTest)
|
---|
1170 | int3
|
---|
1171 | int3
|
---|
1172 | int3
|
---|
1173 | int3
|
---|
1174 | int3
|
---|
1175 | int3
|
---|
1176 |
|
---|
1177 | ;;
|
---|
1178 | ; The Ring-3 init code.
|
---|
1179 | ;
|
---|
1180 | BEGINPROC VBoxGuestOS2InitEPServiceInitReq
|
---|
1181 | push ebp
|
---|
1182 | mov ebp, esp
|
---|
1183 | push es ; bp - 2
|
---|
1184 | push sp ; bp - 4
|
---|
1185 | push -1 ; bp - 6: hfOpen
|
---|
1186 | push 0 ; bp - 8: usAction
|
---|
1187 | and sp, 0fffch
|
---|
1188 |
|
---|
1189 | ; check for the init package.
|
---|
1190 | cmp word [es:bx + PKTHDR.cmd], 0
|
---|
1191 | jne near .not_init
|
---|
1192 |
|
---|
1193 | ; check that we found the VMMDev.
|
---|
1194 | test byte [NAME(g_fFoundAdapter)], 1
|
---|
1195 | jz near .done_err
|
---|
1196 |
|
---|
1197 | ;
|
---|
1198 | ; Copy the data out of the init packet.
|
---|
1199 | ;
|
---|
1200 | mov eax, [es:bx + PKTINITIN.fpfnDevHlp]
|
---|
1201 | mov [NAME(g_fpfnDevHlp)], eax
|
---|
1202 | mov edx, [es:bx + PKTINITIN.fpszArgs]
|
---|
1203 | mov [g_fpszArgs], edx
|
---|
1204 |
|
---|
1205 | ;
|
---|
1206 | ; Open the first driver, close it, and check status.
|
---|
1207 | ;
|
---|
1208 |
|
---|
1209 | ; APIRET _Pascal DosOpen(PSZ pszFname, PHFILE phfOpen, PUSHORT pusAction,
|
---|
1210 | ; ULONG ulFSize, USHORT usAttr, USHORT fsOpenFlags,
|
---|
1211 | ; USHORT fsOpenMode, ULONG ulReserved);
|
---|
1212 | push seg g_szDeviceName ; pszFname
|
---|
1213 | push g_szDeviceName
|
---|
1214 | push ss ; phfOpen
|
---|
1215 | lea dx, [bp - 6]
|
---|
1216 | push dx
|
---|
1217 | push ss ; pusAction
|
---|
1218 | lea dx, [bp - 8]
|
---|
1219 | push dx
|
---|
1220 | push dword 0 ; ulFSize
|
---|
1221 | push 0 ; usAttr = FILE_NORMAL
|
---|
1222 | push 1 ; fsOpenFlags = FILE_OPEN
|
---|
1223 | push 00040h ; fsOpenMode = OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY
|
---|
1224 | push dword 0 ; ulReserved
|
---|
1225 | call far DOS16OPEN
|
---|
1226 |
|
---|
1227 | push ax ; Quickly flush any text.
|
---|
1228 | call NAME(VBoxGuestOS2InitFlushText)
|
---|
1229 | pop ax
|
---|
1230 |
|
---|
1231 | or ax, ax
|
---|
1232 | jnz .done_err
|
---|
1233 |
|
---|
1234 | ; APIRET APIENTRY DosClose(HFILE hf);
|
---|
1235 | mov cx, [bp - 6]
|
---|
1236 | push cx
|
---|
1237 | call far DOS16CLOSE
|
---|
1238 | or ax, ax
|
---|
1239 | jnz .done_err ; This can't happen (I hope).
|
---|
1240 |
|
---|
1241 | ;
|
---|
1242 | ; Ok, we're good.
|
---|
1243 | ;
|
---|
1244 | mov word [es:bx + PKTHDR.status], 00100h ; done, ok.
|
---|
1245 | mov byte [es:bx + PKTINITOUT.cUnits], 0
|
---|
1246 | mov word [es:bx + PKTINITOUT.cbCode16], NAME(g_InitCodeStart) wrt CODE16
|
---|
1247 | mov word [es:bx + PKTINITOUT.cbData16], NAME(g_InitDataStart) wrt DATA16
|
---|
1248 | mov dword [es:bx + PKTINITOUT.fpaBPBs], 0
|
---|
1249 | jmp .done
|
---|
1250 |
|
---|
1251 | ;
|
---|
1252 | ; Init failure.
|
---|
1253 | ;
|
---|
1254 | .done_err:
|
---|
1255 | mov word [es:bx + PKTHDR.status], 0810fh ; error, done, init failed.
|
---|
1256 | mov byte [es:bx + PKTINITOUT.cUnits], 0
|
---|
1257 | mov word [es:bx + PKTINITOUT.cbCode16], 0
|
---|
1258 | mov word [es:bx + PKTINITOUT.cbData16], 0
|
---|
1259 | mov dword [es:bx + PKTINITOUT.fpaBPBs], 0
|
---|
1260 | jmp .done
|
---|
1261 |
|
---|
1262 | ;
|
---|
1263 | ; Not init, return 'unknown command'.
|
---|
1264 | ;
|
---|
1265 | .not_init:
|
---|
1266 | mov word [es:bx + PKTHDR.status], 08103h ; error, done, unknown command.
|
---|
1267 | jmp .done
|
---|
1268 |
|
---|
1269 | ;
|
---|
1270 | ; Request done.
|
---|
1271 | ;
|
---|
1272 | .done:
|
---|
1273 | mov sp, bp
|
---|
1274 | pop ebp
|
---|
1275 | retf
|
---|
1276 | ENDPROC VBoxGuestOS2InitEPServiceInitReq
|
---|
1277 |
|
---|
1278 |
|
---|
1279 | ;;
|
---|
1280 | ; The Ring-0 init code.
|
---|
1281 | ;
|
---|
1282 | BEGINPROC VBoxGuestRing0Init
|
---|
1283 | push es
|
---|
1284 | push esi
|
---|
1285 | push ebp
|
---|
1286 | mov ebp, esp
|
---|
1287 | and sp, 0fffch
|
---|
1288 |
|
---|
1289 | ;
|
---|
1290 | ; Thunk the argument string pointer first.
|
---|
1291 | ;
|
---|
1292 | movzx esi, word [g_fpszArgs] ; offset
|
---|
1293 | mov ax, [g_fpszArgs + 2] ; selector
|
---|
1294 | mov dl, DevHlp_VirtToLin
|
---|
1295 | call far [NAME(g_fpfnDevHlp)]
|
---|
1296 | jc near VBoxGuestRing0Init_done ; eax is non-zero on failure (can't happen)
|
---|
1297 | push eax ; 00h - pszArgs (for VBoxGuestOS2Init).
|
---|
1298 |
|
---|
1299 | ;
|
---|
1300 | ; Do 16-bit init?
|
---|
1301 | ;
|
---|
1302 |
|
---|
1303 |
|
---|
1304 | ;
|
---|
1305 | ; Do 32-bit init
|
---|
1306 | ;
|
---|
1307 | JMP16TO32 VBoxGuestRing0Init_32
|
---|
1308 | segment TEXT32
|
---|
1309 | GLOBALNAME VBoxGuestRing0Init_32
|
---|
1310 |
|
---|
1311 | ; switch stack to 32-bit.
|
---|
1312 | mov ax, DATA32 wrt FLAT
|
---|
1313 | mov ds, ax
|
---|
1314 | mov es, ax
|
---|
1315 | call KernThunkStackTo32
|
---|
1316 |
|
---|
1317 | ; call the C code.
|
---|
1318 | call NAME(VBoxGuestOS2Init)
|
---|
1319 |
|
---|
1320 | ; switch back the stack and reload ds.
|
---|
1321 | push eax
|
---|
1322 | call KernThunkStackTo16
|
---|
1323 | pop eax
|
---|
1324 |
|
---|
1325 | mov dx, seg NAME(g_fInitialized)
|
---|
1326 | mov ds, dx
|
---|
1327 |
|
---|
1328 | JMP32TO16 VBoxGuestRing0Init_16
|
---|
1329 | segment CODE16_INIT
|
---|
1330 | GLOBALNAME VBoxGuestRing0Init_16
|
---|
1331 |
|
---|
1332 | ; check the result and set g_fInitialized on success.
|
---|
1333 | or eax, eax
|
---|
1334 | jnz VBoxGuestRing0Init_done
|
---|
1335 | mov byte [NAME(g_fInitialized)], 1
|
---|
1336 |
|
---|
1337 | VBoxGuestRing0Init_done:
|
---|
1338 | mov sp, bp
|
---|
1339 | pop ebp
|
---|
1340 | pop esi
|
---|
1341 | pop es
|
---|
1342 | ret
|
---|
1343 | ENDPROC VBoxGuestRing0Init
|
---|
1344 |
|
---|
1345 |
|
---|
1346 | ;;
|
---|
1347 | ; Flush any text in the text buffer.
|
---|
1348 | ;
|
---|
1349 | BEGINPROC VBoxGuestOS2InitFlushText
|
---|
1350 | push bp
|
---|
1351 | mov bp, sp
|
---|
1352 |
|
---|
1353 | ; Anything in the buffer?
|
---|
1354 | mov ax, [NAME(g_cchInitText)]
|
---|
1355 | or ax, ax
|
---|
1356 | jz .done
|
---|
1357 |
|
---|
1358 | %if 1
|
---|
1359 | ; Write it to STDOUT.
|
---|
1360 | ; APIRET _Pascal DosWrite(HFILE hf, PVOID pvBuf, USHORT cbBuf, PUSHORT pcbBytesWritten);
|
---|
1361 | push ax ; bp - 2 : cbBytesWritten
|
---|
1362 | mov cx, sp
|
---|
1363 | push 1 ; STDOUT
|
---|
1364 | push seg NAME(g_szInitText) ; pvBuf
|
---|
1365 | push NAME(g_szInitText)
|
---|
1366 | push ax ; cbBuf
|
---|
1367 | push ss ; pcbBytesWritten
|
---|
1368 | push cx
|
---|
1369 | %if 0 ; wlink generates a non-aliased fixup here which results in 16-bit offset with the flat 32-bit selector.
|
---|
1370 | call far DOS16WRITE
|
---|
1371 | %else
|
---|
1372 | ; convert flat pointer to a far pointer using the tiled algorithm.
|
---|
1373 | push ds
|
---|
1374 | mov ax, DATA32 wrt FLAT
|
---|
1375 | mov ds, ax
|
---|
1376 | mov eax, g_pfnDos16Write wrt FLAT
|
---|
1377 | movzx eax, word [eax + 2] ; High word of the flat address (in DATA32).
|
---|
1378 | shl ax, 3
|
---|
1379 | or ax, 0007h
|
---|
1380 | pop ds
|
---|
1381 | mov [NAME(g_fpfnDos16Write) + 2], ax ; Update the selector (in DATA16_INIT).
|
---|
1382 | ; do the call
|
---|
1383 | call far [NAME(g_fpfnDos16Write)]
|
---|
1384 | %endif
|
---|
1385 |
|
---|
1386 | %else ; alternative workaround for the wlink issue.
|
---|
1387 | ; Use the save message devhlp.
|
---|
1388 | push esi
|
---|
1389 | push ebx
|
---|
1390 | xor bx, bx
|
---|
1391 | mov si, NAME(g_MsgTab)
|
---|
1392 | mov dx, seg NAME(g_MsgTab)
|
---|
1393 | mov ds, dx
|
---|
1394 | mov dl, DevHlp_SAVE_MESSAGE
|
---|
1395 | call far [NAME(g_fpfnDevHlp)]
|
---|
1396 | pop ebx
|
---|
1397 | pop esi
|
---|
1398 | %endif
|
---|
1399 |
|
---|
1400 | ; Empty the buffer.
|
---|
1401 | mov word [NAME(g_cchInitText)], 0
|
---|
1402 | mov byte [NAME(g_szInitText)], 0
|
---|
1403 |
|
---|
1404 | .done:
|
---|
1405 | mov sp, bp
|
---|
1406 | pop bp
|
---|
1407 | ret
|
---|
1408 | ENDPROC VBoxGuestOS2InitFlushText
|
---|
1409 |
|
---|
1410 |
|
---|
1411 | ;; The device name for DosOpen.
|
---|
1412 | g_szOemHlpDevName:
|
---|
1413 | db '\DEV\OEMHLP$', 0
|
---|
1414 |
|
---|
1415 |
|
---|
1416 | ;;
|
---|
1417 | ; Talks to OEMHLP$ about finding the VMMDev PCI adapter.
|
---|
1418 | ;
|
---|
1419 | ; On success g_fFoundAdapter is set to 1, and g_cbMMIO,
|
---|
1420 | ; g_PhysMMIOBase and g_IOPortBase are initialized with
|
---|
1421 | ; the PCI data.
|
---|
1422 | ;
|
---|
1423 | ; @returns 0 on success, non-zero on failure. (eax)
|
---|
1424 | ;
|
---|
1425 | ; @remark ASSUMES DS:DATA16.
|
---|
1426 | ; @uses nothing.
|
---|
1427 | ;
|
---|
1428 | BEGINPROC VBoxGuestFindAdapter
|
---|
1429 | push ebx
|
---|
1430 | push ecx
|
---|
1431 | push edx
|
---|
1432 | push esi
|
---|
1433 | push edi
|
---|
1434 | push ebp
|
---|
1435 | mov ebp, esp
|
---|
1436 | push -1 ; bp - 2: hfOpen
|
---|
1437 | %define hfOpen bp - 2
|
---|
1438 | push 0 ; bp - 4: usAction
|
---|
1439 | %define usAction bp - 4
|
---|
1440 | sub sp, 20h ; bp - 44: 32 byte parameter buffer.
|
---|
1441 | %define abParm bp - 24h
|
---|
1442 | sub sp, 40h ; bp - c4: 32 byte data buffer.
|
---|
1443 | %define abData bp - 44h
|
---|
1444 |
|
---|
1445 | ;; VBox stuff
|
---|
1446 | %define VBOX_PCI_VENDORID 080eeh
|
---|
1447 | %define VMMDEV_DEVICEID 0cafeh
|
---|
1448 |
|
---|
1449 | ;; OEMHLP$ stuff.
|
---|
1450 | %define IOCTL_OEMHLP 80h
|
---|
1451 | %define OEMHLP_PCI 0bh
|
---|
1452 | %define PCI_FIND_DEVICE 1
|
---|
1453 | %define PCI_READ_CONFIG 3
|
---|
1454 |
|
---|
1455 | ;; PCI stuff
|
---|
1456 | %define PCI_INTERRUPT_LINE 03ch ;;< 8-bit RW - Interrupt line.
|
---|
1457 | %define PCI_BASE_ADDRESS_0 010h ;;< 32-bit RW */
|
---|
1458 | %define PCI_BASE_ADDRESS_1 014h ;;< 32-bit RW */
|
---|
1459 |
|
---|
1460 |
|
---|
1461 | %macro CallIOCtl 2
|
---|
1462 | ; APIRET _Pascal DosDevIOCtl2(PVOID pData, USHORT cbData, PVOID pParm,
|
---|
1463 | ; USHORT cbParm, USHORT usFun, USHORT usCategory,
|
---|
1464 | ; HFILE hDev);
|
---|
1465 | push ss ; pData
|
---|
1466 | lea dx, [abData]
|
---|
1467 | push dx
|
---|
1468 | push %2 ; cbData
|
---|
1469 |
|
---|
1470 | push ss ; pParm
|
---|
1471 | lea dx, [abParm]
|
---|
1472 | push dx
|
---|
1473 | push %1 ; cbParm
|
---|
1474 | push OEMHLP_PCI ; usFun
|
---|
1475 | push IOCTL_OEMHLP ; usCategory
|
---|
1476 |
|
---|
1477 | mov ax, [hfOpen] ; hDev
|
---|
1478 | push ax
|
---|
1479 | call far DOS16DEVIOCTL2
|
---|
1480 |
|
---|
1481 | ; check for error.
|
---|
1482 | test ax, ax
|
---|
1483 | jnz near .done_err_close
|
---|
1484 | cmp [abData + 0], byte 0
|
---|
1485 | jne near .done_err_close
|
---|
1486 | %endmacro
|
---|
1487 |
|
---|
1488 |
|
---|
1489 | ;
|
---|
1490 | ; Open the OEMHLP$ driver.
|
---|
1491 | ;
|
---|
1492 |
|
---|
1493 | ; APIRET _Pascal DosOpen(PSZ pszFname, PHFILE phfOpen, PUSHORT pusAction,
|
---|
1494 | ; ULONG ulFSize, USHORT usAttr, USHORT fsOpenFlags,
|
---|
1495 | ; USHORT fsOpenMode, ULONG ulReserved);
|
---|
1496 | mov di, '0'
|
---|
1497 | push seg g_szOemHlpDevName ; pszFname
|
---|
1498 | push g_szOemHlpDevName
|
---|
1499 | push ss ; phfOpen
|
---|
1500 | lea dx, [hfOpen]
|
---|
1501 | push dx
|
---|
1502 | push ss ; pusAction
|
---|
1503 | lea dx, [usAction]
|
---|
1504 | push dx
|
---|
1505 | push dword 0 ; ulFSize
|
---|
1506 | push 0 ; usAttr = FILE_NORMAL
|
---|
1507 | push 1 ; fsOpenFlags = FILE_OPEN
|
---|
1508 | push 00040h ; fsOpenMode = OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY
|
---|
1509 | push dword 0 ; ulReserved
|
---|
1510 | call far DOS16OPEN
|
---|
1511 | or ax, ax
|
---|
1512 | jnz near .done
|
---|
1513 |
|
---|
1514 |
|
---|
1515 | ;
|
---|
1516 | ; Send a PCI_FIND_DEVICE request.
|
---|
1517 | ;
|
---|
1518 |
|
---|
1519 | ; Initialize the parameter packet.
|
---|
1520 | mov [abParm + 0], byte PCI_FIND_DEVICE ; 0 - db - SubFunction Number
|
---|
1521 | mov [abParm + 1], word VMMDEV_DEVICEID ; 1 - dw - Device ID
|
---|
1522 | mov [abParm + 3], word VBOX_PCI_VENDORID ; 3 - dw - Vendor ID
|
---|
1523 | mov [abParm + 5], byte 0 ; 5 - db - (Device) Index
|
---|
1524 |
|
---|
1525 | ; Zero padd the data packet.
|
---|
1526 | mov [abData + 0], dword 0
|
---|
1527 |
|
---|
1528 | mov di, '1'
|
---|
1529 | CallIOCtl 6, 3
|
---|
1530 |
|
---|
1531 | mov al, [abData + 1] ; 1 - db - Bus Number.
|
---|
1532 | mov [NAME(g_bPciBusNo)], al
|
---|
1533 | mov al, [abData + 2] ; 2 - db - DevFunc Number.
|
---|
1534 | mov [NAME(g_bPciDevFunNo)], al
|
---|
1535 |
|
---|
1536 | ;
|
---|
1537 | ; Read the interrupt register (byte).
|
---|
1538 | ;
|
---|
1539 | mov di, '2'
|
---|
1540 | mov ax, PCI_INTERRUPT_LINE | 0100h
|
---|
1541 | call .NestedReadReg
|
---|
1542 | mov [NAME(g_bInterruptLine)], al
|
---|
1543 |
|
---|
1544 | ;
|
---|
1545 | ; Read the first base address (dword), this shall must be in I/O space.
|
---|
1546 | ;
|
---|
1547 | mov di, '3'
|
---|
1548 | mov ax, PCI_BASE_ADDRESS_0 | 0400h
|
---|
1549 | call .NestedReadReg
|
---|
1550 | mov di, '4'
|
---|
1551 | test al, 1h ; Test that it's an I/O space address.
|
---|
1552 | jz .done_err_close
|
---|
1553 | mov di, '5'
|
---|
1554 | test eax, 0ffff0002h ; These shall all be 0 according to the specs.
|
---|
1555 | jnz .done_err_close
|
---|
1556 | and ax, 0fffeh
|
---|
1557 | mov [NAME(g_IOPortBase)], ax
|
---|
1558 |
|
---|
1559 | ;
|
---|
1560 | ; Read the second base address (dword), this shall be in memory space if present.
|
---|
1561 | ;
|
---|
1562 | mov di, '6'
|
---|
1563 | mov ax, PCI_BASE_ADDRESS_1 | 0400h
|
---|
1564 | call .NestedReadReg
|
---|
1565 | mov di, '7'
|
---|
1566 | test al, 1h ; Test that it's a memory space address.
|
---|
1567 | jnz .done_err_close
|
---|
1568 | and eax, 0fffffff0h
|
---|
1569 | mov [NAME(g_PhysMMIOBase)], eax
|
---|
1570 |
|
---|
1571 | ;or eax, eax
|
---|
1572 | ;jz .done_success ; No memory region.
|
---|
1573 | ;; @todo If there is a simple way of determining the size do that, if
|
---|
1574 | ; not we can easily handle it the code that does the actual mapping.
|
---|
1575 |
|
---|
1576 |
|
---|
1577 | ;
|
---|
1578 | ; Ok, we're good!
|
---|
1579 | ;
|
---|
1580 | .done_success:
|
---|
1581 | or [NAME(g_fFoundAdapter)], byte 1
|
---|
1582 | jmp .done_close
|
---|
1583 |
|
---|
1584 | ;
|
---|
1585 | ; Close the OEMHLP$ driver.
|
---|
1586 | ;
|
---|
1587 | .done_err_close:
|
---|
1588 | or ax, 80h
|
---|
1589 | .done_close:
|
---|
1590 | ; APIRET APIENTRY DosClose(HFILE hf);
|
---|
1591 | push ax ; Save result
|
---|
1592 | mov cx, [hfOpen]
|
---|
1593 | push cx
|
---|
1594 | call far DOS16CLOSE
|
---|
1595 | or ax, ax
|
---|
1596 | jnz .bitch ; This can't happen (I hope).
|
---|
1597 | pop ax
|
---|
1598 | or ax, ax
|
---|
1599 | jnz .bitch
|
---|
1600 |
|
---|
1601 | ;
|
---|
1602 | ; Return to VBoxGuestOS2EP_Init.
|
---|
1603 | ;
|
---|
1604 | .done:
|
---|
1605 | mov esp, ebp
|
---|
1606 | pop ebp
|
---|
1607 | pop edi
|
---|
1608 | pop esi
|
---|
1609 | pop edx
|
---|
1610 | pop ecx
|
---|
1611 | pop ebx
|
---|
1612 | ret
|
---|
1613 |
|
---|
1614 |
|
---|
1615 | ;
|
---|
1616 | ; Puts the reason for failure in message buffer.
|
---|
1617 | ; The caller will flush this.
|
---|
1618 | ;
|
---|
1619 | .bitch:
|
---|
1620 | push es
|
---|
1621 |
|
---|
1622 | mov ax, ds
|
---|
1623 | mov es, ax
|
---|
1624 | mov ax, di ; save the reason.
|
---|
1625 | mov di, NAME(g_szInitText)
|
---|
1626 | add di, [NAME(g_cchInitText)]
|
---|
1627 |
|
---|
1628 | mov si, g_achLoadFailureMsg1
|
---|
1629 | mov cx, g_cchLoadFailureMsg1
|
---|
1630 | rep movsb
|
---|
1631 |
|
---|
1632 | stosb
|
---|
1633 |
|
---|
1634 | mov si, g_achLoadFailureMsg2
|
---|
1635 | mov cx, g_cchLoadFailureMsg2
|
---|
1636 | rep movsb
|
---|
1637 |
|
---|
1638 | mov [di], byte 0
|
---|
1639 | sub di, NAME(g_szInitText)
|
---|
1640 | mov [NAME(g_cchInitText)], di
|
---|
1641 |
|
---|
1642 | pop es
|
---|
1643 | jmp .done
|
---|
1644 |
|
---|
1645 |
|
---|
1646 | ;
|
---|
1647 | ; Nested function which reads a PCI config register.
|
---|
1648 | ; (This operates on the VBoxGuestFindAdapter stack frame.)
|
---|
1649 | ;
|
---|
1650 | ; Input:
|
---|
1651 | ; al - register to read
|
---|
1652 | ; ah - register size.
|
---|
1653 | ;
|
---|
1654 | ; Output:
|
---|
1655 | ; eax - the value.
|
---|
1656 | ;
|
---|
1657 | ; Uses:
|
---|
1658 | ; dx
|
---|
1659 | ;
|
---|
1660 | .NestedReadReg:
|
---|
1661 | ; Fill in the request packet.
|
---|
1662 | mov [abParm + 0], byte PCI_READ_CONFIG ; 0 - db - SubFunction Number
|
---|
1663 | mov dl, [NAME(g_bPciBusNo)]
|
---|
1664 | mov [abParm + 1], dl ; 1 - db - Bus Number
|
---|
1665 | mov dl, [NAME(g_bPciDevFunNo)]
|
---|
1666 | mov [abParm + 2], dl ; 2 - db - DevFunc Number
|
---|
1667 | mov [abParm + 3], al ; 3 - db - Configuration Register
|
---|
1668 | mov [abParm + 4], ah ; 4 - db - (Register) Size
|
---|
1669 |
|
---|
1670 | ; Pad the data packet.
|
---|
1671 | mov [abData + 0], dword 0
|
---|
1672 | mov [abData + 4], dword 0
|
---|
1673 |
|
---|
1674 | CallIOCtl 5, 5
|
---|
1675 |
|
---|
1676 | mov eax, [abData + 1] ; 1 - dd - Data
|
---|
1677 |
|
---|
1678 | ret
|
---|
1679 |
|
---|
1680 | ENDPROC VBoxGuestFindAdapter
|
---|
1681 |
|
---|
1682 |
|
---|
1683 |
|
---|
1684 | ;;
|
---|
1685 | ; This must be present
|
---|
1686 | segment DATA32
|
---|
1687 | g_pfnDos16Write:
|
---|
1688 | dd DOS16WRITE ; flat
|
---|
1689 |
|
---|
1690 |
|
---|