pm.c

来自「适合KS8695X」· C语言 代码 · 共 1,995 行 · 第 1/5 页

C
1,995
字号
    ulong BIOSPhysAddr,
    void *mappedBIOS,
    ulong BIOSLen)
{
    (void)axVal;
    (void)BIOSPhysAddr;
    (void)mappedBIOS;
    (void)BIOSLen;
    return false;
}

/****************************************************************************
PARAMETERS:
base    - The starting physical base address of the region
size    - The size in bytes of the region
type    - Type to place into the MTRR register

RETURNS:
Error code describing the result.

REMARKS:
Function to enable write combining for the specified region of memory.
****************************************************************************/
int PMAPI PM_enableWriteCombine(
    ulong base,
    ulong size,
    uint type)
{
    return MTRR_enableWriteCombine(base,size,type);
}

/* TODO: Move the MTRR helper stuff into the call gate, or better yet */
/*       entirely into the ring 0 helper driver!! */

/* MTRR helper functions. To make it easier to implement the MTRR support
 * under OS/2, we simply put our ring 0 helper functions into the
 * helper device driver rather than the entire MTRR module. This makes
 * it easier to maintain the MTRR support since we don't need to deal
 * with 16-bit ring 0 code in the MTRR library.
 */

/****************************************************************************
REMARKS:
Flush the translation lookaside buffer.
****************************************************************************/
void PMAPI PM_flushTLB(void)
{
    CallSDDHelp(PMHELP_FLUSHTLB);
}

/****************************************************************************
REMARKS:
Return true if ring 0 (or if we can call the helpers functions at ring 0)
****************************************************************************/
ibool _ASMAPI _MTRR_isRing0(void)
{
    return true;
}

/****************************************************************************
REMARKS:
Read and return the value of the CR4 register
****************************************************************************/
ulong _ASMAPI _MTRR_saveCR4(void)
{
    return CallSDDHelp(PMHELP_SAVECR4);
}

/****************************************************************************
REMARKS:
Restore the value of the CR4 register
****************************************************************************/
void _ASMAPI _MTRR_restoreCR4(ulong cr4Val)
{
    parmsIn[0] = cr4Val;
    CallSDDHelp(PMHELP_RESTORECR4);
}

/****************************************************************************
REMARKS:
Read a machine status register for the CPU.
****************************************************************************/
void _ASMAPI _MTRR_readMSR(
    ulong reg,
    ulong *eax,
    ulong *edx)
{
    parmsIn[0] = reg;
    CallSDDHelp(PMHELP_READMSR);
    *eax = parmsOut[0];
    *edx = parmsOut[1];
}

/****************************************************************************
REMARKS:
Write a machine status register for the CPU.
****************************************************************************/
void _ASMAPI _MTRR_writeMSR(
    ulong reg,
    ulong eax,
    ulong edx)
{
    parmsIn[0] = reg;
    parmsIn[1] = eax;
    parmsIn[2] = edx;
    CallSDDHelp(PMHELP_WRITEMSR);
}

PM_MODULE PMAPI PM_loadLibrary(
    const char *szDLLName)
{
    /* TODO: Implement this to load shared libraries! */
    (void)szDLLName;
    return NULL;
}

void * PMAPI PM_getProcAddress(
    PM_MODULE hModule,
    const char *szProcName)
{
    /* TODO: Implement this! */
    (void)hModule;
    (void)szProcName;
    return NULL;
}

void PMAPI PM_freeLibrary(
    PM_MODULE hModule)
{
    /* TODO: Implement this! */
    (void)hModule;
}

/****************************************************************************
REMARKS:
Internal function to convert the find data to the generic interface.
****************************************************************************/
static void convertFindData(
    PM_findData *findData,
    FILEFINDBUF3 *blk)
{
    ulong   dwSize = findData->dwSize;

    memset(findData,0,findData->dwSize);
    findData->dwSize = dwSize;
    if (blk->attrFile & FILE_READONLY)
	findData->attrib |= PM_FILE_READONLY;
    if (blk->attrFile & FILE_DIRECTORY)
	findData->attrib |= PM_FILE_DIRECTORY;
    if (blk->attrFile & FILE_ARCHIVED)
	findData->attrib |= PM_FILE_ARCHIVE;
    if (blk->attrFile & FILE_HIDDEN)
	findData->attrib |= PM_FILE_HIDDEN;
    if (blk->attrFile & FILE_SYSTEM)
	findData->attrib |= PM_FILE_SYSTEM;
    findData->sizeLo = blk->cbFile;
    findData->sizeHi = 0;
    strncpy(findData->name,blk->achName,PM_MAX_PATH);
    findData->name[PM_MAX_PATH-1] = 0;
}

