📄 io.c
字号:
/*******************************************************************************
*
* Motorola Inc.
* (c) Copyright 2002 Motorola, Inc.
* ALL RIGHTS RESERVED.
*
* $Element: /project/dsp568_sdk/sdk/src/dsp56838evm/nos/sys/io.c $
* $Author: saa $
* $Revision: /main/2 $
* $VOB: /project/dsp568_sdk $
* $OS: solaris $
*
* Description: POSIX interface support
*
* Notes:
*
******************************************************************************/
#include "port.h"
#include "io.h"
#include "stdarg.h"
extern const struct io_sDevice DeviceTable[];
extern const int DeviceTableLen;
const struct io_sDevice * ResolveDevice( const char *pName );
/*****************************************************************************/
#if 0
handle_t open(const char *pName, int OFlags, ...)
{
UWord16 i;
handle_t Handle;
va_list Args;
void * pParams;
void * pParams2;
void * pParams3;
#if 0
va_start(Args, OFlags);
#else
Args = (char *)&OFlags;
#endif
pParams = va_arg(Args, void *);
pParams2 = va_arg(Args, void *);
pParams3 = va_arg(Args, void *);
va_end(Args);
for(i = 0; i < DeviceTableLen; i++)
{
Handle = DeviceTable[i].pOpen(pName, OFlags, pParams, pParams2, pParams3 );
if(Handle != (handle_t)-1)
{
return Handle;
}
}
return (handle_t)-1;
}
#endif
/*****************************************************************************/
handle_t open(const char *pName, int OFlags, ...)
{
asm( adda #2,SP);
asm( move.l Y, X:(SP)+);
asm( move.l R2, X:(SP)); /* save opens parameters */
asm( jsr ResolveDevice ); /* input R2 - device name */
asm( tfra R2, R3); /* load R3 by open structure */
asm( move.l X:(SP)-, R2); /* restore parameters for opens */
asm( move.l X:(SP)-, Y );
asm( move.l X:(R3 + #dev_preopen), N ); /* load preopen function */
asm( tsta.l N ); /* check "preopen" */
asm( beq callopen );
asm( jmp (N) ); /* go to found "open" */
callopen:
asm( move.l X:(R3 + #dev_open), N ); /* load open function */
asm( jmp (N) ); /* go to found "open" */
}
/*****************************************************************************/
unsigned long no_preOpen(const char *pName, int OFlags, ...)
{
va_list args;
args = (char *)&OFlags;
return va_arg(args, unsigned long); /* parse params */
va_end(args);
}
/*****************************************************************************/
#if 0
const struct io_sDevice * ResolveDevice( const char *pName )
{
union
{
unsigned long l_name;
unsigned char c_name[4];
} name;
int i, j;
const char *pTmpName;
if( (int)pName < 0 )
{ /* simplified device search */
for(i = 0; i < DeviceTableLen; i++)
{
if( pName == DeviceTable[i].tag_name )
return &DeviceTable[i];
}
}
else /* standard device search */
{
name.l_name = 0;
for( i = 0; i < sizeof(long); i++ )
{
if( *pName == '/' || *pName == '\\' || *pName == 0 )
{
break;
}
else
{
name.c_name[i] = *pName;
}
pName++;
}
for(j = 0; j < DeviceTableLen; j++)
{
if( DeviceTable[i].base_name != name.l_name )
continue;
pTmpName = pName;
for( i = 0; ; ) /* scan of suffixes */
{
if( i >= 2 || DeviceTable[j].ext_name[i] == 0 )
return &DeviceTable[j];
if( *pTmpName == 0 )
break;
if( *pTmpName == DeviceTable[j].ext_name[i] )
i++;
pTmpName++;
}
}
}
return &DeviceTable[0]; /* error in device name */
}
#else
const struct io_sDevice * ResolveDevice( const char *pName )
{
const struct io_sDevice * pDev = &DeviceTable[0];
int name = (int)pName & 0xFFF0; /* masked sub(2)device */
while( pDev->tag_name ) /* check terminator */
{
if( name == pDev->tag_name )
return pDev;
pDev++;
}
return pDev;
}
#endif
/*****************************************************************************/
UWord16 ioctl( handle_t FileDesc, UWord16 Cmd, unsigned long params )
{
asm( moveu.w X:(R2), R0 );
asm( moveu.w Y0 , N );
asm( adda N, R0 );
asm( move.l X:(R0), N );
asm( jmp (N) );
}
/*****************************************************************************/
UWord16 close( handle_t FileDesc)
{
asm( moveu.w X:(R2), R0 );
asm( move.l X:(R0 + 4), N ); /* io_close_off */
asm( jmp (N) );
}
/*****************************************************************************/
ssize_t write(handle_t FileDesc, const void * pBuffer, size_t NBytes)
{
/*#if __m56800E_lmm__
asm(move.w A0,A);
asm(move.w A1,Y0);
#else
asm(nop);
asm(nop);
#endif
*/
asm( moveu.w X:(R2), R0 );
asm( move.l X:(R0 + 2), N ); /* io_write_off */
asm( jmp (N) );
}
/*****************************************************************************/
ssize_t read(handle_t FileDesc, void * pBuffer, size_t NBytes)
{
/*
#if __m56800E_lmm__
asm(move.w A0,A);
asm(move.w A1,Y0);
#else
asm(nop);
asm(nop);
#endif
*/
asm( moveu.w X:(R2), R0 );
asm( move.l X:(R0), N ); /* firts parameter */
asm( jmp (N) );
}
/*****************************************************************************/
handle_t no_open(const char *pName, int OFlags, ...)
{
asm( debughlt ); /* not implemented or not specified interface */
}
/*****************************************************************************/
unsigned int no_ioctl( handle_t FileDesc, unsigned long params )
{
asm( debughlt ); /* not implemented or not specified interface */
}
/*****************************************************************************/
int no_close( handle_t FileDesc)
{
asm( debughlt ); /* not implemented or not specified interface */
}
/*****************************************************************************/
ssize_t no_write(handle_t FileDesc, const void * pBuffer, size_t NBytes)
{
asm( debughlt ); /* not implemented or not specified interface */
}
/*****************************************************************************/
ssize_t no_read(handle_t FileDesc, void * pBuffer, size_t NBytes)
{
asm( debughlt ); /* not implemented or not specified interface */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -