Update.
[glibc.git] / sysdeps / unix / sysv / linux / sh / socket.S
blobac732a2f44c5867b3761caa42884099dc9a00fa0
1 /* Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
4    The GNU C Library is free software; you can redistribute it and/or
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.
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
12    Lesser General Public License for more details.
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
19 #include <sysdep-cancel.h>
20 #include <socketcall.h>
21 #include <tls.h>
23 #define P(a, b) P2(a, b)
24 #define P2(a, b) a##b
26         .text
27 /* The socket-oriented system calls are handled unusally in Linux.
28    They are all gated through the single `socketcall' system call number.
29    `socketcall' takes two arguments: the first is the subcode, specifying
30    which socket function is being called; and the second is a pointer to
31    the arguments to the specific function.
33    The .S files for the other calls just #define socket and #include this.  */
35 #ifndef __socket
36 #define __socket P(__,socket)
37 #endif
39 #define PUSHARGS_1      mov.l r4,@-r15
40 #define PUSHARGS_2      mov.l r5,@-r15; PUSHARGS_1
41 #define PUSHARGS_3      mov.l r6,@-r15; PUSHARGS_2
42 #define PUSHARGS_4      mov.l r7,@-r15; PUSHARGS_3
43 #define PUSHARGS_5      PUSHARGS_4      /* Caller has already pushed arg 5 */
44 #define PUSHARGS_6      PUSHARGS_4      /* Caller has already pushed arg 5,6 */
46 #define POPARGS_1       add #4,r15
47 #define POPARGS_2       add #8,r15
48 #define POPARGS_3       add #12,r15
49 #define POPARGS_4       add #16,r15
50 #define POPARGS_5       add #16,r15
51 #define POPARGS_6       add #16,r15 
53 #ifndef NARGS
54 #define NARGS 3                 /* If we were called with no wrapper, this is really socket() */
55 #endif
57 .globl __socket
58 ENTRY (__socket)
59         /* This will not work in the case of a socket call being interrupted
60            by a signal.  If the signal handler uses any stack the arguments
61            to socket will be trashed.  The results of a restart of any
62            socket call are then unpredictable. */
64         /* Push args onto the stack.  */
65         P(PUSHARGS_,NARGS)
67 #if defined NEED_CANCELLATION && defined CENABLE
68         SINGLE_THREAD_P
69         bf .Lsocket_cancel      
70 #endif
72         /* Do the system call trap.  */
73         mov #+P(SOCKOP_,socket), r4
74         mov r15, r5
75         mov.l .L1,r3
76         trapa #0x12
78         /* Pop args off the stack */
79         P(POPARGS_,NARGS)
81         mov     r0, r1
82         mov     #-12, r2
83         shad    r2, r1
84         not     r1, r1                  // r1=0 means r0 = -1 to -4095
85         tst     r1, r1                  // i.e. error in linux
86         bf      .Lpseudo_end
87 .Lsyscall_error:
88         SYSCALL_ERROR_HANDLER
89 .Lpseudo_end:
90         /* Successful; return the syscall's value.  */
91         rts
92          nop
94 #if defined NEED_CANCELLATION && defined CENABLE
95 .Lsocket_cancel:
96         /* Enable asynchronous cancellation.  */
97         sts.l pr,@-r15
98         CENABLE
99         lds.l @r15+,pr
101         /* Do the system call trap.  */
102         mov #+P(SOCKOP_,socket), r4
103         mov r15, r5
104         mov.l .L1,r3
105         trapa #0x12
107         sts.l pr,@-r15
108         mov.l r0,@-r15
109         CDISABLE
110         mov.l @r15+,r0
111         lds.l @r15+,pr
113         /* Pop args off the stack */
114         P(POPARGS_,NARGS)
116         mov     r0, r1
117         mov     #-12, r2
118         shad    r2, r1
119         not     r1, r1                  // r1=0 means r0 = -1 to -4095
120         tst     r1, r1                  // i.e. error in linux
121         bf      .Lpseudo_end
122         bra     .Lsyscall_error
123          nop
124 #endif
125         .align 2
126 .L1:
127         .long   SYS_ify(socketcall)
129 PSEUDO_END (__socket)
131 weak_alias (__socket, socket)