Author: hbelusca
Date: Sat Mar 14 03:37:54 2015
New Revision: 66675
URL:
http://svn.reactos.org/svn/reactos?rev=66675&view=rev
Log:
[NTVDM]: Move EMS support as a BIOS module (and initialize it after the BIOS has finished
its initialization, including resetting the INT handlers).
Added:
trunk/reactos/subsystems/mvdm/ntvdm/bios/bios32/ems.c
- copied, changed from r66673, trunk/reactos/subsystems/mvdm/ntvdm/ems.c
trunk/reactos/subsystems/mvdm/ntvdm/bios/bios32/ems.h
- copied, changed from r66673, trunk/reactos/subsystems/mvdm/ntvdm/ems.h
Removed:
trunk/reactos/subsystems/mvdm/ntvdm/ems.c
trunk/reactos/subsystems/mvdm/ntvdm/ems.h
Modified:
trunk/reactos/subsystems/mvdm/ntvdm/CMakeLists.txt
trunk/reactos/subsystems/mvdm/ntvdm/bios/bios32/bios32.c
trunk/reactos/subsystems/mvdm/ntvdm/emulator.c
Modified: trunk/reactos/subsystems/mvdm/ntvdm/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/CMak…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/CMakeLists.txt [iso-8859-1] Sat Mar 14 03:37:54
2015
@@ -10,6 +10,7 @@
bios/bios32/kbdbios32.c
bios/bios32/vidbios32.c
bios/bios32/moubios32.c
+ bios/bios32/ems.c
bios/bios.c
bios/kbdbios.c
bios/rom.c
@@ -33,7 +34,6 @@
dos/mouse32.c
dos/dem.c
clock.c
- ems.c
emulator.c
int32.c
io.c
Modified: trunk/reactos/subsystems/mvdm/ntvdm/bios/bios32/bios32.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/bios…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/bios/bios32/bios32.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/bios/bios32/bios32.c [iso-8859-1] Sat Mar 14
03:37:54 2015
@@ -25,6 +25,8 @@
#include "kbdbios32.h"
#include "vidbios32.h"
#include "moubios32.h"
+
+#include "ems.h"
#include "io.h"
#include "hardware/cmos.h"
@@ -665,6 +667,9 @@
SearchAndInitRoms(&BiosContext);
+ /* Initialize EMS */
+ EmsInitialize();
+
/*
* End of the 32-bit POST portion. We then fall back into 16-bit where
* the rest of the POST code is executed, typically calling INT 19h
@@ -726,6 +731,7 @@
VOID Bios32Cleanup(VOID)
{
+ EmsCleanup();
MouseBios32Cleanup();
VidBios32Cleanup();
KbdBios32Cleanup();
Copied: trunk/reactos/subsystems/mvdm/ntvdm/bios/bios32/ems.c (from r66673,
trunk/reactos/subsystems/mvdm/ntvdm/ems.c)
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/bios…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/ems.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/bios/bios32/ems.c [iso-8859-1] Sat Mar 14 03:37:54
2015
@@ -195,6 +195,14 @@
break;
}
+ /* Get EMM Version */
+ case 0x46:
+ {
+ setAH(EMS_STATUS_OK);
+ setAL(EMS_VERSION_NUM);
+ break;
+ }
+
/* Move/Exchange Memory */
case 0x57:
{
Copied: trunk/reactos/subsystems/mvdm/ntvdm/bios/bios32/ems.h (from r66673,
trunk/reactos/subsystems/mvdm/ntvdm/ems.h)
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/bios…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/ems.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/bios/bios32/ems.h [iso-8859-1] Sat Mar 14 03:37:54
2015
@@ -11,6 +11,7 @@
/* DEFINITIONS ****************************************************************/
+#define EMS_VERSION_NUM 0x04
#define EMS_INTERRUPT_NUM 0x67
#define EMS_SEGMENT 0xD000
#define EMS_MAX_HANDLES 16
Removed: trunk/reactos/subsystems/mvdm/ntvdm/ems.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/ems.…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/ems.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/ems.c (removed)
@@ -1,368 +0,0 @@
-/*
- * COPYRIGHT: GPLv2+ - See COPYING in the top level directory
- * PROJECT: ReactOS Virtual DOS Machine
- * FILE: ems.c
- * PURPOSE: Expanded Memory Support
- * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
- */
-
-/* INCLUDES *******************************************************************/
-
-#define NDEBUG
-
-#include "emulator.h"
-#include "bios/bios32/bios32p.h"
-#include <ndk/rtltypes.h>
-#include <ndk/rtlfuncs.h>
-#include "ems.h"
-#include "memory.h"
-
-/* PRIVATE VARIABLES **********************************************************/
-
-static RTL_BITMAP AllocBitmap;
-static ULONG BitmapBuffer[(EMS_TOTAL_PAGES + sizeof(ULONG) - 1) / sizeof(ULONG)];
-static EMS_PAGE PageTable[EMS_TOTAL_PAGES];
-static EMS_HANDLE HandleTable[EMS_MAX_HANDLES];
-static PVOID Mapping[EMS_PHYSICAL_PAGES] = { NULL };
-
-/* PRIVATE FUNCTIONS **********************************************************/
-
-static USHORT EmsFree(USHORT Handle)
-{
- PLIST_ENTRY Entry;
- PEMS_HANDLE HandleEntry = &HandleTable[Handle];
-
- if (Handle >= EMS_MAX_HANDLES || !HandleEntry->Allocated)
- {
- return EMS_STATUS_INVALID_HANDLE;
- }
-
- for (Entry = HandleEntry->PageList.Flink;
- Entry != &HandleEntry->PageList;
- Entry = Entry->Flink)
- {
- PEMS_PAGE PageEntry = (PEMS_PAGE)CONTAINING_RECORD(Entry, EMS_PAGE, Entry);
- ULONG PageNumber = ARRAY_INDEX(PageEntry, PageTable);
-
- /* Free the page */
- RtlClearBits(&AllocBitmap, PageNumber, 1);
- }
-
- HandleEntry->Allocated = FALSE;
- HandleEntry->PageCount = 0;
- InitializeListHead(&HandleEntry->PageList);
-
- return EMS_STATUS_OK;
-}
-
-static UCHAR EmsAlloc(USHORT NumPages, PUSHORT Handle)
-{
- ULONG i, CurrentIndex = 0;
- PEMS_HANDLE HandleEntry;
-
- if (NumPages == 0) return EMS_STATUS_ZERO_PAGES;
-
- for (i = 0; i < EMS_MAX_HANDLES; i++)
- {
- HandleEntry = &HandleTable[i];
- if (!HandleEntry->Allocated)
- {
- *Handle = i;
- break;
- }
- }
-
- if (i == EMS_MAX_HANDLES) return EMS_STATUS_NO_MORE_HANDLES;
- HandleEntry->Allocated = TRUE;
-
- while (HandleEntry->PageCount < NumPages)
- {
- ULONG RunStart;
- ULONG RunSize = RtlFindNextForwardRunClear(&AllocBitmap, CurrentIndex,
&RunStart);
-
- if (RunSize == 0)
- {
- /* Free what's been allocated already and report failure */
- EmsFree(*Handle);
- return EMS_STATUS_INSUFFICIENT_PAGES;
- }
- else if ((HandleEntry->PageCount + RunSize) > NumPages)
- {
- /* We don't need the entire run */
- RunSize = NumPages - HandleEntry->PageCount;
- }
-
- CurrentIndex = RunStart + RunSize;
- HandleEntry->PageCount += RunSize;
- RtlSetBits(&AllocBitmap, RunStart, RunSize);
-
- for (i = 0; i < RunSize; i++)
- {
- PageTable[RunStart + i].Handle = *Handle;
- InsertTailList(&HandleEntry->PageList, &PageTable[RunStart +
i].Entry);
- }
- }
-
- return EMS_STATUS_OK;
-}
-
-static PEMS_PAGE GetLogicalPage(PEMS_HANDLE Handle, USHORT LogicalPage)
-{
- PLIST_ENTRY Entry = Handle->PageList.Flink;
-
- while (LogicalPage)
- {
- if (Entry == &Handle->PageList) return NULL;
- LogicalPage--;
- Entry = Entry->Flink;
- }
-
- return (PEMS_PAGE)CONTAINING_RECORD(Entry, EMS_PAGE, Entry);
-}
-
-static USHORT EmsMap(USHORT Handle, UCHAR PhysicalPage, USHORT LogicalPage)
-{
- PEMS_PAGE PageEntry;
- PEMS_HANDLE HandleEntry = &HandleTable[Handle];
-
- if (PhysicalPage >= EMS_PHYSICAL_PAGES) return EMS_STATUS_INV_PHYSICAL_PAGE;
- if (LogicalPage == 0xFFFF)
- {
- /* Unmap */
- Mapping[PhysicalPage] = NULL;
- return EMS_STATUS_OK;
- }
-
- if (Handle >= EMS_MAX_HANDLES || !HandleEntry->Allocated) return
EMS_STATUS_INVALID_HANDLE;
-
- PageEntry = GetLogicalPage(HandleEntry, LogicalPage);
- if (!PageEntry) return EMS_STATUS_INV_LOGICAL_PAGE;
-
- Mapping[PhysicalPage] = (PVOID)(EMS_ADDRESS + ARRAY_INDEX(PageEntry, PageTable) *
EMS_PAGE_SIZE);
- return EMS_STATUS_OK;
-}
-
-static VOID WINAPI EmsIntHandler(LPWORD Stack)
-{
- switch (getAH())
- {
- /* Get Manager Status */
- case 0x40:
- {
- setAH(EMS_STATUS_OK);
- break;
- }
-
- /* Get Page Frame Segment */
- case 0x41:
- {
- setAH(EMS_STATUS_OK);
- setBX(EMS_SEGMENT);
- break;
- }
-
- /* Get Number Of Pages */
- case 0x42:
- {
- setAH(EMS_STATUS_OK);
- setBX(RtlNumberOfClearBits(&AllocBitmap));
- setDX(EMS_TOTAL_PAGES);
- break;
- }
-
- /* Get Handle And Allocate Memory */
- case 0x43:
- {
- USHORT Handle;
- UCHAR Status = EmsAlloc(getBX(), &Handle);
-
- setAH(Status);
- if (Status == EMS_STATUS_OK) setDX(Handle);
- break;
- }
-
- /* Map Memory */
- case 0x44:
- {
- setAH(EmsMap(getDX(), getAL(), getBX()));
- break;
- }
-
- /* Release Handle And Memory */
- case 0x45:
- {
- setAH(EmsFree(getDX()));
- break;
- }
-
- /* Move/Exchange Memory */
- case 0x57:
- {
- PUCHAR SourcePtr, DestPtr;
- PEMS_HANDLE HandleEntry;
- PEMS_PAGE PageEntry;
- BOOLEAN Exchange = getAL();
- PEMS_COPY_DATA Data = (PEMS_COPY_DATA)SEG_OFF_TO_PTR(getDS(), getSI());
-
- if (Data->SourceType)
- {
- /* Expanded memory */
- HandleEntry = &HandleTable[Data->SourceHandle];
-
- if (Data->SourceHandle >= EMS_MAX_HANDLES ||
!HandleEntry->Allocated)
- {
- setAL(EMS_STATUS_INVALID_HANDLE);
- break;
- }
-
- PageEntry = GetLogicalPage(HandleEntry, Data->SourceSegment);
-
- if (!PageEntry)
- {
- setAL(EMS_STATUS_INV_LOGICAL_PAGE);
- break;
- }
-
- SourcePtr = (PUCHAR)REAL_TO_PHYS(EMS_ADDRESS
- + ARRAY_INDEX(PageEntry, PageTable)
- * EMS_PAGE_SIZE
- + Data->SourceOffset);
- }
- else
- {
- /* Conventional memory */
- SourcePtr = (PUCHAR)SEG_OFF_TO_PTR(Data->SourceSegment,
Data->SourceOffset);
- }
-
- if (Data->DestType)
- {
- /* Expanded memory */
- HandleEntry = &HandleTable[Data->DestHandle];
-
- if (Data->SourceHandle >= EMS_MAX_HANDLES ||
!HandleEntry->Allocated)
- {
- setAL(EMS_STATUS_INVALID_HANDLE);
- break;
- }
-
- PageEntry = GetLogicalPage(HandleEntry, Data->DestSegment);
-
- if (!PageEntry)
- {
- setAL(EMS_STATUS_INV_LOGICAL_PAGE);
- break;
- }
-
- DestPtr = (PUCHAR)REAL_TO_PHYS(EMS_ADDRESS
- + ARRAY_INDEX(PageEntry, PageTable)
- * EMS_PAGE_SIZE
- + Data->DestOffset);
- }
- else
- {
- /* Conventional memory */
- DestPtr = (PUCHAR)SEG_OFF_TO_PTR(Data->DestSegment,
Data->DestOffset);
- }
-
- if (Exchange)
- {
- ULONG i;
-
- /* Exchange */
- for (i = 0; i < Data->RegionLength; i++)
- {
- UCHAR Temp = DestPtr[i];
- DestPtr[i] = SourcePtr[i];
- SourcePtr[i] = Temp;
- }
- }
- else
- {
- /* Move */
- RtlMoveMemory(DestPtr, SourcePtr, Data->RegionLength);
- }
-
- setAL(EMS_STATUS_OK);
- break;
- }
-
- default:
- {
- DPRINT1("EMS function AH = %02X NOT IMPLEMENTED\n", getAH());
- setAH(EMS_STATUS_UNKNOWN_FUNCTION);
- break;
- }
- }
-}
-
-static VOID NTAPI EmsReadMemory(ULONG Address, PVOID Buffer, ULONG Size)
-{
- ULONG i;
- ULONG RelativeAddress = Address - TO_LINEAR(EMS_SEGMENT, 0);
- ULONG FirstPage = RelativeAddress / EMS_PAGE_SIZE;
- ULONG LastPage = (RelativeAddress + Size - 1) / EMS_PAGE_SIZE;
- ULONG Offset, Length;
-
- for (i = FirstPage; i <= LastPage; i++)
- {
- Offset = (i == FirstPage) ? Address & (EMS_PAGE_SIZE - 1) : 0;
- Length = ((i == LastPage)
- ? (Address + Size - (LastPage << EMS_PAGE_BITS))
- : EMS_PAGE_SIZE) - Offset;
-
- if (Mapping[i]) RtlCopyMemory(Buffer, (PVOID)((ULONG_PTR)Mapping[i] + Offset),
Length);
- Buffer = (PVOID)((ULONG_PTR)Buffer + Length);
- }
-}
-
-static BOOLEAN NTAPI EmsWriteMemory(ULONG Address, PVOID Buffer, ULONG Size)
-{
- ULONG i;
- ULONG RelativeAddress = Address - TO_LINEAR(EMS_SEGMENT, 0);
- ULONG FirstPage = RelativeAddress / EMS_PAGE_SIZE;
- ULONG LastPage = (RelativeAddress + Size - 1) / EMS_PAGE_SIZE;
- ULONG Offset, Length;
-
- for (i = FirstPage; i <= LastPage; i++)
- {
- Offset = (i == FirstPage) ? Address & (EMS_PAGE_SIZE - 1) : 0;
- Length = ((i == LastPage)
- ? (Address + Size - (LastPage << EMS_PAGE_BITS))
- : EMS_PAGE_SIZE) - Offset;
-
- if (Mapping[i]) RtlCopyMemory((PVOID)((ULONG_PTR)Mapping[i] + Offset), Buffer,
Length);
- Buffer = (PVOID)((ULONG_PTR)Buffer + Length);
- }
-
- return TRUE;
-}
-
-/* PUBLIC FUNCTIONS ***********************************************************/
-
-VOID EmsInitialize(VOID)
-{
- ULONG i;
-
- RtlZeroMemory(BitmapBuffer, sizeof(BitmapBuffer));
- RtlInitializeBitMap(&AllocBitmap, BitmapBuffer, EMS_TOTAL_PAGES);
-
- for (i = 0; i < EMS_MAX_HANDLES; i++)
- {
- HandleTable[i].Allocated = FALSE;
- HandleTable[i].PageCount = 0;
- InitializeListHead(&HandleTable[i].PageList);
- }
-
- MemInstallFastMemoryHook((PVOID)TO_LINEAR(EMS_SEGMENT, 0),
- EMS_PHYSICAL_PAGES * EMS_PAGE_SIZE,
- EmsReadMemory,
- EmsWriteMemory);
-
- RegisterBiosInt32(EMS_INTERRUPT_NUM, EmsIntHandler);
-}
-
-VOID EmsCleanup(VOID)
-{
- MemRemoveFastMemoryHook((PVOID)TO_LINEAR(EMS_SEGMENT, 0),
- EMS_PHYSICAL_PAGES * EMS_PAGE_SIZE);
-}
Removed: trunk/reactos/subsystems/mvdm/ntvdm/ems.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/ems.…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/ems.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/ems.h (removed)
@@ -1,72 +0,0 @@
-/*
- * COPYRIGHT: GPLv2+ - See COPYING in the top level directory
- * PROJECT: ReactOS Virtual DOS Machine
- * FILE: ems.h
- * PURPOSE: Expanded Memory Support
- * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
- */
-
-#ifndef _EMS_H_
-#define _EMS_H_
-
-/* DEFINITIONS ****************************************************************/
-
-#define EMS_INTERRUPT_NUM 0x67
-#define EMS_SEGMENT 0xD000
-#define EMS_MAX_HANDLES 16
-#define EMS_TOTAL_PAGES 256
-#define EMS_PAGE_BITS 14
-#define EMS_PAGE_SIZE (1 << EMS_PAGE_BITS)
-#define EMS_ADDRESS 0xA00000
-#define EMS_PHYSICAL_PAGES 4
-
-#define EMS_STATUS_OK 0x00
-#define EMS_STATUS_INTERNAL_ERROR 0x80
-#define EMS_STATUS_INVALID_HANDLE 0x83
-#define EMS_STATUS_NO_MORE_HANDLES 0x85
-#define EMS_STATUS_INSUFFICIENT_PAGES 0x88
-#define EMS_STATUS_ZERO_PAGES 0x89
-#define EMS_STATUS_INV_LOGICAL_PAGE 0x8A
-#define EMS_STATUS_INV_PHYSICAL_PAGE 0x8B
-#define EMS_STATUS_UNKNOWN_FUNCTION 0x8F
-
-#define ARRAY_INDEX(ptr, array) ((ULONG)(((ULONG_PTR)(ptr) - (ULONG_PTR)(array)) /
sizeof(*array)))
-
-typedef struct _EMS_HANDLE
-{
- BOOLEAN Allocated;
- USHORT PageCount;
- LIST_ENTRY PageList;
-} EMS_HANDLE, *PEMS_HANDLE;
-
-typedef struct _EMS_PAGE
-{
- LIST_ENTRY Entry;
- USHORT Handle;
-} EMS_PAGE, *PEMS_PAGE;
-
-#pragma pack(push, 1)
-
-typedef struct _EMS_COPY_DATA
-{
- ULONG RegionLength;
- UCHAR SourceType;
- USHORT SourceHandle;
- USHORT SourceOffset;
- USHORT SourceSegment;
- UCHAR DestType;
- USHORT DestHandle;
- USHORT DestOffset;
- USHORT DestSegment;
-} EMS_COPY_DATA, *PEMS_COPY_DATA;
-
-#pragma pack(pop)
-
-/* FUNCTIONS ******************************************************************/
-
-VOID EmsInitialize(VOID);
-VOID EmsCleanup(VOID);
-
-#endif // _EMS_H_
-
-/* EOF */
Modified: trunk/reactos/subsystems/mvdm/ntvdm/emulator.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/emul…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/emulator.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/emulator.c [iso-8859-1] Sat Mar 14 03:37:54 2015
@@ -31,7 +31,6 @@
#include "hardware/sound/speaker.h"
#include "hardware/pit.h"
#include "hardware/video/vga.h"
-#include "ems.h"
#include "vddsup.h"
#include "io.h"
@@ -469,9 +468,6 @@
/* Initialize I/O ports */
/* Initialize RAM */
- /* Initialize EMS */
- EmsInitialize();
-
/* Initialize the CPU */
/* Initialize the internal clock */
@@ -557,7 +553,6 @@
PS2Cleanup();
- EmsCleanup();
SpeakerCleanup();
CmosCleanup();
// PitCleanup();