📄 sys.c
字号:
/* * TOPPERS/JSP Kernel * Toyohashi Open Platform for Embedded Real-Time Systems/ * Just Standard Profile Kernel * * Additional routine * * Copyright (C) 2003 by SEIKO EPSON Corp, JAPAN * * 惧淡螟侯涪荚は·Free Software Foundation によって给山されている * GNU General Public License の Version 2 に淡揭されている掘凤か·笆 * 布の(1)×(4)の掘凤を塔たす眷圭に嘎り·塑ソフトウェア∈塑ソフトウェ * アを猖恃したものを崔むˉ笆布票じ∷を蝗脱ˇ剩澜ˇ猖恃ˇ浩芹邵∈笆布· * 网脱と钙ぶ∷することを痰浸で钓满するˉ * (1) 塑ソフトウェアをソ〖スコ〖ドの妨で网脱する眷圭には·惧淡の螟侯 * 涪山绩·この网脱掘凤および布淡の痰瘦沮惮年が·そのままの妨でソ〖 * スコ〖ド面に崔まれていることˉ * (2) 塑ソフトウェアを浩网脱材墙なバイナリコ〖ド∈リロケ〖タブルオブ * ジェクトファイルやライブラリなど∷の妨で网脱する眷圭には·网脱 * に燃うドキュメント∈网脱荚マニュアルなど∷に·惧淡の螟侯涪山绩· * この网脱掘凤および布淡の痰瘦沮惮年を非很することˉ * (3) 塑ソフトウェアを浩网脱稍材墙なバイナリコ〖ドの妨または怠达に寥 * み哈んだ妨で网脱する眷圭には·肌のいずれかの掘凤を塔たすことˉ * (a) 网脱に燃うドキュメント∈网脱荚マニュアルなど∷に·惧淡の螟侯 * 涪山绩·この网脱掘凤および布淡の痰瘦沮惮年を非很することˉ * (b) 网脱の妨轮を·侍に年める数恕によって·惧淡螟侯涪荚に鼠桂する * ことˉ * (4) 塑ソフトウェアの网脱により木儡弄または粗儡弄に栏じるいかなる禄 * 巢からも·惧淡螟侯涪荚を倘勒することˉ * * 塑ソフトウェアは·痰瘦沮で捏丁されているものであるˉ惧淡螟侯涪荚は· * 塑ソフトウェアに簇して·その努脱材墙拉も崔めて·いかなる瘦沮も乖わ * ないˉまた·塑ソフトウェアの网脱により木儡弄または粗儡弄に栏じたい * かなる禄巢に簇しても·その勒扦を砷わないˉ * */#include "cpu_rename.h"unsigned char WRITE_BUF[65];/* buffer for simulated stdin, WRITE_BUF[0] is size (1-0x40, 0 means no data) WRITE_BUF[1-64] is buffer area for data, max 64 bytes used in write () */unsigned char READ_BUF[65];/* buffer for simulated stdin, READ_BUF[0] is size (1-0x40, 0 means EOF) READ_BUF[1-64] is buffer area for data, max 64 bytes used in read() */static unsigned char READ_EOF; /* if 1: READ_BUFFER become EOF, 0: not EOF *//* * void _exit * _exit execute inifinity loop. */void _exit(){LOOP: goto LOOP;}/* * void _init_sys * _init_sys initialize read() and write() bffer area */void init_sys(){ READ_EOF = 0; /* not EOF */ READ_BUF[0] = 0; /* BUFFER is empty */}/* * read * Read() get and return required bytes with using simulated input. * If EOF return 0. * READ_FLASH: is break point label for stdin * READ_BUF is buffer area for stdin */int read (int fhDummy, char *psReadBuf, int iReadBytes){ int iBytes; /* data size written to psReadBuf */ int iSize; /* data size in READ_BUF */ char *psBuf; /* top of read buffer */ static int iNdxPos; /* current positon in READ_BUF*//* start */ iBytes = 0; /* no read now */ psBuf = psReadBuf;/* This loop repeat for each byte to copy READ_BUF to psReadBuf */ for (;;) {/* if iReadByte become 0, return */ if (iReadBytes == 0) /* if required size become 0, return */ return(iBytes);/* if EOF, return 0 */ if (READ_EOF == 1) return(iBytes);/* if there is data, copy 1 byte */ iSize = READ_BUF[0]; if (iSize > 0 ) { *psBuf = READ_BUF[iNdxPos]; psBuf++; iReadBytes--; iNdxPos++; iSize--; iBytes++; READ_BUF[0] = (unsigned char)(iSize & 0xff); }/* if no data, read 0-64 bytes from simulated input */ else { asm(".global READ_FLASH"); asm("READ_FLASH:"); /* label for simulated stdin */ if (READ_BUF[0] == 0) READ_EOF = 1; /* if size is 0, EOF */ iNdxPos = 1; /* reset index position */ } } /* back to for (;;) */}/* * write * write datas with using simulated stdout * WRITE_FLASH: is break point label for stdout * WRITE_BUF is buffer area for stdout */int write (int fhDummy, char *psWriBuf, int iWriBytes){ int iBytes; /* remain data bytes waiting WRITE_BUF */ int iSize; /* data size to write to WRITE_BUF */ int iCount; /* counter to copy data to WRITE_BUF */ iBytes = iWriBytes; for (;;){ /* repeat each 255 bytes *//* if remain 0, return original size */ if (iBytes == 0) /* remain size become 0, so return */ return(iWriBytes);/* if remain > 64, write size is 64 */ if (iBytes > 64) { /* over 64 */ iSize = 64; /* 64 bytes to WRITE_BUF */ iBytes = iBytes - 64; /* remain data */ } else { /* not over 64 */ iSize = iBytes; /* under 64 bytes to WRITE_BUF */ iBytes = 0; /* no remain data */ }/* copy psWriBuf to WRITE_BUF */ WRITE_BUF[0] = (unsigned char)(iSize & 0xff); /* set size */ for (iCount = 1 ; iCount <= iSize ; iCount++) { WRITE_BUF[iCount] = *psWriBuf; /* copy data */ psWriBuf++; } asm(".global WRITE_FLASH"); asm("WRITE_FLASH:"); /* label for simulated stdout */ } /* back to for (;;) */ return(iSize);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -