reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/himem.h

69 lines
2.2 KiB
C
Raw Normal View History

/*
* COPYRIGHT: GPLv2+ - See COPYING in the top level directory
* PROJECT: ReactOS Virtual DOS Machine
* FILE: subsystems/mvdm/ntvdm/dos/dos32krnl/himem.h
[NTVDM] EMS: - Introduce (and use) helpers for checking validity of EMS handles. - Do not hardcode the EMS page frame segment, but instead allow it to be changed (for now, it is still set to a default value; in the future, via some configuration file or via the registry). This is done by acquiring a UMB block (see after). XMS: - Implement functions 0x01 "Request HMA" and 0x02 "Release HMA". - Fix the return value of functions 0x04 "Global disable A20" and 0x08 "Query free Extended Memory"; simplify code of function 0x0B "Move EMB". - Halfplement function 0x0F "Reallocate Extended Memory Block" in the simple case of size reduction (size expansion is left to the programmer as an exercise :PP ) - Rewrite the UMB provider support (functions 0x10, 0x11, 0x12) by calling the Upper Memory Area manager helpers (see after) (this is closer to reality: UMBs are either provided by XMS driver itself, or by an EMS driver which hooks into the XMS driver chain -- as it is done with MS' himem+EMM386; sometimes all that stuff is contained inside one driver only --) instead of calling back into DOS. This is the DOS which calls XMS for getting the UMB blocks and initializing them! (and not the other way around as it was done in r68001!). NTVDM: - Introduce an "Upper Memory Area manager" which maintains a list of areas of upper memory (>= A000:0000 and <= FFFF:000F) that can be used as RAM blocks. It is intended to work closely with the NTVDM memory manager and be used by XMS for getting possible free UMBs, and by VDDs for implementing the VDDInclude/ExcludeMem APIs (which adds/remove blocks in/from the UMB pool; those are unaccessible to DOS if those APIs are called after NTVDM have been started, but are accessible by XMS). DOS: - Add a helper function for detecting early DOS arena corruptions (for debugging purposes only). - Make the DOS memory manager really UMB-compatible. This means: * not hardcoding the start of the UMB chain; * getting all the available UMB blocks from XMS and initializing them, marking the reserved blocks as read-only (with a correct header; reserved blocks are eg. VGA memory area, ROM blocks...). There is room for improvements obviously (see the FIXMEs in the code). Used documentation is mentioned in comments in the code. This commit should fix quite some apps, as well as it fixes corruptions of loaded ROMs in upper memory: that's how I came into working on fixing the UMB support. In other words, during those two last weeks, I was like in: http://i.imgur.com/zoWpqEB.gifv CORE-9969 #resolve svn path=/trunk/; revision=68586
2015-08-01 17:07:07 +00:00
* PURPOSE: DOS XMS Driver and UMB Provider
* PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
[NTVDM] EMS: - Introduce (and use) helpers for checking validity of EMS handles. - Do not hardcode the EMS page frame segment, but instead allow it to be changed (for now, it is still set to a default value; in the future, via some configuration file or via the registry). This is done by acquiring a UMB block (see after). XMS: - Implement functions 0x01 "Request HMA" and 0x02 "Release HMA". - Fix the return value of functions 0x04 "Global disable A20" and 0x08 "Query free Extended Memory"; simplify code of function 0x0B "Move EMB". - Halfplement function 0x0F "Reallocate Extended Memory Block" in the simple case of size reduction (size expansion is left to the programmer as an exercise :PP ) - Rewrite the UMB provider support (functions 0x10, 0x11, 0x12) by calling the Upper Memory Area manager helpers (see after) (this is closer to reality: UMBs are either provided by XMS driver itself, or by an EMS driver which hooks into the XMS driver chain -- as it is done with MS' himem+EMM386; sometimes all that stuff is contained inside one driver only --) instead of calling back into DOS. This is the DOS which calls XMS for getting the UMB blocks and initializing them! (and not the other way around as it was done in r68001!). NTVDM: - Introduce an "Upper Memory Area manager" which maintains a list of areas of upper memory (>= A000:0000 and <= FFFF:000F) that can be used as RAM blocks. It is intended to work closely with the NTVDM memory manager and be used by XMS for getting possible free UMBs, and by VDDs for implementing the VDDInclude/ExcludeMem APIs (which adds/remove blocks in/from the UMB pool; those are unaccessible to DOS if those APIs are called after NTVDM have been started, but are accessible by XMS). DOS: - Add a helper function for detecting early DOS arena corruptions (for debugging purposes only). - Make the DOS memory manager really UMB-compatible. This means: * not hardcoding the start of the UMB chain; * getting all the available UMB blocks from XMS and initializing them, marking the reserved blocks as read-only (with a correct header; reserved blocks are eg. VGA memory area, ROM blocks...). There is room for improvements obviously (see the FIXMEs in the code). Used documentation is mentioned in comments in the code. This commit should fix quite some apps, as well as it fixes corruptions of loaded ROMs in upper memory: that's how I came into working on fixing the UMB support. In other words, during those two last weeks, I was like in: http://i.imgur.com/zoWpqEB.gifv CORE-9969 #resolve svn path=/trunk/; revision=68586
2015-08-01 17:07:07 +00:00
* Hermes Belusca-Maito (hermes.belusca@sfr.fr)
*/
[NTVDM] EMS: - Introduce (and use) helpers for checking validity of EMS handles. - Do not hardcode the EMS page frame segment, but instead allow it to be changed (for now, it is still set to a default value; in the future, via some configuration file or via the registry). This is done by acquiring a UMB block (see after). XMS: - Implement functions 0x01 "Request HMA" and 0x02 "Release HMA". - Fix the return value of functions 0x04 "Global disable A20" and 0x08 "Query free Extended Memory"; simplify code of function 0x0B "Move EMB". - Halfplement function 0x0F "Reallocate Extended Memory Block" in the simple case of size reduction (size expansion is left to the programmer as an exercise :PP ) - Rewrite the UMB provider support (functions 0x10, 0x11, 0x12) by calling the Upper Memory Area manager helpers (see after) (this is closer to reality: UMBs are either provided by XMS driver itself, or by an EMS driver which hooks into the XMS driver chain -- as it is done with MS' himem+EMM386; sometimes all that stuff is contained inside one driver only --) instead of calling back into DOS. This is the DOS which calls XMS for getting the UMB blocks and initializing them! (and not the other way around as it was done in r68001!). NTVDM: - Introduce an "Upper Memory Area manager" which maintains a list of areas of upper memory (>= A000:0000 and <= FFFF:000F) that can be used as RAM blocks. It is intended to work closely with the NTVDM memory manager and be used by XMS for getting possible free UMBs, and by VDDs for implementing the VDDInclude/ExcludeMem APIs (which adds/remove blocks in/from the UMB pool; those are unaccessible to DOS if those APIs are called after NTVDM have been started, but are accessible by XMS). DOS: - Add a helper function for detecting early DOS arena corruptions (for debugging purposes only). - Make the DOS memory manager really UMB-compatible. This means: * not hardcoding the start of the UMB chain; * getting all the available UMB blocks from XMS and initializing them, marking the reserved blocks as read-only (with a correct header; reserved blocks are eg. VGA memory area, ROM blocks...). There is room for improvements obviously (see the FIXMEs in the code). Used documentation is mentioned in comments in the code. This commit should fix quite some apps, as well as it fixes corruptions of loaded ROMs in upper memory: that's how I came into working on fixing the UMB support. In other words, during those two last weeks, I was like in: http://i.imgur.com/zoWpqEB.gifv CORE-9969 #resolve svn path=/trunk/; revision=68586
2015-08-01 17:07:07 +00:00
#ifndef _HIMEM_H_
#define _HIMEM_H_
/* DEFINITIONS ****************************************************************/
[NTVDM] EMS: - Introduce (and use) helpers for checking validity of EMS handles. - Do not hardcode the EMS page frame segment, but instead allow it to be changed (for now, it is still set to a default value; in the future, via some configuration file or via the registry). This is done by acquiring a UMB block (see after). XMS: - Implement functions 0x01 "Request HMA" and 0x02 "Release HMA". - Fix the return value of functions 0x04 "Global disable A20" and 0x08 "Query free Extended Memory"; simplify code of function 0x0B "Move EMB". - Halfplement function 0x0F "Reallocate Extended Memory Block" in the simple case of size reduction (size expansion is left to the programmer as an exercise :PP ) - Rewrite the UMB provider support (functions 0x10, 0x11, 0x12) by calling the Upper Memory Area manager helpers (see after) (this is closer to reality: UMBs are either provided by XMS driver itself, or by an EMS driver which hooks into the XMS driver chain -- as it is done with MS' himem+EMM386; sometimes all that stuff is contained inside one driver only --) instead of calling back into DOS. This is the DOS which calls XMS for getting the UMB blocks and initializing them! (and not the other way around as it was done in r68001!). NTVDM: - Introduce an "Upper Memory Area manager" which maintains a list of areas of upper memory (>= A000:0000 and <= FFFF:000F) that can be used as RAM blocks. It is intended to work closely with the NTVDM memory manager and be used by XMS for getting possible free UMBs, and by VDDs for implementing the VDDInclude/ExcludeMem APIs (which adds/remove blocks in/from the UMB pool; those are unaccessible to DOS if those APIs are called after NTVDM have been started, but are accessible by XMS). DOS: - Add a helper function for detecting early DOS arena corruptions (for debugging purposes only). - Make the DOS memory manager really UMB-compatible. This means: * not hardcoding the start of the UMB chain; * getting all the available UMB blocks from XMS and initializing them, marking the reserved blocks as read-only (with a correct header; reserved blocks are eg. VGA memory area, ROM blocks...). There is room for improvements obviously (see the FIXMEs in the code). Used documentation is mentioned in comments in the code. This commit should fix quite some apps, as well as it fixes corruptions of loaded ROMs in upper memory: that's how I came into working on fixing the UMB support. In other words, during those two last weeks, I was like in: http://i.imgur.com/zoWpqEB.gifv CORE-9969 #resolve svn path=/trunk/; revision=68586
2015-08-01 17:07:07 +00:00
#define XMS_ADDRESS 0x110000 // Just above HMA
#define XMS_BLOCK_SIZE 1024
#define XMS_BLOCKS ((MAX_ADDRESS - XMS_ADDRESS) / XMS_BLOCK_SIZE)
[NTVDM] EMS: - Introduce (and use) helpers for checking validity of EMS handles. - Do not hardcode the EMS page frame segment, but instead allow it to be changed (for now, it is still set to a default value; in the future, via some configuration file or via the registry). This is done by acquiring a UMB block (see after). XMS: - Implement functions 0x01 "Request HMA" and 0x02 "Release HMA". - Fix the return value of functions 0x04 "Global disable A20" and 0x08 "Query free Extended Memory"; simplify code of function 0x0B "Move EMB". - Halfplement function 0x0F "Reallocate Extended Memory Block" in the simple case of size reduction (size expansion is left to the programmer as an exercise :PP ) - Rewrite the UMB provider support (functions 0x10, 0x11, 0x12) by calling the Upper Memory Area manager helpers (see after) (this is closer to reality: UMBs are either provided by XMS driver itself, or by an EMS driver which hooks into the XMS driver chain -- as it is done with MS' himem+EMM386; sometimes all that stuff is contained inside one driver only --) instead of calling back into DOS. This is the DOS which calls XMS for getting the UMB blocks and initializing them! (and not the other way around as it was done in r68001!). NTVDM: - Introduce an "Upper Memory Area manager" which maintains a list of areas of upper memory (>= A000:0000 and <= FFFF:000F) that can be used as RAM blocks. It is intended to work closely with the NTVDM memory manager and be used by XMS for getting possible free UMBs, and by VDDs for implementing the VDDInclude/ExcludeMem APIs (which adds/remove blocks in/from the UMB pool; those are unaccessible to DOS if those APIs are called after NTVDM have been started, but are accessible by XMS). DOS: - Add a helper function for detecting early DOS arena corruptions (for debugging purposes only). - Make the DOS memory manager really UMB-compatible. This means: * not hardcoding the start of the UMB chain; * getting all the available UMB blocks from XMS and initializing them, marking the reserved blocks as read-only (with a correct header; reserved blocks are eg. VGA memory area, ROM blocks...). There is room for improvements obviously (see the FIXMEs in the code). Used documentation is mentioned in comments in the code. This commit should fix quite some apps, as well as it fixes corruptions of loaded ROMs in upper memory: that's how I came into working on fixing the UMB support. In other words, during those two last weeks, I was like in: http://i.imgur.com/zoWpqEB.gifv CORE-9969 #resolve svn path=/trunk/; revision=68586
2015-08-01 17:07:07 +00:00
#define XMS_MAX_HANDLES 16 // Specification: min 1, max 128, default 32
#define XMS_STATUS_SUCCESS 0x00
#define XMS_STATUS_NOT_IMPLEMENTED 0x80
#define XMS_STATUS_A20_ERROR 0x82
#define XMS_STATUS_HMA_DOES_NOT_EXIST 0x90
#define XMS_STATUS_HMA_IN_USE 0x91
#define XMS_STATUS_HMA_MIN_SIZE 0x92
#define XMS_STATUS_HMA_NOT_ALLOCATED 0x93
#define XMS_STATUS_A20_STILL_ENABLED 0x94
#define XMS_STATUS_OUT_OF_MEMORY 0xA0
#define XMS_STATUS_OUT_OF_HANDLES 0xA1
#define XMS_STATUS_INVALID_HANDLE 0xA2
#define XMS_STATUS_BAD_SRC_HANDLE 0xA3
#define XMS_STATUS_BAD_DEST_HANDLE 0xA4
#define XMS_STATUS_BAD_SRC_OFFSET 0xA5
#define XMS_STATUS_BAD_DEST_OFFSET 0xA6
#define XMS_STATUS_NOT_LOCKED 0xAA
#define XMS_STATUS_LOCKED 0xAB
#define XMS_STATUS_LOCK_OVERFLOW 0xAC
#define XMS_STATUS_CANNOT_LOCK 0xAD
#define XMS_STATUS_SMALLER_UMB 0xB0
#define XMS_STATUS_OUT_OF_UMBS 0xB1
#define XMS_STATUS_INVALID_UMB 0xB2
typedef struct _XMS_HANDLE
{
BYTE Handle;
BYTE LockCount;
WORD Size;
DWORD Address;
} XMS_HANDLE, *PXMS_HANDLE;
#pragma pack(push, 1)
typedef struct _XMS_COPY_DATA
{
DWORD Count;
WORD SourceHandle;
DWORD SourceOffset;
WORD DestHandle;
DWORD DestOffset;
} XMS_COPY_DATA, *PXMS_COPY_DATA;
#pragma pack(pop)
/* FUNCTIONS ******************************************************************/
BOOLEAN XmsGetDriverEntry(PDWORD Pointer);
VOID XmsInitialize(VOID);
VOID XmsCleanup(VOID);
[NTVDM] EMS: - Introduce (and use) helpers for checking validity of EMS handles. - Do not hardcode the EMS page frame segment, but instead allow it to be changed (for now, it is still set to a default value; in the future, via some configuration file or via the registry). This is done by acquiring a UMB block (see after). XMS: - Implement functions 0x01 "Request HMA" and 0x02 "Release HMA". - Fix the return value of functions 0x04 "Global disable A20" and 0x08 "Query free Extended Memory"; simplify code of function 0x0B "Move EMB". - Halfplement function 0x0F "Reallocate Extended Memory Block" in the simple case of size reduction (size expansion is left to the programmer as an exercise :PP ) - Rewrite the UMB provider support (functions 0x10, 0x11, 0x12) by calling the Upper Memory Area manager helpers (see after) (this is closer to reality: UMBs are either provided by XMS driver itself, or by an EMS driver which hooks into the XMS driver chain -- as it is done with MS' himem+EMM386; sometimes all that stuff is contained inside one driver only --) instead of calling back into DOS. This is the DOS which calls XMS for getting the UMB blocks and initializing them! (and not the other way around as it was done in r68001!). NTVDM: - Introduce an "Upper Memory Area manager" which maintains a list of areas of upper memory (>= A000:0000 and <= FFFF:000F) that can be used as RAM blocks. It is intended to work closely with the NTVDM memory manager and be used by XMS for getting possible free UMBs, and by VDDs for implementing the VDDInclude/ExcludeMem APIs (which adds/remove blocks in/from the UMB pool; those are unaccessible to DOS if those APIs are called after NTVDM have been started, but are accessible by XMS). DOS: - Add a helper function for detecting early DOS arena corruptions (for debugging purposes only). - Make the DOS memory manager really UMB-compatible. This means: * not hardcoding the start of the UMB chain; * getting all the available UMB blocks from XMS and initializing them, marking the reserved blocks as read-only (with a correct header; reserved blocks are eg. VGA memory area, ROM blocks...). There is room for improvements obviously (see the FIXMEs in the code). Used documentation is mentioned in comments in the code. This commit should fix quite some apps, as well as it fixes corruptions of loaded ROMs in upper memory: that's how I came into working on fixing the UMB support. In other words, during those two last weeks, I was like in: http://i.imgur.com/zoWpqEB.gifv CORE-9969 #resolve svn path=/trunk/; revision=68586
2015-08-01 17:07:07 +00:00
#endif /* _HIMEM_H_ */