]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/arch/arm/generic/libs/misc/system_stub.c
31a8f666942ce366bc33df1a19084dc7cd3476d4
[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
16 /* Register name faking - works in collusion with the linker.  */
17 register char * stack_ptr asm ("sp");
18
19 system_stub_ops_t system_stub_ops;
20
21 int
22 _read (int file,
23        char * ptr,
24        int len)
25 {
26   if(!system_stub_ops.read)
27     return -1;
28   return system_stub_ops.read(file,ptr,len);
29 }
30
31 int
32 _write (int    file,
33         const char * ptr,
34         int    len)
35 {
36   if(!system_stub_ops.write)
37     return len;
38   return system_stub_ops.write(file,ptr,len);
39 }
40
41
42 int
43 _lseek (int file,
44         int pos,
45         int dir)
46 {
47   if(!system_stub_ops.lseek)
48     return -1;
49   return system_stub_ops.lseek(file,pos,dir);
50 }
51
52 int
53 _open (const char * path,
54        int          flags,
55        ...)
56 {
57   if(!system_stub_ops.open)
58     return -1;
59   return system_stub_ops.open(path,flags,0);
60 }
61
62 int
63 _close (int file)
64 {
65   if(!system_stub_ops.close)
66     return -1;
67   return system_stub_ops.close(file);
68 }
69
70 typedef int (local_call_t)(void);
71
72 void
73 _exit (int n)
74 {
75   ((local_call_t*)0)();
76   while(1);
77 }
78
79 void abort(void)
80 {
81   ((local_call_t*)0)();
82   while(1);
83 }
84
85 int
86 _kill (int n, int m)
87 {
88   return -1;
89 }
90
91 int
92 _getpid (void)
93 {
94   return 1;
95 }
96
97
98 void *
99 _sbrk (ptrdiff_t incr)
100 {
101   extern char   end asm ("end");        /* Defined by the linker.  */
102   static char   *heap_end;
103   char *        prev_heap_end;
104
105   incr=(incr+3) & ~3;
106
107   if (heap_end == NULL)
108     heap_end = & end;
109   
110   prev_heap_end = heap_end;
111     
112   if (heap_end + incr > stack_ptr)
113     {
114       /* Some of the libstdc++-v3 tests rely upon detecting
115          out of memory errors, so do not abort here.  */
116 #if 0
117       extern void abort (void);
118
119       _write (1, "_sbrk: Heap and stack collision\n", 32);
120       
121       abort ();
122 #else
123       errno = ENOMEM;
124       return (caddr_t) -1;
125 #endif
126     }
127   
128   heap_end += incr;
129
130   return /*(caddr_t)*/ prev_heap_end;
131 }
132
133 int
134 _fstat (int file, struct stat * st)
135 {
136   return -1;
137 }
138
139 int _stat (const char *fname, struct stat *st)
140 {
141   return -1;
142 }
143
144 int
145 _link (const char *path1, const char *path2 )
146 {
147   return -1;
148 }
149
150 int
151 _unlink (const char *path)
152 {
153   return -1;
154 }
155
156 void
157 _raise (void)
158 {
159   return;
160 }
161
162 int
163 _gettimeofday (struct timeval * tp, struct timezone * tzp)
164 {
165
166   if(tp) 
167     {
168       tp->tv_sec = 0;
169       tp->tv_usec = 0;
170     }
171   /* Return fixed data for the timezone.  */
172   if (tzp)
173     {
174       tzp->tz_minuteswest = 0;
175       tzp->tz_dsttime = 0;
176     }
177
178   return 0;
179 }
180
181 /* Return a clock that ticks at 100Hz.  */
182 clock_t 
183 _times (struct tms * tp)
184 {
185   clock_t timeval = 0;
186   
187   if (tp)
188     {
189       tp->tms_utime  = timeval; /* user time */
190       tp->tms_stime  = 0;       /* system time */
191       tp->tms_cutime = 0;       /* user time, children */
192       tp->tms_cstime = 0;       /* system time, children */
193     }
194   
195   return timeval;
196 };
197
198
199 int
200 isatty (int fd)
201 {
202   return 1;
203 }
204
205 int
206 _system (const char *s)
207 {
208   return -1;
209 }
210
211 int
212 _rename (const char * oldpath, const char * newpath)
213 {
214   return -1;
215 }
216
217 /* extern (.*) ([^ ]*) _PARAMS \(\(struct _reent \*(,*)(.*)\)\); */
218 /* \1 \2 (struct _reent *\3\4) { return \2(\4);} */
219
220 struct _reent;
221
222 int _close_r(struct _reent * reent, int file) 
223   { return _close(file);}
224 /*
225 int _fcntl_r(struct _reent *, int, int, int)
226   { return _fcntl( int, int, int);}
227 */
228 int _fstat_r(struct _reent * reent, int file, struct stat * st)
229   { return _fstat(file, st);}
230
231 int _getpid_r(struct _reent * reent)
232   { return _getpid();}
233
234 int _kill_r(struct _reent * reent, int n, int m)
235   { return _kill(n, m);}
236
237 int _link_r(struct _reent * reent, const char *path1, const char *path2)
238   { return _link(path1, path2);}
239
240 _off_t _lseek_r(struct _reent * reent, int file, _off_t pos, int dir)
241   { return _lseek(file, pos, dir);}
242
243 int _open_r(struct _reent * reent, const char * path, int flags, int opts)
244   { return _open(path, flags, opts);}
245
246 _ssize_t _read_r(struct _reent * reent, int file, void * ptr, size_t len)
247   { return _read(file, ptr, len);}
248
249 void *_sbrk_r(struct _reent * reent, ptrdiff_t incr)
250   { return _sbrk(incr);}
251
252 int _stat_r(struct _reent * reent, const char * path, struct stat * st)
253   { return _stat(path, st);}
254
255 int _unlink_r(struct _reent * reent, const char * path)
256   { return _unlink(path);}
257
258 _ssize_t _write_r(struct _reent * reent, int file, const void * ptr, size_t len)
259   { return _write(file, ptr, len);}