OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [libgloss/] [hp74x/] [io.c] - Blame information for rev 258

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/*
2
 * io.c -- all the code to make GCC and the libraries run on
3
 *         a bare target board.
4
 */
5
 
6
#include <sys/types.h>
7
#include <sys/stat.h>
8
#include <errno.h>
9
 
10
#include "hppa-defs.h"
11
 
12
extern char *_end;                /* _end is set in the linker command file */
13
 
14
/* just in case, most boards have at least some memory */
15
#ifndef RAMSIZE
16
#  define RAMSIZE             (char *)0x100000
17
#endif
18
 
19
int
20
print(ptr)
21
char *ptr;
22
{
23
  while (*ptr)
24
    outbyte (*ptr++);
25
}
26
 
27
int
28
putnum (Num)
29
unsigned int Num;
30
{
31
  char  Buffer[9];
32
  int   Count;
33
  char  *BufPtr = Buffer;
34
  int   Digit;
35
 
36
  for (Count = 7 ; Count >= 0 ; Count--) {
37
    Digit = (Num >> (Count * 4)) & 0xf;
38
 
39
    if (Digit <= 9)
40
      *BufPtr++ = (char) ('0' + Digit);
41
    else
42
      *BufPtr++ = (char) ('a' - 10 + Digit);
43
  }
44
 
45
  *BufPtr = (char) 0;
46
  print (Buffer);
47
  return;
48
}
49
 
50
int
51
delay (x)
52
     int x;
53
{
54
  int  y = 17;
55
  while (x-- !=0)
56
    y = y^2;
57
}
58
 
59
/*
60
 * strobe -- do a zylons thing, toggling each led in sequence forever...
61
 */
62
int
63
zylons()
64
{
65
  while (1) {
66
    strobe();
67
  }
68
}
69
 
70
/*
71
 * strobe -- toggle each led in sequence up and back once.
72
 */
73
int
74
strobe()
75
{
76
  static unsigned char curled = 1;
77
  static unsigned char dir = 0;
78
 
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;
88
 
89
    if (curled == 128) {
90
      dir = ~dir;
91
    }
92
  }
93
  curled = 1;
94
  dir = 0;
95
}
96
 
97
/*
98
 * iodc_io_call -- this makes a call into the IODC routine
99
 */
100
int
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;
103
{
104
  int         (*iodc_entry_point)();
105
 
106
  iodc_entry_point = (int (*)())ep_address;
107
 
108
  return ((*iodc_entry_point)(arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11));
109
}
110
 
111
/*
112
 * pdc_call -- this makes a call into the PDC routine
113
 */
114
int
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;
118
{
119
   return ( CALL_PDC(arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11));
120
}
121
 
122
/*
123
 * put_led -- put a bit pattern on the LED's.
124
 */
125
int
126
led_putnum (byte)
127
     unsigned short byte;
128
{
129
  return (pdc_call(OPT_PDC_CHASSIS,0,byte));
130
}
131
 
132
 
133
/*
134
 * outbyte -- shove a byte out the serial port
135
 */
136
int
137
outbyte(byte)
138
     unsigned char byte;
139
{
140
  int status;
141
  int R_addr[32];
142
  struct _dev *console = (struct _dev *)PGZ_CONSOLE_STRUCT;
143
 
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);
146
 
147
  switch(status)
148
    {
149
    case 0:  return(1);
150
    default: return (-1);
151
    }
152
}
153
 
154
/*
155
 * inbyte -- get a byte from the serial port
156
 */
157
unsigned char
158
inbyte()
159
{
160
  int status;
161
  int R_addr[32];
162
  char inbuf;
163
  struct _dev *console = (struct _dev *)PGZ_CONSOLE_STRUCT;
164
 
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);
168
 
169
    switch (status) {
170
    case 0:
171
    case 2:                                     /* recoverable error */
172
      if (R_addr[0] != 0) {                       /* found a character */
173
        return(inbuf);
174
      }
175
      else
176
        break;                                  /* error, no character */
177
    default:                                    /* error, no character */
178
      return(0);
179
    }
180
  }
181
}
182
 
183
/*
184
 * read  -- read bytes from the serial port. Ignore fd, since
185
 *          we only have stdin.
186
 */
187
int
188
read(fd, buf, nbytes)
189
     int fd;
190
     char *buf;
191
     int nbytes;
192
{
193
  int i = 0;
194
 
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;
200
    }
201
  }
202
  return (i);
203
}
204
 
205
/*
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.
209
 */
210
int
211
write(fd, buf, nbytes)
212
     int fd;
213
     char *buf;
214
     int nbytes;
215
{
216
  int i;
217
 
218
  for (i = 0; i < nbytes; i++) {
219
    if (*(buf + i) == '\n') {
220
      outbyte ('\r');
221
    }
222
    outbyte (*(buf + i));
223
  }
224
  return (nbytes);
225
}
226
 
227
/*
228
 * open -- open a file descriptor. We don't have a filesystem, so
229
 *         we return an error.
230
 */
231
int
232
open(buf, flags, mode)
233
     char *buf;
234
     int flags;
235
     int mode;
236
{
237
  errno = EIO;
238
  return (-1);
239
}
240
 
241
/*
242
 * close -- close a file descriptor. We don't need
243
 *          to do anything, but pretend we did.
244
 */
245
int
246
close(fd)
247
     int fd;
248
{
249
  return (0);
250
}
251
 
252
/*
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.
256
 */
257
char *
258
sbrk(nbytes)
259
     int nbytes;
260
{
261
  static char * heap_ptr = NULL;
262
  char *        base;
263
 
264
  if (heap_ptr == NULL) {
265
    heap_ptr = (char *)&_end;
266
  }
267
 
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);
275
  }
276
}
277
 
278
/*
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.
282
 */
283
int
284
isatty(fd)
285
     int fd;
286
{
287
  return (1);
288
}
289
 
290
/*
291
 * lseek -- move read/write pointer. Since a serial port
292
 *          is non-seekable, we return an error.
293
 */
294
off_t
295
lseek(fd,  offset, whence)
296
     int fd;
297
     off_t offset;
298
     int whence;
299
{
300
  errno = ESPIPE;
301
  return ((off_t)-1);
302
}
303
 
304
/*
305
 * fstat -- get status of a file. Since we have no file
306
 *          system, we just return an error.
307
 */
308
int
309
fstat(fd, buf)
310
     int fd;
311
     struct stat *buf;
312
{
313
  errno = EIO;
314
  return (-1);
315
}
316
 
317
/*
318
 * getpid -- only one process, so just return 1.
319
 */
320
#define __MYPID 1
321
int
322
getpid()
323
{
324
  return __MYPID;
325
}
326
 
327
/*
328
 * kill -- assume mvme.S, and go out via exit...
329
 */
330
int
331
kill(pid, sig)
332
     int pid;
333
     int sig;
334
{
335
  if(pid == __MYPID)
336
    _exit(sig);
337
  return 0;
338
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.