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 / syscall.S.old < prev    next >
Encoding:
Text File  |  1994-08-20  |  2.8 KB  |  116 lines

  1. /* Copyright (C) 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. /* Linux takes system call arguments in registers:
  20.     0: %eax    This is the system call number.
  21.        1: %ebx This is the first argument.
  22.     2: %ecx
  23.     3: %edx
  24.     4: %esi
  25.     5: %edi
  26.  */
  27.  
  28. #define PUSH_0    /* No arguments to push.  */
  29. #define PUSH_1    pushl %ebx;
  30. #define PUSH_2    PUSH_1
  31. #define PUSH_3    PUSH_1
  32. #define PUSH_4    pushl %esi; PUSH_3
  33. #define PUSH_5    pushl %edi; PUSH_4
  34.  
  35. #if defined(__PIC__) || defined (__pic__)
  36. #define    MOVE_0    movl 8(%esp),%eax;
  37. #define    MOVE_1    movl 12(%esp),%eax; movl 16(%esp),%ebx;
  38. #define    MOVE_2    MOVE_1 movl 20(%esp),%ecx;
  39. #define    MOVE_3    MOVE_2 movl 24(%esp),%edx;
  40. #define    MOVE_4    movl 16(%esp),%eax; movl 20(%esp),%ebx; \
  41.             movl 24(%esp),%ecx; movl 28(%esp),%edx; \
  42.             movl 32(%esp),%esi;
  43. #define    MOVE_5    movl 20(%esp),%eax; movl 24(%esp),%ebx; \
  44.             movl 28(%esp),%ecx; movl 32(%esp),%edx; \
  45.             movl 36(%esp),%esi; movl 40(%esp),%edi;
  46.  
  47. #else
  48.  
  49. #define    MOVE_0    movl 4(%esp),%eax;
  50. #define    MOVE_1    movl 8(%esp),%eax; movl 12(%esp),%ebx;
  51. #define    MOVE_2    MOVE_1 movl 16(%esp),%ecx;
  52. #define    MOVE_3    MOVE_2 movl 20(%esp),%edx;
  53. #define    MOVE_4    movl 12(%esp),%eax; movl 16(%esp),%ebx; \
  54.             movl 20(%esp),%ecx; movl 24(%esp),%edx; \
  55.             movl 28(%esp),%esi;
  56. #define    MOVE_5    movl 16(%esp),%eax; movl 20(%esp),%ebx; \
  57.             movl 24(%esp),%ecx; movl 28(%esp),%edx; \
  58.             movl 32(%esp),%esi; movl 36(%esp),%edi;
  59.  
  60. #endif
  61.  
  62. #define POP_0    /* No arguments to pop.  */
  63. #define POP_1    popl %ebx;
  64. #define POP_2    POP_1
  65. #define POP_3    POP_1
  66. #define POP_4    POP_3 popl %esi;
  67. #define POP_5    POP_4 popl %edi;
  68.  
  69.     .text
  70.  
  71. #ifdef __ELF__
  72. #define _syscall syscall
  73. #endif
  74.  
  75. #if defined(__i486__) || defined(i486)
  76.     .align    4
  77. #else
  78.     .align    2
  79. #endif
  80.     .globl _syscall
  81. _syscall:
  82.     PUSH_5
  83. #if defined(__PIC__) || defined (__pic__)
  84.     call    L4
  85. L4:
  86.     popl    %ebx
  87.     addl    $_GLOBAL_OFFSET_TABLE_+[.-L4],%ebx
  88.     pushl    %ebx
  89.     MOVE_5
  90.     int    $0x80
  91.     popl    %ebx
  92.     movl    %eax,%edx
  93.     test    %edx,%edx
  94.     jge    Lexit
  95.     negl    %edx
  96.     movl    _errno@GOT(%ebx),%eax
  97.     movl    %edx,(%eax)
  98.     movl    $-1,%eax
  99. #else
  100.     MOVE_5
  101.     int    $0x80
  102.     test    %eax,%eax
  103.     jge    Lexit
  104.     negl    %eax
  105.     movl    %eax,_errno
  106.     movl    $-1,%eax
  107. #endif
  108.  
  109. Lexit:
  110.     POP_5
  111.     ret
  112.  
  113. #ifdef __ELF__
  114. .type syscall,@function
  115. #endif
  116.