2013-06-26 22:58:41 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: GPL - See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Virtual DOS Machine
|
2015-09-18 17:01:49 +00:00
|
|
|
* FILE: subsystems/mvdm/ntvdm/emulator.h
|
2013-12-24 15:53:30 +00:00
|
|
|
* PURPOSE: Minimal x86 machine emulator for the VDM
|
2013-06-26 22:58:41 +00:00
|
|
|
* PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _EMULATOR_H_
|
|
|
|
#define _EMULATOR_H_
|
|
|
|
|
2015-10-04 11:49:28 +00:00
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
|
|
|
#include <fast486.h>
|
|
|
|
|
2013-06-26 22:58:41 +00:00
|
|
|
/* DEFINES ********************************************************************/
|
|
|
|
|
2021-11-25 21:39:56 +00:00
|
|
|
/*
|
|
|
|
* Basic Memory Management
|
|
|
|
*/
|
|
|
|
#define NULL32 ((ULONG)0)
|
|
|
|
|
2014-02-26 01:07:09 +00:00
|
|
|
#define MEM_ALIGN_DOWN(ptr, align) (PVOID)((ULONG_PTR)(ptr) & ~((align) - 1l))
|
2015-06-15 23:43:16 +00:00
|
|
|
#define MEM_ALIGN_UP(ptr, align) MEM_ALIGN_DOWN((ULONG_PTR)(ptr) + (align) - 1l, (align))
|
2014-02-23 20:40:09 +00:00
|
|
|
|
2014-01-11 20:59:27 +00:00
|
|
|
#define TO_LINEAR(seg, off) (((seg) << 4) + (off))
|
|
|
|
#define MAX_SEGMENT 0xFFFF
|
|
|
|
#define MAX_OFFSET 0xFFFF
|
2014-11-17 02:08:12 +00:00
|
|
|
#define MAX_ADDRESS 0x1000000 // 16 MB of RAM; see also: kernel32/client/vdm.c!BaseGetVdmConfigInfo
|
2015-09-23 01:45:18 +00:00
|
|
|
C_ASSERT(0x100000 <= MAX_ADDRESS); // A minimum of 1 MB is required for PC emulation.
|
2014-01-11 20:59:27 +00:00
|
|
|
|
|
|
|
#define SEG_OFF_TO_PTR(seg, off) \
|
|
|
|
(PVOID)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), (off)))
|
|
|
|
|
2015-06-15 23:43:16 +00:00
|
|
|
#define FAR_POINTER(x) SEG_OFF_TO_PTR(HIWORD(x), LOWORD(x))
|
|
|
|
|
2014-02-23 20:40:09 +00:00
|
|
|
#define REAL_TO_PHYS(ptr) (PVOID)((ULONG_PTR)(ptr) + (ULONG_PTR)BaseAddress)
|
|
|
|
#define PHYS_TO_REAL(ptr) (PVOID)((ULONG_PTR)(ptr) - (ULONG_PTR)BaseAddress)
|
|
|
|
|
2015-03-26 00:21:25 +00:00
|
|
|
#define ARRAY_INDEX(ptr, array) ((ULONG)(((ULONG_PTR)(ptr) - (ULONG_PTR)(array)) / sizeof(*array)))
|
2014-01-11 20:59:27 +00:00
|
|
|
|
2021-11-25 21:39:56 +00:00
|
|
|
/*
|
|
|
|
* BCD-Binary conversion
|
|
|
|
*/
|
2014-01-11 20:59:27 +00:00
|
|
|
|
2015-02-22 16:31:58 +00:00
|
|
|
FORCEINLINE
|
|
|
|
USHORT
|
|
|
|
BINARY_TO_BCD(USHORT Value)
|
|
|
|
{
|
|
|
|
USHORT Result;
|
|
|
|
|
|
|
|
Result = (Value / 1000) << 12;
|
|
|
|
Value %= 1000;
|
|
|
|
Result |= (Value / 100) << 8;
|
|
|
|
Value %= 100;
|
|
|
|
Result |= (Value / 10) << 4;
|
|
|
|
Value %= 10;
|
|
|
|
Result |= Value;
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
|
|
|
USHORT
|
|
|
|
BCD_TO_BINARY(USHORT Value)
|
|
|
|
{
|
|
|
|
USHORT Result;
|
|
|
|
|
|
|
|
Result = Value & 0xF;
|
|
|
|
Value >>= 4;
|
|
|
|
Result += (Value & 0xF) * 10;
|
|
|
|
Value >>= 4;
|
|
|
|
Result += (Value & 0xF) * 100;
|
|
|
|
Value >>= 4;
|
|
|
|
Result += Value * 1000;
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
2014-01-11 20:59:27 +00:00
|
|
|
|
2021-11-25 21:39:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Emulator state
|
|
|
|
*/
|
|
|
|
|
2013-06-26 22:58:41 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
EMULATOR_EXCEPTION_DIVISION_BY_ZERO,
|
|
|
|
EMULATOR_EXCEPTION_DEBUG,
|
|
|
|
EMULATOR_EXCEPTION_NMI,
|
|
|
|
EMULATOR_EXCEPTION_BREAKPOINT,
|
|
|
|
EMULATOR_EXCEPTION_OVERFLOW,
|
|
|
|
EMULATOR_EXCEPTION_BOUND,
|
|
|
|
EMULATOR_EXCEPTION_INVALID_OPCODE,
|
2013-07-07 20:53:23 +00:00
|
|
|
EMULATOR_EXCEPTION_NO_FPU,
|
|
|
|
EMULATOR_EXCEPTION_DOUBLE_FAULT,
|
|
|
|
EMULATOR_EXCEPTION_FPU_SEGMENT,
|
|
|
|
EMULATOR_EXCEPTION_INVALID_TSS,
|
|
|
|
EMULATOR_EXCEPTION_NO_SEGMENT,
|
|
|
|
EMULATOR_EXCEPTION_STACK_SEGMENT,
|
|
|
|
EMULATOR_EXCEPTION_GPF,
|
|
|
|
EMULATOR_EXCEPTION_PAGE_FAULT
|
2013-06-26 22:58:41 +00:00
|
|
|
};
|
|
|
|
|
2015-06-12 03:30:40 +00:00
|
|
|
extern FAST486_STATE EmulatorContext;
|
2014-01-11 20:59:27 +00:00
|
|
|
extern LPVOID BaseAddress;
|
|
|
|
extern BOOLEAN VdmRunning;
|
2013-09-28 00:29:16 +00:00
|
|
|
|
2021-11-25 21:39:56 +00:00
|
|
|
|
2013-06-26 22:58:41 +00:00
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
2014-09-28 16:27:30 +00:00
|
|
|
VOID DumpMemory(BOOLEAN TextFormat);
|
2014-05-17 23:49:35 +00:00
|
|
|
|
2015-09-27 15:24:26 +00:00
|
|
|
VOID MountFloppy(IN ULONG DiskNumber);
|
|
|
|
VOID EjectFloppy(IN ULONG DiskNumber);
|
|
|
|
|
2015-06-12 03:30:40 +00:00
|
|
|
UCHAR FASTCALL EmulatorIntAcknowledge
|
2013-11-09 17:16:04 +00:00
|
|
|
(
|
|
|
|
PFAST486_STATE State
|
|
|
|
);
|
|
|
|
|
2015-06-12 03:30:40 +00:00
|
|
|
VOID FASTCALL EmulatorFpu
|
2015-01-03 15:16:41 +00:00
|
|
|
(
|
|
|
|
PFAST486_STATE State
|
|
|
|
);
|
|
|
|
|
[NTVDM]
- Add support for DOS VDM reentry, i.e. the fact that a DOS app can start a 32-bit app, which in turn can start another DOS app, ad infinitum...
CORE-9711 CORE-9773 #resolve
- Add a small COMMAND.COM which is, for now, completely included in NTVDM. This COMMAND.COM is needed in order to support reentrancy. The fact that I chose to put it inside NTVDM is that any user can use instead his/her own COMMAND.COM, while retaining the possibility to perform VDM reentrancy (on Windows, if you remove the COMMAND.COM in windows\system32 and replace it with your own, you will break VDM reentrancy on windows' ntvdm).
CORE-5221 #resolve #comment I choose for the moment an internal COMMAND.COM, but you can recompile NTVDM to use it externally instead.
Global remarks:
- Quite a few DPRINTs were added for diagnostic purposes (since DOS reentrancy is a new feature), to be sure everything behaves as expected when being used with a large panel of applications. They will be removed when everything is OK.
- Support for current directories and 16/32-bit environment translation (in ntvdm + basevdm-side) remain to be implemented.
Other changes:
- Improve a bit the VDM shutdown code by gathering it at one place (there's still room for other improvements).
- Add suppport for properly pausing/resuming NTVDM.
- Bufferize some console events before dispatching.
Have fun ;^)
svn path=/trunk/; revision=69204
2015-09-12 20:09:25 +00:00
|
|
|
VOID EmulatorInterruptSignal(VOID);
|
2014-01-25 00:21:51 +00:00
|
|
|
VOID EmulatorException(BYTE ExceptionNumber, LPWORD Stack);
|
|
|
|
|
[NTVDM]
- Add support for DOS VDM reentry, i.e. the fact that a DOS app can start a 32-bit app, which in turn can start another DOS app, ad infinitum...
CORE-9711 CORE-9773 #resolve
- Add a small COMMAND.COM which is, for now, completely included in NTVDM. This COMMAND.COM is needed in order to support reentrancy. The fact that I chose to put it inside NTVDM is that any user can use instead his/her own COMMAND.COM, while retaining the possibility to perform VDM reentrancy (on Windows, if you remove the COMMAND.COM in windows\system32 and replace it with your own, you will break VDM reentrancy on windows' ntvdm).
CORE-5221 #resolve #comment I choose for the moment an internal COMMAND.COM, but you can recompile NTVDM to use it externally instead.
Global remarks:
- Quite a few DPRINTs were added for diagnostic purposes (since DOS reentrancy is a new feature), to be sure everything behaves as expected when being used with a large panel of applications. They will be removed when everything is OK.
- Support for current directories and 16/32-bit environment translation (in ntvdm + basevdm-side) remain to be implemented.
Other changes:
- Improve a bit the VDM shutdown code by gathering it at one place (there's still room for other improvements).
- Add suppport for properly pausing/resuming NTVDM.
- Bufferize some console events before dispatching.
Have fun ;^)
svn path=/trunk/; revision=69204
2015-09-12 20:09:25 +00:00
|
|
|
VOID EmulatorPause(VOID);
|
|
|
|
VOID EmulatorResume(VOID);
|
2014-03-02 14:37:51 +00:00
|
|
|
VOID EmulatorTerminate(VOID);
|
|
|
|
|
|
|
|
BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput);
|
|
|
|
VOID EmulatorCleanup(VOID);
|
|
|
|
|
2015-10-04 11:49:28 +00:00
|
|
|
#endif // _EMULATOR_H_
|
|
|
|
|
|
|
|
/* EOF */
|