fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / libgloss / hp74x / io.c
blob054d90ce45f177ea7fbec32356af46f406752981
1 /*
2 * io.c -- all the code to make GCC and the libraries run on
3 * a bare target board.
4 */
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <errno.h>
10 #include "hppa-defs.h"
12 extern char *_end; /* _end is set in the linker command file */
14 /* just in case, most boards have at least some memory */
15 #ifndef RAMSIZE
16 # define RAMSIZE (char *)0x100000
17 #endif
19 int
20 print(ptr)
21 char *ptr;
23 while (*ptr)
24 outbyte (*ptr++);
27 int
28 putnum (Num)
29 unsigned int Num;
31 char Buffer[9];
32 int Count;
33 char *BufPtr = Buffer;
34 int Digit;
36 for (Count = 7 ; Count >= 0 ; Count--) {
37 Digit = (Num >> (Count * 4)) & 0xf;
39 if (Digit <= 9)
40 *BufPtr++ = (char) ('0' + Digit);
41 else
42 *BufPtr++ = (char) ('a' - 10 + Digit);
45 *BufPtr = (char) 0;
46 print (Buffer);
47 return;
50 int
51 delay (x)
52 int x;
54 int y = 17;
55 while (x-- !=0)
56 y = y^2;
60 * strobe -- do a zylons thing, toggling each led in sequence forever...
62 int
63 zylons()
65 while (1) {
66 strobe();
71 * strobe -- toggle each led in sequence up and back once.
73 int
74 strobe()
76 static unsigned char curled = 1;
77 static unsigned char dir = 0;
79 curled = 1;
80 dir = 0;
81 while (curled != 0) {
82 led_putnum (curled);
83 delay (70000);
84 if (dir)
85 curled >>= 1;
86 else
87 curled <<= 1;
89 if (curled == 128) {
90 dir = ~dir;
93 curled = 1;
94 dir = 0;
98 * iodc_io_call -- this makes a call into the IODC routine
101 iodc_io_call(ep_address,arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11)
102 int ep_address, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11;
104 int (*iodc_entry_point)();
106 iodc_entry_point = (int (*)())ep_address;
108 return ((*iodc_entry_point)(arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11));
112 * pdc_call -- this makes a call into the PDC routine
115 pdc_call(arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11)
116 int arg0, arg1, arg2, arg3, arg4, arg5;
117 int arg6, arg7, arg9, arg10, arg11;
119 return ( CALL_PDC(arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11));
123 * put_led -- put a bit pattern on the LED's.
126 led_putnum (byte)
127 unsigned short byte;
129 return (pdc_call(OPT_PDC_CHASSIS,0,byte));
134 * outbyte -- shove a byte out the serial port
137 outbyte(byte)
138 unsigned char byte;
140 int status;
141 int R_addr[32];
142 struct _dev *console = (struct _dev *)PGZ_CONSOLE_STRUCT;
144 status = iodc_io_call(console->iodc_io, console->hpa, IO_CONSOLE_OUTPUT, console->spa,
145 console->layer[0], R_addr, 0, &byte, 1, 0);
147 switch(status)
149 case 0: return(1);
150 default: return (-1);
155 * inbyte -- get a byte from the serial port
157 unsigned char
158 inbyte()
160 int status;
161 int R_addr[32];
162 char inbuf;
163 struct _dev *console = (struct _dev *)PGZ_CONSOLE_STRUCT;
165 while (status == 0) {
166 status = iodc_io_call(console->iodc_io, console->hpa, IO_CONSOLE_INPUT, console->spa,
167 console->layer[0], R_addr, 0, &inbuf, 1, 0);
169 switch (status) {
170 case 0:
171 case 2: /* recoverable error */
172 if (R_addr[0] != 0) { /* found a character */
173 return(inbuf);
175 else
176 break; /* error, no character */
177 default: /* error, no character */
178 return(0);
184 * read -- read bytes from the serial port. Ignore fd, since
185 * we only have stdin.
188 read(fd, buf, nbytes)
189 int fd;
190 char *buf;
191 int nbytes;
193 int i = 0;
195 for (i = 0; i < nbytes; i++) {
196 *(buf + i) = inbyte();
197 if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) {
198 (*(buf + i)) = 0;
199 break;
202 return (i);
206 * write -- write bytes to the serial port. Ignore fd, since
207 * stdout and stderr are the same. Since we have no filesystem,
208 * open will only return an error.
211 write(fd, buf, nbytes)
212 int fd;
213 char *buf;
214 int nbytes;
216 int i;
218 for (i = 0; i < nbytes; i++) {
219 if (*(buf + i) == '\n') {
220 outbyte ('\r');
222 outbyte (*(buf + i));
224 return (nbytes);
228 * open -- open a file descriptor. We don't have a filesystem, so
229 * we return an error.
232 open(buf, flags, mode)
233 char *buf;
234 int flags;
235 int mode;
237 errno = EIO;
238 return (-1);
242 * close -- close a file descriptor. We don't need
243 * to do anything, but pretend we did.
246 close(fd)
247 int fd;
249 return (0);
253 * sbrk -- changes heap size size. Get nbytes more
254 * RAM. We just increment a pointer in what's
255 * left of memory on the board.
257 char *
258 sbrk(nbytes)
259 int nbytes;
261 static char * heap_ptr = NULL;
262 char * base;
264 if (heap_ptr == NULL) {
265 heap_ptr = (char *)&_end;
268 if ((RAMSIZE - heap_ptr) >= 0) {
269 base = heap_ptr;
270 heap_ptr += nbytes;
271 return (heap_ptr);
272 } else {
273 errno = ENOMEM;
274 return ((char *)-1);
279 * isatty -- returns 1 if connected to a terminal device,
280 * returns 0 if not. Since we're hooked up to a
281 * serial port, we'll say yes return a 1.
284 isatty(fd)
285 int fd;
287 return (1);
291 * lseek -- move read/write pointer. Since a serial port
292 * is non-seekable, we return an error.
294 off_t
295 lseek(fd, offset, whence)
296 int fd;
297 off_t offset;
298 int whence;
300 errno = ESPIPE;
301 return ((off_t)-1);
305 * fstat -- get status of a file. Since we have no file
306 * system, we just return an error.
309 fstat(fd, buf)
310 int fd;
311 struct stat *buf;
313 errno = EIO;
314 return (-1);
318 * getpid -- only one process, so just return 1.
320 #define __MYPID 1
322 getpid()
324 return __MYPID;
328 * kill -- assume mvme.S, and go out via exit...
331 kill(pid, sig)
332 int pid;
333 int sig;
335 if(pid == __MYPID)
336 _exit(sig);
337 return 0;