Welcome to mirror list, hosted at ThFree Co, Russian Federation.

redboot-syscalls.c « arm « libgloss - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3b5a02b278daa3fab64d5ae896f3b06a39be79ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
 * redboot-syscalls.c -- provide system call support for RedBoot
 *
 * Copyright (c) 1997, 2001, 2002 Red Hat, Inc.
 *
 * The authors hereby grant permission to use, copy, modify, distribute,
 * and license this software and its documentation for any purpose, provided
 * that existing copyright notices are retained in all copies and that this
 * notice is included verbatim in any distributions. No written agreement,
 * license, or royalty fee is required for any of the authorized uses.
 * Modifications to this software may be copyrighted by their authors
 * and need not follow the licensing terms described here, provided that
 * the new terms are clearly indicated on the first page of each file where
 * they apply.
 *
 */

#include <stdlib.h>
#include <sys/stat.h>
#include <sys/times.h>
#include <errno.h>
#include "syscall.h"

// Use "naked" attribute to suppress C prologue/epilogue
static int __attribute__ ((naked)) __syscall(int func_no, ...)
{
    asm ("mov	r12, lr\n");
#ifdef __thumb__
    asm ("swi 0x18\n");
#else
    asm ("swi 0x180001\n");
#endif
    asm ("mov	pc, r12\n");
}

int
_close(int fd)
{
    int  err;
    err = __syscall(SYS_close, fd);
    if (err<0)
      {
        errno = -err;
        return -1;
      }
    return err;
}


void
_exit(int stat)
{
    while (1)
        __syscall(SYS_exit, stat);
}


int
_stat (const char *filename, struct stat *st)
{
    int err;
    err = __syscall(SYS_stat, filename, st);
    if (err<0)
      {
        errno = -err;
        return -1;
      }
    return err;
}

int
_fstat (int file, struct stat *st)
{
    int err;
    err = __syscall(SYS_fstat, file, st);
    if (err<0)
      {
        errno = -err;
        return -1;
      }
    return err;
}

int
_getpid(void)
{
    return 1;
}


int
_gettimeofday (void * tp, void * tzp)
{
    int err;
    err = __syscall(SYS_gettimeofday, tp, tzp);
    if (err<0)
      {
        errno = -err;
        return -1;
      }
    return err;
}


int
isatty(int fd)
{
    int err;
    err = __syscall(SYS_isatty, fd);
    if (err<0)
      {
        errno = -err;
        return -1;
      }
    return err;
}


int
_kill(int pid, int sig)
{
  if(pid == 1)
    _exit(sig);
  return 0;
}


off_t
_lseek(int fd, off_t offset, int whence)
{
    int err;
    err = __syscall(SYS_lseek, fd, offset, whence);
    if (err<0)
      {
        errno = -err;
        return (off_t)-1;
      }
    return err;
}


int
_open(const char *buf, int flags, int mode)
{
    int err ;
    err = __syscall(SYS_open, buf, flags, mode);
    if (err<0)
      {
        errno = -err;
        return -1;
      }
    return err;
}


int
_write(int fd, const char *buf, int nbytes)
{
    int err;

    err = __syscall(SYS_write, fd, buf, nbytes);
    if (err<0)
      {
        errno = -err;
        return -1;
      }
    return err;
}


void
print(char *ptr)
{
  char *p = ptr;

  while (*p != '\0')
    p++;

  _write (1, ptr, p-ptr);
}

void
_raise (void)
{
    return;
}


int
_read(int fd, char *buf, int nbytes)
{
    int err;
    err = __syscall(SYS_read, fd, buf, nbytes);
    if (err<0)
      {
        errno = -err;
        return -1;
      }
    return err;
}


extern char end[];                /* end is set in the linker command file */

char *heap_ptr;

char *
_sbrk (int nbytes)
{
    char        *base;

    if (!heap_ptr)
	heap_ptr = (char *)&end;
    base = heap_ptr;
    heap_ptr += nbytes;

    return base;
}


clock_t
_times(struct tms * tp)
{
    clock_t utime;
    int err;
    err = __syscall(SYS_times, &utime);
    if (err)
	utime = 0;

    if (tp) {
	tp->tms_utime = utime;
	tp->tms_stime = 0;
	tp->tms_cutime = 0;
	tp->tms_cstime = 0;
    }

    return utime;
}

int
_rename (const char *oldpath, const char *newpath)
{
    int err ;
    err = __syscall(SYS_rename, oldpath, newpath);
    if (err<0)
      {
        errno = -err;
        return -1;
      }
    return err;
}

int
_unlink (const char *pathname)
{
    int err ;
    err = __syscall(SYS_unlink, pathname);
    if (err<0)
      {
        errno = -err;
        return -1;
      }
    return err;
}

int
_system (const char *command)
{
    int err ;
    err = __syscall(SYS_system, command);
    return err;
}

#define SYS_meminfo     1001

void *
__get_memtop(void)
{
  unsigned long totmem = 0, topmem = 0;
  int numbanks;

  __syscall(SYS_meminfo, (unsigned long)&totmem, (unsigned long)&topmem, 0);
  return (void*)topmem;
}