]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/arch/arm/generic/libs/misc/system_stub.c
Update of system-less architecture and board support code to actual uLAN.sf.net version.
[lincan.git] / embedded / arch / arm / generic / libs / misc / system_stub.c
1 /* Support files for GNU libc.  Files in the system namespace go here.
2    Files in the C namespace (ie those that do not start with an
3    underscore) go in .c.  */
4
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <sys/fcntl.h>
8 #include <stdio.h>
9 #include <time.h>
10 #include <sys/time.h>
11 #include <sys/times.h>
12 #include <errno.h>
13 #include <reent.h>
14 #include <system_def.h>
15 #include "system_stub.h"
16
17 /* Register name faking - works in collusion with the linker.  */
18 register char * stack_ptr asm ("sp");
19
20 system_stub_ops_t system_stub_ops;
21
22 int _read(int file, char *ptr, int len);
23 int
24 _read (int file,
25        char * ptr,
26        int len)
27 {
28   if(!system_stub_ops.read)
29     return -1;
30   return system_stub_ops.read(file,ptr,len);
31 }
32
33 int _write(int file, const char *ptr, int len);
34 int
35 _write (int    file,
36         const char * ptr,
37         int    len)
38 {
39   if(!system_stub_ops.write)
40     return len;
41   return system_stub_ops.write(file,ptr,len);
42 }
43
44
45 int
46 _lseek (int file,
47         int pos,
48         int dir)
49 {
50   if(!system_stub_ops.lseek)
51     return -1;
52   return system_stub_ops.lseek(file,pos,dir);
53 }
54
55 int _open(const char *path, int flags,  ...);
56 int
57 _open (const char * path,
58        int          flags,
59        ...)
60 {
61   if(!system_stub_ops.open)
62     return -1;
63   return system_stub_ops.open(path,flags,0);
64 }
65
66 int _close(int file);
67 int
68 _close (int file)
69 {
70   if(!system_stub_ops.close)
71     return -1;
72   return system_stub_ops.close(file);
73 }
74
75 typedef int (local_call_t)(void);
76
77 void _exit(int n);
78 void
79 _exit (int n)
80 {
81   ((local_call_t*)0)();
82   while(1);
83 }
84
85 void abort(void);
86 void abort(void)
87 {
88   ((local_call_t*)0)();
89   while(1);
90 }
91
92 int _kill(int n, int m);
93 int
94 _kill (int n, int m)
95 {
96   return -1;
97 }
98
99 int _getpid(void);
100 int
101 _getpid (void)
102 {
103   return 1;
104 }
105
106
107 void *_sbrk(ptrdiff_t incr);
108 void *
109 _sbrk (ptrdiff_t incr)
110 {
111   extern char   end asm ("end");        /* Defined by the linker.  */
112   static char   *heap_end;
113   char *        prev_heap_end;
114
115   incr=(incr+3) & ~3;
116
117   if (heap_end == NULL)
118     heap_end = & end;
119
120   prev_heap_end = heap_end;
121
122   if (heap_end + incr > stack_ptr)
123     {
124       /* Some of the libstdc++-v3 tests rely upon detecting
125          out of memory errors, so do not abort here.  */
126 #if 0
127       extern void abort (void);
128
129       _write (1, "_sbrk: Heap and stack collision\n", 32);
130
131       abort ();
132 #else
133       errno = ENOMEM;
134       return (caddr_t) -1;
135 #endif
136     }
137
138   heap_end += incr;
139
140   return /*(caddr_t)*/ prev_heap_end;
141 }
142
143 int _fstat(int file, struct stat *st);
144 int
145 _fstat (int file, struct stat * st)
146 {
147   return -1;
148 }
149
150 int _stat (const char *fname, struct stat *st);
151 int _stat (const char *fname, struct stat *st)
152 {
153   return -1;
154 }
155
156 int _link(const char *path1, const char *path2);
157 int
158 _link (const char *path1,
159        const char *path2)
160 {
161   return -1;
162 }
163
164 int _unlink(const char *path);
165 int
166 _unlink (const char *path)
167 {
168   return -1;
169 }
170
171 void _raise(void);
172 void
173 _raise (void)
174 {
175   return;
176 }
177
178 int _gettimeofday(struct timeval *tp, struct timezone *tzp);
179 int
180 _gettimeofday (struct timeval *tp,
181                struct timezone *tzp)
182 {
183
184   if(tp) 
185     {
186       tp->tv_sec = 0;
187       tp->tv_usec = 0;
188     }
189   /* Return fixed data for the timezone.  */
190   if (tzp)
191     {
192       tzp->tz_minuteswest = 0;
193       tzp->tz_dsttime = 0;
194     }
195
196   return 0;
197 }
198
199 /* Return a clock that ticks at 100Hz.  */
200 clock_t _times(struct tms *tp);
201 clock_t 
202 _times (struct tms * tp)
203 {
204   clock_t timeval = 0;
205
206   if (tp)
207     {
208       tp->tms_utime  = timeval; /* user time */
209       tp->tms_stime  = 0;       /* system time */
210       tp->tms_cutime = 0;       /* user time, children */
211       tp->tms_cstime = 0;       /* system time, children */
212     }
213
214   return timeval;
215 };
216
217
218 int isatty(int fd);
219 int
220 isatty (int fd)
221 {
222   return 1;
223 }
224
225 int _system(const char *s);
226 int
227 _system (const char *s)
228 {
229   return -1;
230 }
231
232 int _rename(const char *oldpath, const char *newpath);
233 int
234 _rename (const char * oldpath, const char * newpath)
235 {
236   return -1;
237 }
238
239 /* extern (.*) ([^ ]*) _PARAMS \(\(struct _reent \*(,*)(.*)\)\); */
240 /* \1 \2 (struct _reent *\3\4) { return \2(\4);} */
241
242 struct _reent;
243
244 int _close_r(struct _reent *reent, int file) 
245 { return _close(file);}
246 /*
247   int _fcntl_r(struct _reent *, int, int, int)
248   { return _fcntl( int, int, int);}
249 */
250 int _fstat_r(struct _reent *reent, int file, struct stat *st);
251 int _fstat_r(struct _reent *reent, int file, struct stat *st)
252 { return _fstat(file, st);}
253
254 int _getpid_r(struct _reent *reent);
255 int _getpid_r(struct _reent *reent)
256 { return _getpid();}
257
258 int _kill_r(struct _reent *reent, int n, int m);
259 int _kill_r(struct _reent *reent, int n, int m)
260 { return _kill(n, m);}
261
262 int _link_r(struct _reent *reent, const char *path1, const char *path2);
263 int _link_r(struct _reent *reent, const char *path1, const char *path2)
264 { return _link(path1, path2);}
265
266 _off_t _lseek_r(struct _reent *reent, int file, _off_t pos, int dir);
267 _off_t _lseek_r(struct _reent *reent, int file, _off_t pos, int dir)
268 { return _lseek(file, pos, dir);}
269
270 int _open_r(struct _reent *reent, const char *path, int flags, int opts);
271 int _open_r(struct _reent *reent, const char *path, int flags, int opts)
272 { return _open(path, flags, opts);}
273
274 _ssize_t _read_r(struct _reent *reent, int file, void *ptr, size_t len);
275 _ssize_t _read_r(struct _reent *reent, int file, void *ptr, size_t len)
276 { return _read(file, ptr, len);}
277
278 void *_sbrk_r(struct _reent *reent, ptrdiff_t incr);
279 void *_sbrk_r(struct _reent *reent, ptrdiff_t incr)
280 { return _sbrk(incr);}
281
282 int _stat_r(struct _reent *reent, const char *path, struct stat *st);
283 int _stat_r(struct _reent *reent, const char *path, struct stat *st)
284 { return _stat(path, st);}
285
286 int _unlink_r(struct _reent *reent, const char *path);
287 int _unlink_r(struct _reent *reent, const char *path)
288 { return _unlink(path);}
289
290 _ssize_t _write_r(struct _reent *reent, int file, const void *ptr, size_t len);
291 _ssize_t _write_r(struct _reent *reent, int file, const void *ptr, size_t len)
292 { return _write(file, ptr, len);}
293
294 /* FIXME: TDK added dummy functions. Need to implement. */
295 int _isatty(int fd);
296 int _isatty(int fd)
297 {
298   return -1;
299 }
300
301 int _swistat(int fd, struct stat *st);
302 int _swistat(int fd, struct stat *st)
303 {
304   return -1;
305 }
306
307 /* Return a clock that ticks at 100Hz.  */
308 clock_t _clock(void);
309 clock_t _clock(void)
310 {
311   clock_t timeval=0;
312   return timeval;
313 }
314
315 int _swiclose(int fh);
316 int _swiclose(int fh)
317 {
318   return -1;
319 }
320
321 int _swiopen(const char *path, int flags);
322 int _swiopen(const char *path, int flags)
323 {
324   return -1;
325 }
326
327 int _swiwrite(int fh, char *ptr, int len);
328 int _swiwrite(int fh, char *ptr, int len)
329 {
330   return -1;
331 }
332
333 int _swilseek(int fd, int ptr, int dir);
334 int _swilseek(int fd, int ptr, int dir)
335 {
336   return -1;
337 }
338
339 int _swiread(int fh, char *ptr, int len);
340 int _swiread(int fh, char *ptr, int len)
341 {
342   return -1;
343 }
344
345 void initialise_monitor_handles(void);
346 void initialise_monitor_handles(void)
347 {
348 }