Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
syscall.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Linaro Limited.
3 * Copyright 2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
16
17#ifndef ZEPHYR_INCLUDE_ARCH_ARM_SYSCALL_H_
18#define ZEPHYR_INCLUDE_ARCH_ARM_SYSCALL_H_
19
20#define _SVC_CALL_CONTEXT_SWITCH 0
21#define _SVC_CALL_IRQ_OFFLOAD 1
22#define _SVC_CALL_RUNTIME_EXCEPT 2
23#define _SVC_CALL_SYSTEM_CALL 3
24
25#ifdef CONFIG_USERSPACE
26#ifndef _ASMLANGUAGE
27
28#include <zephyr/types.h>
29#include <stdbool.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37
38/* Syscall invocation macros. arm-specific machine constraints used to ensure
39 * args land in the proper registers.
40 *
41 * Note: r6 carries the syscall call_id into the SVC. The SVC handler
42 * (z_arm_do_syscall) clobbers r6 while indexing the syscall dispatch table and
43 * the exception return does not restore it. r6 must therefore be declared as a
44 * read-write ("+r") operand, otherwise the compiler may assume it survives the
45 * SVC and hoist the (loop-invariant) call_id load out of a retry loop, causing
46 * subsequent iterations to issue the SVC with a corrupted call_id.
47 */
49 uintptr_t arg3, uintptr_t arg4,
50 uintptr_t arg5, uintptr_t arg6,
51 uintptr_t call_id)
52{
53 register uint32_t ret __asm__("r0") = arg1;
54 register uint32_t r1 __asm__("r1") = arg2;
55 register uint32_t r2 __asm__("r2") = arg3;
56 register uint32_t r3 __asm__("r3") = arg4;
57 register uint32_t r4 __asm__("r4") = arg5;
58 register uint32_t r5 __asm__("r5") = arg6;
59 register uint32_t r6 __asm__("r6") = call_id;
60
61 __asm__ volatile("svc %[svid]\n"
62 IF_ENABLED(CONFIG_ARM_BTI, ("bti\n"))
63 : "=r"(ret), "=r"(r1), "=r"(r2), "=r"(r3), "+r" (r6)
64 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
65 "r" (ret), "r" (r1), "r" (r2), "r" (r3),
66 "r" (r4), "r" (r5)
67 : "r8", "memory", "ip");
68
69 return ret;
70}
71
73 uintptr_t arg3, uintptr_t arg4,
74 uintptr_t arg5,
75 uintptr_t call_id)
76{
77 register uint32_t ret __asm__("r0") = arg1;
78 register uint32_t r1 __asm__("r1") = arg2;
79 register uint32_t r2 __asm__("r2") = arg3;
80 register uint32_t r3 __asm__("r3") = arg4;
81 register uint32_t r4 __asm__("r4") = arg5;
82 register uint32_t r6 __asm__("r6") = call_id;
83
84 __asm__ volatile("svc %[svid]\n"
85 IF_ENABLED(CONFIG_ARM_BTI, ("bti\n"))
86 : "=r"(ret), "=r"(r1), "=r"(r2), "=r"(r3), "+r" (r6)
87 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
88 "r" (ret), "r" (r1), "r" (r2), "r" (r3),
89 "r" (r4)
90 : "r8", "memory", "ip");
91
92 return ret;
93}
94
96 uintptr_t arg3, uintptr_t arg4,
97 uintptr_t call_id)
98{
99 register uint32_t ret __asm__("r0") = arg1;
100 register uint32_t r1 __asm__("r1") = arg2;
101 register uint32_t r2 __asm__("r2") = arg3;
102 register uint32_t r3 __asm__("r3") = arg4;
103 register uint32_t r6 __asm__("r6") = call_id;
104
105 __asm__ volatile("svc %[svid]\n"
106 IF_ENABLED(CONFIG_ARM_BTI, ("bti\n"))
107 : "=r"(ret), "=r"(r1), "=r"(r2), "=r"(r3), "+r" (r6)
108 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
109 "r" (ret), "r" (r1), "r" (r2), "r" (r3)
110 : "r8", "memory", "ip");
111
112 return ret;
113}
114
116 uintptr_t arg3,
117 uintptr_t call_id)
118{
119 register uint32_t ret __asm__("r0") = arg1;
120 register uint32_t r1 __asm__("r1") = arg2;
121 register uint32_t r2 __asm__("r2") = arg3;
122 register uint32_t r6 __asm__("r6") = call_id;
123
124 __asm__ volatile("svc %[svid]\n"
125 IF_ENABLED(CONFIG_ARM_BTI, ("bti\n"))
126 : "=r"(ret), "=r"(r1), "=r"(r2), "+r" (r6)
127 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
128 "r" (ret), "r" (r1), "r" (r2)
129 : "r8", "memory", "r3", "ip");
130
131 return ret;
132}
133
135 uintptr_t call_id)
136{
137 register uint32_t ret __asm__("r0") = arg1;
138 register uint32_t r1 __asm__("r1") = arg2;
139 register uint32_t r6 __asm__("r6") = call_id;
140
141 __asm__ volatile("svc %[svid]\n"
142 IF_ENABLED(CONFIG_ARM_BTI, ("bti\n"))
143 : "=r"(ret), "=r"(r1), "+r" (r6)
144 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
145 "r" (ret), "r" (r1)
146 : "r8", "memory", "r2", "r3", "ip");
147
148 return ret;
149}
150
152 uintptr_t call_id)
153{
154 register uint32_t ret __asm__("r0") = arg1;
155 register uint32_t r6 __asm__("r6") = call_id;
156
157 __asm__ volatile("svc %[svid]\n"
158 IF_ENABLED(CONFIG_ARM_BTI, ("bti\n"))
159 : "=r"(ret), "+r" (r6)
160 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
161 "r" (ret)
162 : "r8", "memory", "r1", "r2", "r3", "ip");
163 return ret;
164}
165
167{
168 register uint32_t ret __asm__("r0");
169 register uint32_t r6 __asm__("r6") = call_id;
170
171 __asm__ volatile("svc %[svid]\n"
172 IF_ENABLED(CONFIG_ARM_BTI, ("bti\n"))
173 : "=r"(ret), "+r" (r6)
174 : [svid] "i" (_SVC_CALL_SYSTEM_CALL),
175 "r" (ret)
176 : "r8", "memory", "r1", "r2", "r3", "ip");
177
178 return ret;
179}
180
181static inline bool arch_is_user_context(void)
182{
183#if defined(CONFIG_CPU_CORTEX_M)
184 uint32_t value;
185
186 /* check for handler mode */
187 __asm__ volatile("mrs %0, IPSR\n\t" : "=r"(value));
188 if (value) {
189 return false;
190 }
191#endif
192
193 return z_arm_thread_is_in_user_mode();
194}
195
196#ifdef __cplusplus
197}
198#endif
199
200#endif /* _ASMLANGUAGE */
201#endif /* CONFIG_USERSPACE */
202#endif /* ZEPHYR_INCLUDE_ARCH_ARM_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:89
static uintptr_t arch_syscall_invoke2(uintptr_t arg1, uintptr_t arg2, uintptr_t call_id)
Definition syscall.h:131
static uintptr_t arch_syscall_invoke1(uintptr_t arg1, uintptr_t call_id)
Definition syscall.h:149
static uintptr_t arch_syscall_invoke0(uintptr_t call_id)
Definition syscall.h:165
static bool arch_is_user_context(void)
Definition syscall.h:181
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:65
static uintptr_t arch_syscall_invoke3(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t call_id)
Definition syscall.h:111
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
ARM AArch32 public kernel miscellaneous.
#define IF_ENABLED(_flag, _code)
Insert code if _flag is defined and equals 1.
Definition util_macro.h:278
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Macro utilities.