2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-64 / socket.S
blob91c2a8031e24ec73a028845199892ea0e482fda9
1 /* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
2    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library 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 GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep-cancel.h>
21 #include <socketcall.h>
23 /* &%/$&!! preprocessor */
24 #define P(a, b) P2(a, b)
25 #define P2(a, b) a##b
27         .text
28 /* The socket-oriented system calls are handled unusally in Linux.
29    They are all gated through the single `socketcall' system call number.
30    `socketcall' takes two arguments: the first is the subcode, specifying
31    which socket function is being called; and the second is a pointer to
32    the arguments to the specific function.
34    The .S files for the other calls just #define socket and #include this.  */
36 #ifndef __socket
37 #ifndef NO_WEAK_ALIAS
38 #define __socket P(__,socket)
39 #else
40 #define __socket socket
41 #endif
42 #endif
44 #ifndef NARGS      /* The socket.o object is compiled directly ... */
45 #define NARGS 3
46 #endif
48 .globl __socket
49 ENTRY(__socket)
50         /* Save registers and setup stack.  */
51         stmg    %r6,%r15,48(%r15)       /* Save registers.  */
52         cfi_offset (%r15,-40)
53         cfi_offset (%r14,-48)
54         cfi_offset (%r13,-56)
55         cfi_offset (%r12,-64)
56         cfi_offset (%r11,-72)
57         cfi_offset (%r10,-80)
58         cfi_offset (%r9,-88)
59         cfi_offset (%r8,-96)
60         cfi_offset (%r7,-104)
61         cfi_offset (%r6,-112)
62         lgr     %r1,%r15
63         lg      %r0,8(%r15)             /* Load eos.  */
64         aghi     %r15,-208              /* Buy stack space.  */
65         cfi_adjust_cfa_offset (208)
66         stg     %r1,0(%r15)             /* Store back chain.  */
67         stg     %r0,8(%r15)             /* Store eos.  */
69         /* Reorder arguments.  */
70 #if (NARGS >= 6)
71         mvc     200(8,%r15),368(%r15)   /* Move between parameter lists.  */
72 #endif
73 #if (NARGS >= 5)
74         stg     %r6,192(%r15)           /* Store into parameter list.  */
75 #endif
76 #if (NARGS >= 4)
77         stg     %r5,184(%r15)            /* Store into parameter list.  */
78 #endif
79 #if (NARGS >= 3)
80         stg     %r4,176(%r15)            /* Store into parameter list.  */
81 #endif
82 #if (NARGS >= 2)
83         stg     %r3,168(%r15)           /* Store into parameter list.  */
84         stg     %r2,160(%r15)
85 #endif
87 #if defined NEED_CANCELLATION && defined CENABLE
88         SINGLE_THREAD_P
89         jne     L(socket_cancel)
90 #endif
92         /* Load subcode for socket syscall.  */
93         lghi    %r2,P(SOCKOP_,socket)
94         la      %r3,160(%r15)           /* Load address of parameter list.  */
96         /* Do the system call trap.  */
97         svc     SYS_ify(socketcall)
100         lg      %r15,0(%r15)            /* Load back chain.  */
101         lmg     %r6,15,48(%r15)         /* Load registers.  */
103         /* gpr2 is < 0 if there was an error.  */
104         lghi    %r0,-125 
105         clgr    %r2,%r0
106         jgnl    SYSCALL_ERROR_LABEL
108         /* Successful; return the syscall's value.  */
109         br      %r14
111 #if defined NEED_CANCELLATION && defined CENABLE
112 L(socket_cancel):
113         brasl   %r14,CENABLE
114         lr      %r0,%r2
116         /* Load subcode for socket syscall.  */
117         lghi    %r2,P(SOCKOP_,socket)
118         la      %r3,160(%r15)           /* Load address of parameter list.  */
120         /* Do the system call trap.  */
121         svc     SYS_ify(socketcall)
123         lgr     %r12,%r2
124         lr      %r2,%r0
125         brasl   %r14,CDISABLE
127         lgr     %r2,%r12
128         j       4b
129 #endif
131         SYSCALL_ERROR_HANDLER
132 END (__socket)
134 #ifndef NO_WEAK_ALIAS
135 weak_alias (__socket, socket)
136 #endif