📄 hal_w32.c
字号:
/*-------------------------------------------------------------------------
//
// PCIGetLinAddressW32()
//
// Copyright (c) 2000, 2001 Epson Research and Development, Inc.
// All Rights Reserved.
//
//-----------------------------------------------------------------------*/
#ifdef INTEL_W32
#pragma warning(disable:4001) // Disable the 'single line comment' warning.
#pragma warning(disable:4206) // Disable the 'nonstandard extension used : translation unit is empty' warning
#pragma warning(disable:4115) // ignore "named type definition in parentheses" warning
#pragma warning(disable:4514) // ignore "unreferenced inline function has been removed" warning
#pragma warning(disable:4201) // Disable the 'nonstandard extension used : nameless struct/union'
#pragma warning(disable:4214) // Disable the 'single line comment' warning.
#include <windows.h>
#include <winioctl.h>
#include "ioctl.h"
//----------------------------------------------------------------------------
static int LinearAddress = 0;
//----------------------------------------------------------------------------
//
// _IntelGetLinAddressW32(DWORD physaddr,DWORD *linaddr)
//
// return value:
//
// 0 : No error
// 1 : Device Driver not found
// 2 : PCI bridge adapter not found
//
//----------------------------------------------------------------------------
int _IntelGetLinAddressW32(DWORD physaddr, DWORD *linaddr)
{
HANDLE hDriver;
DWORD cbReturned;
int rc, retVal;
unsigned retArr[2];
// First see if we are running under WinNT
DWORD dwVersion = GetVersion();
LinearAddress = 0;
if (dwVersion < 0x80000000)
{
//
// Try to open the device
//
hDriver = CreateFile("\\\\.\\S1D13xxx", GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
}
else //Win95,98...
{
// Dynamically load and prepare to call S1D13xxx.
// The FILE_FLAG_DELETE_ON_CLOSE flag is used so that CloseHandle can
// be used to dynamically unload the VxD.
// The CREATE_NEW flag is not necessary
hDriver = CreateFile("\\\\.\\S1D13xxx.VXD", 0,0,0,
CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0);
}
if (hDriver == INVALID_HANDLE_VALUE)
return 1;
//---------------------------------------------------
//
// From now on, the code is common for Win95 & WinNT
//
//---------------------------------------------------
if (physaddr == 0) // map in a PCI Board
{
char Buffer[80];
int boardnum = 0;
// Check the environment for
// S5UBOARD=x
// where x is a number 0,1,2,3,4,...
// This is for those rare situations, where we have multiple
// PCI boards and we have "assigned" a command prompt window
// to a particular board using the environment variables.
if (GetEnvironmentVariable("S5UBOARD",Buffer,sizeof(Buffer)))
boardnum = atoi(Buffer);
rc = DeviceIoControl(hDriver,IOCTL_SED_MAP_PCI_BOARD,
&boardnum,sizeof(ULONG),retArr,2*sizeof(ULONG),&cbReturned,NULL);
// upon exit:
// retArr[0] : linear address
// retArr[1] : physical address
if (rc)
{
*linaddr = retArr[0];
LinearAddress = retArr[0];
}
}
else //the user insists on a particular physical address
{
retArr[0] = physaddr;
retArr[1] = 4*1024*1024;
rc = DeviceIoControl(hDriver,IOCTL_SED_MAP_PHYSICAL_MEMORY,
&retArr[0],2*sizeof(ULONG),&retVal,sizeof(ULONG),&cbReturned,NULL);
if (rc)
{
*linaddr = retVal;
LinearAddress = retVal;
}
}
// Close the handle. This will dynamically UNLOAD the Virtual Device for Win95.
CloseHandle(hDriver);
if (rc)
return 0;
return 2;
}
//----------------------------------------------------------------------------
//
// _IntelUnmapLinearMemory(void)
//
// return value:
//
// 0 : No error
// 1 : Device Driver not found
// 2 : PCI bridge adapter not found
//
//----------------------------------------------------------------------------
int _IntelUnmapLinearMemory(void)
{
HANDLE hDriver;
DWORD cbReturned;
int rc;
// First see if we are running under WinNT
DWORD dwVersion = GetVersion();
if (dwVersion < 0x80000000)
{
//
// Try to open the device
//
hDriver = CreateFile("\\\\.\\S1D13xxx", GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
}
else //Win95,98...
{
// Dynamically load and prepare to call S1D13xxx.
// The FILE_FLAG_DELETE_ON_CLOSE flag is used so that CloseHandle can
// be used to dynamically unload the VxD.
// The CREATE_NEW flag is not necessary
hDriver = CreateFile("\\\\.\\S1D13xxx.VXD", 0,0,0,
CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0);
}
if (hDriver == INVALID_HANDLE_VALUE)
return 1;
//---------------------------------------------------
//
// From now on, the code is common for Win95 & WinNT
//
//---------------------------------------------------
rc = DeviceIoControl(hDriver, IOCTL_SED_UNMAP_LINEAR_MEMORY,
&LinearAddress, sizeof(PVOID), NULL, 0, &cbReturned, NULL);
// Close the handle. This will dynamically UNLOAD the Virtual Device for Win95.
CloseHandle(hDriver);
if (rc)
return 0;
return 2;
}
//----------------------------------------------------------------------------
#endif
//----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -