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

📄 io.c

📁 详细介绍了一篇关于pci开发的接口芯片
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
	io.c

	expanded input/output functions
*/

// standard libs..
#include <stdtypes.h>
#include <string.h>
#include <ctype.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>

// custom libs...
#include <clib1.h>

extern CHAR errstring[];



/*
************************************************************************
************************************************************************
**                                                                                                                                        **
** logical <--> physical address conversion routines                              **
**                                                                                                                                        **
************************************************************************
************************************************************************
*/

UINT32 physaddr( void *voidaddr )
{

        UINT32 ulong;

                ulong  = (UINT32)FP_SEG(voidaddr) << 4;
                ulong += (UINT32)FP_OFF(voidaddr);

        return ulong;

}

void *voidaddr( UINT32 physaddr )
{

        if( physaddr > 0x000FFFFFlu )
        {
			fprintf( stderr, "Function voidaddr() called with address > 1mb.\n " );
			exit(1);
        }

        return MK_FP( (UINT16)((physaddr & 0x000FFFF0lu) >> 4), (UINT16)(physaddr & 0x0000000Flu) );

}

/*
************************************************************************
************************************************************************
**                                                                                                                                        **
** endian swapping routines                                                                               **
**                                                                                                                                        **
************************************************************************
************************************************************************
*/

UINT32 swaplong ( UINT32 ulong )
/* swap byte order of 32-bit dword */
{

        UINT8 swapped[4];

        swapped[0] = (UINT8)(ulong >> 24);
        swapped[1] = (UINT8)(ulong >> 16);
        swapped[2] = (UINT8)(ulong >> 8);
        swapped[3] = (UINT8)ulong;

        return( *(UINT32 *)swapped );

}

UINT16 swapword ( UINT16 uword )
/* swap byte order of 16-bit word */
{

        UINT8 swapped[2];

        swapped[0] = (UINT8)(uword >> 8);
        swapped[1] = (UINT8)uword;

        return( *(UINT16 *)swapped );

}


/****************************************************************************/
/*                                                                          */
/*  INSB                                                                    */
/*                                                                          */
/* Purpose: Inputs a string of BYTEs from a hardware port                   */
/*                                                                          */
/* Inputs:                                                                  */
/*                                                                          */
/*    word port                                                             */
/*       hardware port to read from                                         */
/*                                                                          */
/*    void *buf                                                             */
/*       Buffer to read data into                                           */
/*                                                                          */
/*    int count                                                             */
/*       Number of BYTEs to read                                            */
/*                                                                          */
/* Outputs:                                                                 */
/*                                                                          */
/*    None                                                                  */
/*                                                                          */
/****************************************************************************/

void insb(UINT16 port, void *buf, int count)
{
   _ES = FP_SEG(buf);   /* Segment of buf */
   _DI = FP_OFF(buf);   /* Offset of buf  */
   _CX = count;         /* Number to read */
   _DX = port;          /* Port           */
   asm   REP INSB;
}

/****************************************************************************/
/*                                                                          */
/*  INSW                                                                    */
/*                                                                          */
/* Purpose: Inputs a string of WORDs from a hardware port                   */
/*                                                                          */
/* Inputs:                                                                  */
/*                                                                          */
/*    word port                                                             */
/*       hardware port to read from                                         */
/*                                                                          */
/*    void *buf                                                             */
/*       Buffer to read data into                                           */
/*                                                                          */
/*    int count                                                             */
/*       Number of WORDs to read                                            */
/*                                                                          */
/* Outputs:                                                                 */
/*                                                                          */
/*    None                                                                  */
/*                                                                          */
/****************************************************************************/

void insw(UINT16 port, void *buf, int count)
{
   _ES = FP_SEG(buf);   /* Segment of buf */
   _DI = FP_OFF(buf);   /* Offset of buf  */
   _CX = count;         /* Number to read */
   _DX = port;          /* Port           */
   asm   REP INSW;
}

/****************************************************************************/
/*                                                                          */
/*  INSL                                                                    */
/*                                                                          */
/* Purpose: Inputs a string of 32-bit words from a hardware port                  */
/*                                                                          */
/* Inputs:                                                                  */
/*                                                                          */
/*    word port                                                             */
/*       hardware port to read from                                         */
/*                                                                          */
/*    void *buf                                                             */
/*       Buffer to read data into                                           */
/*                                                                          */
/*    int count                                                             */
/*       Number of DWORDs to read                                           */
/*                                                                          */
/* Outputs:                                                                 */
/*                                                                          */
/*    None                                                                  */
/*                                                                          */
/****************************************************************************/

void insl(UINT16 port, void *buf, int count)
{
   _ES = FP_SEG(buf);   /* Segment of buf */
   _DI = FP_OFF(buf);   /* Offset of buf  */
   _CX = count;         /* Number to read */
   _DX = port;          /* Port           */
   __emit__(0xf3, 0x66, 0x6D); /* asm  REP INSD */
}

/****************************************************************************/
/*                                                                          */
/*  OUTSB                                                                   */
/*                                                                          */
/* Purpose: Outputs a string of BYTEs to a hardware port                    */
/*                                                                          */
/* Inputs:                                                                  */
/*                                                                          */
/*    word port                                                             */
/*       hardware port to write to                                          */
/*                                                                          */
/*    void *buf                                                             */
/*       Buffer to write data from                                          */
/*                                                                          */
/*    int count                                                             */
/*       Number of BYTEs to write                                           */
/*                                                                          */
/* Outputs:                                                                 */
/*                                                                          */
/*    None                                                                  */
/*                                                                          */
/****************************************************************************/

void outsb(UINT16 port, void *buf, int count)
{
   _SI = FP_SEG(buf);   /* Offset of buf  */
   _CX = count;         /* Number to read */
   _DX = port;          /* Port           */
   asm   REP OUTSB;
}

/****************************************************************************/
/*                                                                          */
/*  OUTSW                                                                   */
/*                                                                          */
/* Purpose: Outputs a string of WORDs to a hardware port                    */
/*                                                                          */
/* Inputs:                                                                  */
/*                                                                          */
/*    word port                                                             */
/*       hardware port to write to                                          */
/*                                                                          */
/*    void *buf                                                             */
/*       Buffer to write data from                                          */
/*                                                                          */
/*    int count                                                             */
/*       Number of WORDs to write                                           */
/*                                                                          */
/* Outputs:                                                                 */
/*                                                                          */
/*    None                                                                  */
/*                                                                          */
/****************************************************************************/

void outsw(UINT16 port, void *buf, int count)
{
   _SI = FP_SEG(buf);   /* Offset of buf  */
   _CX = count;         /* Number to read */
   _DX = port;          /* Port           */
   asm   REP OUTSW;
}

/****************************************************************************/
/*                                                                          */
/*  OUTSL                                                                   */
/*                                                                          */

⌨️ 快捷键说明

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