pm.c

来自「适合KS8695X」· C语言 代码 · 共 981 行 · 第 1/3 页

C
981
字号
}

/****************************************************************************
REMARKS:
Return the drive letter for the boot drive.
****************************************************************************/
char PMAPI PM_getBootDrive(void)
{
    /* TODO: Return the boot drive letter for the OS. Normally this is 'c' */
    /*       for DOS based OS'es and '/' for Unices. */
    return '/';
}

/****************************************************************************
REMARKS:
Return the path to the VBE/AF driver files (legacy and not used).
****************************************************************************/
const char * PMAPI PM_getVBEAFPath(void)
{
    return PM_getNucleusConfigPath();
}

/****************************************************************************
REMARKS:
Return the path to the Nucleus driver files.
****************************************************************************/
const char * PMAPI PM_getNucleusPath(void)
{
    /* TODO: Change this to the default path to Nucleus driver files. The */
    /*       following is the default for Unices. */
    char *env = getenv("NUCLEUS_PATH");
    return env ? env : "/usr/lib/nucleus";
}

/****************************************************************************
REMARKS:
Return the path to the Nucleus configuration files.
****************************************************************************/
const char * PMAPI PM_getNucleusConfigPath(void)
{
    static char path[256];
    strcpy(path,PM_getNucleusPath());
    PM_backslash(path);
    strcat(path,"config");
    return path;
}

/****************************************************************************
REMARKS:
Return a unique identifier for the machine if possible.
****************************************************************************/
const char * PMAPI PM_getUniqueID(void)
{
    /* TODO: Return a unique ID for the machine. If a unique ID is not */
    /*       available, return the machine name. */
    static char buf[128];
    gethostname(buf, 128);
    return buf;
}

/****************************************************************************
REMARKS:
Get the name of the machine on the network.
****************************************************************************/
const char * PMAPI PM_getMachineName(void)
{
    /* TODO: Return the network machine name for the machine. */
    static char buf[128];
    gethostname(buf, 128);
    return buf;
}

/****************************************************************************
REMARKS:
Return a pointer to the real mode BIOS data area.
****************************************************************************/
void * PMAPI PM_getBIOSPointer(void)
{
    /* TODO: This returns a pointer to the real mode BIOS data area. If you */
    /*       do not support BIOS access, you can simply return NULL here. */
    if (!zeroPtr)
	zeroPtr = PM_mapPhysicalAddr(0,0xFFFFF,true);
    return (void*)(zeroPtr + 0x400);
}

/****************************************************************************
REMARKS:
Return a pointer to 0xA0000 physical VGA graphics framebuffer.
****************************************************************************/
void * PMAPI PM_getA0000Pointer(void)
{
    static void *bankPtr;
    if (!bankPtr)
	bankPtr = PM_mapPhysicalAddr(0xA0000,0xFFFF,true);
    return bankPtr;
}

/****************************************************************************
REMARKS:
Map a physical address to a linear address in the callers process.
****************************************************************************/
void * PMAPI PM_mapPhysicalAddr(
    ulong base,
    ulong limit,
    ibool isCached)
{
    /* TODO: This function maps a physical memory address to a linear */
    /*       address in the address space of the calling process. */

    /* NOTE: This function *must* be able to handle any phsyical base */
    /*       address, and hence you will have to handle rounding of */
    /*       the physical base address to a page boundary (ie: 4Kb on */
    /*       x86 CPU's) to be able to properly map in the memory */
    /*       region. */

    /* NOTE: If possible the isCached bit should be used to ensure that */
    /*       the PCD (Page Cache Disable) and PWT (Page Write Through) */
    /*       bits are set to disable caching for a memory mapping used */
    /*       for MMIO register access. We also disable caching using */
    /*       the MTRR registers for Pentium Pro and later chipsets so if */
    /*       MTRR support is enabled for your OS then you can safely ignore */
    /*       the isCached flag and always enable caching in the page */
    /*       tables. */
    return NULL;
}

/****************************************************************************
REMARKS:
Free a physical address mapping allocated by PM_mapPhysicalAddr.
****************************************************************************/
void PMAPI PM_freePhysicalAddr(
    void *ptr,
    ulong limit)
{
    /* TODO: This function will free a physical memory mapping previously */
    /*       allocated with PM_mapPhysicalAddr() if at all possible. If */
    /*       you can't free physical memory mappings, simply do nothing. */
}

/****************************************************************************
REMARKS:
Find the physical address of a linear memory address in current process.
****************************************************************************/
ulong PMAPI PM_getPhysicalAddr(void *p)
{
    /* TODO: This function should find the physical address of a linear */
    /*       address. */
    return 0xFFFFFFFFUL;
}

void PMAPI PM_sleep(ulong milliseconds)
{
    /* TODO: Put the process to sleep for milliseconds */
}

int PMAPI PM_getCOMPort(int port)
{
    /* TODO: Re-code this to determine real values using the Plug and Play */
    /*       manager for the OS. */
    switch (port) {
	case 0: return 0x3F8;
	case 1: return 0x2F8;
	}
    return 0;
}

int PMAPI PM_getLPTPort(int port)
{
    /* TODO: Re-code this to determine real values using the Plug and Play */
    /*       manager for the OS. */
    switch (port) {
	case 0: return 0x3BC;
	case 1: return 0x378;
	case 2: return 0x278;
	}
    return 0;
}

/****************************************************************************
REMARKS:
Allocate a block of (unnamed) shared memory.
****************************************************************************/
void * PMAPI PM_mallocShared(
    long size)
{
    /* TODO: This is used to allocate memory that is shared between process */
    /*       that all access the common Nucleus drivers via a common display */
    /*       driver DLL. If your OS does not support shared memory (or if */
    /*       the display driver does not need to allocate shared memory */
    /*       for each process address space), this should just call PM_malloc. */
    return PM_malloc(size);
}

/****************************************************************************
REMARKS:
Free a block of shared memory.
****************************************************************************/
void PMAPI PM_freeShared(
    void *ptr)
{
    /* TODO: Free the shared memory block. This will be called in the context */
    /*       of the original calling process that allocated the shared */
    /*       memory with PM_mallocShared. Simply call PM_free if you do not */
    /*       need this. */
    PM_free(ptr);
}

/****************************************************************************
REMARKS:
Map a linear memory address to the calling process address space. The
address will have been allocated in another process using the
PM_mapPhysicalAddr function.
****************************************************************************/
void * PMAPI PM_mapToProcess(
    void *base,
    ulong limit)
{
    /* TODO: This function is used to map a physical memory mapping */
    /*       previously allocated with PM_mapPhysicalAddr into the */
    /*       address space of the calling process. If the memory mapping */
    /*       allocated by PM_mapPhysicalAddr is global to all processes, */
    /*       simply return the pointer. */

    /* NOTE: This function must also handle rounding to page boundaries, */
    /*       since this function is used to map in shared memory buffers */
    /*       allocated with PM_mapPhysicalAddr(). Hence if you aligned */
    /*       the physical address above, then you also need to do it here. */
    return base;
}

/****************************************************************************
REMARKS:
Map a real mode pointer to a protected mode pointer.
****************************************************************************/
void * PMAPI PM_mapRealPointer(
    uint r_seg,
    uint r_off)
{
    /* TODO: This function maps a real mode memory pointer into the */
    /*       calling processes address space as a 32-bit near pointer. If */
    /*       you do not support BIOS access, simply return NULL here. */
    if (!zeroPtr)
	zeroPtr = PM_mapPhysicalAddr(0,0xFFFFF);
    return (void*)(zeroPtr + MK_PHYS(r_seg,r_off));
}

/****************************************************************************
REMARKS:
Allocate a block of real mode memory
****************************************************************************/
void * PMAPI PM_allocRealSeg(
    uint size,
    uint *r_seg,
    uint *r_off)
{
    /* TODO: This function allocates a block of real mode memory for the */
    /*       calling process used to communicate with real mode BIOS */
    /*       functions. If you do not support BIOS access, simply return */
    /*       NULL here. */
    return NULL;
}

/****************************************************************************
REMARKS:
Free a block of real mode memory.
****************************************************************************/
void PMAPI PM_freeRealSeg(
    void *mem)
{
    /* TODO: Frees a previously allocated real mode memory block. If you */
    /*       do not support BIOS access, this function should be empty. */
}

/****************************************************************************
REMARKS:
Issue a real mode interrupt (parameters in DPMI compatible structure)
****************************************************************************/
void PMAPI DPMI_int86(
    int intno,
    DPMI_regs *regs)
{
    /* TODO: This function calls the real mode BIOS using the passed in */
    /*       register structure. If you do not support real mode BIOS */
    /*       access, this function should be empty. */
}

/****************************************************************************
REMARKS:
Issue a real mode interrupt.
****************************************************************************/
int PMAPI PM_int86(
    int intno,
    RMREGS *in,
    RMREGS *out)
{
    /* TODO: This function calls the real mode BIOS using the passed in */
    /*       register structure. If you do not support real mode BIOS */
    /*       access, this function should return 0. */
    return 0;
}

/****************************************************************************
REMARKS:
Issue a real mode interrupt.
****************************************************************************/
int PMAPI PM_int86x(
    int intno,
    RMREGS *in,
    RMREGS *out,
    RMSREGS *sregs)
{
    /* TODO: This function calls the real mode BIOS using the passed in */
    /*       register structure. If you do not support real mode BIOS */
    /*       access, this function should return 0. */
    return 0;
}

/****************************************************************************
REMARKS:
Call a real mode far function.
****************************************************************************/
void PMAPI PM_callRealMode(
    uint seg,
    uint off,
    RMREGS *in,
    RMSREGS *sregs)
{

⌨️ 快捷键说明

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