3 * Code to detect the surrounding DOS/Windows environment and support routines to work with it
4 * (C) 2009-2012 Jonathan Campbell.
5 * Hackipedia DOS library.
7 * This code is licensed under the LGPL.
8 * <insert LGPL legal text here>
16 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */
26 #include <hw/cpu/cpu.h>
27 #include <hw/dos/dos.h>
28 #include <hw/dos/doswin.h>
29 #include <hw/dos/dosntvdm.h>
31 unsigned char vcpi_probed = 0;
32 unsigned char vcpi_present = 0;
33 unsigned char vcpi_major_version,vcpi_minor_version;
35 /* NTS: According to the VCPI specification this call is only supposed to report
36 * the physical memory address for anything below the 1MB boundary. And so
37 * far EMM386.EXE strictly adheres to that rule by not reporting success for
38 * addresses >= 1MB. The 32-bit limitation is a result of the VCPI system
39 * call, since the physical address is returned in EDX. */
40 uint32_t dos_linear_to_phys_vcpi(uint32_t pn) {
41 uint32_t r=0xFFFFFFFFUL;
49 jnz err1 ; if AH == 0 then EDX = page phys addr
57 #if !defined(TARGET_WINDOWS)
58 static int int67_null() {
61 #if TARGET_MSDOS == 32
62 ptr = ((uint32_t*)0)[0x67];
64 ptr = *((uint32_t far*)MK_FP(0,0x67*4));;
72 #if defined(TARGET_WINDOWS)
74 /* NTS: Whoever said Windows 3.0 used VCPI at it's core, is a liar */
79 /* =================== MSDOS ================== */
80 unsigned char err=0xFF;
85 /* if virtual 8086 mode isn't active, then VCPI isn't there */
86 /* FIXME: What about cases where VCPI might be there, but is inactive (such as: EMM386.EXE resident but disabled) */
90 /* NOTE: VCPI can be present whether we're 16-bit real mode or
91 * 32-bit protected mode. Unlike DPMI we cannot assume it's
92 * present just because we're 32-bit. */
94 /* Do not call INT 67h if the vector is uninitialized */
98 /* Do not attempt to probe for VCPI if Windows 3.1/95/98/ME
99 * is running. Windows 9x blocks VCPI and if called, interrupts
100 * our execution to inform the user that the program should be
101 * run in DOS mode. */
103 if (windows_mode != WINDOWS_NONE)
106 /* NTS: we load DS for each var because Watcom might put it in
107 * another data segment, especially in Large memory model.
108 * failure to account for this was the cause of mysterious
109 * hangs and crashes. */
111 ; NTS: Save DS and ES because Microsoft EMM386.EXE
112 ; appears to change their contents.
119 mov ax,seg vcpi_major_version
121 mov vcpi_major_version,bh
123 mov ax,seg vcpi_minor_version
125 mov vcpi_minor_version,bl