1 | /*
|
---|
2 | * TOPPERS/JSP Kernel
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
4 | * Just Standard Profile Kernel
|
---|
5 | *
|
---|
6 | * Additional routine
|
---|
7 | *
|
---|
8 | * Copyright (C) 2003 by SEIKO EPSON Corp, JAPAN
|
---|
9 | *
|
---|
10 | * ä¸è¨è使¨©è
|
---|
11 | ã¯ï¼Free Software Foundation ã«ãã£ã¦å
|
---|
12 | ¬è¡¨ããã¦ãã
|
---|
13 | * GNU General Public License ã® Version 2 ã«è¨è¿°ããã¦ããæ¡ä»¶ãï¼ä»¥
|
---|
14 | * ä¸ã®(1)ã(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§
|
---|
15 | * ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
16 | å¸ï¼ä»¥ä¸ï¼
|
---|
17 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
18 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
19 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
20 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
21 | * (2) æ¬ã½ããã¦ã§ã¢ãåå©ç¨å¯è½ãªãã¤ããªã³ã¼ãï¼ãªãã±ã¼ã¿ãã«ãªã
|
---|
22 | * ã¸ã§ã¯ããã¡ã¤ã«ãã©ã¤ãã©ãªãªã©ï¼ã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼å©ç¨
|
---|
23 | * ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
24 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è使¨©è¡¨ç¤ºï¼
|
---|
25 | * ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
26 | * (3) æ¬ã½ããã¦ã§ã¢ãåå©ç¨ä¸å¯è½ãªãã¤ããªã³ã¼ãã®å½¢ã¾ãã¯æ©å¨ã«çµ
|
---|
27 | * ã¿è¾¼ãã å½¢ã§å©ç¨ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
28 | * (a) å©ç¨ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
29 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½
|
---|
30 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
31 | * (b) å©ç¨ã®å½¢æ
|
---|
32 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼ä¸è¨è使¨©è
|
---|
33 | ã«å ±åãã
|
---|
34 | * ãã¨ï¼
|
---|
35 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
36 | * 害ãããï¼ä¸è¨è使¨©è
|
---|
37 | ãå
|
---|
38 | 責ãããã¨ï¼
|
---|
39 | *
|
---|
40 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨è使¨©è
|
---|
41 | ã¯ï¼
|
---|
42 | * æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ã
|
---|
43 | * ãªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çããã
|
---|
44 | * ããªãæå®³ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
45 | *
|
---|
46 | */
|
---|
47 |
|
---|
48 | #include "cpu_rename.h"
|
---|
49 |
|
---|
50 | unsigned char WRITE_BUF[65];
|
---|
51 |
|
---|
52 | /* buffer for simulated stdin, WRITE_BUF[0] is size (1-0x40, 0 means no data)
|
---|
53 | WRITE_BUF[1-64] is buffer area for data, max 64 bytes
|
---|
54 | used in write () */
|
---|
55 |
|
---|
56 | unsigned char READ_BUF[65];
|
---|
57 |
|
---|
58 | /* buffer for simulated stdin, READ_BUF[0] is size (1-0x40, 0 means EOF)
|
---|
59 | READ_BUF[1-64] is buffer area for data, max 64 bytes
|
---|
60 | used in read() */
|
---|
61 |
|
---|
62 | static unsigned char READ_EOF; /* if 1: READ_BUFFER become EOF, 0: not EOF */
|
---|
63 |
|
---|
64 | /*
|
---|
65 | * void _exit
|
---|
66 | * _exit execute inifinity loop.
|
---|
67 | */
|
---|
68 |
|
---|
69 | void _exit()
|
---|
70 | {
|
---|
71 | LOOP:
|
---|
72 | goto LOOP;
|
---|
73 | }
|
---|
74 |
|
---|
75 | /*
|
---|
76 | * void _init_sys
|
---|
77 | * _init_sys initialize read() and write() bffer area
|
---|
78 | */
|
---|
79 |
|
---|
80 | void init_sys()
|
---|
81 | {
|
---|
82 | READ_EOF = 0; /* not EOF */
|
---|
83 | READ_BUF[0] = 0; /* BUFFER is empty */
|
---|
84 | }
|
---|
85 |
|
---|
86 | /*
|
---|
87 | * read
|
---|
88 | * Read() get and return required bytes with using simulated input.
|
---|
89 | * If EOF return 0.
|
---|
90 | * READ_FLASH: is break point label for stdin
|
---|
91 | * READ_BUF is buffer area for stdin
|
---|
92 | */
|
---|
93 |
|
---|
94 | int read (int fhDummy, char *psReadBuf, int iReadBytes)
|
---|
95 | {
|
---|
96 | int iBytes; /* data size written to psReadBuf */
|
---|
97 | int iSize; /* data size in READ_BUF */
|
---|
98 | char *psBuf; /* top of read buffer */
|
---|
99 | static int iNdxPos; /* current positon in READ_BUF*/
|
---|
100 |
|
---|
101 | /* start */
|
---|
102 |
|
---|
103 | iBytes = 0; /* no read now */
|
---|
104 | psBuf = psReadBuf;
|
---|
105 |
|
---|
106 | /* This loop repeat for each byte to copy READ_BUF to psReadBuf */
|
---|
107 |
|
---|
108 | for (;;)
|
---|
109 | {
|
---|
110 |
|
---|
111 | /* if iReadByte become 0, return */
|
---|
112 |
|
---|
113 | if (iReadBytes == 0) /* if required size become 0, return */
|
---|
114 | return(iBytes);
|
---|
115 |
|
---|
116 | /* if EOF, return 0 */
|
---|
117 |
|
---|
118 | if (READ_EOF == 1)
|
---|
119 | return(iBytes);
|
---|
120 |
|
---|
121 | /* if there is data, copy 1 byte */
|
---|
122 |
|
---|
123 | iSize = READ_BUF[0];
|
---|
124 | if (iSize > 0 )
|
---|
125 | {
|
---|
126 | *psBuf = READ_BUF[iNdxPos];
|
---|
127 | psBuf++;
|
---|
128 | iReadBytes--;
|
---|
129 | iNdxPos++;
|
---|
130 | iSize--;
|
---|
131 | iBytes++;
|
---|
132 | READ_BUF[0] = (unsigned char)(iSize & 0xff);
|
---|
133 | }
|
---|
134 |
|
---|
135 | /* if no data, read 0-64 bytes from simulated input */
|
---|
136 |
|
---|
137 | else
|
---|
138 | {
|
---|
139 | asm(".global READ_FLASH");
|
---|
140 | asm("READ_FLASH:"); /* label for simulated stdin */
|
---|
141 | if (READ_BUF[0] == 0)
|
---|
142 | READ_EOF = 1; /* if size is 0, EOF */
|
---|
143 | iNdxPos = 1; /* reset index position */
|
---|
144 | }
|
---|
145 | } /* back to for (;;) */
|
---|
146 | }
|
---|
147 |
|
---|
148 | /*
|
---|
149 | * write
|
---|
150 | * write datas with using simulated stdout
|
---|
151 | * WRITE_FLASH: is break point label for stdout
|
---|
152 | * WRITE_BUF is buffer area for stdout
|
---|
153 | */
|
---|
154 |
|
---|
155 | int write (int fhDummy, char *psWriBuf, int iWriBytes)
|
---|
156 | {
|
---|
157 | int iBytes; /* remain data bytes waiting WRITE_BUF */
|
---|
158 | int iSize; /* data size to write to WRITE_BUF */
|
---|
159 | int iCount; /* counter to copy data to WRITE_BUF */
|
---|
160 |
|
---|
161 | iBytes = iWriBytes;
|
---|
162 |
|
---|
163 | for (;;){ /* repeat each 255 bytes */
|
---|
164 |
|
---|
165 | /* if remain 0, return original size */
|
---|
166 |
|
---|
167 | if (iBytes == 0) /* remain size become 0, so return */
|
---|
168 | return(iWriBytes);
|
---|
169 |
|
---|
170 | /* if remain > 64, write size is 64 */
|
---|
171 |
|
---|
172 | if (iBytes > 64)
|
---|
173 | { /* over 64 */
|
---|
174 | iSize = 64; /* 64 bytes to WRITE_BUF */
|
---|
175 | iBytes = iBytes - 64; /* remain data */
|
---|
176 | }
|
---|
177 | else
|
---|
178 | { /* not over 64 */
|
---|
179 | iSize = iBytes; /* under 64 bytes to WRITE_BUF */
|
---|
180 | iBytes = 0; /* no remain data */
|
---|
181 | }
|
---|
182 |
|
---|
183 | /* copy psWriBuf to WRITE_BUF */
|
---|
184 |
|
---|
185 | WRITE_BUF[0] = (unsigned char)(iSize & 0xff); /* set size */
|
---|
186 | for (iCount = 1 ; iCount <= iSize ; iCount++)
|
---|
187 | {
|
---|
188 | WRITE_BUF[iCount] = *psWriBuf; /* copy data */
|
---|
189 | psWriBuf++;
|
---|
190 | }
|
---|
191 | asm(".global WRITE_FLASH");
|
---|
192 | asm("WRITE_FLASH:"); /* label for simulated stdout */
|
---|
193 |
|
---|
194 | } /* back to for (;;) */
|
---|
195 |
|
---|
196 | return(iSize);
|
---|
197 | }
|
---|
198 |
|
---|