FreeNOS
ARM64Traps.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Ivan Tan
3 * Copyright (C) 2020 Niek Linnenbank
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef __LIB_LIBARCH_ARM64_ARM64TRAPS_H
20#define __LIB_LIBARCH_ARM64_ARM64TRAPS_H
21
22#include <Types.h>
23
60inline ulong trapKernel1(ulong api, ulong arg1)
61{
62 register unsigned reg8 asm ("x8") = api;
63 register unsigned reg0 asm ("x0") = arg1;
64
65 asm volatile ("svc #0\n"
66 : "+r"(reg0)
67 : "r"(reg8), "r"(reg0)
68 : "memory");
69 return reg0;
70}
71
81inline ulong trapKernel2(ulong api, ulong arg1, ulong arg2)
82{
83 register unsigned reg8 asm ("x8") = api;
84 register unsigned reg0 asm ("x0") = arg1;
85 register unsigned reg1 asm ("x1") = arg2;
86
87 asm volatile ("svc #0\n"
88 : "+r"(reg0)
89 : "r"(reg8), "r"(reg0), "r"(reg1)
90 : "memory");
91 return reg0;
92}
93
104inline ulong trapKernel3(ulong api, ulong arg1, ulong arg2, ulong arg3)
105{
106 register unsigned reg8 asm ("x8") = api;
107 register unsigned reg0 asm ("x0") = arg1;
108 register unsigned reg1 asm ("x1") = arg2;
109 register unsigned reg2 asm ("x2") = arg3;
110
111 asm volatile ("svc #0\n"
112 : "+r"(reg0)
113 : "r"(reg8), "r"(reg0), "r"(reg1), "r"(reg2)
114 : "memory");
115 return reg0;
116}
117
129inline ulong trapKernel4(ulong api, ulong arg1, ulong arg2, ulong arg3,
130 ulong arg4)
131{
132 register unsigned reg8 asm ("x8") = api;
133 register unsigned reg0 asm ("x0") = arg1;
134 register unsigned reg1 asm ("x1") = arg2;
135 register unsigned reg2 asm ("x2") = arg3;
136 register unsigned reg3 asm ("x3") = arg4;
137
138 asm volatile ("svc #0\n"
139 : "+r"(reg0)
140 : "r"(reg8), "r"(reg0), "r"(reg1), "r"(reg2), "r"(reg3)
141 : "memory");
142 return reg0;
143}
144
157inline ulong trapKernel5(ulong api, ulong arg1, ulong arg2, ulong arg3,
158 ulong arg4, ulong arg5)
159{
160 register unsigned reg8 asm ("x8") = api;
161 register unsigned reg0 asm ("x0") = arg1;
162 register unsigned reg1 asm ("x1") = arg2;
163 register unsigned reg2 asm ("x2") = arg3;
164 register unsigned reg3 asm ("x3") = arg4;
165 register unsigned reg4 asm ("x4") = arg5;
166
167 asm volatile ("svc #0\n"
168 : "+r"(reg0)
169 : "r"(reg8), "r"(reg0), "r"(reg1), "r"(reg2), "r"(reg3), "r"(reg4)
170 : "memory");
171 return reg0;
172}
173
181#endif /* __LIB_LIBARCH_ARM64_ARM64TRAPS_H */
ulong trapKernel3(ulong api, ulong arg1, ulong arg2, ulong arg3)
Perform a kernel trap with 3 arguments.
Definition ARMTraps.h:103
ulong trapKernel4(ulong api, ulong arg1, ulong arg2, ulong arg3, ulong arg4)
Perform a kernel trap with 4 arguments.
Definition ARMTraps.h:128
ulong trapKernel5(ulong api, ulong arg1, ulong arg2, ulong arg3, ulong arg4, ulong arg5)
Perform a kernel trap with 5 arguments.
Definition ARMTraps.h:156
ulong trapKernel1(ulong api, ulong arg1)
Perform a kernel trap with 1 argument.
Definition ARMTraps.h:59
ulong trapKernel2(ulong api, ulong arg1, ulong arg2)
Perform a kernel trap with 2 arguments.
Definition ARMTraps.h:80
unsigned long ulong
Unsigned long number.
Definition Types.h:47