#define FIND_MASK   (FILE_ARCHIVED | FILE_DIRECTORY | FILE_SYSTEM | FILE_HIDDEN | FILE_READONLY)

/****************************************************************************
REMARKS:
Function to find the first file matching a search criteria in a directory.
****************************************************************************/
void *PMAPI PM_findFirstFile(
    const char *filename,
    PM_findData *findData)
{
    FILEFINDBUF3    blk;
    HDIR            hdir = HDIR_CREATE;
    ulong           count = 1;

    if (DosFindFirst((PSZ)filename,&hdir,FIND_MASK,&blk,sizeof(blk),&count,FIL_STANDARD) == NO_ERROR) {
	convertFindData(findData,&blk);
	return (void*)hdir;
	}
    return PM_FILE_INVALID;
}

/****************************************************************************
REMARKS:
Function to find the next file matching a search criteria in a directory.
****************************************************************************/
ibool PMAPI PM_findNextFile(
    void *handle,
    PM_findData *findData)
{
    FILEFINDBUF3    blk;
    ulong           count = 1;

    if (DosFindNext((HDIR)handle,&blk,sizeof(blk),&count) == NO_ERROR) {
	convertFindData(findData,&blk);
	return true;
	}
    return false;
}

/****************************************************************************
REMARKS:
Function to close the find process
****************************************************************************/
void PMAPI PM_findClose(
    void *handle)
{
    DosFindClose((HDIR)handle);
}

/****************************************************************************
REMARKS:
Function to determine if a drive is a valid drive or not. Under Unix this
function will return false for anything except a value of 3 (considered
the root drive, and equivalent to C: for non-Unix systems). The drive
numbering is:

    0   - Current drive
    1   - Drive A:
    2   - Drive B:
    3   - Drive C:
    etc

****************************************************************************/
ibool PMAPI PM_driveValid(
    char drive)
{
    ulong   cntDisk,cntDriveMap;
    ibool   valid;

    DosQueryCurrentDisk(&cntDisk,&cntDriveMap);
    valid = (DosSetDefaultDisk(drive) == NO_ERROR);
    DosSetDefaultDisk(cntDisk);
    return valid;
}

/****************************************************************************
REMARKS:
Function to get the current working directory for the specififed drive.
Under Unix this will always return the current working directory regardless
of what the value of 'drive' is.
****************************************************************************/
void PMAPI PM_getdcwd(
    int drive,
    char *dir,
    int len)
{
    ulong length = len;

    DosQueryCurrentDir(drive, (PSZ)dir, &length);
}

/****************************************************************************
REMARKS:
Function to change the file attributes for a specific file.
****************************************************************************/
void PMAPI PM_setFileAttr(
    const char *filename,
    uint attrib)
{
    FILESTATUS3 s;

    if (DosQueryPathInfo((PSZ)filename,FIL_STANDARD,(PVOID)&s,sizeof(s)))
	return;
    s.attrFile = 0;
    if (attrib & PM_FILE_READONLY)
	s.attrFile |= FILE_READONLY;
    if (attrib & PM_FILE_ARCHIVE)
	s.attrFile |= FILE_ARCHIVED;
    if (attrib & PM_FILE_HIDDEN)
	s.attrFile |= FILE_HIDDEN;
    if (attrib & PM_FILE_SYSTEM)
	s.attrFile |= FILE_SYSTEM;
    DosSetPathInfo((PSZ)filename,FIL_STANDARD,(PVOID)&s,sizeof(s),0L);
}

