-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsyscall.c
More file actions
319 lines (270 loc) · 9.77 KB
/
syscall.c
File metadata and controls
319 lines (270 loc) · 9.77 KB
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/*
*
* Copyright 2018 The wookey project team <wookey@ssi.gouv.fr>
* - Ryad Benadjila
* - Arnauld Michelizza
* - Mathieu Renard
* - Philippe Thierry
* - Philippe Trebuchet
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* the Free Software Foundation; either version 2.1 of the License, or (at
* ur option) any later version.
*
* This package is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with this package; if not, write to the Free Software Foundation, Inc., 51
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "libc/types.h"
#include "libc/syscall.h"
#ifdef CONFIG_ARCH_ARMV7M
#include "arch/cores/armv7-m/m4_syscall.h"
#else
#error "Architecture not yet supported by Libstd Syscall API"
#endif
/* Required for variadic macros, compatible with gcc and llvm/clang */
#define __GNU_SOURCES
#ifdef __clang__
/*** Clang/LLVM builtins ****/
static inline __IN_SEC_VDSO void _memset(void *s, int c, uint32_t n)
{
char *bytes = s;
while (n) {
*bytes = c;
bytes++;
n--;
}
return;
}
static inline __IN_SEC_VDSO void _memcpy(void *dest, const void *src, uint32_t n)
{
char *d_bytes = dest;
const char *s_bytes = src;
while (n) {
*d_bytes = *s_bytes;
d_bytes++;
s_bytes++;
n--;
}
return;
}
__IN_SEC_VDSO void __aeabi_memclr(void *dest, int n)
{
_memset(dest, 0, n);
}
__IN_SEC_VDSO void __aeabi_memclr4(void *dest, int n)
{
_memset(dest, 0, n);
}
__IN_SEC_VDSO void __aeabi_memclr8(void *dest, int n)
{
_memset(dest, 0, n);
}
__IN_SEC_VDSO void __aeabi_memcpy(void *dest, const void *src, uint32_t n)
{
_memcpy(dest, src, n);
}
__IN_SEC_VDSO void __aeabi_memcpy4(void *dest, const void *src, uint32_t n)
{
_memcpy(dest, src, n);
}
__IN_SEC_VDSO void __aeabi_memcpy8(void *dest, const void *src, uint32_t n)
{
_memcpy(dest, src, n);
}
#endif
/*
** Syscalls user interface implementation
*/
__IN_SEC_VDSO e_syscall_ret sys_yield(void)
{
struct gen_syscall_args args = { 0, 0, 0, 0 };
return do_syscall(SVC_YIELD, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_exit(void)
{
struct gen_syscall_args args = { 0, 0, 0, 0 };
return do_syscall(SVC_EXIT, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_panic(void)
{
struct gen_syscall_args args = { 0, 0, 0, 0 };
return do_syscall(SVC_PANIC, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_lock(uint32_t action)
{
struct gen_syscall_args args = { 0, 0, 0, 0 };
switch (action) {
case LOCK_ENTER:
return do_syscall(SVC_LOCK_ENTER, &args);
case LOCK_EXIT:
return do_syscall(SVC_LOCK_EXIT, &args);
default:
return SYS_E_INVAL;
}
}
__IN_SEC_VDSO e_syscall_ret sys_sleep(uint32_t time, sleep_mode_t mode)
{
struct gen_syscall_args args = { time, mode, 0, 0 };
return do_syscall(SVC_SLEEP, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_reset(void)
{
struct gen_syscall_args args = { 0, 0, 0, 0 };
return do_syscall(SVC_RESET, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_get_systick(uint64_t * val, e_tick_type type)
{
struct gen_syscall_args args = { (uint32_t) val, type, 0, 0 };
return do_syscall(SVC_GET_TIME, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_get_random(char *val, uint16_t len)
{
struct gen_syscall_args args = { (uint32_t) val, (uint32_t) len, 0, 0 };
return do_syscall(SVC_GET_RANDOM, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_log(logsize_t size, const char *msg)
{
struct gen_syscall_args args = { (uint32_t) size, (uint32_t) msg, 0, 0 };
return do_syscall(SVC_LOG, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_alarm(uint32_t time, alarm_handler_t handler)
{
struct gen_syscall_args args = { time, (uint32_t) handler, 0, 0 };
return do_syscall(SVC_ALARM, &args);
}
/*************************************************
* sys_ipc functions
************************************************/
__IN_SEC_VDSO e_syscall_ret sys_ipc_IPC_SEND_SYNC( __attribute__ ((unused)) uint32_t ipctype,
uint8_t receiver, logsize_t size,
const char *msg)
{
struct gen_syscall_args args =
{ (uint32_t) receiver, (uint32_t) size, (uint32_t) msg, 0 };
return do_syscall(SVC_IPC_SEND_SYNC, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_ipc_IPC_RECV_SYNC( __attribute__ ((unused)) uint32_t ipctype,
uint8_t * sender, logsize_t * size,
char *msg)
{
struct gen_syscall_args args =
{ (uint32_t) sender, (uint32_t) size, (uint32_t) msg, 0 };
return do_syscall(SVC_IPC_RECV_SYNC, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_ipc_IPC_SEND_ASYNC( __attribute__ ((unused)) uint32_t ipctype,
uint8_t receiver, logsize_t size,
const char *msg)
{
struct gen_syscall_args args =
{ (uint32_t) receiver, (uint32_t) size, (uint32_t) msg, 0 };
return do_syscall(SVC_IPC_SEND_ASYNC, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_ipc_IPC_RECV_ASYNC( __attribute__ ((unused)) uint32_t ipctype,
uint8_t * sender, logsize_t * size,
char *msg)
{
struct gen_syscall_args args =
{ (uint32_t) sender, (uint32_t) size, (uint32_t) msg, 0 };
return do_syscall(SVC_IPC_RECV_ASYNC, &args);
}
/*************************************************
* sys_cfg functions
************************************************/
__IN_SEC_VDSO e_syscall_ret sys_cfg_CFG_GPIO_SET( __attribute__ ((unused)) uint32_t cfgtype,
uint8_t gpioref, uint8_t value)
{
struct gen_syscall_args args = { gpioref, value, 0, 0 };
return do_syscall(SVC_GPIO_SET, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_cfg_CFG_GPIO_GET( __attribute__ ((unused)) uint32_t cfgtype,
uint8_t gpioref, uint8_t * value)
{
struct gen_syscall_args args = { gpioref, (uint32_t) value, 0, 0 };
return do_syscall(SVC_GPIO_GET, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_cfg_CFG_GPIO_UNLOCK_EXTI( __attribute__ ((unused)) uint32_t
cfgtype, uint8_t gpioref)
{
struct gen_syscall_args args = { gpioref, 0, 0, 0 };
return do_syscall(SVC_GPIO_UNLOCK_EXTI, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_cfg_CFG_DMA_RECONF( __attribute__ ((unused)) uint32_t cfgtype,
dma_t * dma, dma_reconf_mask_t mask,
int descriptor)
{
struct gen_syscall_args args =
{ (uint32_t) dma, (uint32_t) mask, (uint32_t) descriptor, 0 };
return do_syscall(SVC_DMA_RECONF, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_cfg_CFG_DMA_RELOAD( __attribute__ ((unused)) uint32_t cfgtype,
int descriptor)
{
struct gen_syscall_args args = { (uint32_t) descriptor, 0, 0, 0 };
return do_syscall(SVC_DMA_RELOAD, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_cfg_CFG_DMA_DISABLE( __attribute__ ((unused)) uint32_t
cfgtype, int descriptor)
{
struct gen_syscall_args args = { (uint32_t) descriptor, 0, 0, 0 };
return do_syscall(SVC_DMA_DISABLE, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_cfg_CFG_DEV_MAP( __attribute__ ((unused)) uint32_t cfgtype,
uint32_t devid)
{
struct gen_syscall_args args = { devid, 0, 0, 0 };
return do_syscall(SVC_DEV_MAP, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_cfg_CFG_DEV_UNMAP( __attribute__ ((unused)) uint32_t cfgtype,
uint32_t devid)
{
struct gen_syscall_args args = { devid, 0, 0, 0 };
return do_syscall(SVC_DEV_UNMAP, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_cfg_CFG_DEV_RELEASE( __attribute__ ((unused)) uint32_t
cfgtype, uint32_t devid)
{
struct gen_syscall_args args = { devid, 0, 0, 0 };
return do_syscall(SVC_DEV_RELEASE, &args);
}
/*************************************************
* sys_init functions
************************************************/
__IN_SEC_VDSO e_syscall_ret sys_init_INIT_DEVACCESS( __attribute__ ((unused)) uint32_t
inittype, const device_t * device,
int *descriptor)
{
struct gen_syscall_args args =
{ (uint32_t) device, (uint32_t) descriptor, 0, 0 };
return do_syscall(SVC_REGISTER_DEVICE, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_init_INIT_DMA( __attribute__ ((unused)) uint32_t inittype,
volatile dma_t * dma, int *descriptor)
{
struct gen_syscall_args args =
{ (uint32_t) dma, (uint32_t) descriptor, 0, 0 };
return do_syscall(SVC_REGISTER_DMA, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_init_INIT_DMA_SHM( __attribute__ ((unused)) uint32_t inittype,
dma_shm_t * dmashm)
{
struct gen_syscall_args args = { (uint32_t) dmashm, 0, 0, 0 };
return do_syscall(SVC_REGISTER_DMA_SHM, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_init_INIT_GETTASKID( __attribute__ ((unused)) uint32_t
inittype, char *name, uint8_t * id)
{
struct gen_syscall_args args = { (uint32_t) name, (uint32_t) id, 0, 0 };
return do_syscall(SVC_GET_TASKID, &args);
}
__IN_SEC_VDSO e_syscall_ret sys_init_INIT_DONE( __attribute__ ((unused)) uint32_t inittype)
{
struct gen_syscall_args args = { 0, 0, 0, 0 };
return do_syscall(SVC_INIT_DONE, &args);
}