summaryrefslogtreecommitdiffstats
path: root/libgloss/arm/redboot-syscalls.c
blob: 6b9d550c1730f569daa8f436f4f4d074070c38c4 (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
/*
 * redboot-syscalls.c -- provide system call support for RedBoot
 *
 * Copyright (c) 1997, 2001 Cygnus Support
 *
 * 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)
	errno = err;
    return err;
}


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


int
_fstat (int file, struct stat *st)
{
    st->st_mode = S_IFCHR;
    st->st_blksize = 4096;
    return 0;
}

int
_getpid(void)
{
    return 1;
}


int
_gettimeofday (void * tp, void * tzp)
{
    return 0;
}


int
isatty(int fd)
{
    return (1);
}


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)
	errno = err;
    return err;
}


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


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

    err = __syscall(SYS_write, fd, buf, nbytes);
    if (err)
	errno = err;
    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)
	errno = err;
    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;
#ifdef HAVE_BSP_CLOCK
    int err;
    err = __syscall(SYS_utime, &utime);
    if (err)
	utime = 0;
#else
    utime = 0;
#endif

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

    return utime;
}


int
_unlink (const char *pathname)
{
  return -1;
}