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