Cygwin: cygwin_GetCommandLineW/A: don't rely on __argv[0] content
[newlib-cygwin.git] / libgloss / arm / linux-syscalls0.S
blob17d246e1ca6316c218c2be827104734d9ad66ec1
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  */
9         .syntax unified
11 #include "linux-syscall.h"
13 #if __thumb__
14 # define FUNC(name) .type name, %function; .thumb_func; name:
15 # define SET .thumb_set
16 #else
17 # define FUNC(name) .type name, %function; name:
18 # define SET .set
19 #endif
21 #define GLOBAL(name) .global name; FUNC(name)
22 #define SIZE(name) .size name, .-name
24 # define SYSCALL4(name) \
25         GLOBAL(_ ## name); \
26         swi #SYS_ ## name; \
27         b _set_errno; \
28         SIZE(_ ## name)
30 # define SYSCALL6(name) \
31         GLOBAL(_ ## name); \
32         push { r4 - r5 }; \
33         ldr r4, [sp, #8]; \
34         ldr r5, [sp, #12]; \
35         swi #SYS_ ## name; \
36         pop { r4 - r5 }; \
37         b _set_errno; \
38         SIZE(_ ## name)
40 #define SYSCALL0(name) SYSCALL3(name)
41 #define SYSCALL3(name) SYSCALL4(name)
42 #define SYSCALL1(name) SYSCALL3(name)
43 #define SYSCALL2(name) SYSCALL3(name)
44 #define SYSCALL5(name) SYSCALL6(name)
46 SYSCALL1(alarm)
47 SYSCALL1(brk)
48 SYSCALL1(chdir)
49 SYSCALL2(chmod)
50 SYSCALL3(chown)
51 SYSCALL1(close)
52 SYSCALL1(dup)
53 SYSCALL2(dup2)
54 SYSCALL3(execve)
55 SYSCALL1(exit)
56 SYSCALL3(fcntl)
57 SYSCALL2(fstat)
58 SYSCALL2(ftruncate)
59 SYSCALL3(getdents)
60 SYSCALL0(getegid)
61 SYSCALL0(geteuid)
62 SYSCALL0(getgid)
63 SYSCALL2(getgroups)
64 SYSCALL1(getpgid)
65 SYSCALL0(getpgrp)
66 SYSCALL0(getpid)
67 SYSCALL0(getuid)
68 SYSCALL2(gettimeofday)
69 SYSCALL3(ioctl)
70 SYSCALL2(kill)
71 SYSCALL3(lchown)
72 SYSCALL2(link)
73 SYSCALL3(lseek)
74 SYSCALL2(lstat)
75 SYSCALL2(mkdir)
76 SYSCALL3(mknod)
77 SYSCALL2(nanosleep)
78 SYSCALL3(open)
79 SYSCALL0(pause)
80 SYSCALL1(pipe)
81 SYSCALL3(read)
82 SYSCALL3(readlink)
83 SYSCALL4(reboot)
84 SYSCALL1(rmdir)
85 SYSCALL5(select)
86 SYSCALL2(setpgid)
87 SYSCALL1(setgid)
88 SYSCALL0(setsid)
89 SYSCALL1(setuid)
90 SYSCALL3(sigprocmask)
91 SYSCALL2(socketcall)
92 SYSCALL2(stat)
93 SYSCALL1(stime)
94 SYSCALL2(symlink)
95 SYSCALL1(sync)
96 SYSCALL1(sysinfo)
97 SYSCALL1(times)
98 SYSCALL2(truncate)
99 SYSCALL1(umask)
100 SYSCALL1(uname)
101 SYSCALL1(unlink)
102 SYSCALL2(utime)
103 SYSCALL0(vfork)
104 SYSCALL4(wait4)
105 SYSCALL3(write)
107 #define ALIAS(name) .GLOBAL name; SET name, _ ## name
109 ALIAS(alarm)
110 ALIAS(chdir)
111 ALIAS(chmod)
112 ALIAS(chown)
113 ALIAS(dup)
114 ALIAS(dup2)
115 ALIAS(ftruncate)
116 ALIAS(getdents)
117 ALIAS(getegid)
118 ALIAS(geteuid)
119 ALIAS(getgid)
120 ALIAS(getgroups)
121 ALIAS(getpgid)
122 ALIAS(getpgrp)
123 ALIAS(getuid)
124 ALIAS(ioctl)
125 ALIAS(lchown)
126 ALIAS(lstat)
127 ALIAS(mkdir)
128 ALIAS(mknod)
129 ALIAS(nanosleep)
130 ALIAS(pause)
131 ALIAS(pipe)
132 ALIAS(readlink)
133 ALIAS(rmdir)
134 ALIAS(select)
135 ALIAS(setgid)
136 ALIAS(setpgid)
137 ALIAS(setsid)
138 ALIAS(setuid)
139 ALIAS(sigprocmask)
140 ALIAS(stime)
141 ALIAS(symlink)
142 ALIAS(sync)
143 ALIAS(sysinfo)
144 ALIAS(truncate)
145 ALIAS(umask)
146 ALIAS(uname)
147 ALIAS(utime)
148 ALIAS(vfork)
149 ALIAS(wait4)
151 #if defined (__thumb__) && !defined (__thumb2__)
152 # define SOCKETCALL(name, NAME) \
153         GLOBAL(name); \
154         push { r0 - r3 }; \
155         movs r0, #SYS_ ## NAME; \
156         b _socketcall_tail; \
157         SIZE(name)
158 #else
159 # define SOCKETCALL(name, NAME) \
160         GLOBAL(name); \
161         push { r0 - r3 }; \
162         mov r0, #SYS_ ## NAME; \
163         b _socketcall_tail; \
164         SIZE(name)
165 #endif
167 FUNC(_socketcall_tail)
168         mov r1, sp
169         push { lr }
170         bl _socketcall
171         pop { r3 }
172         add sp, #16
173 #if defined(__ARM_ARCH_2__) || defined(__ARM_ARCH_3__) \
174     || defined(__ARM_ARCH_3M__) || defined(__ARM_ARCH_4__)
175         mov pc, r3
176 #else
177         bx r3
178 #endif
179         SIZE(_socketcall_tail)
181 #define SOCKETCALL2(name, NAME) SOCKETCALL(name, NAME)
182 #define SOCKETCALL3(name, NAME) SOCKETCALL(name, NAME)
183 #define SOCKETCALL4(name, NAME) SOCKETCALL(name, NAME)
184 #define SOCKETCALL5(name, NAME) SOCKETCALL(name, NAME)
185 #define SOCKETCALL6(name, NAME) SOCKETCALL(name, NAME)
187 SOCKETCALL3(accept, ACCEPT)
188 SOCKETCALL3(bind, BIND)
189 SOCKETCALL3(connect, CONNECT)
190 SOCKETCALL3(getpeername, GETPEERNAME)
191 SOCKETCALL3(getsockname, GETSOCKNAME)
192 SOCKETCALL5(getsockopt, GETSOCKOPT)
193 SOCKETCALL2(listen, LISTEN)
194 SOCKETCALL4(recv, RECV)
195 SOCKETCALL6(recvfrom, RECVFROM)
196 SOCKETCALL3(recvmsg, RECVMSG)
197 SOCKETCALL4(send, SEND)
198 SOCKETCALL3(sendmsg, SENDMSG)
199 SOCKETCALL6(sendto, SENDTO)
200 SOCKETCALL5(setsockopt, SETSOCKOPT)
201 SOCKETCALL2(shutdown, SHUTDOWN)
202 SOCKETCALL3(socket, SOCKET)
203 SOCKETCALL4(socketpair, SOCKETPAIR)