]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/sh/socket.S
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sh / socket.S
CommitLineData
d4697bc9 1/* Copyright (C) 1999-2014 Free Software Foundation, Inc.
3846ef75
UD
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
3846ef75
UD
8
9 The GNU C Library 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 GNU
41bdb6e2 12 Lesser General Public License for more details.
3846ef75 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
3846ef75 17
bbd17455 18#include <sysdep-cancel.h>
3846ef75 19#include <socketcall.h>
bbd17455 20#include <tls.h>
3846ef75
UD
21
22#define P(a, b) P2(a, b)
23#define P2(a, b) a##b
24
25 .text
26/* The socket-oriented system calls are handled unusally in Linux.
27 They are all gated through the single `socketcall' system call number.
28 `socketcall' takes two arguments: the first is the subcode, specifying
29 which socket function is being called; and the second is a pointer to
30 the arguments to the specific function.
31
32 The .S files for the other calls just #define socket and #include this. */
33
34#ifndef __socket
71b8b018 35#ifndef NO_WEAK_ALIAS
3846ef75 36#define __socket P(__,socket)
71b8b018
UD
37#else
38#define __socket socket
39#endif
3846ef75
UD
40#endif
41
07bd2a3f
UD
42#define PUSHARGS_1 mov.l r4,@-r15; \
43 cfi_adjust_cfa_offset (4); \
44 cfi_rel_offset (r4, 0)
45#define PUSHARGS_2 mov.l r5,@-r15; \
46 cfi_adjust_cfa_offset (4); \
47 cfi_rel_offset (r5, 0); \
48 PUSHARGS_1
49#define PUSHARGS_3 mov.l r6,@-r15; \
50 cfi_adjust_cfa_offset (4); \
51 cfi_rel_offset (r6, 0); \
52 PUSHARGS_2
53#define PUSHARGS_4 mov.l r7,@-r15; \
54 cfi_adjust_cfa_offset (4); \
55 cfi_rel_offset (r7, 0); \
56 PUSHARGS_3
3846ef75
UD
57#define PUSHARGS_5 PUSHARGS_4 /* Caller has already pushed arg 5 */
58#define PUSHARGS_6 PUSHARGS_4 /* Caller has already pushed arg 5,6 */
59
07bd2a3f
UD
60#define POPARGS_1 add #4,r15; cfi_adjust_cfa_offset (-4)
61#define POPARGS_2 add #8,r15; cfi_adjust_cfa_offset (-8)
62#define POPARGS_3 add #12,r15; cfi_adjust_cfa_offset (-12)
63#define POPARGS_4 add #16,r15; cfi_adjust_cfa_offset (-16)
64#define POPARGS_5 POPARGS_4
65#define POPARGS_6 POPARGS_4
66
67#define ADJUSTCFI_1 cfi_adjust_cfa_offset (4); \
68 cfi_offset (r4, -4)
69#define ADJUSTCFI_2 cfi_adjust_cfa_offset (8); \
70 cfi_offset (r4, -4); \
71 cfi_offset (r5, -8)
72#define ADJUSTCFI_3 cfi_adjust_cfa_offset (12); \
73 cfi_offset (r4, -4); \
74 cfi_offset (r5, -8); \
75 cfi_offset (r6, -12)
76#define ADJUSTCFI_4 cfi_adjust_cfa_offset (16); \
77 cfi_offset (r4, -4); \
78 cfi_offset (r5, -8); \
79 cfi_offset (r6, -12); \
80 cfi_offset (r7, -16)
81#define ADJUSTCFI_5 ADJUSTCFI_4
82#define ADJUSTCFI_6 ADJUSTCFI_4
3846ef75
UD
83
84#ifndef NARGS
07bd2a3f
UD
85/* If we were called with no wrapper, this is really socket(). */
86#define NARGS 3
3846ef75
UD
87#endif
88
89.globl __socket
90ENTRY (__socket)
91 /* This will not work in the case of a socket call being interrupted
92 by a signal. If the signal handler uses any stack the arguments
93 to socket will be trashed. The results of a restart of any
07bd2a3f 94 socket call are then unpredictable. */
3846ef75
UD
95
96 /* Push args onto the stack. */
97 P(PUSHARGS_,NARGS)
98
bbd17455
UD
99#if defined NEED_CANCELLATION && defined CENABLE
100 SINGLE_THREAD_P
07bd2a3f 101 bf .Lsocket_cancel
bbd17455
UD
102#endif
103
104 /* Do the system call trap. */
3846ef75
UD
105 mov #+P(SOCKOP_,socket), r4
106 mov r15, r5
876f9634
UD
107 mov.l .L1,r3
108 trapa #0x12
3846ef75
UD
109
110 /* Pop args off the stack */
111 P(POPARGS_,NARGS)
112
113 mov r0, r1
114 mov #-12, r2
115 shad r2, r1
116 not r1, r1 // r1=0 means r0 = -1 to -4095
117 tst r1, r1 // i.e. error in linux
bbd17455
UD
118 bf .Lpseudo_end
119.Lsyscall_error:
120 SYSCALL_ERROR_HANDLER
121.Lpseudo_end:
3846ef75
UD
122 /* Successful; return the syscall's value. */
123 rts
124 nop
bbd17455
UD
125
126#if defined NEED_CANCELLATION && defined CENABLE
127.Lsocket_cancel:
128 /* Enable asynchronous cancellation. */
07bd2a3f 129 P(ADJUSTCFI_,NARGS)
4a17085f 130 sts.l pr,@-r15
07bd2a3f
UD
131 cfi_adjust_cfa_offset (4)
132 cfi_rel_offset (pr, 0)
bbd17455 133 CENABLE
4a17085f 134 lds.l @r15+,pr
07bd2a3f
UD
135 cfi_adjust_cfa_offset (-4)
136 cfi_restore (pr)
bbd17455
UD
137
138 /* Do the system call trap. */
139 mov #+P(SOCKOP_,socket), r4
140 mov r15, r5
141 mov.l .L1,r3
142 trapa #0x12
143
4a17085f 144 sts.l pr,@-r15
07bd2a3f
UD
145 cfi_adjust_cfa_offset (4)
146 cfi_rel_offset (pr, 0)
bbd17455 147 mov.l r0,@-r15
07bd2a3f
UD
148 cfi_adjust_cfa_offset (4)
149 cfi_rel_offset (r0, 0)
bbd17455
UD
150 CDISABLE
151 mov.l @r15+,r0
07bd2a3f
UD
152 cfi_adjust_cfa_offset (-4)
153 cfi_restore (r0)
4a17085f 154 lds.l @r15+,pr
07bd2a3f
UD
155 cfi_adjust_cfa_offset (-4)
156 cfi_restore (pr)
bbd17455
UD
157
158 /* Pop args off the stack */
159 P(POPARGS_,NARGS)
160
161 mov r0, r1
162 mov #-12, r2
163 shad r2, r1
164 not r1, r1 // r1=0 means r0 = -1 to -4095
165 tst r1, r1 // i.e. error in linux
166 bf .Lpseudo_end
167 bra .Lsyscall_error
168 nop
169#endif
07bd2a3f 170
3846ef75
UD
171 .align 2
172.L1:
173 .long SYS_ify(socketcall)
3846ef75
UD
174
175PSEUDO_END (__socket)
176
71b8b018 177#ifndef NO_WEAK_ALIAS
3846ef75 178weak_alias (__socket, socket)
71b8b018 179#endif