⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ioctl.c

📁 我自己编译的armv4i wince60模拟器的bps源文件,已经验证可以使用,欢迎下载
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//------------------------------------------------------------------------------
//
//  File: ioctl.c           
//
//  This file implements the OEM's IO Control (IOCTL) functions and declares
//  global variables used by the IOCTL component.
//
#include <bsp.h>

// callstack 
#define IOCTL_GET_CALLSTACK        CTL_CODE(FILE_DEVICE_HAL,1099, METHOD_BUFFERED, FILE_ANY_ACCESS)
extern ULONG SC_GetThreadCallStack (HANDLE hThrd, ULONG dwMaxFrames, CallSnapshot lpFrames[], DWORD dwFlags, DWORD dwSkip);
extern CPUPowerReset();

// ioctls to read or change BSP Args to indicate storage is mounted or unmounted
#define IOCTL_HAL_GET_SHARED_FOLDER_FLAG      CTL_CODE(FILE_DEVICE_HAL,1097, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_HAL_SET_SHARED_FOLDER_FLAG      CTL_CODE(FILE_DEVICE_HAL,1098, METHOD_BUFFERED, FILE_ANY_ACCESS)


//------------------------------------------------------------------------------
//
//  Global: g_oalIoctlPlatformType/OEM    
//
//  Platform Type/OEM
//
LPCWSTR g_oalIoCtlPlatformType = IOCTL_PLATFORM_TYPE;
LPCWSTR g_oalIoCtlPlatformOEM  = IOCTL_PLATFORM_OEM;

//------------------------------------------------------------------------------
//
//  Global: g_oalIoctlProcessorVendor/Name/Core
//
//  Processor information
//
LPCWSTR g_oalIoCtlProcessorVendor = IOCTL_PROCESSOR_VENDOR;
LPCWSTR g_oalIoCtlProcessorName   = IOCTL_PROCESSOR_NAME;
LPCWSTR g_oalIoCtlProcessorCore   = IOCTL_PROCESSOR_CORE;

UINT32 g_oalIoCtlInstructionSet = IOCTL_PROCESSOR_INSTRUCTION_SET;
UINT32 g_oalIoCtlClockSpeed = IOCTL_PROCESSOR_CLOCK_SPEED;


//------------------------------------------------------------------------------
//
//  Global: g_dwExtensionRAMFMDSize and g_pvExtensionRAMFMDBaseAddr
//
//  RAMFMD initializers used by OEMGetExtensionDRAM
//
//  g_dwExtensionRAMFMDSize updated via FIXUPVAR in config.bib, must 
//  be a multiple of 4K.
//
//  g_pvExtensionRAMFMDBaseAddr filled in by OEMGetExtensionDRAM()
//  if sufficient extension memory is available.
const volatile DWORD g_dwExtensionRAMFMDSize = 0;
PVOID g_pvExtensionRAMFMDBaseAddr;

static BOOL
OALIoInitRtc(
    UINT32  code,
    VOID   *pInBuffer,
    UINT32  inSize,
    VOID   *pOutBuffer,
    UINT32  outSize,
    UINT32 *pOutSize
) {
    // Add static mapping for RTC alarm
    OALIntrStaticTranslate(SYSINTR_RTC_ALARM, IRQ_RTC);

    // Do nothing for the RTC on the emulator.
    // We leverage the host sides RTC which is always init'ed.
    if (pOutSize) {
        *pOutSize = 0;
    }
    return TRUE;
}

// Make sure that this is defined in configurations that may not include filesys.  In the event
// that filesys isn't present this routine will never be called since nobody invokes
// the IOCTL_HAL_INITREGISTRY kernel IOCTL.
#ifndef HKEY_LOCAL_MACHINE
#define HKEY_LOCAL_MACHINE          (( HKEY ) (ULONG_PTR)0x80000002 )
#endif  // HKEY_LOCAL_MACHINE

