Mon Mar 25 03:35:16 1996 Roland McGrath <roland@charlie-brown.gnu.ai.mit.edu>
[platform/upstream/glibc.git] / sysdeps / unix / sysv / linux / m68k / sysdep.h
1 /* Copyright (C) 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Written by Andreas Schwab, <schwab@issan.informatik.uni-dortmund.de>,
4 December 1995.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB.  If
18 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 Cambridge, MA 02139, USA.  */
20
21 #include <sysdeps/unix/sysdep.h>
22
23 /* For Linux we can use the system call table in the header file
24         /usr/include/asm/unistd.h
25    of the kernel.  But these symbols do not follow the SYS_* syntax
26    so we have to redefine the `SYS_ify' macro here.  */
27 #undef SYS_ify
28 #ifdef __STDC__
29 # define SYS_ify(syscall_name)  __NR_##syscall_name
30 #else
31 # define SYS_ify(syscall_name)  __NR_/**/syscall_name
32 #endif
33
34 #ifdef ASSEMBLER
35
36 #define POUND #
37
38 /* Define an entry point visible from C.  */
39 #define ENTRY(name)                                                           \
40   .globl name;                                                                \
41   .type name, @function;                                                      \
42   .align 4;                                                                   \
43   C_LABEL(name)                                                               \
44   CALL_MCOUNT
45
46 /* If compiled for profiling, call `_mcount' at the start of each function.  */
47 #ifdef  PROF
48 /* The mcount code relies on a normal frame pointer being on the stack
49    to locate our caller, so push one just for its benefit.  */
50 #define CALL_MCOUNT \
51   move.l %fp, -(%sp); move.l %sp, %fp;                                        \
52   jbsr JUMPTARGET (_mcount);                                                  \
53   move.l (%sp)+, %fp;
54 #else
55 #define CALL_MCOUNT             /* Do nothing.  */
56 #endif
57
58 #ifdef PIC
59 #define JUMPTARGET(name)        name##@PLTPC
60 #else
61 #define JUMPTARGET(name)        name
62 #endif
63
64 /* Since C identifiers are not normally prefixed with an underscore
65    on this system, the asm identifier `syscall_error' intrudes on the
66    C name space.  Make sure we use an innocuous name.  */
67 #define syscall_error   __syscall_error
68
69 /* Linux uses a negative return value to indicate syscall errors, unlike
70    most Unices, which use the condition codes' carry flag.  */
71 #define PSEUDO(name, syscall_name, args)                                      \
72   .text;                                                                      \
73   SYSCALL_ERROR_HANDLER                                                       \
74   ENTRY (name)                                                                \
75     DO_CALL (POUND SYS_ify (syscall_name), args);                             \
76     tst.l %d0;                                                                \
77     jmi syscall_error;
78
79 #ifdef PIC
80 /* Store (- %d0) into errno through the GOT.  */
81 #define SYSCALL_ERROR_HANDLER                                                 \
82 syscall_error:                                                                \
83     move.l (errno@GOTPC, %pc), %a0;                                           \
84     neg.l %d0;                                                                \
85     move.l %d0, (%a0);                                                        \
86     move.l POUND -1, %d0;                                                     \
87     /* Copy return value to %a0 for syscalls that are declared to return      \
88        a pointer (e.g., mmap).  */                                            \
89     move.l %d0, %a0;                                                          \
90     rts;
91 #else
92 #define SYSCALL_ERROR_HANDLER   /* Nothing here; code in sysdep.S is used.  */
93 #endif
94
95 /* Linux takes system call arguments in registers:
96
97         syscall number  %d0          call-clobbered
98         arg 1           %d1          call-clobbered
99         arg 2           %d2          call-saved
100         arg 3           %d3          call-saved
101         arg 4           %d4          call-saved
102         arg 5           %d5          call-saved
103
104    The stack layout upon entering the function is:
105
106         20(%sp)         Arg# 5
107         16(%sp)         Arg# 4
108         12(%sp)         Arg# 3
109          8(%sp)         Arg# 2
110          4(%sp)         Arg# 1
111           (%sp)         Return address
112
113    (Of course a function with say 3 arguments does not have entries for
114    arguments 4 and 5.)
115
116    Separate move's are faster than movem, but need more space.  Since
117    speed is more important, we don't use movem.  Since %a0 and %a1 are
118    scratch registers, we can use them for saving as well.  */
119
120 #define DO_CALL(syscall, args)                                                \
121     move.l syscall, %d0;                                                      \
122     DOARGS_##args                                                             \
123     trap POUND 0;                                                             \
124     UNDOARGS_##args
125
126 #define DOARGS_0        /* No arguments to frob.  */
127 #define UNDOARGS_0      /* No arguments to unfrob.  */
128 #define _DOARGS_0(n)    /* No arguments to frob.  */
129
130 #define DOARGS_1        _DOARGS_1 (4)
131 #define _DOARGS_1(n)    move.l n(%sp), %d1; _DOARGS_0 (n)
132 #define UNDOARGS_1      UNDOARGS_0
133
134 #define DOARGS_2        _DOARGS_2 (8)
135 #define _DOARGS_2(n)    move.l %d2, %a0; move.l n(%sp), %d2; _DOARGS_1 (n-4)
136 #define UNDOARGS_2      UNDOARGS_1; move.l %a0, %d2
137
138 #define DOARGS_3        _DOARGS_3 (12)
139 #define _DOARGS_3(n)    move.l %d3, %a1; move.l n(%sp), %d3; _DOARGS_2 (n-4)
140 #define UNDOARGS_3      UNDOARGS_2; move.l %a1, %d3
141
142 #define DOARGS_4        _DOARGS_4 (16)
143 #define _DOARGS_4(n)    move.l %d4, -(%sp); move.l n+4(%sp), %d4; _DOARGS_3 (n)
144 #define UNDOARGS_4      UNDOARGS_3; move.l (%sp)+, %d4
145
146 #define DOARGS_5        _DOARGS_5 (20)
147 #define _DOARGS_5(n)    move.l %d5, -(%sp); move.l n+4(%sp), %d5; _DOARGS_4 (n)
148 #define UNDOARGS_5      UNDOARGS_4; move.l (%sp)+, %d5
149
150
151 #define ret     rts
152 #if 0 /* Not used by Linux */
153 #define r0      %d0
154 #define r1      %d1
155 #define MOVE(x,y)       movel x , y
156 #endif
157
158 #endif  /* ASSEMBLER */