source: trunk/libs/newlib/src/libgloss/arm/redboot-syscalls.c @ 559

Last change on this file since 559 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 4.3 KB
Line 
1/*
2 * redboot-syscalls.c -- provide system call support for RedBoot
3 *
4 * Copyright (c) 1997, 2001, 2002 Red Hat, Inc.
5 *
6 * The authors hereby grant permission to use, copy, modify, distribute,
7 * and license this software and its documentation for any purpose, provided
8 * that existing copyright notices are retained in all copies and that this
9 * notice is included verbatim in any distributions. No written agreement,
10 * license, or royalty fee is required for any of the authorized uses.
11 * Modifications to this software may be copyrighted by their authors
12 * and need not follow the licensing terms described here, provided that
13 * the new terms are clearly indicated on the first page of each file where
14 * they apply.
15 *
16 */
17
18#include <stdlib.h>
19#include <sys/stat.h>
20#include <sys/times.h>
21#include <errno.h>
22#include "syscall.h"
23
24// Use "naked" attribute to suppress C prologue/epilogue
25static int __attribute__ ((naked)) __syscall(int func_no, ...)
26{
27    asm ("mov   r12, lr\n");
28#ifdef __thumb__
29    asm ("swi 0x18\n");
30#else
31    asm ("swi 0x180001\n");
32#endif
33    asm ("mov   pc, r12\n");
34}
35
36int
37_close(int fd)
38{
39    int  err;
40    err = __syscall(SYS_close, fd);
41    if (err<0)
42      {
43        errno = -err;
44        return -1;
45      }
46    return err;
47}
48
49
50void
51_exit(int stat)
52{
53    while (1)
54        __syscall(SYS_exit, stat);
55}
56
57
58int
59_stat (const char *filename, struct stat *st)
60{
61    int err;
62    err = __syscall(SYS_stat, filename, st);
63    if (err<0)
64      {
65        errno = -err;
66        return -1;
67      }
68    return err;
69}
70
71int
72_fstat (int file, struct stat *st)
73{
74    int err;
75    err = __syscall(SYS_fstat, file, st);
76    if (err<0)
77      {
78        errno = -err;
79        return -1;
80      }
81    return err;
82}
83
84int
85_getpid(void)
86{
87    return 1;
88}
89
90
91int
92_gettimeofday (void * tp, void * tzp)
93{
94    int err;
95    err = __syscall(SYS_gettimeofday, tp, tzp);
96    if (err<0)
97      {
98        errno = -err;
99        return -1;
100      }
101    return err;
102}
103
104
105int
106_isatty(int fd)
107{
108    int err;
109    err = __syscall(SYS_isatty, fd);
110    if (err<0)
111      {
112        errno = -err;
113        return -1;
114      }
115    return err;
116}
117
118
119int
120_kill(int pid, int sig)
121{
122  if(pid == 1)
123    _exit(sig);
124  return 0;
125}
126
127
128off_t
129_lseek(int fd, off_t offset, int whence)
130{
131    int err;
132    err = __syscall(SYS_lseek, fd, offset, whence);
133    if (err<0)
134      {
135        errno = -err;
136        return (off_t)-1;
137      }
138    return err;
139}
140
141
142int
143_open(const char *buf, int flags, int mode)
144{
145    int err ;
146    err = __syscall(SYS_open, buf, flags, mode);
147    if (err<0)
148      {
149        errno = -err;
150        return -1;
151      }
152    return err;
153}
154
155
156int
157_write(int fd, const char *buf, int nbytes)
158{
159    int err;
160
161    err = __syscall(SYS_write, fd, buf, nbytes);
162    if (err<0)
163      {
164        errno = -err;
165        return -1;
166      }
167    return err;
168}
169
170
171void
172print(char *ptr)
173{
174  char *p = ptr;
175
176  while (*p != '\0')
177    p++;
178
179  _write (1, ptr, p-ptr);
180}
181
182void
183_raise (void)
184{
185    return;
186}
187
188
189int
190_read(int fd, char *buf, int nbytes)
191{
192    int err;
193    err = __syscall(SYS_read, fd, buf, nbytes);
194    if (err<0)
195      {
196        errno = -err;
197        return -1;
198      }
199    return err;
200}
201
202
203extern char end[];                /* end is set in the linker command file */
204
205char *heap_ptr;
206
207char *
208_sbrk (int nbytes)
209{
210    char        *base;
211
212    if (!heap_ptr)
213        heap_ptr = (char *)&end;
214    base = heap_ptr;
215    heap_ptr += nbytes;
216
217    return base;
218}
219
220
221clock_t
222_times(struct tms * tp)
223{
224    clock_t utime;
225    int err;
226    err = __syscall(SYS_times, &utime);
227    if (err)
228        utime = 0;
229
230    if (tp) {
231        tp->tms_utime = utime;
232        tp->tms_stime = 0;
233        tp->tms_cutime = 0;
234        tp->tms_cstime = 0;
235    }
236
237    return utime;
238}
239
240int
241_rename (const char *oldpath, const char *newpath)
242{
243    int err ;
244    err = __syscall(SYS_rename, oldpath, newpath);
245    if (err<0)
246      {
247        errno = -err;
248        return -1;
249      }
250    return err;
251}
252
253int
254_unlink (const char *pathname)
255{
256    int err ;
257    err = __syscall(SYS_unlink, pathname);
258    if (err<0)
259      {
260        errno = -err;
261        return -1;
262      }
263    return err;
264}
265
266int
267_system (const char *command)
268{
269    int err ;
270    err = __syscall(SYS_system, command);
271    return err;
272}
273
274#define SYS_meminfo     1001
275
276void *
277__get_memtop(void)
278{
279  unsigned long totmem = 0, topmem = 0;
280  int numbanks;
281
282  __syscall(SYS_meminfo, (unsigned long)&totmem, (unsigned long)&topmem, 0);
283  return (void*)topmem;
284}
Note: See TracBrowser for help on using the repository browser.