OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [sys/] [linux/] [linuxthreads/] [machine/] [i386/] [sysdep.h] - Blame information for rev 262

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/* Copyright (C) 1992, 93, 95, 96, 97, 98, 99, 00 Free Software Foundation, Inc.
2
   This file is part of the GNU C Library.
3
   Contributed by Ulrich Drepper, <drepper@gnu.org>, August 1995.
4
 
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.
9
 
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.
14
 
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.  */
19
 
20
#ifndef _LINUX_I386_SYSDEP_H
21
#define _LINUX_I386_SYSDEP_H 1
22
 
23
#include "i386-sysdep.h"
24
 
25
/* For Linux we can use the system call table in the header file
26
        /usr/include/asm/unistd.h
27
   of the kernel.  But these symbols do not follow the SYS_* syntax
28
   so we have to redefine the `SYS_ify' macro here.  */
29
#undef SYS_ify
30
#define SYS_ify(syscall_name)   __NR_##syscall_name
31
 
32
/* ELF-like local names start with `.L'.  */
33
#undef L
34
#define L(name) .L##name
35
 
36
#ifdef __ASSEMBLER__
37
 
38
/* Linux uses a negative return value to indicate syscall errors,
39
   unlike most Unices, which use the condition codes' carry flag.
40
 
41
   Since version 2.1 the return value of a system call might be
42
   negative even if the call succeeded.  E.g., the `lseek' system call
43
   might return a large offset.  Therefore we must not anymore test
44
   for < 0, but test for a real error by making sure the value in %eax
45
   is a real error number.  Linus said he will make sure the no syscall
46
   returns a value in -1 .. -4095 as a valid result so we can savely
47
   test with -4095.  */
48
 
49
/* We don't want the label for the error handle to be global when we define
50
   it here.  */
51
#ifdef PIC
52
# define SYSCALL_ERROR_LABEL 0f
53
#else
54
# define SYSCALL_ERROR_LABEL syscall_error
55
#endif
56
 
57
#undef  PSEUDO
58
#define PSEUDO(name, syscall_name, args)                                      \
59
  .text;                                                                      \
60
  ENTRY (name)                                                                \
61
    DO_CALL (args, syscall_name);                                             \
62
    cmpl $-4095, %eax;                                                        \
63
    jae SYSCALL_ERROR_LABEL;                                                  \
64
  L(pseudo_end):
65
 
66
#undef  PSEUDO_END
67
#define PSEUDO_END(name)                                                      \
68
  SYSCALL_ERROR_HANDLER                                                       \
69
  END (name)
70
 
71
#ifndef PIC
72
#define SYSCALL_ERROR_HANDLER   /* Nothing here; code in sysdep.S is used.  */
73
#else
74
/* Store (- %eax) into errno through the GOT.  */
75
#ifdef _LIBC_REENTRANT
76
#define SYSCALL_ERROR_HANDLER                                                 \
77
0:pushl %ebx;                                                                  \
78
  call 1f;                                                                    \
79
1:popl %ebx;                                                                  \
80
  xorl %edx, %edx;                                                            \
81
  addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx;                                   \
82
  subl %eax, %edx;                                                            \
83
  pushl %edx;                                                                 \
84
  PUSH_ERRNO_LOCATION_RETURN;                                                 \
85
  call BP_SYM (__errno_location)@PLT;                                         \
86
  POP_ERRNO_LOCATION_RETURN;                                                  \
87
  popl %ecx;                                                                  \
88
  popl %ebx;                                                                  \
89
  movl %ecx, (%eax);                                                          \
90
  orl $-1, %eax;                                                              \
91
  jmp L(pseudo_end);
92
/* A quick note: it is assumed that the call to `__errno_location' does
93
   not modify the stack!  */
94
#else
95
#define SYSCALL_ERROR_HANDLER                                                 \
96
0:call 1f;                                                                     \
97
1:popl %ecx;                                                                  \
98
  xorl %edx, %edx;                                                            \
99
  addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ecx;                                   \
100
  subl %eax, %edx;                                                            \
101
  movl errno@GOT(%ecx), %ecx;                                                 \
102
  movl %edx, (%ecx);                                                          \
103
  orl $-1, %eax;                                                              \
104
  jmp L(pseudo_end);
105
#endif  /* _LIBC_REENTRANT */
106
#endif  /* PIC */
107
 
