-
Notifications
You must be signed in to change notification settings - Fork 0
/
stf_syscalls_minimal.c
202 lines (167 loc) · 3.5 KB
/
stf_syscalls_minimal.c
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
/**
* <b>File:</b> stf_syscalls_minimal.c
*
* <b>Project:</b> FreeRTOS.org STM32 demo using Eclipse
*
* <b>Description:</b> This is the complete set of system definitions (primarily subroutines) required.
* It implements the minimal functionality required to allow libc to link, and fail gracefully where OS services
* are not available.
*
* For more information see the newlib documentation at http://sourceware.org/newlib/
*
* <b>Cereated:</b> 09/04/2009
*
* <dl>
* <dt><b>Autor</b>:</dt>
* <dd>Stefano Oliveri</dd>
* <dt><b>E-mail:</b></dt>
* <dd>software@stf12.net</dd>
* </dl>
*/
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <sys/stat.h>
#include "symbol.h"
// Function declaration.
void _exit(int i);
int _open(const char *name, int flags, int mode);
int _read(int file, char *ptr, int len);
int _write(int file, char *buffer, unsigned int count);
int _lseek(int file, int ptr, int dir);
int _fstat(int file, struct stat *st);
int _link(char *old, char *new);
int _unlink(char *name);
int _stat(char *file, struct stat *st);
int _close(int file);
int _execve(char *name, char **argv, char **env);
int _fork();
int _getpid();
int _isatty(int file);
int _kill(int pid, int sig);
caddr_t _sbrk(int incr);
int times(struct tm *buf);
int _wait(int *status);
#undef errno
extern int errno;
char *__env[1] = {0};
char **__environ = __env;
extern unsigned int _heap;
extern unsigned int _eheap;
unsigned int _heap;
unsigned int _eheap;
static caddr_t heap = NULL;
// Function definition.
void _exit(int i)
{
printf("Program exit with code %d", i);
while (1);
}
int putChar(int ch);
int _write(int file, char *buffer, unsigned int count)
{
register unsigned int i;
for (i = 0; i < count; ++i) {
putChar(*buffer++);
}
return count;
}
int _close(int file)
{
return -1;
}
int _fstat(int file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}
int _isatty(int file)
{
return 1;
}
int _lseek(int file, int ptr, int dir)
{
return 0;
}
int _read(int file, char *ptr, int len)
{
return 0;
}
caddr_t _sbrk(int incr)
{
caddr_t prevHeap;
caddr_t nextHeap;
if (heap == NULL)
{ // first allocation
heap = (caddr_t) & _heap;
}
prevHeap = heap;
// Always return data aligned on a 8 byte boundary
nextHeap = (caddr_t) (((unsigned int) (heap + incr) + 7) & ~7);
// Check enough space and there is no collision with stack coming the other way
// if stack is above start of heap
if (nextHeap >= (caddr_t) & _eheap)
{
errno = ENOMEM;
return NULL; // error - no more memory
}
else
{
heap = nextHeap;
return (caddr_t) prevHeap;
}
}
int _open(const char *name, int flags, int mode)
{
return -1;
}
int _link(char *old, char *new)
{
errno = EMLINK;
return -1;
}
int _unlink(char *name)
{
errno = ENOENT;
return -1;
}
int _stat(char *file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}
int _execve(char *name, char **argv, char **env)
{
errno = ENOMEM;
return -1;
}
int _fork()
{
errno = EAGAIN;
return -1;
}
int _getpid()
{
return 1;
}
int _kill(int pid, int sig)
{
errno = EINVAL;
return (-1);
}
int times(struct tm *buf)
{
return -1;
}
int _wait(int *status)
{
errno = ECHILD;
return -1;
}
int putChar(int ch)
{
//while((U0LSR & (1<<5)) == 0); /* Wait for empty U0THR */ //where function U0THR ??????????????
//U0THR = ch;
return ch;
}