static BOOL 
OALIoCtlDeviceEmulatorHalInitRegistry( 
    UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer, 
    UINT32 outSize, UINT32 *pOutSize
){
#ifdef DEBUG
    LPCWSTR pszFname = L"OALIoCtlDeviceEmulatorHalInitRegistry";
#endif  // DEBUG
    BOOL fOk = TRUE;
    BSP_ARGS *pBSPArgs = ((BSP_ARGS *) IMAGE_SHARE_ARGS_UA_START);

    if (pOutSize) {
        *pOutSize = 0;
    }

    {
        HKEY    hKey;
        DWORD   dwRotation = 0;
        DWORD   dwStatus;
        LPCWSTR pszKeyPath = L"System\\GDI\\Rotation";
        DWORD   dwDesposition = 0;

        switch (pBSPArgs->ScreenOrientation) {
          default:case 0:
            dwRotation = 0;
            break;
          case 1:
            dwRotation= 90;
            break;
          case 2:
            dwRotation = 180;
            break;
          case 3:
            dwRotation = 270 ;
            break;
        }
        DEBUGMSG(TRUE, (L"%s: Set Orientation to %d pBSPArgs->ScreenOrientation = %d \r\n", pszFname,dwRotation,pBSPArgs->ScreenOrientation));
        dwStatus = NKRegCreateKeyExW(HKEY_LOCAL_MACHINE, pszKeyPath, 0, NULL, 0, 0, NULL, &hKey,&dwDesposition);
        
        if(dwStatus != ERROR_SUCCESS) {
            DEBUGMSG(TRUE, (L"%s: NKRegOpenKeyExW('%s') failed %u - 0x%08x rotation is unused\r\n", 
                pszFname, pszKeyPath, dwStatus, dwRotation));
        } else {
            dwStatus = NKRegSetValueEx(hKey, L"Angle", 0, REG_DWORD, (LPBYTE) &dwRotation, sizeof(DWORD));
            if(dwStatus != ERROR_SUCCESS) {
                DEBUGMSG(TRUE, (L"%s: NKRegSetValueEx('Angle') failed %u\r\n", pszFname, dwStatus));
            }
            NKRegCloseKey(hKey);
        }
    }

    // determine the FMD size
    if(g_pvExtensionRAMFMDBaseAddr != NULL) {
        pBSPArgs->pvExtensionRAMFMDBaseAddr = g_pvExtensionRAMFMDBaseAddr;
        pBSPArgs->dwExtensionRAMFMDSize = g_dwExtensionRAMFMDSize;
    }

    // none of the RAMFMD issues are fatal, so we don't set fOk to FALSE even
    // if there's a problem
    DEBUGMSG(TRUE, (L"%s: FMD reserve size 0x%08x; base addr 0x%08x\r\n", pszFname,
        pBSPArgs->dwExtensionRAMFMDSize, pBSPArgs->pvExtensionRAMFMDBaseAddr));
    if(pBSPArgs->dwExtensionRAMFMDSize != 0) {
        if(pBSPArgs->pvExtensionRAMFMDBaseAddr == NULL) {
            DEBUGMSG(TRUE, (L"%s: couldn't reserve 0x%08x bytes; not modifying FMD registry\r\n",
                pszFname, pBSPArgs->dwExtensionRAMFMDSize));
        } else {
            HKEY hKey;
            LPCWSTR pszKeyPath = L"Drivers\\BlockDevice\\RAMFMD";
            DWORD dwStatus, dwDesposition;
            dwStatus = NKRegCreateKeyExW(HKEY_LOCAL_MACHINE, pszKeyPath, 0, NULL, 0, 0, NULL, &hKey,&dwDesposition);
            if(dwStatus != ERROR_SUCCESS) {
                DEBUGMSG(TRUE, (L"%s: NKRegOpenKeyExW('%s') failed %u - 0x%08x bytes extension ram unused\r\n", 
                    pszFname, pszKeyPath, dwStatus, pBSPArgs->dwExtensionRAMFMDSize));
            } else {
                dwStatus = NKRegSetValueEx(hKey, L"Address", 0, REG_DWORD, 
                    (LPBYTE) &pBSPArgs->pvExtensionRAMFMDBaseAddr, sizeof(DWORD));
                if(dwStatus != ERROR_SUCCESS) {
                    DEBUGMSG(TRUE, (L"%s: NKRegSetValueEx('Address') failed %u\r\n", 
                        pszFname, dwStatus));
                }
                dwStatus = NKRegSetValueEx(hKey, L"Size", 0, REG_DWORD, 
                    (LPBYTE) &pBSPArgs->dwExtensionRAMFMDSize, sizeof(DWORD));
                if(dwStatus != ERROR_SUCCESS) {
                    DEBUGMSG(TRUE, (L"%s: NKRegSetValueEx('Size') failed %u\r\n", 
                        pszFname, dwStatus));
                }
                NKRegCloseKey(hKey);
            }
        }
    }
    if(fOk) {
        fOk = OALIoCtlHalInitRegistry(code, pInpBuffer, inpSize, pOutBuffer,
            outSize, pOutSize);
    }
    return fOk;
}

static BOOL 
OALIoCtlHalReboot( 
    UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer, 
    UINT32 outSize, UINT32 *pOutSize
)
{
    RETAILMSG(1,(TEXT("Calling CPUPowerReset\r\n")));
    CPUPowerReset();
    return TRUE;
}

static BOOL
OALIoCtlHalGetSharedFolderFlag(
    UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer, 
    UINT32 outSize, UINT32 *pOutSize)
{
    BSP_ARGS *pBSPArgs = ((BSP_ARGS *) IMAGE_SHARE_ARGS_UA_START);

    if(pOutSize)
    {
      *pOutSize = sizeof(pBSPArgs->fStorageMounted);
    }

    if((!pOutBuffer) || (outSize != sizeof(pBSPArgs->fStorageMounted)))
    {
        NKSetLastError(ERROR_INVALID_PARAMETER);
        OALMSG(OAL_WARN, (L"WARN: OALIoCtlHalGetStorageFlag: Invalid parameter\r\n"));
        return FALSE;
    }

    *((BOOL*)pOutBuffer) = pBSPArgs->fStorageMounted;

    return TRUE;

}

static BOOL
OALIoCtlHalSetSharedFolderFlag(
    UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer, 
    UINT32 outSize, UINT32 *pOutSize
)
{
    BSP_ARGS *pBSPArgs = ((BSP_ARGS *) IMAGE_SHARE_ARGS_UA_START);
    BOOL inputStorageFlag;

    if(pOutSize)
    {
      *pOutSize = 0;
    }

    if((!pInpBuffer) || (inpSize != sizeof(pBSPArgs->fStorageMounted)))
    {
        NKSetLastError(ERROR_INVALID_PARAMETER);
        OALMSG(OAL_WARN, (L"WARN: OALIoCtlHalSetStorageFlag: Invalid parameter\r\n"));
        return FALSE;
    }

    inputStorageFlag = *((BOOL*)pInpBuffer);

    pBSPArgs->fStorageMounted = inputStorageFlag;

    return TRUE;

}

//------------------------------------------------------------------------------
//
//  Global: g_oalIoCtlTable[]    
//
//  IOCTL handler table. This table includes the IOCTL code/handler pairs  
//  defined in the IOCTL configuration file. This global array is exported 
//  via oal_ioctl.h and is used by the OAL IOCTL component.
//
const OAL_IOCTL_HANDLER g_oalIoCtlTable[] = {
#include "ioctl_tab.h"
};

//------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -