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

📄 dbgport.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
    // connected to.
    PDEVICE_OBJECT                  PortDeviceObject;
    
    // This holds the result of the get parallel port info
    // request to the port driver.
    PHYSICAL_ADDRESS                OriginalController;
    PUCHAR                          Controller;
    ULONG                           SpanOfController;
    PPARALLEL_FREE_ROUTINE          FreePort;
    PPARALLEL_TRY_ALLOCATE_ROUTINE  TryAllocatePort;
    PVOID                           AllocFreePortContext;
    
    // Records whether we actually created the symbolic link name
    // at driver load time and the symbolic link itself.  If we didn't
    // create it, we won't try to destroy it when we unload.
    BOOLEAN                         CreatedSymbolicLink;
    UNICODE_STRING                  SymbolicLinkName;
    
    // Internal variables used by the driver
    unsigned                        DataPort;
    unsigned                        CtlPort1;
    unsigned                        CtlPort2;
    UCHAR                           CableType;
    UCHAR                           TwidleCount;
    bool                            TwidleOn;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;

// This is the "structure" of the IOPM.  It is just a simple
// character array of length 0x2000.
//
// This holds 8K * 8 bits -> 64K bits of the IOPM, which maps the
// entire 64K I/O space of the x86 processor.  Any 0 bits will give
// access to the corresponding port for user mode processes.  Any 1
// bits will disallow I/O access to the corresponding port.
#define IOPM_SIZE       0x2000
typedef UCHAR IOPM[IOPM_SIZE];

// This will hold simply an array of 0's which will be copied
// into our actual IOPM in the TSS by Ke386SetIoAccessMap().
// The memory is allocated at driver load time.
IOPM *IOPM_local = 0;
IOPM *IOPM_saved = 0;

/*-------------------------- Implementation -------------------------------*/

// These are the three undocumented calls that we will use to give
// the calling process I/O access.
//
// Ke386IoSetAccessMap() copies the passed map to the TSS.
//
// Ke386IoSetAccessProcess() adjusts the IOPM offset pointer so that
// the newly copied map is actually used.  Otherwise, the IOPM offset
// points beyond the end of the TSS segment limit, causing any I/O
// access by the user mode process to generate an exception.
void PORTSTDCALL Ke386SetIoAccessMap(int, IOPM *);
void PORTSTDCALL Ke386QueryIoAccessMap(int, IOPM *);
void PORTSTDCALL Ke386IoSetAccessProcess(PEPROCESS, int);

void NTAPI ZwYieldExecution(void);

void NothingToDo(void)
{
    ZwYieldExecution();
}

unsigned long Ticks(void)
{
    _int64 ticks;

    KeQueryTickCount((PLARGE_INTEGER)&ticks);
    return (unsigned long)(ticks / 10);
}

/*
 * if wait is not KEEP or RELINQUISH it is the latest time that this
 * operation should take before it times out
 */

static int DataGet(
    PDEVICE_EXTENSION ext,
    unsigned long wait )
{
    UCHAR                data;
    
    switch( ext->CableType ) {
    case WATCOM_VAL:
        RaiseCtl2();            /* Hi, I'm ready to read */
        while( Ctl1Lo() ) {     /* wait till he's written the data */
            TWIDDLE_THUMBS;
        }
        data = ReadData();      /* bag the bits */
        LowerCtl2();            /* Hey you! I got the bits */
        while( Ctl1Hi() ) {     /* Wait till he heard us */
            TWIDDLE_THUMBS;
        }
        break;
    case FMR_VAL:
        /* We're talking to the FMR which can't RaiseCtl1/LowerCtl1 */
        /* get the low nibble */
        RaiseCtl2();                    /* ready to read */
        while( FM_Ctl1Lo() ) {          /* wait for data */
            TWIDDLE_THUMBS;
        }
        data = ReadData() & 0x0f;       /* bag the bits */
        LowerCtl2();                    /* Hey you! I got the bits */
        while( FM_Ctl1Hi() ) {          /* Wait till he heard us */
            TWIDDLE_THUMBS;
        }
        /*get the high nibble */
        RaiseCtl2();                    /* ready to read */
        while( FM_Ctl1Lo() ) {          /* wait for data */
            TWIDDLE_THUMBS;
        }
        data |= ( ReadData() << 4 );    /* bag the bits */
        LowerCtl2();                    /* Hey you! I got the bits */
        while( FM_Ctl1Hi() ) {          /* Wait till he heard us */
            TWIDDLE_THUMBS;
        }
        break;
    case LAPLINK_VAL:
        /* get the low nibble */
        LL_RaiseCtl2();                 /* ready to read */
        while( LL_Ctl1Lo() ) {          /* wait for data */
            TWIDDLE_THUMBS;
        }
        data = LL_ReadData();           /* bag the bits */
        LL_LowerCtl2();                 /* Hey you! I got the bits */
        while( LL_Ctl1Hi() ) {          /* Wait till he heard us */
            TWIDDLE_THUMBS;
        }
        /*get the high nibble */
        LL_RaiseCtl2();                 /* ready to read */
        while( LL_Ctl1Lo() ) {          /* wait for data */
            TWIDDLE_THUMBS;
        }
        data |= ( LL_ReadData() << 4 ); /* bag the bits */
        LL_LowerCtl2();                 /* Hey you! I got the bits */
        while( LL_Ctl1Hi() ) {          /* Wait till he heard us */
            TWIDDLE_THUMBS;
        }
        break;
    case DUTCHMAN_VAL:
        /* get the low nibble */
        FD_RaiseCtl2();                 /* ready to read */
        while( FD_Ctl1Lo() ) {          /* wait for data */
            TWIDDLE_THUMBS;
        }
        data = FD_ReadData();           /* bag the bits */
        FD_LowerCtl2();                 /* Hey you! I got the bits */
        while( FD_Ctl1Hi() ) {          /* Wait till he heard us */
            TWIDDLE_THUMBS;
        }
        /*get the high nibble */
        FD_RaiseCtl2();                 /* ready to read */
        while( FD_Ctl1Lo() ) {          /* wait for data */
            TWIDDLE_THUMBS;
        }
        data |= ( FD_ReadData() << 4 ); /* bag the bits */
        FD_LowerCtl2();                 /* Hey you! I got the bits */
        while( FD_Ctl1Hi() ) {          /* Wait till he heard us */
            TWIDDLE_THUMBS;
        }
        break;
    }
    return( data );
}

/* if wait is not KEEP or RELINQUISH it is the latest time that this
 * operation should take before it times out
 */

static int DataPut(
    PDEVICE_EXTENSION ext,
    unsigned data,
    unsigned long wait )
{
    switch( ext->CableType ) {
    case WATCOM_VAL:
        while( Ctl2Lo() ) {             /* wait till he's ready to read */
            TWIDDLE_THUMBS;
        }
        WriteData( data );              /* write the data */
        RaiseCtl1();                    /* tell him the data's there */
        while( Ctl2Hi() ) {             /* wait till he got the bits */
            TWIDDLE_THUMBS;
        }
        LowerCtl1();                    /* clear control line */
        break;
    case FMR_VAL:
        /* We're talking to the FMR which can RaiseCtl2/LowerCtl2 */
        while( Ctl2Lo() ) {             /* wait till he's ready to read */
            TWIDDLE_THUMBS;
        }
        WriteData( data );              /* write the data */
        RaiseCtl1();                    /* tell him the data's there */
        while( Ctl2Hi() ) {             /* wait till he got the bits */
            TWIDDLE_THUMBS;
        }
        LowerCtl1();                    /* clear control line */
        break;
    case LAPLINK_VAL:
        /* send low nibble */
        while( LL_Ctl2Lo() ) {          /* wait till he's ready to read */
            TWIDDLE_THUMBS;
        }
        LL_WriteData( data & 0x0f );    /* write the data */
                                        /* and tell him the data's there */
        while( LL_Ctl2Hi() ) {          /* wait till he got the bits */
            TWIDDLE_THUMBS;
        }
        LL_LowerCtl1();                 /* clear control line */
        /* send high nibble */
        while( LL_Ctl2Lo() ) {          /* wait till he's ready to read */
            TWIDDLE_THUMBS;
        }
        LL_WriteData( data >> 4 );      /* write the data */
                                        /* and tell him the data's there */
        while( LL_Ctl2Hi() ) {          /* wait till he got the bits */
            TWIDDLE_THUMBS;
        }
        LL_LowerCtl1();                 /* clear control line */
        break;
    case DUTCHMAN_VAL:
        /* send low nibble */
        while( FD_Ctl2Lo() ) {          /* wait till he's ready to read */
            TWIDDLE_THUMBS;
        }
        FD_WriteData( data & 0x0f );    /* write the data */
        FD_RaiseCtl1();                 /* tell him the data's there */
        while( FD_Ctl2Hi() ) {          /* wait till he got the bits */
            TWIDDLE_THUMBS;
        }
        FD_LowerCtl1();                 /* clear control line */
        /* send high nibble */
        while( FD_Ctl2Lo() ) {          /* wait till he's ready to read */
            TWIDDLE_THUMBS;
        }
        FD_WriteData( data >> 4 );      /* write the data */
        FD_RaiseCtl1();                 /* tell him the data's there */
        while( FD_Ctl2Hi() ) {          /* wait till he got the bits */
            TWIDDLE_THUMBS;
        }
        FD_LowerCtl1();                 /* clear control line */
        break;
    }
    return( 0 );
}

unsigned RemoteGet(
    PDEVICE_EXTENSION ext,
    char *rec,
    unsigned len )
{
    unsigned    get_len;
    unsigned    i;
    
    get_len = DataGet( ext, RELINQUISH );
    if( get_len & 0x80 ) {
        get_len = ((get_len & 0x7f) << 8) | DataGet( ext, KEEP );
    }
    i = get_len;
    for( ; i != 0; --i, ++rec ) {
        *rec = DataGet( ext, KEEP );
    }
    return( get_len );
}

unsigned RemotePut(
    PDEVICE_EXTENSION ext,
    char *snd,
    unsigned len )
{
    unsigned    count;
    
    if( len >= 0x80 ) {
        DataPut( ext, ((len >> 8) | 0x80), RELINQUISH );
    }
    DataPut( ext, (len & 0xff), RELINQUISH );
    for( count = len; count != 0; --count, ++snd ) {
        DataPut( ext, *snd, KEEP );
    }
    return( len );
}

/*
 * Synch - see if server and client are ready
 */

static bool Synch(
    PDEVICE_EXTENSION ext)
{
    switch( ext->CableType ) {
    case WATCOM_VAL:
    case FMR_VAL:
        if( Ctl2Lo() ) {
            return( TRUE );
        }
        break;
    case LAPLINK_VAL:
        if( LL_Ctl1Lo() ) return( TRUE );
        break;
    case DUTCHMAN_VAL:
        if( FD_Ctl1Lo() ) return( TRUE );
        break;
    }
    return( FALSE );
}

static bool CountTwidle(
    PDEVICE_EXTENSION ext)
{
    UCHAR                type;
    
    type = ReadData();
    if( !ext->TwidleOn ) {
        if( type == WATCOM_VAL ||
            type == FMR_VAL ||
            type == LAPLINK_VAL ||
            type == DUTCHMAN_VAL ) {
            ext->TwidleOn = TRUE;
            if( type != ext->CableType ) {
                ext->TwidleCount = 0;
                ext->CableType = type;
            }
        }
    } else {
        if( type != ext->CableType )  {
            ext->TwidleCount ++;
            ext->TwidleOn = FALSE;
            if( ext->TwidleCount == TWIDLE_NUM ) return( TRUE );
        }
    }
    return( FALSE );
}

⌨️ 快捷键说明

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