sys.c
来自「AT91所有开发板的资料 AT91所有开发板的资料」· C语言 代码 · 共 1,017 行 · 第 1/3 页
C
1,017 行
LogInfo(LOG_SYS, ("sys_time: got time %ld\n", currenttime)); if (h_timer == -1) { /* set up a 1 second tick */ h_timer = Timer_NewTimer(1000, TF_RELOAD, sys_time_tick, 0); LogInfo(LOG_SYS, ("sys_time: set up timer tick on timer %d\n", h_timer)); } } else { LogInfo(LOG_SYS, ("sys_time: CL_Time failed status %d\n", status)); } angel_ChannelReleaseBuffer(rbuff); } #else time_t currenttime; if (_sys_build_and_transact(&rbuff, CL_Time|HtoT, (word *)&status, "%w%w%w%w", CL_Time |TtoH, 0, ADP_HandleUnknown, ADP_HandleUnknown)) return -1; if (status) currenttime = -1; else currenttime = PREAD(LE,(word *)(BUFFERDATA(rbuff)+20)); angel_ChannelReleaseBuffer(rbuff);#endif LogInfo(LOG_SYS, ("sys_time: return %ld\n", currenttime)); return currenttime;}static int _sys_system(unsigned char *name, int namelen){ p_Buffer pbuff, rbuff; int status, data, count; if (name == NULL) return 0; /* NULL line do nothing */ pbuff = angel_ChannelAllocBuffer(Angel_ChanBuffSize); if (pbuff!=NULL) { count = msgbuild(BUFFERDATA(pbuff),"%w%w%w%w%w", CL_System|TtoH, 0, ADP_HandleUnknown, ADP_HandleUnknown, namelen); MEMCPY_FROM_TARGET((char *)BUFFERDATA(pbuff)+count, name, namelen+1); count += (namelen+1); /* allow for trailing NULL */ if (_sys_do_transaction(pbuff, count, &rbuff, CL_System|HtoT, (word *)&status)) { LogInfo(LOG_SYS, ("sys_system: Comms failure\n")); return -1; } data = GET32LE(BUFFERDATA(rbuff)+20); angel_ChannelReleaseBuffer(rbuff); if (status) { LogInfo(LOG_SYS, ("sys_system: status: %d\n", status)); return status; } else { LogInfo(LOG_SYS, ("sys_system: data: %d\n", data)); return data; } } return -1;}static int _sys_remove(unsigned char *name, int namelen){ p_Buffer pbuff; int status,count; pbuff = angel_ChannelAllocBuffer(Angel_ChanBuffSize); if (pbuff!=NULL) { count = msgbuild(BUFFERDATA(pbuff),"%w%w%w%w%w", CL_Remove|TtoH, 0, ADP_HandleUnknown, ADP_HandleUnknown, namelen); MEMCPY_FROM_TARGET((char *)BUFFERDATA(pbuff)+count, name, namelen+1); count += (namelen+1); /* allow for trailing NULL */ if ( _sys_do_transaction(pbuff, count, NULL, CL_Remove|HtoT, (word *)&status)) { LogInfo(LOG_SYS, ("sys_remove: Comms failure\n")); return -1; } else { LogInfo(LOG_SYS, ("sys_remove: status: %d\n", status)); return status; } } return -1;}static int _sys_rename(unsigned char *oldname, int oldnamelen, unsigned char *newname, int newnamelen){ p_Buffer pbuff; int status, count, count2; pbuff = angel_ChannelAllocBuffer(Angel_ChanBuffSize); if (pbuff!=NULL) { count = msgbuild(BUFFERDATA(pbuff),"%w%w%w%w%w", CL_Rename|TtoH, 0, ADP_HandleUnknown, ADP_HandleUnknown, oldnamelen); MEMCPY_FROM_TARGET((char *)BUFFERDATA(pbuff)+count, oldname,++oldnamelen); count += oldnamelen; /* allow for trailing NULL */ count2 = count; PUT32LE((char *)(BUFFERDATA(pbuff)+count), newnamelen); count+=4; MEMCPY_FROM_TARGET((char *)BUFFERDATA(pbuff)+count, newname,++newnamelen); count +=newnamelen; if (_sys_do_transaction(pbuff, count, NULL, CL_Rename|HtoT, (word *)&status)) { LogInfo(LOG_SYS, ("sys_rename: Comms failure\n")); return -1; } else { LogInfo(LOG_SYS, ("sys_rename: status: %d\n", status)); return status; } } return -1;}static int _sys_getcmdline(unsigned char *cmdline){ p_Buffer rbuff; int status, cmdlen; if (_sys_build_and_transact(&rbuff, CL_GetCmdLine|HtoT, (word *)&status, "%w%w%w%w", CL_GetCmdLine|TtoH, 0, ADP_HandleUnknown, ADP_HandleUnknown)) { LogInfo(LOG_SYS, ("sys_getcmdline: Comms failure\n")); return -1; } if (status == 0) { cmdlen = PREAD(LE,(word *)(BUFFERDATA(rbuff)+20)); /* overwrite buffer, but that's okay */ ((char *)BUFFERDATA(rbuff))[24+cmdlen] = '\0'; MEMCPY_TO_TARGET(cmdline,(char *)BUFFERDATA(rbuff)+24, cmdlen+1); } LogInfo(LOG_SYS, ("sys_getcmdline: status: %d\n", status)); angel_ChannelReleaseBuffer(rbuff); return status;}/* Put the following data into the datablock passed to us: * datablock[0] = heap base * datablock[1] = heap limit * datablock[2] = stack base * datablock[3] = stack limit */static int _sys_heapinfo(unsigned *datablock){ *(AngelHeapStackDesc *)datablock = angel_heapstackdesc; LogInfo(LOG_SYS, ("sys_heapinfo: info @ %x\n", datablock)); return (int) datablock;}/* * The main decoder for the C library support routines... * * sysCode is the Semihosting Call number for the SH SWI * r1 points at the args of the function. for details see sys.h * * Remember that r1 is a target address at this point; if running in * a memory space other than the target's (e.g. E-ICE), appropriate action * will have to be taken to get the data required from the target. * */#define MAX_ARGS 4static word RealSysLibraryHandler(unsigned int sysCode, word r1){ int *args; LogInfo(LOG_SYS, ("SYScall: code = 0x%x, r1 = 0x%x.\n", sysCode, r1)); if (boot_completed == 0) { LogWarning(LOG_SYS, ("RealSysLibraryHandler: Not booted -- unable to do semihosting!\n" )); return -1; } /* these operations do their own parameter management */ switch (sysCode) { case SYS_WRITEC: return _sys_writeC((unsigned char *)r1); case SYS_WRITE0: return _sys_write0((unsigned char *)r1); default: break; } /* grab the parameter list from the target for the functions below. */ if ( r1 != NULL ) { /* for direct Angel, r1 is already a suitable pointer to the args. */ args = (int*)r1; } switch (sysCode) { case SYS_OPEN: return _sys_open((char *)args[0], args[1], args[2]); case SYS_CLOSE: return _sys_close((FILEHANDLE)args[0]); case SYS_WRITE: return _sys_write((FILEHANDLE)args[0], (unsigned char *)args[1], (unsigned)args[2]); case SYS_READC: return _sys_readc(); case SYS_READ: return _sys_read((FILEHANDLE)args[0], (unsigned char *)args[1], (unsigned)args[2],args[3]); case SYS_ISTTY: return _sys_istty((FILEHANDLE )args[0]); case SYS_ENSURE: return _sys_ensure((FILEHANDLE )args[0]); case SYS_ISERROR: return _sys_iserror(args[0]); case SYS_SEEK: return _sys_seek((FILEHANDLE)args[0],(long)args[1]); case SYS_FLEN: return (word)_sys_flen((FILEHANDLE)args[0]); case SYS_TMPNAM: return _sys_tmpnam((char *)args[0],args[1], (unsigned) args[2]); case SYS_GET_CMDLINE: return _sys_getcmdline((unsigned char *)args[0]); case SYS_HEAPINFO: return _sys_heapinfo((unsigned *) args[0]); case SYS_RENAME: return _sys_rename((unsigned char *)args[0],args[1], (unsigned char *)args[2],args[3]); case SYS_REMOVE: return _sys_remove((unsigned char *)args[0],args[1]); case SYS_SYSTEM: return _sys_system((unsigned char *)args[0],args[1]); case SYS_TIME: return _sys_time(); case SYS_CLOCK: return _sys_clock(); case SYS_ERRNO: return _sys_errno(); default: LogWarning(LOG_SYS, ("RealSysLibraryHandler: Unknown SYS call %d\n", sysCode)); break; } return -1;}word SysLibraryHandler(unsigned int sysCode, word r1){ word retval; sys_handler_running = 1; retval = RealSysLibraryHandler(sysCode, r1); sys_handler_running = 0; return retval;}/* * This routine is called by Angel Startup to initialise the C library support * code. */void angel_SysLibraryInit(void){ sys_handler_running = 0; /* * if we have timer support, we can use it to implement SYS_TIME && SYS_CLOCK * locally; in case this is not wanted the define SYS_USES_TIMER, if set to 0 * in devconf, etc, will return to the previous behaviour. */#if SYS_USES_TIMER && TIMER_SUPPORTED currenttime = (time_t)-1; h_timer = -1; set_time = FALSE;#endif return;}/* * This routine is called by Angel when the debugger calls ADP_InitialiseApplication. */void Angel_SysApplInit(void){#if SYS_USES_TIMER && TIMER_SUPPORTED currenttime = (time_t)-1; set_time = FALSE; /* don't reset h_timer unless you delete any existing timer */#endif return;}int Angel_IsSysHandlerRunning(void){ return sys_handler_running;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?