Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
syscall.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Carlo Caione <ccaione@baylibre.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
16#ifndef ZEPHYR_INCLUDE_ARCH_ARM64_SYSCALL_H_
17#define ZEPHYR_INCLUDE_ARCH_ARM64_SYSCALL_H_
18
19#define _SVC_CALL_CONTEXT_SWITCH 0
20#define _SVC_CALL_IRQ_OFFLOAD 1
21#define _SVC_CALL_RUNTIME_EXCEPT 2
22#define _SVC_CALL_SYSTEM_CALL 3
23
24#ifdef CONFIG_USERSPACE
25#ifndef _ASMLANGUAGE
26
27#include <zephyr/types.h>
28#include <stdbool.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/*
37 * Syscall invocation macros. arm-specific machine constraints used to ensure
38 * args land in the proper registers.
39 */
41 uintptr_t arg3, uintptr_t arg4,
42 uintptr_t arg5, uintptr_t arg6,
43 uintptr_t call_id)
44{
45 register uint64_t ret __asm__("x0") = arg1;
46 register uint64_t r1 __asm__("x1") = arg2;
47 register uint64_t r2 __asm__("x2") = arg3;
48 register uint64_t r3 __asm__("x3") = arg4;
49 register uint64_t r4 __asm__("x4") = arg5;
50 register uint64_t r5 __asm__("x5") = arg6;
51 register uint64_t r8 __asm__("x8") = call_id;
52
53 __asm__ volatile("svc %[svid]\n"
54 : "=r"(ret)
55 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
56 "r" (ret), "r" (r1), "r" (r2), "r" (r3),
57 "r" (r4), "r" (r5), "r" (r8)
58 : "memory");
59
60 return ret;
61}
62
64 uintptr_t arg3, uintptr_t arg4,
65 uintptr_t arg5,
66 uintptr_t call_id)
67{
68 register uint64_t ret __asm__("x0") = arg1;
69 register uint64_t r1 __asm__("x1") = arg2;
70 register uint64_t r2 __asm__("x2") = arg3;
71 register uint64_t r3 __asm__("x3") = arg4;
72 register uint64_t r4 __asm__("x4") = arg5;
73 register uint64_t r8 __asm__("x8") = call_id;
74
75 __asm__ volatile("svc %[svid]\n"
76 : "=r"(ret)
77 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
78 "r" (ret), "r" (r1), "r" (r2), "r" (r3),
79 "r" (r4), "r" (r8)
80 : "memory");
81
82 return ret;
83}
84
86 uintptr_t arg3, uintptr_t arg4,
87 uintptr_t call_id)
88{
89 register uint64_t ret __asm__("x0") = arg1;
90 register uint64_t r1 __asm__("x1") = arg2;
91 register uint64_t r2 __asm__("x2") = arg3;
92 register uint64_t r3 __asm__("x3") = arg4;
93 register uint64_t r8 __asm__("x8") = call_id;
94
95 __asm__ volatile("svc %[svid]\n"
96 : "=r"(ret)
97 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
98 "r" (ret), "r" (r1), "r" (r2), "r" (r3),
99 "r" (r8)
100 : "memory");
101
102 return ret;
103}
104
106 uintptr_t arg3,
107 uintptr_t call_id)
108{
109 register uint64_t ret __asm__("x0") = arg1;
110 register uint64_t r1 __asm__("x1") = arg2;
111 register uint64_t r2 __asm__("x2") = arg3;
112 register uint64_t r8 __asm__("x8") = call_id;
113
114 __asm__ volatile("svc %[svid]\n"
115 : "=r"(ret)
116 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
117 "r" (ret), "r" (r1), "r" (r2), "r" (r8)
118 : "memory");
119
120 return ret;
121}
122
124 uintptr_t call_id)
125{
126 register uint64_t ret __asm__("x0") = arg1;
127 register uint64_t r1 __asm__("x1") = arg2;
128 register uint64_t r8 __asm__("x8") = call_id;
129
130 __asm__ volatile("svc %[svid]\n"
131 : "=r"(ret)
132 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
133 "r" (ret), "r" (r1), "r" (r8)
134 : "memory");
135
136 return ret;
137}
138
140 uintptr_t call_id)
141{
142 register uint64_t ret __asm__("x0") = arg1;
143 register uint64_t r8 __asm__("x8") = call_id;
144
145 __asm__ volatile("svc %[svid]\n"
146 : "=r"(ret)
147 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
148 "r" (ret), "r" (r8)
149 : "memory");
150 return ret;
151}
152
154{
155 register uint64_t ret __asm__("x0");
156 register uint64_t r8 __asm__("x8") = call_id;
157
158 __asm__ volatile("svc %[svid]\n"
159 : "=r"(ret)
160 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
161 "r" (ret), "r" (r8)
162 : "memory");
163
164 return ret;
165}
166
167static inline bool arch_is_user_context(void)
168{
169 return (read_tpidrro_el0() & TPIDRROEL0_IN_EL0) != 0;
170}
171
172#ifdef __cplusplus
173}
174#endif
175
176#endif /* _ASMLANGUAGE */
177#endif /* CONFIG_USERSPACE */
178
179#endif /* ZEPHYR_INCLUDE_ARCH_ARM64_SYSCALL_H_ */
static uintptr_t arch_syscall_invoke4(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t call_id)
Definition: syscall.h:85
static uintptr_t arch_syscall_invoke2(uintptr_t arg1, uintptr_t arg2, uintptr_t call_id)
Definition: syscall.h:123
static uintptr_t arch_syscall_invoke1(uintptr_t arg1, uintptr_t call_id)
Definition: syscall.h:139
static uintptr_t arch_syscall_invoke0(uintptr_t call_id)
Definition: syscall.h:153
static bool arch_is_user_context(void)
Definition: syscall.h:167
static uintptr_t arch_syscall_invoke5(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, uintptr_t call_id)
Definition: syscall.h:63
static uintptr_t arch_syscall_invoke3(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t call_id)
Definition: syscall.h:105
static uintptr_t arch_syscall_invoke6(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, uintptr_t arg6, uintptr_t call_id)
Definition: syscall.h:40
static ZTEST_BMEM volatile int ret
Definition: k_float_disable.c:28
static ALWAYS_INLINE uint64_t read_tpidrro_el0(void)
Definition: lib_helpers.h:69
__UINT64_TYPE__ uint64_t
Definition: stdint.h:61
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:75
tpidrro_el0 bits allocation
#define TPIDRROEL0_IN_EL0
Definition: tpidrro_el0.h:20