108
/* Linux takes system call arguments in registers:
109
 
110
        syscall number  %eax         call-clobbered
111
        arg 1           %ebx         call-saved
112
        arg 2           %ecx         call-clobbered
113
        arg 3           %edx         call-clobbered
114
        arg 4           %esi         call-saved
115
        arg 5           %edi         call-saved
116
 
117
   The stack layout upon entering the function is:
118
 
119
        20(%esp)        Arg# 5
120
        16(%esp)        Arg# 4
121
        12(%esp)        Arg# 3
122
         8(%esp)        Arg# 2
123
         4(%esp)        Arg# 1
124
          (%esp)        Return address
125
 
126
   (Of course a function with say 3 arguments does not have entries for
127
   arguments 4 and 5.)
128
 
129
   The following code tries hard to be optimal.  A general assumption
130
   (which is true according to the data books I have) is that
131
 
132
        2 * xchg        is more expensive than  pushl + movl + popl
133
 
134
   Beside this a neat trick is used.  The calling conventions for Linux
135
   tell that among the registers used for parameters %ecx and %edx need
136
   not be saved.  Beside this we may clobber this registers even when
137
   they are not used for parameter passing.
138
 
139
   As a result one can see below that we save the content of the %ebx
140
   register in the %edx register when we have less than 3 arguments
141
   (2 * movl is less expensive than pushl + popl).
142
 
143
   Second unlike for the other registers we don't save the content of
144
   %ecx and %edx when we have more than 1 and 2 registers resp.
145
 
146
   The code below might look a bit long but we have to take care for
147
   the pipelined processors (i586).  Here the `pushl' and `popl'
148
   instructions are marked as NP (not pairable) but the exception is
149
   two consecutive of these instruction.  This gives no penalty on
150
   other processors though.  */
151
 
152
#undef  DO_CALL
153
#define DO_CALL(args, syscall_name)                                           \
154
    PUSHARGS_##args                                                           \
155
    DOARGS_##args                                                             \
156
    movl $SYS_ify (syscall_name), %eax;                                       \
157
    int $0x80                                                                 \
158
    POPARGS_##args
159
 
160
#define PUSHARGS_0      /* No arguments to push.  */
161
#define DOARGS_0        /* No arguments to frob.  */
162
#define POPARGS_0       /* No arguments to pop.  */
163
#define _PUSHARGS_0     /* No arguments to push.  */
164
#define _DOARGS_0(n)    /* No arguments to frob.  */
165
#define _POPARGS_0      /* No arguments to pop.  */
166
 
167
#define PUSHARGS_1      movl %ebx, %edx; PUSHARGS_0
168
#define DOARGS_1        _DOARGS_1 (4)
169
#define POPARGS_1       POPARGS_0; movl %edx, %ebx
170
#define _PUSHARGS_1     pushl %ebx; _PUSHARGS_0
171
#define _DOARGS_1(n)    movl n(%esp), %ebx; _DOARGS_0(n-4)
172
#define _POPARGS_1      _POPARGS_0; popl %ebx
173
 
174
#define PUSHARGS_2      PUSHARGS_1
175
#define DOARGS_2        _DOARGS_2 (8)
176
#define POPARGS_2       POPARGS_1
177
#define _PUSHARGS_2     _PUSHARGS_1
178
#define _DOARGS_2(n)    movl n(%esp), %ecx; _DOARGS_1 (n-4)
179
#define _POPARGS_2      _POPARGS_1
180
 
181
#define PUSHARGS_3      _PUSHARGS_2
182
#define DOARGS_3        _DOARGS_3 (16)
183
#define POPARGS_3       _POPARGS_3
184
#define _PUSHARGS_3     _PUSHARGS_2
185
#define _DOARGS_3(n)    movl n(%esp), %edx; _DOARGS_2 (n-4)
186
#define _POPARGS_3      _POPARGS_2
187
 
188
#define PUSHARGS_4      _PUSHARGS_4
189
#define DOARGS_4        _DOARGS_4 (24)
190
#define POPARGS_4       _POPARGS_4
191
#define _PUSHARGS_4     pushl %esi; _PUSHARGS_3
192
#define _DOARGS_4(n)    movl n(%esp), %esi; _DOARGS_3 (n-4)
193
#define _POPARGS_4      _POPARGS_3; popl %esi
194
 
195
#define PUSHARGS_5      _PUSHARGS_5
196
#define DOARGS_5        _DOARGS_5 (32)
197
#define POPARGS_5       _POPARGS_5
198
#define _PUSHARGS_5     pushl %edi; _PUSHARGS_4
199
#define _DOARGS_5(n)    movl n(%esp), %edi; _DOARGS_4 (n-4)
200
#define _POPARGS_5      _POPARGS_4; popl %edi
201
 
202
#else   /* !__ASSEMBLER__ */
203
 
204
/* We need some help from the assembler to generate optimal code.  We
205
   define some macros here which later will be used.  */
206
asm (".L__X'%ebx = 1\n\t"
207
     ".L__X'%ecx = 2\n\t"
208
     ".L__X'%edx = 2\n\t"
209
     ".L__X'%eax = 3\n\t"
210
     ".L__X'%esi = 3\n\t"
211
     ".L__X'%edi = 3\n\t"
212
     ".L__X'%ebp = 3\n\t"
213
     ".L__X'%esp = 3\n\t"
214
     ".macro bpushl name reg\n\t"
215
     ".if 1 - \\name\n\t"
216
     ".if 2 - \\name\n\t"
217
     "pushl %ebx\n\t"
218
     ".else\n\t"
219
     "xchgl \\reg, %ebx\n\t"
220
     ".endif\n\t"
221
     ".endif\n\t"
222
     ".endm\n\t"
223
     ".macro bpopl name reg\n\t"
224
     ".if 1 - \\name\n\t"
225
     ".if 2 - \\name\n\t"
226
     "popl %ebx\n\t"
227
     ".else\n\t"
228
     "xchgl \\reg, %ebx\n\t"
229
     ".endif\n\t"
230
     ".endif\n\t"
231
     ".endm\n\t"
232
     ".macro bmovl name reg\n\t"
233
     ".if 1 - \\name\n\t"
234
     ".if 2 - \\name\n\t"
235
     "movl \\reg, %ebx\n\t"
236
     ".endif\n\t"
237
     ".endif\n\t"
238
     ".endm\n\t");
239
 
240
/* Define a macro which expands inline into the wrapper code for a system
241
   call.  */
242
#undef INLINE_SYSCALL
243
#define INLINE_SYSCALL(name, nr, args...) \
244
  ({                                                                          \
245
    unsigned int resultvar;                                                   \
246
    asm volatile (                                                            \
247
    LOADARGS_##nr                                                             \
248
    "movl %1, %%eax\n\t"                                                      \
249
    "int $0x80\n\t"                                                           \
250
    RESTOREARGS_##nr                                                          \
251
    : "=a" (resultvar)                                                        \
252
    : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc");                  \
253
    if (resultvar >= 0xfffff001)                                              \
254
      {                                                                       \
255
        __set_errno (-resultvar);                                             \
256
        resultvar = 0xffffffff;                                               \
257
      }                                                                       \
258
    (int) resultvar; })
259
 
260
#define LOADARGS_0
261
#define LOADARGS_1 \
262
    "bpushl .L__X'%k2, %k2\n\t"                                               \
263
    "bmovl .L__X'%k2, %k2\n\t"
264
#define LOADARGS_2      LOADARGS_1
265
#define LOADARGS_3      LOADARGS_1
266
#define LOADARGS_4      LOADARGS_1
267
#define LOADARGS_5      LOADARGS_1
268
 
269
#define RESTOREARGS_0
270
#define RESTOREARGS_1 \
271
    "bpopl .L__X'%k2, %k2\n\t"
272
#define RESTOREARGS_2   RESTOREARGS_1
273
#define RESTOREARGS_3   RESTOREARGS_1
274
#define RESTOREARGS_4   RESTOREARGS_1
275
#define RESTOREARGS_5   RESTOREARGS_1
276
 
277
#define ASMFMT_0()
278
#define ASMFMT_1(arg1) \
279
        , "acdSD" (arg1)
280
#define ASMFMT_2(arg1, arg2) \
281
        , "adCD" (arg1), "c" (arg2)
282
#define ASMFMT_3(arg1, arg2, arg3) \
283
        , "aCD" (arg1), "c" (arg2), "d" (arg3)
284
#define ASMFMT_4(arg1, arg2, arg3, arg4) \
285
        , "aD" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
286
#define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
287
        , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
288
 
289
#endif  /* __ASSEMBLER__ */
290
 
291
#endif /* linux/i386/sysdep.h */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.