home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / LIBC / LIBC-4.6 / LIBC-4 / libc-linux / sysdeps / linux / i386 / sysdep.h < prev   
Encoding:
C/C++ Source or Header  |  1994-09-14  |  4.2 KB  |  158 lines

  1. /* Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
  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
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  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
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <sysdeps/linux/sysdep.h>
  20.  
  21. #if defined(__i486__) || defined(i486)
  22. #define ALIGN 4
  23. #else
  24. #define ALIGN 2
  25. #endif
  26.  
  27. #ifdef __ELF__
  28. #define SYMBOL_NAME(X) X
  29. #define SYMBOL_NAME_LABEL(X) X##:
  30. #else
  31. #define SYMBOL_NAME(X) _##X
  32. #define SYMBOL_NAME_LABEL(X) _##X##:
  33. #endif
  34.  
  35. #define ERRNO SYMBOL_NAME(errno)
  36.  
  37. #ifdef __ELF__
  38. #define    ENTRY(name)                                  \
  39.   .globl SYMBOL_NAME(name);                              \
  40.   .globl ERRNO;                                      \
  41.   .align ALIGN;                                      \
  42.   SYMBOL_NAME_LABEL(name)
  43. #else
  44. #define    ENTRY(name)                                  \
  45.   .globl _##name##;                                  \
  46.   .align ALIGN;                                      \
  47.   SYMBOL_NAME_LABEL(name)
  48. #endif
  49.  
  50. /* Use this for the different syntaxes for local assembler labels */
  51. #ifdef __ELF__
  52. #define L(X) .L##X
  53. #define LF(X) .L##X
  54. #define LL(X) .L##X##:
  55. #else
  56. #define L(X) X
  57. #define LF(X) X##f
  58. #define LL(X) X##:
  59. #endif
  60.  
  61. #if defined(__PIC__) || defined (__pic__)
  62. #define    PSEUDO(name, syscall_name, args)                      \
  63.   .text;                                      \
  64.   ENTRY (name)                                      \
  65.     pushl %ebp;                                      \
  66.     movl %esp,%ebp;                                  \
  67.     PUSH_##args                                      \
  68.     call L(L4);                                      \
  69.    LL(L4)                                      \
  70.     popl %ebx;                                      \
  71.     addl $_GLOBAL_OFFSET_TABLE_+[.-L(L4)],%ebx;                      \
  72.     pushl %ebx;                                      \
  73.     movl $SYS_##syscall_name, %eax;                          \
  74.     MOVE_##args                                      \
  75.     int $0x80;                                      \
  76.     popl %ebx;                                      \
  77.     movl %eax,%edx;                                  \
  78.     test %edx,%edx;                                  \
  79.     jge    L(Lexit);                                  \
  80.     negl %edx;                                      \
  81.     movl ERRNO@GOT(%ebx),%eax;                              \
  82.     movl %edx,(%eax);                                  \
  83.     movl $-1,%eax;                                  \
  84.    LL(Lexit)                                      \
  85.     POP_##args                                       \
  86.     movl %ebp,%esp;                                  \
  87.     popl %ebp;
  88.  
  89. #else
  90.  
  91. /* This is not ELF compatible, but it does not matter, since ELF is
  92.    always PIC */
  93. #define    PSEUDO(name, syscall_name, args)                      \
  94.   .text;                                      \
  95.   ENTRY (name)                                      \
  96.     pushl %ebp;                                      \
  97.     movl %esp,%ebp;                                  \
  98.     PUSH_##args                                      \
  99.     movl $(SYS_##syscall_name), %eax;                          \
  100.     MOVE_##args                                      \
  101.     int $0x80;                                      \
  102.     test %eax, %eax;                                  \
  103.     jge    Lexit;                                      \
  104.     negl %eax;                                      \
  105.     movl %eax,_errno;                                  \
  106.     movl $-1,%eax;                                  \
  107.    Lexit:                                      \
  108.     POP_##args                                      \
  109.     movl %ebp,%esp;                                  \
  110.     popl %ebp;
  111.  
  112. #endif
  113.  
  114. /* Linux takes system call arguments in registers:
  115.     0: %eax    This is the system call number.
  116.        1: %ebx This is the first argument.
  117.     2: %ecx
  118.     3: %edx
  119.     4: %esi
  120.     5: %edi
  121.  */
  122.  
  123. #if defined(__PIC__) || defined (__pic__)
  124. #define PUSH_0    pushl %ebx;
  125. #else
  126. #define PUSH_0    /* No arguments to push.  */
  127. #endif
  128. #define PUSH_1    pushl %ebx;
  129. #define PUSH_2    PUSH_1
  130. #define PUSH_3    PUSH_1
  131. #define PUSH_4    pushl %esi; PUSH_3
  132. #define PUSH_5    pushl %edi; PUSH_4
  133.  
  134. #define    MOVE_0    /* No arguments to move.  */
  135. #define    MOVE_1    movl 8(%ebp),%ebx;
  136. #define    MOVE_2    MOVE_1 movl 12(%ebp),%ecx;
  137. #define    MOVE_3    MOVE_2 movl 16(%ebp),%edx;
  138. #define    MOVE_4    MOVE_3 movl 20(%ebp),%esi;
  139. #define    MOVE_5    MOVE_4 movl 24(%ebp),%edi;
  140.  
  141. #if defined(__PIC__) || defined (__pic__)
  142. #define POP_0    popl %ebx;
  143. #else
  144. #define POP_0    /* No arguments to pop.  */
  145. #endif
  146. #define POP_1    popl %ebx;
  147. #define POP_2    POP_1
  148. #define POP_3    POP_1
  149. #define POP_4    POP_3 popl %esi;
  150. #define POP_5    POP_4 popl %edi;
  151.  
  152. /* Linux doesn't use it. */
  153. #if 0
  154. #define    r0    %eax
  155. #define    r1    %edx
  156. #define MOVE(x,y)    movl x , y
  157. #endif
  158.