1 | /** Linux system call interface for the ARM processor. |
---|
2 | * Written by Shaun Jackman <sjackman@gmail.com>. |
---|
3 | * Copyright 2006 Pathway Connectivity |
---|
4 | * |
---|
5 | * Permission to use, copy, modify, and distribute this software |
---|
6 | * is freely granted, provided that this notice is preserved. |
---|
7 | */ |
---|
8 | |
---|
9 | #include "linux-syscall.h" |
---|
10 | |
---|
11 | #if __thumb__ |
---|
12 | # define FUNC(name) .type name, %function; .thumb_func; name: |
---|
13 | # define SET .thumb_set |
---|
14 | #else |
---|
15 | # define FUNC(name) .type name, %function; name: |
---|
16 | # define SET .set |
---|
17 | #endif |
---|
18 | |
---|
19 | #define GLOBAL(name) .global name; FUNC(name) |
---|
20 | #define SIZE(name) .size name, .-name |
---|
21 | |
---|
22 | # define SYSCALL4(name) \ |
---|
23 | GLOBAL(_ ## name); \ |
---|
24 | swi #SYS_ ## name; \ |
---|
25 | b _set_errno; \ |
---|
26 | SIZE(_ ## name) |
---|
27 | |
---|
28 | # define SYSCALL6(name) \ |
---|
29 | GLOBAL(_ ## name); \ |
---|
30 | push { r4 - r5 }; \ |
---|
31 | ldr r4, [sp, #8]; \ |
---|
32 | ldr r5, [sp, #12]; \ |
---|
33 | swi #SYS_ ## name; \ |
---|
34 | pop { r4 - r5 }; \ |
---|
35 | b _set_errno; \ |
---|
36 | SIZE(_ ## name) |
---|
37 | |
---|
38 | #define SYSCALL0(name) SYSCALL3(name) |
---|
39 | #define SYSCALL3(name) SYSCALL4(name) |
---|
40 | #define SYSCALL1(name) SYSCALL3(name) |
---|
41 | #define SYSCALL2(name) SYSCALL3(name) |
---|
42 | #define SYSCALL5(name) SYSCALL6(name) |
---|
43 | |
---|
44 | SYSCALL1(alarm) |
---|
45 | SYSCALL1(brk) |
---|
46 | SYSCALL1(chdir) |
---|
47 | SYSCALL2(chmod) |
---|
48 | SYSCALL3(chown) |
---|
49 | SYSCALL1(close) |
---|
50 | SYSCALL1(dup) |
---|
51 | SYSCALL2(dup2) |
---|
52 | SYSCALL3(execve) |
---|
53 | SYSCALL1(exit) |
---|
54 | SYSCALL3(fcntl) |
---|
55 | SYSCALL2(fstat) |
---|
56 | SYSCALL2(ftruncate) |
---|
57 | SYSCALL3(getdents) |
---|
58 | SYSCALL0(getegid) |
---|
59 | SYSCALL0(geteuid) |
---|
60 | SYSCALL0(getgid) |
---|
61 | SYSCALL2(getgroups) |
---|
62 | SYSCALL1(getpgid) |
---|
63 | SYSCALL0(getpgrp) |
---|
64 | SYSCALL0(getpid) |
---|
65 | SYSCALL0(getuid) |
---|
66 | SYSCALL2(gettimeofday) |
---|
67 | SYSCALL3(ioctl) |
---|
68 | SYSCALL2(kill) |
---|
69 | SYSCALL3(lchown) |
---|
70 | SYSCALL2(link) |
---|
71 | SYSCALL3(lseek) |
---|
72 | SYSCALL2(lstat) |
---|
73 | SYSCALL2(mkdir) |
---|
74 | SYSCALL3(mknod) |
---|
75 | SYSCALL2(nanosleep) |
---|
76 | SYSCALL3(open) |
---|
77 | SYSCALL0(pause) |
---|
78 | SYSCALL1(pipe) |
---|
79 | SYSCALL3(read) |
---|
80 | SYSCALL3(readlink) |
---|
81 | SYSCALL4(reboot) |
---|
82 | SYSCALL1(rmdir) |
---|
83 | SYSCALL5(select) |
---|
84 | SYSCALL2(setpgid) |
---|
85 | SYSCALL1(setgid) |
---|
86 | SYSCALL0(setsid) |
---|
87 | SYSCALL1(setuid) |
---|
88 | SYSCALL3(sigprocmask) |
---|
89 | SYSCALL2(socketcall) |
---|
90 | SYSCALL2(stat) |
---|
91 | SYSCALL1(stime) |
---|
92 | SYSCALL2(symlink) |
---|
93 | SYSCALL1(sync) |
---|
94 | SYSCALL1(sysinfo) |
---|
95 | SYSCALL1(times) |
---|
96 | SYSCALL2(truncate) |
---|
97 | SYSCALL1(umask) |
---|
98 | SYSCALL1(uname) |
---|
99 | SYSCALL1(unlink) |
---|
100 | SYSCALL2(utime) |
---|
101 | SYSCALL0(vfork) |
---|
102 | SYSCALL4(wait4) |
---|
103 | SYSCALL3(write) |
---|
104 | |
---|
105 | #define ALIAS(name) .GLOBAL name; SET name, _ ## name |
---|
106 | |
---|
107 | ALIAS(alarm) |
---|
108 | ALIAS(chdir) |
---|
109 | ALIAS(chmod) |
---|
110 | ALIAS(chown) |
---|
111 | ALIAS(dup) |
---|
112 | ALIAS(dup2) |
---|
113 | ALIAS(ftruncate) |
---|
114 | ALIAS(getdents) |
---|
115 | ALIAS(getegid) |
---|
116 | ALIAS(geteuid) |
---|
117 | ALIAS(getgid) |
---|
118 | ALIAS(getgroups) |
---|
119 | ALIAS(getpgid) |
---|
120 | ALIAS(getpgrp) |
---|
121 | ALIAS(getuid) |
---|
122 | ALIAS(ioctl) |
---|
123 | ALIAS(lchown) |
---|
124 | ALIAS(lstat) |
---|
125 | ALIAS(mkdir) |
---|
126 | ALIAS(mknod) |
---|
127 | ALIAS(nanosleep) |
---|
128 | ALIAS(pause) |
---|
129 | ALIAS(pipe) |
---|
130 | ALIAS(readlink) |
---|
131 | ALIAS(rmdir) |
---|
132 | ALIAS(select) |
---|
133 | ALIAS(setgid) |
---|
134 | ALIAS(setpgid) |
---|
135 | ALIAS(setsid) |
---|
136 | ALIAS(setuid) |
---|
137 | ALIAS(sigprocmask) |
---|
138 | ALIAS(stime) |
---|
139 | ALIAS(symlink) |
---|
140 | ALIAS(sync) |
---|
141 | ALIAS(sysinfo) |
---|
142 | ALIAS(truncate) |
---|
143 | ALIAS(umask) |
---|
144 | ALIAS(uname) |
---|
145 | ALIAS(utime) |
---|
146 | ALIAS(vfork) |
---|
147 | ALIAS(wait4) |
---|
148 | |
---|
149 | # define SOCKETCALL(name, NAME) \ |
---|
150 | GLOBAL(name); \ |
---|
151 | push { r0 - r3 }; \ |
---|
152 | mov r0, #SYS_ ## NAME; \ |
---|
153 | b _socketcall_tail; \ |
---|
154 | SIZE(name) |
---|
155 | |
---|
156 | FUNC(_socketcall_tail) |
---|
157 | mov r1, sp |
---|
158 | push { lr } |
---|
159 | bl _socketcall |
---|
160 | pop { r3 } |
---|
161 | add sp, #16 |
---|
162 | #if defined(__ARM_ARCH_2__) || defined(__ARM_ARCH_3__) \ |
---|
163 | || defined(__ARM_ARCH_3M__) || defined(__ARM_ARCH_4__) |
---|
164 | mov pc, r3 |
---|
165 | #else |
---|
166 | bx r3 |
---|
167 | #endif |
---|
168 | SIZE(_socketcall_tail) |
---|
169 | |
---|
170 | #define SOCKETCALL2(name, NAME) SOCKETCALL(name, NAME) |
---|
171 | #define SOCKETCALL3(name, NAME) SOCKETCALL(name, NAME) |
---|
172 | #define SOCKETCALL4(name, NAME) SOCKETCALL(name, NAME) |
---|
173 | #define SOCKETCALL5(name, NAME) SOCKETCALL(name, NAME) |
---|
174 | #define SOCKETCALL6(name, NAME) SOCKETCALL(name, NAME) |
---|
175 | |
---|
176 | SOCKETCALL3(accept, ACCEPT) |
---|
177 | SOCKETCALL3(bind, BIND) |
---|
178 | SOCKETCALL3(connect, CONNECT) |
---|
179 | SOCKETCALL3(getpeername, GETPEERNAME) |
---|
180 | SOCKETCALL3(getsockname, GETSOCKNAME) |
---|
181 | SOCKETCALL5(getsockopt, GETSOCKOPT) |
---|
182 | SOCKETCALL2(listen, LISTEN) |
---|
183 | SOCKETCALL4(recv, RECV) |
---|
184 | SOCKETCALL6(recvfrom, RECVFROM) |
---|
185 | SOCKETCALL3(recvmsg, RECVMSG) |
---|
186 | SOCKETCALL4(send, SEND) |
---|
187 | SOCKETCALL3(sendmsg, SENDMSG) |
---|
188 | SOCKETCALL6(sendto, SENDTO) |
---|
189 | SOCKETCALL5(setsockopt, SETSOCKOPT) |
---|
190 | SOCKETCALL2(shutdown, SHUTDOWN) |
---|
191 | SOCKETCALL3(socket, SOCKET) |
---|
192 | SOCKETCALL4(socketpair, SOCKETPAIR) |
---|