/****************************************************************************
REMARKS:
Function to get the file attributes for a specific file.
****************************************************************************/
uint PMAPI PM_getFileAttr(
    const char *filename)
{
    FILESTATUS3 fs3;
    uint        retval = 0;

    if (DosQueryPathInfo((PSZ)filename, FIL_STANDARD, &fs3, sizeof(FILESTATUS3)))
	return 0;
    if (fs3.attrFile & FILE_READONLY)
	retval |= PM_FILE_READONLY;
    if (fs3.attrFile & FILE_ARCHIVED)
	retval |= PM_FILE_ARCHIVE;
    if (fs3.attrFile & FILE_HIDDEN)
	retval |= PM_FILE_HIDDEN;
    if (fs3.attrFile & FILE_SYSTEM)
	retval |= PM_FILE_SYSTEM;
    return retval;
}

/****************************************************************************
REMARKS:
Function to create a directory.
****************************************************************************/
ibool PMAPI PM_mkdir(
    const char *filename)
{
    return DosCreateDir((PSZ)filename,NULL) == NO_ERROR;
}

/****************************************************************************
REMARKS:
Function to remove a directory.
****************************************************************************/
ibool PMAPI PM_rmdir(
    const char *filename)
{
    return DosDeleteDir((PSZ)filename) == NO_ERROR;
}

/****************************************************************************
REMARKS:
Function to get the file time and date for a specific file.
****************************************************************************/
ibool PMAPI PM_getFileTime(
    const char *filename,
    ibool gmTime,
    PM_time *time)
{
    FILESTATUS3 fs3;
    struct tm   tc;
    struct tm   *ret;
    time_t      tt;

    if (DosQueryPathInfo((PSZ)filename, FIL_STANDARD, &fs3, sizeof(FILESTATUS3)))
	return false;
    if (gmTime) {
	tc.tm_year = fs3.fdateLastWrite.year + 80;
	tc.tm_mon = fs3.fdateLastWrite.month - 1;
	tc.tm_mday = fs3.fdateLastWrite.day;
	tc.tm_hour = fs3.ftimeLastWrite.hours;
	tc.tm_min = fs3.ftimeLastWrite.minutes;
	tc.tm_sec = fs3.ftimeLastWrite.twosecs * 2;
	if((tt = mktime(&tc)) == -1)
	    return false;
	if(!(ret = gmtime(&tt)))
	    return false;
	time->sec = ret->tm_sec;
	time->day = ret->tm_mday;
	time->mon = ret->tm_mon + 1;
	time->year = ret->tm_year - 80;
	time->min = ret->tm_min;
	time->hour = ret->tm_hour;
	}
    else {
	time->sec = fs3.ftimeLastWrite.twosecs * 2;
	time->day = fs3.fdateLastWrite.day;
	time->mon = fs3.fdateLastWrite.month;
	time->year = fs3.fdateLastWrite.year;
	time->min = fs3.ftimeLastWrite.minutes;
	time->hour = fs3.ftimeLastWrite.hours;
	}
    return true;
}

/****************************************************************************
REMARKS:
Function to set the file time and date for a specific file.
****************************************************************************/
ibool PMAPI PM_setFileTime(
    const char *filename,
    ibool gmTime,
    PM_time *time)
{
    FILESTATUS3 fs3;
    struct tm   tc;
    struct tm   *ret;
    time_t      tt;

    if (DosQueryPathInfo((PSZ)filename,FIL_STANDARD,(PVOID)&fs3,sizeof(fs3)))
	return false;
    if (gmTime) {
	tc.tm_year = time->year + 80;
	tc.tm_mon = time->mon - 1;
	tc.tm_mday = time->day;
	tc.tm_hour = time->hour;
	tc.tm_min = time->min;
	tc.tm_sec = time->sec;
	if((tt = mktime(&tc)) == -1)
	    return false;
	ret = localtime(&tt);
	fs3.ftimeLastWrite.twosecs = ret->tm_sec / 2;
	fs3.fdateLastWrite.day = ret->tm_mday;
	fs3.fdateLastWrite.month = ret->tm_mon + 1;
	fs3.fdateLastWrite.year = ret->tm_year - 80;
	fs3.ftimeLastWrite.minutes = ret->tm_min;
	fs3.ftimeLastWrite.hours = ret->tm_hour;
	}
    else {
	fs3.ftimeL

⌨️ 快捷键说明

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