INF: Accessing Physical Memory Using Kernel Exported Selectors

ID Number: Q64151

3.00

WINDOWS

Summary:

In Windows version 3.0, the Kernel exports a number of selectors that

Windows programs can use to access commonly used hardware memory. The

exported selectors include the following:

__0000h, __0040h, __A000h, __B000h, __B800h, __C000h,

__D000h, __E000h, __F000h

The four letters after the leading "__" represent the real mode

address that the selector is for. Each of the selectors has a 64K

limit.

In order to use one of these selectors, implement one of the following

methods:

Method 1

--------

If the code is being written in assembler, declare the selector

variable as follows:

extrn MySelector:ABS

(or "externA MySelector" using C-macros)

Then import the selector in the definition file, as follows:

IMPORTS MySelector = KERNEL.__B000h

In the same program, if the C routines need to use the selector value,

another global selector may be declared across the assembly code and

the C code. Then, assign "MySelector" to the variable in the assembly

code.

Method 2

--------

Declare an extern variable in the C routine and then use the address

of the extern variable as the selector. For example:

extern WORD _MyB000h ;

#define MySelector (&_MyB000h)

Now the variable MySelector can be used to access segment B000h.

Remember to import it using the correct name (one more underscore).

For example:

IMPORTS

__MyB000h = KERNEL.__B000h

Method 3

--------

GetProcAddress can also be called with the Kernel's module handle and

the name of the selector. The lower word of the return value is the

selector value.

More Information:

There are no protections on these selectors. Any other Windows program

can access them at the same time. It is strongly recommended to use

these selectors only in a Windows dynamic-link library (DLL). By

accessing the hardware memory only through a DLL, the Windows

application is given the maximum hardware independence. This method

also minimizes possibilities of conflicts caused by different Windows

applications trying to access the same memory at the same time.

Additional reference words: 3.0 3.00