?? maptest.c
字號:
/*++
Copyright (c) 1993 Microsoft Corporation
Module Name:
maptest.h
Abstract:
Win32 test app for the MAPMEM driver
Environment:
User mode
Notes:
Revision History:
--*/
#include "windows.h"
#include "winioctl.h"
#include "stdio.h"
#include "stdlib.h"
//
// For Alpha platforms, include uhal.h to for the READ/WRITE register routines.
//
#ifdef _M_ALPHA
#include "uhal.h"
#else
#include "F:\NTDDK\src\video\displays\inc\ioaccess.h"
#endif
//
// A couple of typedefs mapmem.h depends on from MINIPORT.H & NTDDK.H.
//
typedef enum _INTERFACE_TYPE
{
Internal,
Isa,
Eisa,
MicroChannel,
TurboChannel,
PCIBus,
MaximumInterfaceType
} INTERFACE_TYPE, *PINTERFACE_TYPE;
typedef LARGE_INTEGER PHYSICAL_ADDRESS;
#include "mapmem.h"
int
__cdecl
main(
IN int argc,
IN char *argv[])
/*++
Routine Description:
Tries to open the MAPMEM driver & send it a couple of IOCTLs.
Arguments:
argc - count of command line arguments
argv - command line arguments
Return Value:
--*/
{
HANDLE hDriver;
PHYSICAL_MEMORY_INFO pmi;
PVOID pPartyMem;
DWORD cbReturned;
ULONG length;
char *aInterfaceType[] = {"Internal",
"Isa",
"Eisa",
"MicroChannel",
"TurboChannel",
"PCIBus" };
if (argc < 4)
{
//
// Display usage message
//
printf ("\nUsage: maptest <InterfaceType> <BusNumber> <BusAddress> <AddressSpace> <length>\n\n");
printf ("\t<InterfaceType>: 1 = Isa, 2 = Eisa, 3 = Microchannel,\n");
printf ("\t 4 = TurboChannel, 5 = PCIBus\n");
printf ("\t<BusNumber> : bus number");
#ifdef _M_ALPHA
printf("\n");
#else
printf(", i.e. 0 for standard x86 ISA systems\n");
#endif // _M_ALPHA
printf ("\t<BusAddress> : physical address to map (hex)\n");
//
// display Alpha-specific options for Address Space
// Please note that _M_ALPHA is automatically defined by Alpha VC++ compiler.
//
#ifdef _M_ALPHA
printf ("\t<AddressSpace> : 6 = UserMode view of dense memory,\n");
printf ("\tExample: 'maptest 5 0 0xa0000 6 0x2000'\n");
#else
printf ("\t<AddressSpace> : 0 = memory, 1 = I/O\n");
printf ("\tExample: 'maptest 1 0 0xa0000 0 0x2000'\n");
#endif // _M_ALPHA
return 0;
}
//
// Parse the args
//
#ifdef _M_ALPHA
//
// On the Alpha, make sure AddressSpace is the correct value. If not, exit program.
// You MUST use AddressSpace equals 6 for the UHAL to wrok correctly.
//
if (atoi(argv[4]) != 6) {
printf("\nAddressSpace must be 6.\n\n");
return 1;
}
#endif // _M_ALPHA
pmi.InterfaceType = (INTERFACE_TYPE) atoi (argv[1]);
pmi.BusNumber = (ULONG) atoi (argv[2]);
pmi.BusAddress.HighPart = (LONG) 0x00000000;
pmi.AddressSpace = (LONG) atoi (argv[4]);
sscanf (argv[3], "%x", &pmi.BusAddress.LowPart);
sscanf (argv[5], "%x", &pmi.Length);
printf ("\tInterfaceType = %s\n", aInterfaceType[pmi.InterfaceType]);
printf ("\tBusNumber = %d\n", pmi.BusNumber);
printf ("\tBusAddress = 0x%x\n", pmi.BusAddress.LowPart, pmi.BusAddress.LowPart);
printf ("\tAddressSpace = %d\n", pmi.AddressSpace);
printf ("\tLength = 0x%x\n", pmi.Length, pmi.Length);
length = pmi.Length;
//
// Try to open the device
//
if ((hDriver = CreateFile("\\\\.\\MAPMEM",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
)) != ((HANDLE)-1))
printf ("\nRetrieved valid handle for MAPMEM driver\n");
else
{
printf ("Can't get a handle to MAPMEM driver\n");
return 0;
}
//
// Try to map the memory
//
if (DeviceIoControl (hDriver,
(DWORD) IOCTL_MAPMEM_MAP_USER_PHYSICAL_MEMORY,
&pmi,
sizeof(PHYSICAL_MEMORY_INFO),
&pPartyMem,
sizeof(PVOID),
&cbReturned,
0
) )
{
ULONG j;
//
// party on memory...
//
if (pPartyMem)
{
UCHAR uc;
// For Alpha, if you need to read/write multiple bytes, words, dwords,
// you can also use the buffer routines. Please see User HAL (UHAL) under Alpha
// Related Information in the Supplemental Documentation of the DDK documentation.
//
for (j = 0; j < length; j++) {
uc = READ_REGISTER_UCHAR( (PUCHAR)pPartyMem + j );
printf("Read %x\n", uc);
WRITE_REGISTER_UCHAR( (PUCHAR)pPartyMem + j , 0x47 );
printf("Wrote %x\n", 0x47);
uc = READ_REGISTER_UCHAR( (PUCHAR)pPartyMem + j );
printf("Read %x\n\n", uc);
}
//
// Unmap the memory
//
DeviceIoControl (hDriver,
(DWORD) IOCTL_MAPMEM_UNMAP_USER_PHYSICAL_MEMORY,
&pPartyMem,
sizeof(PVOID),
NULL,
0,
&cbReturned,
0
);
}
else
printf ("pPartyMem = NULL\n");
} else {
//
// We failed to map, possibly due to resource conflicts (i.e
// some other driver/device already grabbed the section we
// wanted).
//
printf ("DeviceIoControl failed\n");
}
CloseHandle(hDriver);
return 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -